Skip to content

Commit c829d2c

Browse files
committed
KVM: nVMX: Use vmcs01's controls shadow to check for IRQ/NMI windows at VM-Enter
Use vmcs01's execution controls shadow to check for IRQ/NMI windows after a successful nested VM-Enter, instead of snapshotting the information prior to emulating VM-Enter. It's quite difficult to see that the entire reason controls are snapshot prior nested VM-Enter is to read them from vmcs01 (vmcs02 is loaded if nested VM-Enter is successful). That could be solved with a comment, but explicitly using vmcs01's shadow makes the code self-documenting to a certain extent. No functional change intended (vmcs01's execution controls must not be modified during emulation of nested VM-Enter). Link: https://lore.kernel.org/r/20241101191447.1807602-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b2868b5 commit c829d2c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
35003500
struct vcpu_vmx *vmx = to_vmx(vcpu);
35013501
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
35023502
enum vm_entry_failure_code entry_failure_code;
3503-
bool evaluate_pending_interrupts;
35043503
union vmx_exit_reason exit_reason = {
35053504
.basic = EXIT_REASON_INVALID_STATE,
35063505
.failed_vmentry = 1,
@@ -3519,9 +3518,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
35193518

35203519
kvm_service_local_tlb_flush_requests(vcpu);
35213520

3522-
evaluate_pending_interrupts = exec_controls_get(vmx) &
3523-
(CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING);
3524-
35253521
if (!vmx->nested.nested_run_pending ||
35263522
!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
35273523
vmx->nested.pre_vmenter_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
@@ -3604,9 +3600,11 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
36043600
* Re-evaluate pending events if L1 had a pending IRQ/NMI/INIT/SIPI
36053601
* when it executed VMLAUNCH/VMRESUME, as entering non-root mode can
36063602
* effectively unblock various events, e.g. INIT/SIPI cause VM-Exit
3607-
* unconditionally.
3603+
* unconditionally. Take care to pull data from vmcs01 as appropriate,
3604+
* e.g. when checking for interrupt windows, as vmcs02 is now loaded.
36083605
*/
3609-
if (unlikely(evaluate_pending_interrupts) ||
3606+
if ((__exec_controls_get(&vmx->vmcs01) & (CPU_BASED_INTR_WINDOW_EXITING |
3607+
CPU_BASED_NMI_WINDOW_EXITING)) ||
36103608
kvm_apic_has_pending_init_or_sipi(vcpu) ||
36113609
kvm_apic_has_interrupt(vcpu))
36123610
kvm_make_request(KVM_REQ_EVENT, vcpu);

0 commit comments

Comments
 (0)