diff mbox series

[for-9.1,6/7] target/i386: Fix duplicated kvmclock name in FEAT_KVM

Message ID 20240329101954.3954987-7-zhao1.liu@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series target/i386/kvm: Cleanup the kvmclock feature name | expand

Commit Message

Zhao Liu March 29, 2024, 10:19 a.m. UTC
From: Tim Wiederhake <twiederh@redhat.com>

The commit 642258c6c7 ("kvm: add kvmclock to its second bit") gave the
old and new kvmclocks with the same name "kvmclock", to facilitate user
to set/unset the feature bits for both 2 kvmclock features together.

This could work because:
* QEMU side:
  - x86_cpu_register_bit_prop() supports "the same property name can be
    registered multiple times to make it affect multiple bits in the
    same FeatureWord".
* KVM side:
  - The only difference between 2 version kvmclocks is their MSRs have
    different addresses.
  - When 2 kvmclocks are both enabled, KVM will prioritize the use of
    new kvmclock's MSRs.

However, there're reasons we need give the second kvmclock a new name:
* Based on the KVM mechanism, it doesn't make sense to bind two
  kvmclocks together. Since kvmclock is enabled by default in most cases
  as a KVM PV feature, the benefit of the same naming is reflected in
  the fact that -kvmclock can disable both. But, following the KVM
  interface style (i.e., separating the two kvmclocks) is clearly
  clearer to the user.
* For developers, identical names have been creating confusion along
  with persistent doubts about the naming.
* FeatureWordInfo should define names based on hardware/Host CPUID bit,
  and the name is used to distinguish the bit.
* User actions based on +/- feature names should only work on
  independent feature bits. The common effect of multiple features
  should be controlled by an additional CPU property or additional code
  logic to show the association between different feature bits.
* The old kvmclock will eventually be removed. Different naming can ease
  the burden of future cleanups.

Therefore, rename the new kvmclock feature as "kvmclock2".

Additionally, add "kvmclock2" entry in kvm_default_props[] since the
oldest kernel supported by QEMU (v4.5) has supported the new kvm clock.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Based on Tim's original patch, rewrote the commit message and added the
tiny fix for compatibility.
---
 target/i386/cpu.c         | 2 +-
 target/i386/kvm/kvm-cpu.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1b6caf071a6d..0a1dac60f5de 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -855,7 +855,7 @@  FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
     [FEAT_KVM] = {
         .type = CPUID_FEATURE_WORD,
         .feat_names = {
-            "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
+            "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock2",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
             NULL, "kvm-pv-tlb-flush", "kvm-asyncpf-vmexit", "kvm-pv-ipi",
             "kvm-poll-control", "kvm-pv-sched-yield", "kvm-asyncpf-int", "kvm-msi-ext-dest-id",
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index ae3cb27c8aa8..753f90c18bd6 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -77,7 +77,7 @@  static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
 
     if (cpu->legacy_kvmclock) {
         /*
-         * The old and new kvmclock are both set by default from the
+         * The kvmclock and kvmclock2 are both set by default from the
          * oldest KVM supported (v4.5, see "OS requirements" section at
          * docs/system/target-i386.rst). So when one of them is missing,
          * it is only possible that the user is actively masking it.
@@ -179,6 +179,7 @@  static void kvm_cpu_xsave_init(void)
  */
 static PropValue kvm_default_props[] = {
     { "kvmclock", "on" },
+    { "kvmclock2", "on" },
     { "kvm-nopiodelay", "on" },
     { "kvm-asyncpf", "on" },
     { "kvm-steal-time", "on" },