Skip to content

Commit 0a5f784

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: SVM: extract avic_ring_doorbell
The check on the current CPU adds an extra level of indentation to svm_deliver_avic_intr and conflates documentation on what happens if the vCPU exits (of interest to svm_deliver_avic_intr) and migrates (only of interest to avic_ring_doorbell, which calls get/put_cpu()). Extract the wrmsr to a separate function and rewrite the comment in svm_deliver_avic_intr(). Co-developed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0316dbb commit 0a5f784

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,22 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)
269269
return 0;
270270
}
271271

272+
static void avic_ring_doorbell(struct kvm_vcpu *vcpu)
273+
{
274+
/*
275+
* Note, the vCPU could get migrated to a different pCPU at any point,
276+
* which could result in signalling the wrong/previous pCPU. But if
277+
* that happens the vCPU is guaranteed to do a VMRUN (after being
278+
* migrated) and thus will process pending interrupts, i.e. a doorbell
279+
* is not needed (and the spurious one is harmless).
280+
*/
281+
int cpu = READ_ONCE(vcpu->cpu);
282+
283+
if (cpu != get_cpu())
284+
wrmsrl(MSR_AMD64_SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu));
285+
put_cpu();
286+
}
287+
272288
static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source,
273289
u32 icrl, u32 icrh)
274290
{
@@ -669,19 +685,12 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)
669685
* automatically process AVIC interrupts at VMRUN.
670686
*/
671687
if (vcpu->mode == IN_GUEST_MODE) {
672-
int cpu = READ_ONCE(vcpu->cpu);
673-
674688
/*
675-
* Note, the vCPU could get migrated to a different pCPU at any
676-
* point, which could result in signalling the wrong/previous
677-
* pCPU. But if that happens the vCPU is guaranteed to do a
678-
* VMRUN (after being migrated) and thus will process pending
679-
* interrupts, i.e. a doorbell is not needed (and the spurious
680-
* one is harmless).
689+
* Signal the doorbell to tell hardware to inject the IRQ. If
690+
* the vCPU exits the guest before the doorbell chimes, hardware
691+
* will automatically process AVIC interrupts at the next VMRUN.
681692
*/
682-
if (cpu != get_cpu())
683-
wrmsrl(MSR_AMD64_SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu));
684-
put_cpu();
693+
avic_ring_doorbell(vcpu);
685694
} else {
686695
/*
687696
* Wake the vCPU if it was blocking. KVM will then detect the

0 commit comments

Comments
 (0)