Re: [RFC PATCH 5/5] target/arm/cpu: Add the kvm-adjvtime CPU property

2019-10-09 Thread Richard Henderson
On 10/7/19 1:06 PM, Andrew Jones wrote:
> kvm-adjvtime is a KVM specific CPU property and a first of its kind.
> To accommodate it we also add kvm_arm_add_vcpu_properties() and a
> KVM specific CPU properties description to the CPU features document.
> 
> Signed-off-by: Andrew Jones 
> ---

Reviewed-by: Richard Henderson 


r~



[RFC PATCH 5/5] target/arm/cpu: Add the kvm-adjvtime CPU property

2019-10-07 Thread Andrew Jones
kvm-adjvtime is a KVM specific CPU property and a first of its kind.
To accommodate it we also add kvm_arm_add_vcpu_properties() and a
KVM specific CPU properties description to the CPU features document.

Signed-off-by: Andrew Jones 
---
 docs/arm-cpu-features.rst | 27 ++-
 target/arm/cpu.c  |  2 ++
 target/arm/cpu64.c|  1 +
 target/arm/kvm.c  | 27 +++
 target/arm/kvm_arm.h  | 11 +++
 target/arm/monitor.c  |  1 +
 tests/arm-cpu-features.c  |  4 
 7 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/docs/arm-cpu-features.rst b/docs/arm-cpu-features.rst
index 1b367e22e16e..5c317296845f 100644
--- a/docs/arm-cpu-features.rst
+++ b/docs/arm-cpu-features.rst
@@ -31,7 +31,9 @@ supporting the feature or only supporting the feature under 
certain
 configurations.  For example, the `aarch64` CPU feature, which, when
 disabled, enables the optional AArch32 CPU feature, is only supported
 when using the KVM accelerator and when running on a host CPU type that
-supports the feature.
+supports the feature.  While `aarch64` currently only works with KVM,
+it could work with TCG.  CPU features that are specific to KVM are
+prefixed with "kvm-" and are described in "KVM VCPU Features".
 
 CPU Feature Probing
 ===
@@ -171,6 +173,29 @@ disabling many SVE vector lengths would be quite verbose, 
the `sve` CPU
 properties have special semantics (see "SVE CPU Property Parsing
 Semantics").
 
+KVM VCPU Features
+=
+
+KVM VCPU features are CPU features that are specific to KVM, such as
+paravirt features or features that enable CPU virtualization extensions.
+The features' CPU properties are only available when KVM is enabled and are
+named with the prefix "kvm-".  KVM VCPU features may be probed, enabled, and
+disabled in the same way as other CPU features.  Below is the list of KVM
+VCPU features and their descriptions.
+
+  kvm-adjvtime When enabled, each time the VM transitions back
+   to running state the VCPU's vitual counter is
+   updated to ensure stopped time is not counted.
+   This avoids time jumps surprising guest OSes and
+   applications, as long as they use the virtual
+   counter for timekeeping, but has the side effect
+   of the virtual and physical counters diverging.
+   All timekeeping based on the virtual counter will
+   appear to lag behind any timekeeping that does
+   not subtract VM stopped time.  The guest may
+   resynchronize its virtual counter with other time
+   sources as needed.
+
 SVE CPU Properties
 ==
 
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 7695ae551218..d8ad26438f9f 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2483,6 +2483,7 @@ static void arm_max_initfn(Object *obj)
 
 if (kvm_enabled()) {
 kvm_arm_set_cpu_features_from_host(cpu);
+kvm_arm_add_vcpu_properties(obj);
 } else {
 cortex_a15_initfn(obj);
 
@@ -2674,6 +2675,7 @@ static void arm_host_initfn(Object *obj)
 if (arm_feature(>env, ARM_FEATURE_AARCH64)) {
 aarch64_add_sve_properties(obj);
 }
+kvm_arm_add_vcpu_properties(obj);
 arm_cpu_post_init(obj);
 }
 
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 68baf0482ffa..c9a657a178ce 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -620,6 +620,7 @@ static void aarch64_max_initfn(Object *obj)
 
 if (kvm_enabled()) {
 kvm_arm_set_cpu_features_from_host(cpu);
+kvm_arm_add_vcpu_properties(obj);
 } else {
 uint64_t t;
 uint32_t u;
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index f79b9b8ef57a..1652e3febe51 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -17,6 +17,8 @@
 #include "qemu/timer.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "qom/object.h"
+#include "qapi/error.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
 #include "sysemu/kvm_int.h"
@@ -179,6 +181,31 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
 env->features = arm_host_cpu_features.features;
 }
 
+static bool kvm_adjvtime_get(Object *obj, Error **errp)
+{
+return ARM_CPU(obj)->kvm_adjvtime;
+}
+
+static void kvm_adjvtime_set(Object *obj, bool value, Error **errp)
+{
+ARM_CPU(obj)->kvm_adjvtime = value;
+}
+
+/* KVM VCPU properties should be prefixed with "kvm-". */
+void kvm_arm_add_vcpu_properties(Object *obj)
+{
+if (!kvm_enabled()) {
+return;
+}
+
+object_property_add_bool(obj, "kvm-adjvtime", kvm_adjvtime_get,
+ kvm_adjvtime_set, _abort);
+object_property_set_description(obj, "kvm-adjvtime",
+"Set on to