From 6149d8a244d58da6c8fb84220370ca2275720091 Mon Sep 17 00:00:00 2001 From: Yihao Wu Date: Mon, 4 Jan 2021 17:48:26 +0800 Subject: [PATCH 2515/2944] alinux: locking/qspinlock/x86: Fix performance regression caused by virt_spin_lock fix #31434803 commit 9043442b43b1 ("locking/paravirt: Use new static key for controlling call of virt_spin_lock()") was intended to address the performance issue on baremetal machine ( or dedicated VM ). Because in these two situations, qspinlock is preferred rather than trivial cmpxchg. The intention is good but didn't apply to our environment. 9043442b431 uses KVM_HINTS_REALTIME to know if it's baremetal or dedicated. But we uses KVM_FEATURE_PV_UNHALT to do the same thing. So virt_spin_lock always gets to run, because it always treat our environment as non-baremetal, non-dedicated. Huge performance loss is resulted from this path. Signed-off-by: Yihao Wu Reviewed-by: Artie Ding --- arch/x86/kernel/kvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index cee45d4..bc174c0 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -543,7 +543,8 @@ static void kvm_setup_pv_ipi(void) static void __init kvm_smp_prepare_cpus(unsigned int max_cpus) { native_smp_prepare_cpus(max_cpus); - if (kvm_para_has_hint(KVM_HINTS_REALTIME)) + if (kvm_para_has_hint(KVM_HINTS_REALTIME) || + !kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) static_branch_disable(&virt_spin_lock_key); } -- 1.8.3.1