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

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