Skip to content

Commit 5faaffa

Browse files
sashukla1sean-jc
authored andcommitted
KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR
Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting virtual interrupts in order to request an interrupt window, as KVM has usurped vmcb02's int_ctl. If an interrupt window opens before the next VM-Exit, svm_clear_vintr() will restore vmcb12's int_ctl. If no window opens, V_IRQ will be correctly preserved in vmcb12's int_ctl (because it was never recognized while L2 was running). Suggested-by: Sean Christopherson <seanjc@google.com> Link: https://lkml.kernel.org/r/Y9hybI65So5X2LFg%40google.com Signed-off-by: Santosh Shukla <Santosh.Shukla@amd.com> Link: https://lore.kernel.org/r/20230227084016.3368-2-santosh.shukla@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent d8708b8 commit 5faaffa

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,17 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *svm)
416416

417417
/* Only a few fields of int_ctl are written by the processor. */
418418
mask = V_IRQ_MASK | V_TPR_MASK;
419-
if (!(svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK) &&
420-
svm_is_intercept(svm, INTERCEPT_VINTR)) {
421-
/*
422-
* In order to request an interrupt window, L0 is usurping
423-
* svm->vmcb->control.int_ctl and possibly setting V_IRQ
424-
* even if it was clear in L1's VMCB. Restoring it would be
425-
* wrong. However, in this case V_IRQ will remain true until
426-
* interrupt_window_interception calls svm_clear_vintr and
427-
* restores int_ctl. We can just leave it aside.
428-
*/
419+
/*
420+
* Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting
421+
* virtual interrupts in order to request an interrupt window, as KVM
422+
* has usurped vmcb02's int_ctl. If an interrupt window opens before
423+
* the next VM-Exit, svm_clear_vintr() will restore vmcb12's int_ctl.
424+
* If no window opens, V_IRQ will be correctly preserved in vmcb12's
425+
* int_ctl (because it was never recognized while L2 was running).
426+
*/
427+
if (svm_is_intercept(svm, INTERCEPT_VINTR) &&
428+
!test_bit(INTERCEPT_VINTR, (unsigned long *)svm->nested.ctl.intercepts))
429429
mask &= ~V_IRQ_MASK;
430-
}
431430

432431
if (nested_vgif_enabled(svm))
433432
mask |= V_GIF_MASK;

0 commit comments

Comments
 (0)