Skip to content

Commit 7e548b0

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: VMX: Add a helper for NMI handling
Add a helper to handles NMI exit. TDX handles the NMI exit the same as VMX case. Add a helper to share the code with TDX, expose the helper in common.h. No functional change intended. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Co-developed-by: Binbin Wu <binbin.wu@linux.intel.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250222014757.897978-15-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d5bc91e commit 7e548b0

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

arch/x86/kvm/vmx/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,6 @@ static inline void __vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu,
177177
kvm_vcpu_trigger_posted_interrupt(vcpu, POSTED_INTR_VECTOR);
178178
}
179179

180+
noinstr void vmx_handle_nmi(struct kvm_vcpu *vcpu);
181+
180182
#endif /* __KVM_X86_VMX_COMMON_H */

arch/x86/kvm/vmx/vmx.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,6 +7214,20 @@ static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu,
72147214
}
72157215
}
72167216

7217+
noinstr void vmx_handle_nmi(struct kvm_vcpu *vcpu)
7218+
{
7219+
if ((u16)vmx_get_exit_reason(vcpu).basic != EXIT_REASON_EXCEPTION_NMI ||
7220+
!is_nmi(vmx_get_intr_info(vcpu)))
7221+
return;
7222+
7223+
kvm_before_interrupt(vcpu, KVM_HANDLING_NMI);
7224+
if (cpu_feature_enabled(X86_FEATURE_FRED))
7225+
fred_entry_from_kvm(EVENT_TYPE_NMI, NMI_VECTOR);
7226+
else
7227+
vmx_do_nmi_irqoff();
7228+
kvm_after_interrupt(vcpu);
7229+
}
7230+
72177231
static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
72187232
unsigned int flags)
72197233
{
@@ -7257,15 +7271,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
72577271
if (likely(!vmx_get_exit_reason(vcpu).failed_vmentry))
72587272
vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
72597273

7260-
if ((u16)vmx_get_exit_reason(vcpu).basic == EXIT_REASON_EXCEPTION_NMI &&
7261-
is_nmi(vmx_get_intr_info(vcpu))) {
7262-
kvm_before_interrupt(vcpu, KVM_HANDLING_NMI);
7263-
if (cpu_feature_enabled(X86_FEATURE_FRED))
7264-
fred_entry_from_kvm(EVENT_TYPE_NMI, NMI_VECTOR);
7265-
else
7266-
vmx_do_nmi_irqoff();
7267-
kvm_after_interrupt(vcpu);
7268-
}
7274+
vmx_handle_nmi(vcpu);
72697275

72707276
out:
72717277
guest_state_exit_irqoff();

0 commit comments

Comments
 (0)