diff options
Diffstat (limited to 'meta-amd-bsp/recipes-kernel/linux/linux-yocto-5.15/0044-KVM-SVM-Ensure-target-pCPU-is-read-once-when-signall.patch')
-rw-r--r-- | meta-amd-bsp/recipes-kernel/linux/linux-yocto-5.15/0044-KVM-SVM-Ensure-target-pCPU-is-read-once-when-signall.patch | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/meta-amd-bsp/recipes-kernel/linux/linux-yocto-5.15/0044-KVM-SVM-Ensure-target-pCPU-is-read-once-when-signall.patch b/meta-amd-bsp/recipes-kernel/linux/linux-yocto-5.15/0044-KVM-SVM-Ensure-target-pCPU-is-read-once-when-signall.patch new file mode 100644 index 00000000..8fb738a3 --- /dev/null +++ b/meta-amd-bsp/recipes-kernel/linux/linux-yocto-5.15/0044-KVM-SVM-Ensure-target-pCPU-is-read-once-when-signall.patch @@ -0,0 +1,58 @@ +From 2f27ec6013d852b663320f5bc9e31f44e19ea974 Mon Sep 17 00:00:00 2001 +From: Sean Christopherson <seanjc@google.com> +Date: Fri, 8 Oct 2021 19:11:55 -0700 +Subject: [PATCH 44/86] KVM: SVM: Ensure target pCPU is read once when + signalling AVIC doorbell + +commit 91b01895071770ed0c256869d0f94d69a2fb8ecf upstream + +Ensure vcpu->cpu is read once when signalling the AVIC doorbell. If the +compiler rereads the field and the vCPU is migrated between the check and +writing the doorbell, KVM would signal the wrong physical CPU. + +Functionally, signalling the wrong CPU in this case is not an issue as +task migration means the vCPU has exited and will pick up any pending +interrupts on the next VMRUN. Add the READ_ONCE() purely to clean up the +code. + +Opportunistically add a comment explaining the task migration behavior, +and rename cpuid=>cpu to avoid conflating the CPU number with KVM's more +common usage of CPUID. + +Signed-off-by: Sean Christopherson <seanjc@google.com> +Message-Id: <20211009021236.4122790-3-seanjc@google.com> +Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> +Signed-off-by: Zhaolong Zhang <zhaolong.zhang@windriver.com> +--- + arch/x86/kvm/svm/avic.c | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c +index 3d3f8dfb8045..f535918220ec 100644 +--- a/arch/x86/kvm/svm/avic.c ++++ b/arch/x86/kvm/svm/avic.c +@@ -673,10 +673,18 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) + smp_mb__after_atomic(); + + if (avic_vcpu_is_running(vcpu)) { +- int cpuid = vcpu->cpu; ++ int cpu = READ_ONCE(vcpu->cpu); + +- if (cpuid != get_cpu()) +- wrmsrl(SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpuid)); ++ /* ++ * Note, the vCPU could get migrated to a different pCPU at any ++ * point, which could result in signalling the wrong/previous ++ * pCPU. But if that happens the vCPU is guaranteed to do a ++ * VMRUN (after being migrated) and thus will process pending ++ * interrupts, i.e. a doorbell is not needed (and the spurious ++ * one is harmless). ++ */ ++ if (cpu != get_cpu()) ++ wrmsrl(SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu)); + put_cpu(); + } else + kvm_vcpu_wake_up(vcpu); +-- +2.37.3 + |