KVM: fix avic_set_running for preemptable kernels
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 30 Nov 2021 08:46:07 +0000 (03:46 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Dec 2021 08:04:43 +0000 (09:04 +0100)
commitf1a1693ea4e2646280a618e52e8ae33f44e64744
treeb68bb0794aaa451003ff583f9f37e5cc8773567b
parent245241821ecf73a80e398f835d5510a9a80f6d31
KVM: fix avic_set_running for preemptable kernels

commit 7cfc5c653b07782e7059527df8dc1e3143a7591e upstream.

avic_set_running() passes the current CPU to avic_vcpu_load(), albeit
via vcpu->cpu rather than smp_processor_id().  If the thread is migrated
while avic_set_running runs, the call to avic_vcpu_load() can use a stale
value for the processor id.  Avoid this by blocking preemption over the
entire execution of avic_set_running().

Reported-by: Sean Christopherson <seanjc@google.com>
Fixes: 8221c1370056 ("svm: Manage vcpu load/unload when enable AVIC")
Cc: stable@vger.kernel.org
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/svm/avic.c