Blame SOURCES/kvm-target-arm-cpu-Add-the-kvm-no-adjvtime-CPU-property.patch

22c213
From 730f72105b478553c4f22555c29b0f64224ff914 Mon Sep 17 00:00:00 2001
22c213
From: Andrew Jones <drjones@redhat.com>
22c213
Date: Fri, 31 Jan 2020 14:23:14 +0000
22c213
Subject: [PATCH 12/15] target/arm/cpu: Add the kvm-no-adjvtime CPU property
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Andrew Jones <drjones@redhat.com>
22c213
Message-id: <20200131142314.13175-6-drjones@redhat.com>
22c213
Patchwork-id: 93623
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 5/5] target/arm/cpu: Add the kvm-no-adjvtime CPU property
22c213
Bugzilla: 1647366
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
22c213
RH-Acked-by: Gavin Shan <gshan@redhat.com>
22c213
22c213
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1647366
22c213
22c213
Author: Andrew Jones <drjones@redhat.com>
22c213
Date:   Thu, 30 Jan 2020 16:02:06 +0000
22c213
22c213
    target/arm/cpu: Add the kvm-no-adjvtime CPU property
22c213
22c213
    kvm-no-adjvtime is a KVM specific CPU property and a first of its
22c213
    kind. To accommodate it we also add kvm_arm_add_vcpu_properties()
22c213
    and a KVM specific CPU properties description to the CPU features
22c213
    document.
22c213
22c213
    Signed-off-by: Andrew Jones <drjones@redhat.com>
22c213
    Message-id: 20200120101023.16030-7-drjones@redhat.com
22c213
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
22c213
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22c213
22c213
(cherry picked from commit dea101a1ae9968c9fec6ab0291489dad7c49f36f)
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
22c213
Conflicts:
22c213
	Dropped the second hunk of the hw/arm/virt.c changes
22c213
        as they would patch dead code.
22c213
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 docs/arm-cpu-features.rst | 37 ++++++++++++++++++++++++++++++++++++-
22c213
 hw/arm/virt.c             |  5 +++++
22c213
 include/hw/arm/virt.h     |  1 +
22c213
 target/arm/cpu.c          |  2 ++
22c213
 target/arm/cpu64.c        |  1 +
22c213
 target/arm/kvm.c          | 28 ++++++++++++++++++++++++++++
22c213
 target/arm/kvm_arm.h      | 11 +++++++++++
22c213
 target/arm/monitor.c      |  1 +
22c213
 tests/arm-cpu-features.c  |  4 ++++
22c213
 9 files changed, 89 insertions(+), 1 deletion(-)
22c213
22c213
diff --git a/docs/arm-cpu-features.rst b/docs/arm-cpu-features.rst
22c213
index 1b367e2..45d1eb6 100644
22c213
--- a/docs/arm-cpu-features.rst
22c213
+++ b/docs/arm-cpu-features.rst
22c213
@@ -31,7 +31,9 @@ supporting the feature or only supporting the feature under certain
22c213
 configurations.  For example, the `aarch64` CPU feature, which, when
22c213
 disabled, enables the optional AArch32 CPU feature, is only supported
22c213
 when using the KVM accelerator and when running on a host CPU type that
22c213
-supports the feature.
22c213
+supports the feature.  While `aarch64` currently only works with KVM,
22c213
+it could work with TCG.  CPU features that are specific to KVM are
22c213
+prefixed with "kvm-" and are described in "KVM VCPU Features".
22c213
 
22c213
 CPU Feature Probing
22c213
 ===================
22c213
@@ -171,6 +173,39 @@ disabling many SVE vector lengths would be quite verbose, the `sve<N>` CPU
22c213
 properties have special semantics (see "SVE CPU Property Parsing
22c213
 Semantics").
22c213
 
22c213
+KVM VCPU Features
22c213
+=================
22c213
+
22c213
+KVM VCPU features are CPU features that are specific to KVM, such as
22c213
+paravirt features or features that enable CPU virtualization extensions.
22c213
+The features' CPU properties are only available when KVM is enabled and
22c213
+are named with the prefix "kvm-".  KVM VCPU features may be probed,
22c213
+enabled, and disabled in the same way as other CPU features.  Below is
22c213
+the list of KVM VCPU features and their descriptions.
22c213
+
22c213
+  kvm-no-adjvtime          By default kvm-no-adjvtime is disabled.  This
22c213
+                           means that by default the virtual time
22c213
+                           adjustment is enabled (vtime is *not not*
22c213
+                           adjusted).
22c213
+
22c213
+                           When virtual time adjustment is enabled each
22c213
+                           time the VM transitions back to running state
22c213
+                           the VCPU's virtual counter is updated to ensure
22c213
+                           stopped time is not counted.  This avoids time
22c213
+                           jumps surprising guest OSes and applications,
22c213
+                           as long as they use the virtual counter for
22c213
+                           timekeeping.  However it has the side effect of
22c213
+                           the virtual and physical counters diverging.
22c213
+                           All timekeeping based on the virtual counter
22c213
+                           will appear to lag behind any timekeeping that
22c213
+                           does not subtract VM stopped time.  The guest
22c213
+                           may resynchronize its virtual counter with
22c213
+                           other time sources as needed.
22c213
+
22c213
+                           Enable kvm-no-adjvtime to disable virtual time
22c213
+                           adjustment, also restoring the legacy (pre-5.0)
22c213
+                           behavior.
22c213
+
22c213
 SVE CPU Properties
22c213
 ==================
22c213
 
22c213
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
22c213
index e108391..d30d38c 100644
22c213
--- a/hw/arm/virt.c
22c213
+++ b/hw/arm/virt.c
22c213
@@ -1707,6 +1707,11 @@ static void machvirt_init(MachineState *machine)
22c213
             }
22c213
         }
22c213
 
22c213
+        if (vmc->kvm_no_adjvtime &&
22c213
+            object_property_find(cpuobj, "kvm-no-adjvtime", NULL)) {
22c213
+            object_property_set_bool(cpuobj, true, "kvm-no-adjvtime", NULL);
22c213
+        }
22c213
+
22c213
         if (vmc->no_pmu && object_property_find(cpuobj, "pmu", NULL)) {
22c213
             object_property_set_bool(cpuobj, false, "pmu", NULL);
22c213
         }
22c213
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
22c213
index 53fdf16..77828ce 100644
22c213
--- a/include/hw/arm/virt.h
22c213
+++ b/include/hw/arm/virt.h
22c213
@@ -109,6 +109,7 @@ typedef struct {
22c213
     bool smbios_old_sys_ver;
22c213
     bool no_highmem_ecam;
22c213
     bool no_ged;   /* Machines < 4.2 has no support for ACPI GED device */
22c213
+    bool kvm_no_adjvtime;
22c213
 } VirtMachineClass;
22c213
 
22c213
 typedef struct {
22c213
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
22c213
index 3788fc3..e46efe9 100644
22c213
--- a/target/arm/cpu.c
22c213
+++ b/target/arm/cpu.c
22c213
@@ -2482,6 +2482,7 @@ static void arm_max_initfn(Object *obj)
22c213
 
22c213
     if (kvm_enabled()) {
22c213
         kvm_arm_set_cpu_features_from_host(cpu);
22c213
+        kvm_arm_add_vcpu_properties(obj);
22c213
     } else {
22c213
         cortex_a15_initfn(obj);
22c213
 
22c213
@@ -2673,6 +2674,7 @@ static void arm_host_initfn(Object *obj)
22c213
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
22c213
         aarch64_add_sve_properties(obj);
22c213
     }
22c213
+    kvm_arm_add_vcpu_properties(obj);
22c213
     arm_cpu_post_init(obj);
22c213
 }
22c213
 
22c213
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
22c213
index a39d6fc..3cd416d 100644
22c213
--- a/target/arm/cpu64.c
22c213
+++ b/target/arm/cpu64.c
22c213
@@ -605,6 +605,7 @@ static void aarch64_max_initfn(Object *obj)
22c213
 
22c213
     if (kvm_enabled()) {
22c213
         kvm_arm_set_cpu_features_from_host(cpu);
22c213
+        kvm_arm_add_vcpu_properties(obj);
22c213
     } else {
22c213
         uint64_t t;
22c213
         uint32_t u;
22c213
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
22c213
index 26d7f8b..4be9497 100644
22c213
--- a/target/arm/kvm.c
22c213
+++ b/target/arm/kvm.c
22c213
@@ -17,6 +17,8 @@
22c213
 #include "qemu/timer.h"
22c213
 #include "qemu/error-report.h"
22c213
 #include "qemu/main-loop.h"
22c213
+#include "qom/object.h"
22c213
+#include "qapi/error.h"
22c213
 #include "sysemu/sysemu.h"
22c213
 #include "sysemu/kvm.h"
22c213
 #include "sysemu/kvm_int.h"
22c213
@@ -179,6 +181,32 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
22c213
     env->features = arm_host_cpu_features.features;
22c213
 }
22c213
 
22c213
+static bool kvm_no_adjvtime_get(Object *obj, Error **errp)
22c213
+{
22c213
+    return !ARM_CPU(obj)->kvm_adjvtime;
22c213
+}
22c213
+
22c213
+static void kvm_no_adjvtime_set(Object *obj, bool value, Error **errp)
22c213
+{
22c213
+    ARM_CPU(obj)->kvm_adjvtime = !value;
22c213
+}
22c213
+
22c213
+/* KVM VCPU properties should be prefixed with "kvm-". */
22c213
+void kvm_arm_add_vcpu_properties(Object *obj)
22c213
+{
22c213
+    if (!kvm_enabled()) {
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    ARM_CPU(obj)->kvm_adjvtime = true;
22c213
+    object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get,
22c213
+                             kvm_no_adjvtime_set, &error_abort);
22c213
+    object_property_set_description(obj, "kvm-no-adjvtime",
22c213
+                                    "Set on to disable the adjustment of "
22c213
+                                    "the virtual counter. VM stopped time "
22c213
+                                    "will be counted.", &error_abort);
22c213
+}
22c213
+
22c213
 bool kvm_arm_pmu_supported(CPUState *cpu)
22c213
 {
22c213
     KVMState *s = KVM_STATE(current_machine->accelerator);
22c213
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
22c213
index 01a9a18..ae9e075 100644
22c213
--- a/target/arm/kvm_arm.h
22c213
+++ b/target/arm/kvm_arm.h
22c213
@@ -256,6 +256,15 @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map);
22c213
 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
22c213
 
22c213
 /**
22c213
+ * kvm_arm_add_vcpu_properties:
22c213
+ * @obj: The CPU object to add the properties to
22c213
+ *
22c213
+ * Add all KVM specific CPU properties to the CPU object. These
22c213
+ * are the CPU properties with "kvm-" prefixed names.
22c213
+ */
22c213
+void kvm_arm_add_vcpu_properties(Object *obj);
22c213
+
22c213
+/**
22c213
  * kvm_arm_aarch32_supported:
22c213
  * @cs: CPUState
22c213
  *
22c213
@@ -345,6 +354,8 @@ static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
22c213
     cpu->host_cpu_probe_failed = true;
22c213
 }
22c213
 
22c213
+static inline void kvm_arm_add_vcpu_properties(Object *obj) {}
22c213
+
22c213
 static inline bool kvm_arm_aarch32_supported(CPUState *cs)
22c213
 {
22c213
     return false;
22c213
diff --git a/target/arm/monitor.c b/target/arm/monitor.c
22c213
index fa054f8..9725dff 100644
22c213
--- a/target/arm/monitor.c
22c213
+++ b/target/arm/monitor.c
22c213
@@ -103,6 +103,7 @@ static const char *cpu_model_advertised_features[] = {
22c213
     "sve128", "sve256", "sve384", "sve512",
22c213
     "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280",
22c213
     "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048",
22c213
+    "kvm-no-adjvtime",
22c213
     NULL
22c213
 };
22c213
 
22c213
diff --git a/tests/arm-cpu-features.c b/tests/arm-cpu-features.c
22c213
index 89285ca..ba1a6fe 100644
22c213
--- a/tests/arm-cpu-features.c
22c213
+++ b/tests/arm-cpu-features.c
22c213
@@ -428,6 +428,8 @@ static void test_query_cpu_model_expansion(const void *data)
22c213
     assert_has_feature_enabled(qts, "cortex-a15", "pmu");
22c213
     assert_has_not_feature(qts, "cortex-a15", "aarch64");
22c213
 
22c213
+    assert_has_not_feature(qts, "max", "kvm-no-adjvtime");
22c213
+
22c213
     if (g_str_equal(qtest_get_arch(), "aarch64")) {
22c213
         assert_has_feature_enabled(qts, "max", "aarch64");
22c213
         assert_has_feature_enabled(qts, "max", "sve");
22c213
@@ -462,6 +464,8 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
22c213
         return;
22c213
     }
22c213
 
22c213
+    assert_has_feature_disabled(qts, "host", "kvm-no-adjvtime");
22c213
+
22c213
     if (g_str_equal(qtest_get_arch(), "aarch64")) {
22c213
         bool kvm_supports_sve;
22c213
         char max_name[8], name[8];
22c213
-- 
22c213
1.8.3.1
22c213