KVM: x86: Fix vCPUs >= 64 can't be online and hotplugged in some scenarios
Subsystems (2)
Quoted 29 lines · Zelin Deng
pvclock data pointers of vCPUs >=
HVC_BOOT_ARRAY_SIZE(64) are stored inhvclock_memwihch is initialized inkvmclock_init_mem(). Here're 3 scenarios in current implementation:
- no-kvmclock is set in cmdline. kvm pv clock driver is disabled, no impact.
- no-kvmclock-vsyscall is set in cmdline.kvmclock_init_mem()won't be called. No memory for storing pvclock data of vCPUs >= 64, vCPUs >= 64 can not be online or hotpluged.
- tsc unstable.kvmclock_init_mem()won't be called. vCPUs >= 64 can not be online or hotpluged.
It's not reasonable that vCPUs hotplug have been impacted by last 2 scenarios. Hence movekvmclock_init_mem()to front, in casehvclock_memcan not be initialized unexpectedly.Fixes 6a1cac56f41f9 (x86/kvm: Use __bss_decrypted attribute in shared variables)Cc <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Brijesh Singh <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Zelin Deng <[email protected]>--- arch/x86/kernel/kvmclock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)arch/x86/kernel/kvmclock.c +0
-0
arch/x86/kernel/kvmclock.c static int __init kvm_setup_vsyscall_timeinfo(void) · line 277
Quoted 7 lines
arch/x86/kernel/kvmclock.c +4
-0@@ -271,7 +271,14 @@ static int __init kvm_setup_vsyscall_timeinfo(void) {#ifdef CONFIG_X86_64 u8 flags; +#endif + +if (!kvmclock) +return 0 ;
Overall, I agree with the fix to move the kvmclock_init_mem() in the beginning of the function so that memory hvclock_mem is allocated. But curious, why do we need this check? The if (kvmclock) did not exist in original function and I don't think kvmclock_init_mem() has any dependency with it, am I missing something ?
Quoted 16 lines
arch/x86/kernel/kvmclock.c +3
-2+ +kvmclock_init_mem (); +#ifdef CONFIG_X86_64 if (!per_cpu (hv_clock_per_cpu,0 ) || !kvmclock_vsyscall)return 0 ;@@ -282,8 +289,6 @@ static int __init kvm_setup_vsyscall_timeinfo(void) kvm_clock.vdso_clock_mode =VDSO_CLOCKMODE_PVCLOCK ;#endif -kvmclock_init_mem (); -return 0 ; }early_initcall (kvm_setup_vsyscall_timeinfo);
Quoted 37 lines · Brijesh Singh
Quoted 35 lines · Zelin Deng
pvclock data pointers of vCPUs >=
HVC_BOOT_ARRAY_SIZE(64) are stored inhvclock_memwihch is initialized inkvmclock_init_mem(). Here're 3 scenarios in current implementation:
- no-kvmclock is set in cmdline. kvm pv clock driver is disabled, no impact.
- no-kvmclock-vsyscall is set in cmdline.kvmclock_init_mem()won't be called. No memory for storing pvclock data of vCPUs >= 64, vCPUs >= 64 can not be online or hotpluged.
- tsc unstable.kvmclock_init_mem()won't be called. vCPUs >= 64 can not be online or hotpluged.
It's not reasonable that vCPUs hotplug have been impacted by last 2 scenarios. Hence movekvmclock_init_mem()to front, in casehvclock_memcan not be initialized unexpectedly.Fixes 6a1cac56f41f9 (x86/kvm: Use __bss_decrypted attribute in shared variables)Cc <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Brijesh Singh <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Zelin Deng <[email protected]>--- arch/x86/kernel/kvmclock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)arch/x86/kernel/kvmclock.c +3
-0@@ -271,7 +271,14 @@ static int __init kvm_setup_vsyscall_timeinfo(void) {#ifdef CONFIG_X86_64 u8 flags; +#endif + +if (!kvmclock)
Quoted 10 lines
arch/x86/kernel/kvmclock.c static int __init kvm_setup_vsyscall_timeinfo(void) · line 277
Quoted 1 line
arch/x86/kernel/kvmclock.c +1
-0+return 0 ;Overall, I agree with the fix to move the
kvmclock_init_mem()in the beginning of the function so that memoryhvclock_memis allocated. But curious, why do we need this check? The if (kvmclock) did not exist in original function and I don't thinkkvmclock_init_mem()has any dependency with it, am I missing something ?
Per my under standing if "no-kvmclock" is set in cmdline, pvclock will be disabled in guest kernel kvmclock_init() just returns without doing anything right? However in this scenarios, this function still will be executed as it is a early_initcall. To avoid a waste of memory, is it reasonable to do this check?
Quoted 16 lines
Quoted 16 lines
arch/x86/kernel/kvmclock.c +3
-2+ +kvmclock_init_mem (); +#ifdef CONFIG_X86_64 if (!per_cpu (hv_clock_per_cpu,0 ) || !kvmclock_vsyscall)return 0 ;@@ -282,8 +289,6 @@ static int __init kvm_setup_vsyscall_timeinfo(void) kvm_clock.vdso_clock_mode =VDSO_CLOCKMODE_PVCLOCK ;#endif -kvmclock_init_mem (); -return 0 ; }early_initcall (kvm_setup_vsyscall_timeinfo);