Skip to content

Commit 7cfc5c6

Browse files
committed
KVM: fix avic_set_running for preemptable kernels
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: 8221c13 ("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>
1 parent e90e51d commit 7cfc5c6

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

arch/x86/kvm/svm/avic.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -989,16 +989,18 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
989989
static void avic_set_running(struct kvm_vcpu *vcpu, bool is_run)
990990
{
991991
struct vcpu_svm *svm = to_svm(vcpu);
992+
int cpu = get_cpu();
992993

994+
WARN_ON(cpu != vcpu->cpu);
993995
svm->avic_is_running = is_run;
994996

995-
if (!kvm_vcpu_apicv_active(vcpu))
996-
return;
997-
998-
if (is_run)
999-
avic_vcpu_load(vcpu, vcpu->cpu);
1000-
else
1001-
avic_vcpu_put(vcpu);
997+
if (kvm_vcpu_apicv_active(vcpu)) {
998+
if (is_run)
999+
avic_vcpu_load(vcpu, cpu);
1000+
else
1001+
avic_vcpu_put(vcpu);
1002+
}
1003+
put_cpu();
10021004
}
10031005

10041006
void svm_vcpu_blocking(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)