target/i386/kvm: Cleanup the kvmclock feature name
cover target/i386/kvm: Cleanup the kvmclock feature name
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's guest_phys_bits patchset [1].
Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Next Step
=========
This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/
Thanks and Best Regards,
Zhao
---
Tim Wiederhake (1):
target/i386: Fix duplicated kvmclock name in FEAT_KVM
Zhao Liu (6):
target/i386/kvm: Add feature bit definitions for KVM CPUID target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and
MSR_KVM_SYSTEM_TIME definitions
target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled target/i386/kvm: Save/load MSRs of new kvmclock
(KVM_FEATURE_CLOCKSOURCE2)
target/i386/kvm: Add legacy_kvmclock cpu property target/i386/kvm: Update comment in kvm_cpu_realizefn()
hw/i386/kvm/clock.c | 5 ++-- hw/i386/pc.c | 1 + target/i386/cpu.c | 3 +- target/i386/cpu.h | 32 +++++++++++++++++++++ target/i386/kvm/kvm-cpu.c | 25 ++++++++++++++++- target/i386/kvm/kvm.c | 59 +++++++++++++++++++++++++-------------- 6 files changed, 99 insertions(+), 26 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/7 target/i386/kvm: Add feature bit definitions for KVM CPUID
From: Zhao Liu <[email protected]>
Add feature definiations for KVM_CPUID_FEATURES in CPUID ( CPUID[4000_0001].EAX and CPUID[4000_0001].EDX), to get rid of lots of offset calculations.
--- hw/i386/kvm/clock.c | 5 ++--- target/i386/cpu.h | 23 +++++++++++++++++++++++ target/i386/kvm/kvm.c | 28 ++++++++++++++-------------- 3 files changed, 39 insertions(+), 17 deletions(-)
hw/i386/kvm/clock.c +2 -3
@@ -27,7 +27,6 @@#include "qapi/error.h" #include <linux/kvm.h> -#include "standard-headers/asm-x86/kvm_para.h" #include "qom/object.h" #define TYPE_KVM_CLOCK "kvmclock"
@@ -334,8 +333,8 @@ void kvmclock_create(bool create_always)assert (kvm_enabled ());if (create_always || - cpu->env.features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | - (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) { + cpu->env.features[FEAT_KVM ] & (CPUID_FEAT_KVM_CLOCK | +CPUID_FEAT_KVM_CLOCK2 )) {sysbus_create_simple (TYPE_KVM_CLOCK ,-1 ,NULL ); } }
target/i386/cpu.h +23 -0
@@ -27,6 +27,7 @@#include "qapi/qapi-types-common.h" #include "qemu/cpu-float.h" #include "qemu/timer.h" +#include "standard-headers/asm-x86/kvm_para.h" #define XEN_NR_VIRQS 24
@@ -951,6 +952,28 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,/* Packets which contain IP payload have LIP values */ #define CPUID_14_0_ECX_LIP (1U << 31) +/* (Old) KVM paravirtualized clocksource */ +#define CPUID_FEAT_KVM_CLOCK (1U << KVM_FEATURE_CLOCKSOURCE) +/* (New) KVM specific paravirtualized clocksource */ +#define CPUID_FEAT_KVM_CLOCK2 (1U << KVM_FEATURE_CLOCKSOURCE2) +/* KVM asynchronous page fault */ +#define CPUID_FEAT_KVM_ASYNCPF (1U << KVM_FEATURE_ASYNC_PF) +/* KVM stolen (when guest vCPU is not running) time accounting */ +#define CPUID_FEAT_KVM_STEAL_TIME (1U << KVM_FEATURE_STEAL_TIME) +/* KVM paravirtualized end-of-interrupt signaling */ +#define CPUID_FEAT_KVM_PV_EOI (1U << KVM_FEATURE_PV_EOI) +/* KVM paravirtualized spinlocks support */ +#define CPUID_FEAT_KVM_PV_UNHALT (1U << KVM_FEATURE_PV_UNHALT) +/* KVM host-side polling on HLT control from the guest */ +#define CPUID_FEAT_KVM_POLL_CONTROL (1U << KVM_FEATURE_POLL_CONTROL) +/* KVM interrupt based asynchronous page fault*/ +#define CPUID_FEAT_KVM_ASYNCPF_INT (1U << KVM_FEATURE_ASYNC_PF_INT) +/* KVM 'Extended Destination ID' support for external interrupts */ +#define CPUID_FEAT_KVM_MSI_EXT_DEST_ID (1U << KVM_FEATURE_MSI_EXT_DEST_ID) + +/* Hint to KVM that vCPUs expect never preempted for an unlimited time */ +#define CPUID_FEAT_KVM_HINTS_REALTIME (1U << KVM_HINTS_REALTIME) +/* CLZERO instruction */ #define CPUID_8000_0008_EBX_CLZERO (1U << 0)/* Always save/restore FP error pointers */
target/i386/kvm/kvm.c +14 -14
@@ -481,13 +481,13 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,* be enabled without the in-kernel irqchip */ if (!kvm_irqchip_in_kernel ()) { - ret &= ~(1U <<KVM_FEATURE_PV_UNHALT ); + ret &= ~CPUID_FEAT_KVM_PV_UNHALT ; }if (kvm_irqchip_is_split ()) { - ret |=1U <<KVM_FEATURE_MSI_EXT_DEST_ID ; + ret |=CPUID_FEAT_KVM_MSI_EXT_DEST_ID ; } }else if (function ==KVM_CPUID_FEATURES && reg ==R_EDX ) { - ret |=1U <<KVM_HINTS_REALTIME ; + ret |=CPUID_FEAT_KVM_HINTS_REALTIME ; }return ret;
@@ -3324,20 +3324,20 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,MSR_IA32_TSC , env->tsc);kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr);kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF_INT )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT , env->async_pf_int_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN , env->async_pf_en_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_PV_EOI ) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN , env->pv_eoi_en_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_STEAL_TIME ) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME , env->steal_time_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_POLL_CONTROL )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_POLL_CONTROL ) {kvm_msr_entry_add (cpu,MSR_KVM_POLL_CONTROL , env->poll_control_msr); }
@@ -3789,19 +3789,19 @@ static int kvm_get_msrs(X86CPU *cpu)#endif kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 );kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF_INT )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_PV_EOI ) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_STEAL_TIME ) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_POLL_CONTROL )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_POLL_CONTROL ) {kvm_msr_entry_add (cpu,MSR_KVM_POLL_CONTROL ,1 ); }if (has_architectural_pmu_version >0 ) {
@@ -5434,7 +5434,7 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address)return address; } env = &X86_CPU (first_cpu)->env; -if (!(env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_MSI_EXT_DEST_ID ))) { +if (!(env->features[FEAT_KVM ] &CPUID_FEAT_KVM_MSI_EXT_DEST_ID )) {return address; }
Signature · 1 line
2.34.1
Re: [PATCH for-9.1 1/7] target/i386/kvm: Add feature bit definitions for KVM CPUID
Quoted 49 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Add feature definiations for
KVM_CPUID_FEATURESin CPUID ( CPUID[4000_0001].EAX and CPUID[4000_0001].EDX), to get rid of lots of offset calculations.Signed-off-by Zhao Liu <[email protected]>--- hw/i386/kvm/clock.c | 5 ++--- target/i386/cpu.h | 23 +++++++++++++++++++++++ target/i386/kvm/kvm.c | 28 ++++++++++++++-------------- 3 files changed, 39 insertions(+), 17 deletions(-)hw/i386/kvm/clock.c +2
-3@@ -27,7 +27,6 @@#include "qapi/error.h" #include <linux/kvm.h> -#include "standard-headers/asm-x86/kvm_para.h" #include "qom/object.h" #define TYPE_KVM_CLOCK "kvmclock"@@ -334,8 +333,8 @@ void kvmclock_create(bool create_always)assert (kvm_enabled ());if (create_always || - cpu->env.features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | - (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) { + cpu->env.features[FEAT_KVM ] & (CPUID_FEAT_KVM_CLOCK | +CPUID_FEAT_KVM_CLOCK2 )) {sysbus_create_simple (TYPE_KVM_CLOCK ,-1 ,NULL ); } }target/i386/cpu.h +1
-0@@ -27,6 +27,7 @@#include "qapi/qapi-types-common.h" #include "qemu/cpu-float.h" #include "qemu/timer.h" +#include "standard-headers/asm-x86/kvm_para.h" #define XEN_NR_VIRQS 24
target/i386/cpu.h uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, · line 956
Quoted 5 lines
target/i386/cpu.h +2
-0@@ -951,6 +952,28 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,/* Packets which contain IP payload have LIP values */ #define CPUID_14_0_ECX_LIP (1U << 31) +/* (Old) KVM paravirtualized clocksource */ +#define CPUID_FEAT_KVM_CLOCK (1U << KVM_FEATURE_CLOCKSOURCE)
we can drop the _FEAT_, just name it as
CPUID_KVM_CLOCK
Quoted 104 lines
target/i386/cpu.h +20
-0+/* (New) KVM specific paravirtualized clocksource */ +#define CPUID_FEAT_KVM_CLOCK2 (1U << KVM_FEATURE_CLOCKSOURCE2) +/* KVM asynchronous page fault */ +#define CPUID_FEAT_KVM_ASYNCPF (1U << KVM_FEATURE_ASYNC_PF) +/* KVM stolen (when guest vCPU is not running) time accounting */ +#define CPUID_FEAT_KVM_STEAL_TIME (1U << KVM_FEATURE_STEAL_TIME) +/* KVM paravirtualized end-of-interrupt signaling */ +#define CPUID_FEAT_KVM_PV_EOI (1U << KVM_FEATURE_PV_EOI) +/* KVM paravirtualized spinlocks support */ +#define CPUID_FEAT_KVM_PV_UNHALT (1U << KVM_FEATURE_PV_UNHALT) +/* KVM host-side polling on HLT control from the guest */ +#define CPUID_FEAT_KVM_POLL_CONTROL (1U << KVM_FEATURE_POLL_CONTROL) +/* KVM interrupt based asynchronous page fault*/ +#define CPUID_FEAT_KVM_ASYNCPF_INT (1U << KVM_FEATURE_ASYNC_PF_INT) +/* KVM 'Extended Destination ID' support for external interrupts */ +#define CPUID_FEAT_KVM_MSI_EXT_DEST_ID (1U << KVM_FEATURE_MSI_EXT_DEST_ID) + +/* Hint to KVM that vCPUs expect never preempted for an unlimited time */ +#define CPUID_FEAT_KVM_HINTS_REALTIME (1U << KVM_HINTS_REALTIME) +/* CLZERO instruction */ #define CPUID_8000_0008_EBX_CLZERO (1U << 0)/* Always save/restore FP error pointers */ target/i386/kvm/kvm.c +14
-14@@ -481,13 +481,13 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,* be enabled without the in-kernel irqchip */ if (!kvm_irqchip_in_kernel ()) { - ret &= ~(1U <<KVM_FEATURE_PV_UNHALT ); + ret &= ~CPUID_FEAT_KVM_PV_UNHALT ; }if (kvm_irqchip_is_split ()) { - ret |=1U <<KVM_FEATURE_MSI_EXT_DEST_ID ; + ret |=CPUID_FEAT_KVM_MSI_EXT_DEST_ID ; } }else if (function ==KVM_CPUID_FEATURES && reg ==R_EDX ) { - ret |=1U <<KVM_HINTS_REALTIME ; + ret |=CPUID_FEAT_KVM_HINTS_REALTIME ; }return ret;@@ -3324,20 +3324,20 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,MSR_IA32_TSC , env->tsc);kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr);kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF_INT )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT , env->async_pf_int_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN , env->async_pf_en_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_PV_EOI ) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN , env->pv_eoi_en_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_STEAL_TIME ) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME , env->steal_time_msr); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_POLL_CONTROL )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_POLL_CONTROL ) {kvm_msr_entry_add (cpu,MSR_KVM_POLL_CONTROL , env->poll_control_msr); }@@ -3789,19 +3789,19 @@ static int kvm_get_msrs(X86CPU *cpu)#endif kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 );kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF_INT )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_PV_EOI ) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_STEAL_TIME ) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME ,0 ); } -if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_POLL_CONTROL )) { +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_POLL_CONTROL ) {kvm_msr_entry_add (cpu,MSR_KVM_POLL_CONTROL ,1 ); }if (has_architectural_pmu_version >0 ) {@@ -5434,7 +5434,7 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address)return address; } env = &X86_CPU (first_cpu)->env; -if (!(env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_MSI_EXT_DEST_ID ))) { +if (!(env->features[FEAT_KVM ] &CPUID_FEAT_KVM_MSI_EXT_DEST_ID )) {return address; }
PATCH 2/7 target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and MSR_KVM_SYSTEM_TIME definitions
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
These 2 MSRs have been already defined in the kvm_para header (standard-headers/asm-x86/kvm_para.h).
Remove QEMU local definitions to avoid duplication.
--- target/i386/kvm/kvm.c | 3 --- 1 file changed, 3 deletions(-)
target/i386/kvm/kvm.c +0 -3
@@ -78,9 +78,6 @@#define KVM_APIC_BUS_CYCLE_NS 1#define KVM_APIC_BUS_FREQUENCY (1000000000ULL / KVM_APIC_BUS_CYCLE_NS) -#define MSR_KVM_WALL_CLOCK 0x11 -#define MSR_KVM_SYSTEM_TIME 0x12 -/* A 4096-byte buffer can hold the 8-byte kvm_msrs header, plus * 255 kvm_msr_entry structs */ #define MSR_BUF_SIZE 4096
Signature · 1 line
2.34.1
Re: [PATCH for-9.1 2/7] target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and MSR_KVM_SYSTEM_TIME definitions
Quoted 8 lines · Zhao Liu
From: Zhao Liu <[email protected]>
These 2 MSRs have been already defined in the
kvm_paraheader (standard-headers/asm-x86/kvm_para.h).Remove QEMU local definitions to avoid duplication.
Signed-off-by Zhao Liu <[email protected]>
Quoted 18 lines
--- target/i386/kvm/kvm.c | 3 --- 1 file changed, 3 deletions(-)target/i386/kvm/kvm.c +0
-3@@ -78,9 +78,6 @@#define KVM_APIC_BUS_CYCLE_NS 1#define KVM_APIC_BUS_FREQUENCY (1000000000ULL / KVM_APIC_BUS_CYCLE_NS) -#define MSR_KVM_WALL_CLOCK 0x11 -#define MSR_KVM_SYSTEM_TIME 0x12 -/* A 4096-byte buffer can hold the 8-byte kvm_msrs header, plus * 255 kvm_msr_entry structs */ #define MSR_BUF_SIZE 4096
PATCH 3/7 target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
MSR_KVM_SYSTEM_TIME and MSR_KVM_WALL_CLOCK are attached with the (old) kvmclock feature (KVM_FEATURE_CLOCKSOURCE).
So, just save/load them only when kvmclock (KVM_FEATURE_CLOCKSOURCE) is enabled.
--- target/i386/kvm/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
target/i386/kvm/kvm.c +8 -4
@@ -3319,8 +3319,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)*/ if (level >=KVM_PUT_RESET_STATE ) {kvm_msr_entry_add (cpu,MSR_IA32_TSC , env->tsc); -kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr); -kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK ) { +kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr); +kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); + }if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT , env->async_pf_int_msr); }
@@ -3784,8 +3786,10 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_LSTAR, 0); }#endif -kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 ); -kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK ) { +kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 ); +kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); + }if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT ,0 ); }
Signature · 1 line
2.34.1
PATCH 4/7 target/i386/kvm: Save/load MSRs of new kvmclock (KVM_FEATURE_CLOCKSOURCE2)
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
MSR_KVM_SYSTEM_TIME_NEW and MSR_KVM_WALL_CLOCK_NEW are bound to new kvmclock (KVM_FEATURE_CLOCKSOURCE2).
Add the save/load support for these 2 MSRs.
--- target/i386/cpu.h | 2 ++ target/i386/kvm/kvm.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
target/i386/cpu.h +2 -0
@@ -1741,6 +1741,8 @@ typedef struct CPUArchState {uint64_t system_time_msr;uint64_t wall_clock_msr; +uint64_t system_time_new_msr; +uint64_t wall_clock_new_msr;uint64_t steal_time_msr;uint64_t async_pf_en_msr;uint64_t async_pf_int_msr;
target/i386/kvm/kvm.c +16 -0
@@ -3323,6 +3323,12 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr);kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); } +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK2 ) { +kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME_NEW , + env->system_time_new_msr); +kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK_NEW , + env->wall_clock_new_msr); + }if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT , env->async_pf_int_msr); }
@@ -3790,6 +3796,10 @@ static int kvm_get_msrs(X86CPU *cpu)kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 );kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); } +if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK2 ) { +kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME_NEW ,0 ); +kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK_NEW ,0 ); + }if (env->features[FEAT_KVM ] &CPUID_FEAT_KVM_ASYNCPF_INT ) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_INT ,0 ); }
@@ -4029,6 +4039,12 @@ static int kvm_get_msrs(X86CPU *cpu)case MSR_KVM_WALL_CLOCK : env->wall_clock_msr = msrs[i].data;break ; +case MSR_KVM_SYSTEM_TIME_NEW : + env->system_time_new_msr = msrs[i].data; +break ; +case MSR_KVM_WALL_CLOCK_NEW : + env->wall_clock_new_msr = msrs[i].data; +break ;case MSR_MCG_STATUS : env->mcg_status = msrs[i].data;break ;
Signature · 1 line
2.34.1
PATCH 5/7 target/i386/kvm: Add legacy_kvmclock cpu property
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
Currently, the old kvmclock (KVM_FEATURE_CLOCKSOURCE) and the new (KVM_FEATURE_CLOCKSOURCE2) are always set/unset together since they have the same feature name "kvmclock" since the commit 642258c6c7 ("kvm: add kvmclock to its second bit").
Before renaming the new kvmclock, introduce legacy_kvmclock to inherit the behavior of both old and new kvmclocks being enabled/disabled at the same time.
--- hw/i386/pc.c | 1 + target/i386/cpu.c | 1 + target/i386/cpu.h | 7 +++++++ target/i386/kvm/kvm-cpu.c | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+)
hw/i386/pc.c +1 -0
@@ -80,6 +80,7 @@GlobalProperty pc_compat_9_0[] = { {TYPE_X86_CPU ,"guest-phys-bits" ,"0" }, + {TYPE_X86_CPU ,"legacy-kvmclock" ,"true" }, };const size_t pc_compat_9_0_len =G_N_ELEMENTS (pc_compat_9_0);
target/i386/cpu.c +1 -0
@@ -7941,6 +7941,7 @@ static Property x86_cpu_properties[] = {*/ DEFINE_PROP_BOOL ("legacy-cache" ,X86CPU , legacy_cache, true),DEFINE_PROP_BOOL ("xen-vapic" ,X86CPU , xen_vapic, false), + DEFINE_PROP_BOOL("legacy-kvmclock", X86CPU, legacy_kvmclock, false),/* * From "Requirements for Implementing the Microsoft
target/i386/cpu.h +7 -0
@@ -2070,6 +2070,13 @@ struct ArchCPU {int32_t hv_max_vps;bool xen_vapic; + +/* +* Compatibility bits for old machine types. +* If true, always set/unset KVM_FEATURE_CLOCKSOURCE and +* KVM_FEATURE_CLOCKSOURCE2 at the same time. +*/ +bool legacy_kvmclock; };typedef struct X86CPUModel X86CPUModel ;
target/i386/kvm/kvm-cpu.c +19 -0
@@ -18,6 +18,8 @@#include "kvm_i386.h" #include "hw/core/accel-cpu.h" +#include "standard-headers/asm-x86/kvm_para.h" +static void kvm_set_guest_phys_bits (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);
@@ -72,6 +74,23 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) MSR_IA32_UCODE_REV); } } + +if (cpu->legacy_kvmclock) { +/* +* The old and new kvmclock 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. +* Then, mask both at the same time for compatibility with v9.0 +* and older QEMU's kvmclock behavior. +*/ +if (!(env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK ) || + !(env->features[FEAT_KVM ] &CPUID_FEAT_KVM_CLOCK2 )) { + env->features[FEAT_KVM ] &= ~(CPUID_FEAT_KVM_CLOCK | +CPUID_FEAT_KVM_CLOCK2 ); + } + } + ret =host_cpu_realizefn (cs, errp);if (!ret) {return ret;
Signature · 1 line
2.34.1
PATCH 6/7 target/i386: Fix duplicated kvmclock name in FEAT_KVM
In reply to Zhao LiuFrom: Tim Wiederhake <[email protected]>
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.
---
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(-)
target/i386/cpu.c +1 -1
@@ -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",
target/i386/kvm/kvm-cpu.c +2 -1
@@ -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" },
Signature · 1 line
2.34.1
PATCH 7/7 target/i386/kvm: Update comment in kvm_cpu_realizefn()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
With the guest_phys_bits and legacy_kvmclock change, update the comment about function call flow.
--- target/i386/kvm/kvm-cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/i386/kvm/kvm-cpu.c +4 -1
@@ -60,7 +60,10 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)* -> x86_cpu_expand_features() * -> cpu_exec_realizefn(): * -> accel_cpu_common_realize() -* kvm_cpu_realizefn() -> host_cpu_realizefn() +* kvm_cpu_realizefn() +* -> update cpu_pm, ucode_rev, kvmclock +* host_cpu_realizefn() +* update guest_phys_bits on Host support * -> cpu_common_realizefn() * -> check/update ucode_rev, phys_bits, mwait */
Signature · 1 line
2.34.1
Hi maintainers,
Ping. Do you like this diea?
Thanks,
Zhao
Quoted 76 lines · Zhao Liu
Date: Fri, 29 Mar 2024 18:19:47 +0800
From: Zhao Liu <[email protected]>
Subject: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock feature
name
X-Mailer: git-send-email 2.34.1From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Next Step
=========This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/Thanks and Best Regards,
Zhao---
Tim Wiederhake (1):
target/i386: Fix duplicated kvmclock name inFEAT_KVMZhao Liu (6):
target/i386/kvm: Add feature bit definitions for KVM CPUID target/i386/kvm: Remove localMSR_KVM_WALL_CLOCKand
MSR_KVM_SYSTEM_TIMEdefinitions
target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled target/i386/kvm: Save/load MSRs of new kvmclock
(KVM_FEATURE_CLOCKSOURCE2)
target/i386/kvm: Addlegacy_kvmclockcpu property target/i386/kvm: Update comment inkvm_cpu_realizefn()hw/i386/kvm/clock.c | 5 ++-- hw/i386/pc.c | 1 + target/i386/cpu.c | 3 +- target/i386/cpu.h | 32 +++++++++++++++++++++ target/i386/kvm/kvm-cpu.c | 25 ++++++++++++++++- target/i386/kvm/kvm.c | 59 +++++++++++++++++++++++++-------------- 6 files changed, 99 insertions(+), 26 deletions(-)Signature · 1 line
2.34.1
Quoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
Quoted 7 lines
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Quoted 6 lines
Next Step
=========This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
No. It will break existing guests that use KVM_FEATURE_CLOCKSOURCE.
Quoted 32 lines
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/Thanks and Best Regards,
Zhao---
Tim Wiederhake (1):
target/i386: Fix duplicated kvmclock name inFEAT_KVMZhao Liu (6):
target/i386/kvm: Add feature bit definitions for KVM CPUID target/i386/kvm: Remove localMSR_KVM_WALL_CLOCKand
MSR_KVM_SYSTEM_TIMEdefinitions
target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled target/i386/kvm: Save/load MSRs of new kvmclock
(KVM_FEATURE_CLOCKSOURCE2)
target/i386/kvm: Addlegacy_kvmclockcpu property target/i386/kvm: Update comment inkvm_cpu_realizefn()hw/i386/kvm/clock.c | 5 ++-- hw/i386/pc.c | 1 + target/i386/cpu.c | 3 +- target/i386/cpu.h | 32 +++++++++++++++++++++ target/i386/kvm/kvm-cpu.c | 25 ++++++++++++++++- target/i386/kvm/kvm.c | 59 +++++++++++++++++++++++++-------------- 6 files changed, 99 insertions(+), 26 deletions(-)
Hi Xiaoyao,
Quoted 29 lines · Xiaoyao Li
Date: Wed, 24 Apr 2024 23:57:11 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
Quoted 8 lines
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
It's enough to just enable kvmclock2 for Guest; kvmclock (old) is redundant in the presence of kvmclock2.
So operating both feature bits at the same time is not a reasonable choice, we should only keep kvmclock2 for Guest. It's possible because the oldest linux (v4.5) which QEMU i386 supports has kvmclock2.
Pls see:
https://elixir.bootlin.com/linux/v4.5/source/arch/x86/include/uapi/asm/kvm_para.h#L22
With this in mind, I'm trying to implement a silky smooth transition to "only kcmclock2 support".
This series is now separating kvmclock and kvmclock2, and then I plan to go to the KVM side and deprecate kvmclock2, and then finally remove kvmclock (old) in QEMU. Separating the two features makes the process clearer.
Continuing to use the same name equally would have silently caused the CPUID to change on the Guest side, which would have hurt compatibility as well.
Quoted 7 lines
Quoted 7 lines
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Quoted 8 lines
Quoted 6 lines
Next Step
=========This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
No. It will break existing guests that use
KVM_FEATURE_CLOCKSOURCE.
Please refer to my elaboration on v4.5 above, where kvmclock2 is available, it should be used in priority.
Quoted 6 lines
Quoted 6 lines
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
Zhao
Quoted 41 lines · Zhao Liu
Hi Xiaoyao,
Quoted 29 lines · Xiaoyao Li
Date: Wed, 24 Apr 2024 23:57:11 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
Quoted 8 lines
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
Quoted 6 lines
It's enough to just enable kvmclock2 for Guest; kvmclock (old) is redundant in the presence of kvmclock2.
So operating both feature bits at the same time is not a reasonable choice, we should only keep kvmclock2 for Guest. It's possible because the oldest linux (v4.5) which QEMU i386 supports has kvmclock2.
who said the oldest Linux QEMU supports is from 4.5? what about 2.x kernel?
Besides, not only the Linux guest, whatever guest OS is, it will be broken if the guest is using kvmclock and QEMU starts to drop support of kvmclock.
So, again, hard NAK to drop the support of kvmclock. It breaks existing guests that use kvmclock. You cannot force people to upgrade their existing VMs to use kvmclock2 instead of kvmclock.
Quoted 45 lines
Pls see:
https://elixir.bootlin.com/linux/v4.5/source/arch/x86/include/uapi/asm/kvm_para.h#L22With this in mind, I'm trying to implement a silky smooth transition to "only kcmclock2 support".
This series is now separating kvmclock and kvmclock2, and then I plan to go to the KVM side and deprecate kvmclock2, and then finally remove kvmclock (old) in QEMU. Separating the two features makes the process clearer.
Continuing to use the same name equally would have silently caused the CPUID to change on the Guest side, which would have hurt compatibility as well.
Quoted 7 lines
Quoted 7 lines
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Quoted 8 lines
Quoted 6 lines
Next Step
=========This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
No. It will break existing guests that use
KVM_FEATURE_CLOCKSOURCE.Please refer to my elaboration on v4.5 above, where kvmclock2 is available, it should be used in priority.
Quoted 6 lines
Quoted 6 lines
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/Thanks,
Zhao
Quoted 47 lines · Xiaoyao Li
Date: Thu, 25 Apr 2024 16:40:10 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 41 lines · Zhao Liu
Hi Xiaoyao,
Quoted 37 lines · Xiaoyao Li
Date: Wed, 24 Apr 2024 23:57:11 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
Quoted 8 lines
Quoted 6 lines
It's enough to just enable kvmclock2 for Guest; kvmclock (old) is redundant in the presence of kvmclock2.
So operating both feature bits at the same time is not a reasonable choice, we should only keep kvmclock2 for Guest. It's possible because the oldest linux (v4.5) which QEMU i386 supports has kvmclock2.
who said the oldest Linux QEMU supports is from 4.5? what about 2.x kernel?
For Host (docs/system/target-i386.rst).
Quoted 2 lines
Besides, not only the Linux guest, whatever guest OS is, it will be broken if the guest is using kvmclock and QEMU starts to drop support of kvmclock.
I'm not aware of any minimum version requirements for Guest supported by KVM, but there are no commitment.
Quoted 3 lines
So, again, hard NAK to drop the support of kvmclock. It breaks existing guests that use kvmclock. You cannot force people to upgrade their existing VMs to use kvmclock2 instead of kvmclock.
I agree, legacy kvmclock can be left out, if the old kernel does not support kvmclock2 and strongly requires kvmclock, it can be enabled using 9.1 and earlier machines or legacy-kvmclock, as long as Host still supports it.
What's the gap in handling it this way? especially considering that kvmclock2 was introduced in v2.6.35, and earlier kernels are no longer maintained. The availability of the PV feature requires compatibility for both Host and Guest.
Anyway, the above discussion here is about future plans, and this series does not prevent any Guest from ignoring kvmclock2 in favor of kvmclock.
What this series is doing, i.e. separating the current two kvmclock and ensuring CPUID compatibility via legacy-kvmclock, could balance the compatibility requirements of the ancient (unmaintained kernel) with the need for future feature changes.
Thanks,
Zhao
Quoted 57 lines · Zhao Liu
Quoted 47 lines · Xiaoyao Li
Date: Thu, 25 Apr 2024 16:40:10 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 41 lines · Zhao Liu
Hi Xiaoyao,
Quoted 37 lines · Xiaoyao Li
Date: Wed, 24 Apr 2024 23:57:11 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
Quoted 8 lines
Quoted 6 lines
It's enough to just enable kvmclock2 for Guest; kvmclock (old) is redundant in the presence of kvmclock2.
So operating both feature bits at the same time is not a reasonable choice, we should only keep kvmclock2 for Guest. It's possible because the oldest linux (v4.5) which QEMU i386 supports has kvmclock2.
who said the oldest Linux QEMU supports is from 4.5? what about 2.x kernel?
Quoted 7 lines
For Host (
docs/system/target-i386.rst).Quoted 2 lines
Besides, not only the Linux guest, whatever guest OS is, it will be broken if the guest is using kvmclock and QEMU starts to drop support of kvmclock.
I'm not aware of any minimum version requirements for Guest supported by KVM, but there are no commitment.
the common commitment is at least keeping backwards compatibility.
Quoted 14 lines
Quoted 3 lines
So, again, hard NAK to drop the support of kvmclock. It breaks existing guests that use kvmclock. You cannot force people to upgrade their existing VMs to use kvmclock2 instead of kvmclock.
I agree, legacy kvmclock can be left out, if the old kernel does not support kvmclock2 and strongly requires kvmclock, it can be enabled using 9.1 and earlier machines or legacy-kvmclock, as long as Host still supports it.
What's the gap in handling it this way? especially considering that kvmclock2 was introduced in v2.6.35, and earlier kernels are no longer maintained. The availability of the PV feature requires compatibility for both Host and Guest.
Quoted 7 lines
Anyway, the above discussion here is about future plans, and this series does not prevent any Guest from ignoring kvmclock2 in favor of kvmclock.
What this series is doing, i.e. separating the current two kvmclock and ensuring CPUID compatibility via legacy-kvmclock, could balance the compatibility requirements of the ancient (unmaintained kernel) with the need for future feature changes.
You introduce a user-visible change that people need to use "-kvmclock,-kvmclock2" to totally disable kvmclock.
The only difference between kvmclock and kvmclock2 is the MSR index. And from users' perspective, they don't care this difference. The existing usage is simple. When I want kvmclock, use "+kvmclock". When I don't want it, use "-kvmclock".
You are complicating things and I don't see a strong reason that we have to do it.
Quoted 3 lines
Thanks,
Zhao
Quoted 98 lines · Xiaoyao Li
Date: Thu, 25 Apr 2024 20:04:46 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 57 lines · Zhao Liu
Quoted 47 lines · Xiaoyao Li
Date: Thu, 25 Apr 2024 16:40:10 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 41 lines · Zhao Liu
Hi Xiaoyao,
Quoted 37 lines · Xiaoyao Li
Date: Wed, 24 Apr 2024 23:57:11 +0800
From: Xiaoyao Li <[email protected]>
Subject: Re: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock
feature nameQuoted 13 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
Quoted 7 lines
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
The commit message of [3] said the reason clearly:
When we tweak flags involving this value - specially when we use "-", we have to act on both.
So you are trying to change it to "when people want to disable kvmclock, they need to use '-kvmclock,-kvmclock2' instead of '-kvmclock'"
IMHO, I prefer existing code and I don't see much value of differentiating them. If the current code puzzles you, then we can add comment to explain.
Quoted 8 lines
Quoted 6 lines
It's enough to just enable kvmclock2 for Guest; kvmclock (old) is redundant in the presence of kvmclock2.
So operating both feature bits at the same time is not a reasonable choice, we should only keep kvmclock2 for Guest. It's possible because the oldest linux (v4.5) which QEMU i386 supports has kvmclock2.
who said the oldest Linux QEMU supports is from 4.5? what about 2.x kernel?
Quoted 7 lines
For Host (
docs/system/target-i386.rst).Quoted 2 lines
Besides, not only the Linux guest, whatever guest OS is, it will be broken if the guest is using kvmclock and QEMU starts to drop support of kvmclock.
I'm not aware of any minimum version requirements for Guest supported by KVM, but there are no commitment.
the common commitment is at least keeping backwards compatibility.
Quoted 14 lines
Quoted 3 lines
So, again, hard NAK to drop the support of kvmclock. It breaks existing guests that use kvmclock. You cannot force people to upgrade their existing VMs to use kvmclock2 instead of kvmclock.
I agree, legacy kvmclock can be left out, if the old kernel does not support kvmclock2 and strongly requires kvmclock, it can be enabled using 9.1 and earlier machines or legacy-kvmclock, as long as Host still supports it.
What's the gap in handling it this way? especially considering that kvmclock2 was introduced in v2.6.35, and earlier kernels are no longer maintained. The availability of the PV feature requires compatibility for both Host and Guest.
Quoted 7 lines
Anyway, the above discussion here is about future plans, and this series does not prevent any Guest from ignoring kvmclock2 in favor of kvmclock.
What this series is doing, i.e. separating the current two kvmclock and ensuring CPUID compatibility via legacy-kvmclock, could balance the compatibility requirements of the ancient (unmaintained kernel) with the need for future feature changes.
You introduce a user-visible change that people need to use "-kvmclock,-kvmclock2" to totally disable kvmclock.
Quoted 8 lines
The only difference between kvmclock and kvmclock2 is the MSR index. And from users' perspective, they don't care this difference. The existing usage is simple. When I want kvmclock, use "+kvmclock". When I don't want it, use "-kvmclock".
You are complicating things and I don't see a strong reason that we have to do it.
Okay, only when old kvmclock deprecation occurs can the values (of renaming) be recognized, then I'll hold the renamed patches for now and only keep some of the other cleanups.
Thanks for your review,
-Zhao
Hi Paolo,
Sorry to re-pick this series, is it an acceptable cleanup to separate the current kvmclock/kvmclock2 if the old kvmclock can't be dropped?
Thanks,
Zhao
Quoted 76 lines · Zhao Liu
Date: Fri, 29 Mar 2024 18:19:47 +0800
From: Zhao Liu <[email protected]>
Subject: [PATCH for-9.1 0/7] target/i386/kvm: Cleanup the kvmclock feature
name
X-Mailer: git-send-email 2.34.1From: Zhao Liu <[email protected]>
Hi list,
This series is based on Paolo's
guest_phys_bitspatchset [1].Currently, the old and new kvmclocks have the same feature name "kvmclock" in FeatureWordInfo[FEAT_KVM].
When I tried to dig into the history of this unusual naming and fix it, I realized that Tim was already trying to rename it, so I picked up his renaming patch [2] (with a new commit message and other minor changes).
13 years age, the same name was introduced in [3], and its main purpose is to make it easy for users to enable/disable 2 kvmclocks. Then, in 2012, Don tried to rename the new kvmclock, but the follow-up did not address Igor and Eduardo's comments about compatibility.
Tim [2], not long ago, and I just now, were both puzzled by the naming one after the other.
So, this series is to push for renaming the new kvmclock feature to "kvmclock2" and adding compatibility support for older machines (PC 9.0 and older).
Finally, let's put an end to decades of doubt about this name.
Next Step
=========This series just separates the two kvmclocks from the naming, and in subsequent patches I plan to stop setting kvmclock(old kcmclock) by default as long as KVM supports kvmclock2 (new kvmclock).
Also, try to deprecate the old kvmclock in KVM side.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
[3]: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: https://lore.kernel.org/qemu-devel/[email protected]/Thanks and Best Regards,
Zhao---
Tim Wiederhake (1):
target/i386: Fix duplicated kvmclock name inFEAT_KVMZhao Liu (6):
target/i386/kvm: Add feature bit definitions for KVM CPUID target/i386/kvm: Remove localMSR_KVM_WALL_CLOCKand
MSR_KVM_SYSTEM_TIMEdefinitions
target/i386/kvm: Only Save/load kvmclock MSRs when kvmclock enabled target/i386/kvm: Save/load MSRs of new kvmclock
(KVM_FEATURE_CLOCKSOURCE2)
target/i386/kvm: Addlegacy_kvmclockcpu property target/i386/kvm: Update comment inkvm_cpu_realizefn()hw/i386/kvm/clock.c | 5 ++-- hw/i386/pc.c | 1 + target/i386/cpu.c | 3 +- target/i386/cpu.h | 32 +++++++++++++++++++++ target/i386/kvm/kvm-cpu.c | 25 ++++++++++++++++- target/i386/kvm/kvm.c | 59 +++++++++++++++++++++++++-------------- 6 files changed, 99 insertions(+), 26 deletions(-)Signature · 1 line
2.34.1