Skip to content

Commit d7eb79c

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged
# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 88 On-line CPU(s) list: 0-63 Off-line CPU(s) list: 64-87 # cat /proc/cmdline BOOT_IMAGE=/vmlinuz-5.10.0-rc3-tlinux2-0050+ root=/dev/mapper/cl-root ro rd.lvm.lv=cl/root rhgb quiet console=ttyS0 LANG=en_US .UTF-8 no-kvmclock-vsyscall # echo 1 > /sys/devices/system/cpu/cpu76/online -bash: echo: write error: Cannot allocate memory The per-cpu vsyscall pvclock data pointer assigns either an element of the static array hv_clock_boot (#vCPU <= 64) or dynamically allocated memory hvclock_mem (vCPU > 64), the dynamically memory will not be allocated if kvmclock vsyscall is disabled, this can result in cpu hotpluged fails in kvmclock_setup_percpu() which returns -ENOMEM. It's broken for no-vsyscall and sometimes you end up with vsyscall disabled if the host does something strange. This patch fixes it by allocating this dynamically memory unconditionally even if vsyscall is disabled. Fixes: 6a1cac5 ("x86/kvm: Use __bss_decrypted attribute in shared variables") Reported-by: Zelin Deng <zelin.deng@linux.alibaba.com> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: stable@vger.kernel.org#v4.19-rc5+ Signed-off-by: Wanpeng Li <wanpengli@tencent.com> Message-Id: <1614130683-24137-1-git-send-email-wanpengli@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6fcd9cb commit d7eb79c

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

arch/x86/kernel/kvmclock.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,20 @@ static void __init kvmclock_init_mem(void)
268268

269269
static int __init kvm_setup_vsyscall_timeinfo(void)
270270
{
271-
#ifdef CONFIG_X86_64
272-
u8 flags;
271+
kvmclock_init_mem();
273272

274-
if (!per_cpu(hv_clock_per_cpu, 0) || !kvmclock_vsyscall)
275-
return 0;
273+
#ifdef CONFIG_X86_64
274+
if (per_cpu(hv_clock_per_cpu, 0) && kvmclock_vsyscall) {
275+
u8 flags;
276276

277-
flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
278-
if (!(flags & PVCLOCK_TSC_STABLE_BIT))
279-
return 0;
277+
flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
278+
if (!(flags & PVCLOCK_TSC_STABLE_BIT))
279+
return 0;
280280

281-
kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
281+
kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
282+
}
282283
#endif
283284

284-
kvmclock_init_mem();
285-
286285
return 0;
287286
}
288287
early_initcall(kvm_setup_vsyscall_timeinfo);

0 commit comments

Comments
 (0)