return 0;
 }
 
+static void avic_ring_doorbell(struct kvm_vcpu *vcpu)
+{
+       /*
+        * 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).
+        */
+       int cpu = READ_ONCE(vcpu->cpu);
+
+       if (cpu != get_cpu())
+               wrmsrl(MSR_AMD64_SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu));
+       put_cpu();
+}
+
 static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source,
                                   u32 icrl, u32 icrh)
 {
         * automatically process AVIC interrupts at VMRUN.
         */
        if (vcpu->mode == IN_GUEST_MODE) {
-               int cpu = READ_ONCE(vcpu->cpu);
-
                /*
-                * 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).
+                * Signal the doorbell to tell hardware to inject the IRQ.  If
+                * the vCPU exits the guest before the doorbell chimes, hardware
+                * will automatically process AVIC interrupts at the next VMRUN.
                 */
-               if (cpu != get_cpu())
-                       wrmsrl(MSR_AMD64_SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu));
-               put_cpu();
+               avic_ring_doorbell(vcpu);
        } else {
                /*
                 * Wake the vCPU if it was blocking.  KVM will then detect the