yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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