Skip to content

Commit b5861e5

Browse files
Liran Alonrkrcmar
authored andcommitted
KVM: nVMX: Fix loss of pending IRQ/NMI before entering L2
Consider the case L1 had a IRQ/NMI event until it executed VMLAUNCH/VMRESUME which wasn't delivered because it was disallowed (e.g. interrupts disabled). When L1 executes VMLAUNCH/VMRESUME, L0 needs to evaluate if this pending event should cause an exit from L2 to L1 or delivered directly to L2 (e.g. In case L1 don't intercept EXTERNAL_INTERRUPT). Usually this would be handled by L0 requesting a IRQ/NMI window by setting VMCS accordingly. However, this setting was done on VMCS01 and now VMCS02 is active instead. Thus, when L1 executes VMLAUNCH/VMRESUME we force L0 to perform pending event evaluation by requesting a KVM_REQ_EVENT. Note that above scenario exists when L1 KVM is about to enter L2 but requests an "immediate-exit". As in this case, L1 will disable-interrupts and then send a self-IPI before entering L2. Reviewed-by: Nikita Leshchenko <nikita.leshchenko@oracle.com> Co-developed-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Liran Alon <liran.alon@oracle.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
1 parent 564ad0a commit b5861e5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

arch/x86/kvm/vmx.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12537,8 +12537,11 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
1253712537
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
1253812538
bool from_vmentry = !!exit_qual;
1253912539
u32 dummy_exit_qual;
12540+
u32 vmcs01_cpu_exec_ctrl;
1254012541
int r = 0;
1254112542

12543+
vmcs01_cpu_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
12544+
1254212545
enter_guest_mode(vcpu);
1254312546

1254412547
if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
@@ -12574,6 +12577,25 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
1257412577
kvm_make_request(KVM_REQ_GET_VMCS12_PAGES, vcpu);
1257512578
}
1257612579

12580+
/*
12581+
* If L1 had a pending IRQ/NMI until it executed
12582+
* VMLAUNCH/VMRESUME which wasn't delivered because it was
12583+
* disallowed (e.g. interrupts disabled), L0 needs to
12584+
* evaluate if this pending event should cause an exit from L2
12585+
* to L1 or delivered directly to L2 (e.g. In case L1 don't
12586+
* intercept EXTERNAL_INTERRUPT).
12587+
*
12588+
* Usually this would be handled by L0 requesting a
12589+
* IRQ/NMI window by setting VMCS accordingly. However,
12590+
* this setting was done on VMCS01 and now VMCS02 is active
12591+
* instead. Thus, we force L0 to perform pending event
12592+
* evaluation by requesting a KVM_REQ_EVENT.
12593+
*/
12594+
if (vmcs01_cpu_exec_ctrl &
12595+
(CPU_BASED_VIRTUAL_INTR_PENDING | CPU_BASED_VIRTUAL_NMI_PENDING)) {
12596+
kvm_make_request(KVM_REQ_EVENT, vcpu);
12597+
}
12598+
1257712599
/*
1257812600
* Note no nested_vmx_succeed or nested_vmx_fail here. At this point
1257912601
* we are no longer running L1, and VMLAUNCH/VMRESUME has not yet

0 commit comments

Comments
 (0)