Skip to content

Commit 52d826c

Browse files
committed
KVM: SVM: Add a comment to explain why avic_vcpu_blocking() ignores IRQ blocking
Add a comment to explain why KVM clears IsRunning when putting a vCPU, even though leaving IsRunning=1 would be ok from a functional perspective. Per Maxim's experiments, a misbehaving VM could spam the AVIC doorbell so fast as to induce a 50%+ loss in performance. Link: https://lore.kernel.org/all/8d7e0d0391df4efc7cb28557297eb2ec9904f1e5.camel@redhat.com Cc: Maxim Levitsky <mlevitsk@redhat.com> Acked-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://lore.kernel.org/r/20250611224604.313496-22-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6737557 commit 52d826c

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,19 +1122,24 @@ void avic_vcpu_blocking(struct kvm_vcpu *vcpu)
11221122
if (!kvm_vcpu_apicv_active(vcpu))
11231123
return;
11241124

1125-
/*
1126-
* Unload the AVIC when the vCPU is about to block, _before_
1127-
* the vCPU actually blocks.
1128-
*
1129-
* Any IRQs that arrive before IsRunning=0 will not cause an
1130-
* incomplete IPI vmexit on the source, therefore vIRR will also
1131-
* be checked by kvm_vcpu_check_block() before blocking. The
1132-
* memory barrier implicit in set_current_state orders writing
1133-
* IsRunning=0 before reading the vIRR. The processor needs a
1134-
* matching memory barrier on interrupt delivery between writing
1135-
* IRR and reading IsRunning; the lack of this barrier might be
1136-
* the cause of errata #1235).
1137-
*/
1125+
/*
1126+
* Unload the AVIC when the vCPU is about to block, _before_ the vCPU
1127+
* actually blocks.
1128+
*
1129+
* Note, any IRQs that arrive before IsRunning=0 will not cause an
1130+
* incomplete IPI vmexit on the source; kvm_vcpu_check_block() handles
1131+
* this by checking vIRR one last time before blocking. The memory
1132+
* barrier implicit in set_current_state orders writing IsRunning=0
1133+
* before reading the vIRR. The processor needs a matching memory
1134+
* barrier on interrupt delivery between writing IRR and reading
1135+
* IsRunning; the lack of this barrier might be the cause of errata #1235).
1136+
*
1137+
* Clear IsRunning=0 even if guest IRQs are disabled, i.e. even if KVM
1138+
* doesn't need to detect events for scheduling purposes. The doorbell
1139+
* used to signal running vCPUs cannot be blocked, i.e. will perturb the
1140+
* CPU and cause noisy neighbor problems if the VM is sending interrupts
1141+
* to the vCPU while it's scheduled out.
1142+
*/
11381143
avic_vcpu_put(vcpu);
11391144
}
11401145

0 commit comments

Comments
 (0)