* [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged
@ 2021-02-24 1:37 Wanpeng Li
2021-03-11 3:08 ` Wanpeng Li
2021-03-12 18:18 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Wanpeng Li @ 2021-02-24 1:37 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel, Brijesh Singh
From: Wanpeng Li <wanpengli@tencent.com>
# 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: 6a1cac56f4 ("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>
---
v3 -> v4:
* fix kernel test robot report WARNING
v2 -> v3:
* allocate dynamically memory unconditionally
v1 -> v2:
* add code comments
arch/x86/kernel/kvmclock.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index aa59374..1fc0962 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -268,21 +268,20 @@ static void __init kvmclock_init_mem(void)
static int __init kvm_setup_vsyscall_timeinfo(void)
{
-#ifdef CONFIG_X86_64
- u8 flags;
+ kvmclock_init_mem();
- if (!per_cpu(hv_clock_per_cpu, 0) || !kvmclock_vsyscall)
- return 0;
+#ifdef CONFIG_X86_64
+ if (per_cpu(hv_clock_per_cpu, 0) && kvmclock_vsyscall) {
+ u8 flags;
- flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
- if (!(flags & PVCLOCK_TSC_STABLE_BIT))
- return 0;
+ flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
+ if (!(flags & PVCLOCK_TSC_STABLE_BIT))
+ return 0;
- kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
+ kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
+ }
#endif
- kvmclock_init_mem();
-
return 0;
}
early_initcall(kvm_setup_vsyscall_timeinfo);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged
2021-02-24 1:37 [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged Wanpeng Li
@ 2021-03-11 3:08 ` Wanpeng Li
2021-03-12 18:18 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Wanpeng Li @ 2021-03-11 3:08 UTC (permalink / raw)
To: LKML, kvm
Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel, Brijesh Singh
ping, :)
On Wed, 24 Feb 2021 at 09:38, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> From: Wanpeng Li <wanpengli@tencent.com>
>
> # 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: 6a1cac56f4 ("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>
> ---
> v3 -> v4:
> * fix kernel test robot report WARNING
> v2 -> v3:
> * allocate dynamically memory unconditionally
> v1 -> v2:
> * add code comments
>
> arch/x86/kernel/kvmclock.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
> index aa59374..1fc0962 100644
> --- a/arch/x86/kernel/kvmclock.c
> +++ b/arch/x86/kernel/kvmclock.c
> @@ -268,21 +268,20 @@ static void __init kvmclock_init_mem(void)
>
> static int __init kvm_setup_vsyscall_timeinfo(void)
> {
> -#ifdef CONFIG_X86_64
> - u8 flags;
> + kvmclock_init_mem();
>
> - if (!per_cpu(hv_clock_per_cpu, 0) || !kvmclock_vsyscall)
> - return 0;
> +#ifdef CONFIG_X86_64
> + if (per_cpu(hv_clock_per_cpu, 0) && kvmclock_vsyscall) {
> + u8 flags;
>
> - flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
> - if (!(flags & PVCLOCK_TSC_STABLE_BIT))
> - return 0;
> + flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
> + if (!(flags & PVCLOCK_TSC_STABLE_BIT))
> + return 0;
>
> - kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
> + kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
> + }
> #endif
>
> - kvmclock_init_mem();
> -
> return 0;
> }
> early_initcall(kvm_setup_vsyscall_timeinfo);
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged
2021-02-24 1:37 [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged Wanpeng Li
2021-03-11 3:08 ` Wanpeng Li
@ 2021-03-12 18:18 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-03-12 18:18 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel, kvm
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, Brijesh Singh
On 24/02/21 02:37, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> # 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: 6a1cac56f4 ("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>
> ---
> v3 -> v4:
> * fix kernel test robot report WARNING
> v2 -> v3:
> * allocate dynamically memory unconditionally
> v1 -> v2:
> * add code comments
>
> arch/x86/kernel/kvmclock.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
> index aa59374..1fc0962 100644
> --- a/arch/x86/kernel/kvmclock.c
> +++ b/arch/x86/kernel/kvmclock.c
> @@ -268,21 +268,20 @@ static void __init kvmclock_init_mem(void)
>
> static int __init kvm_setup_vsyscall_timeinfo(void)
> {
> -#ifdef CONFIG_X86_64
> - u8 flags;
> + kvmclock_init_mem();
>
> - if (!per_cpu(hv_clock_per_cpu, 0) || !kvmclock_vsyscall)
> - return 0;
> +#ifdef CONFIG_X86_64
> + if (per_cpu(hv_clock_per_cpu, 0) && kvmclock_vsyscall) {
> + u8 flags;
>
> - flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
> - if (!(flags & PVCLOCK_TSC_STABLE_BIT))
> - return 0;
> + flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
> + if (!(flags & PVCLOCK_TSC_STABLE_BIT))
> + return 0;
>
> - kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
> + kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
> + }
> #endif
>
> - kvmclock_init_mem();
> -
> return 0;
> }
> early_initcall(kvm_setup_vsyscall_timeinfo);
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-12 18:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 1:37 [PATCH v4] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged Wanpeng Li
2021-03-11 3:08 ` Wanpeng Li
2021-03-12 18:18 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).