Skip to content

Commit 6c441e4

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Handle EXIT_REASON_OTHER_SMI
Handle VM exit caused by "other SMI" for TDX, by returning back to userspace for Machine Check System Management Interrupt (MSMI) case or ignoring it and resume vCPU for non-MSMI case. For VMX, SMM transition can happen in both VMX non-root mode and VMX root mode. Unlike VMX, in SEAM root mode (TDX module), all interrupts are blocked. If an SMI occurs in SEAM non-root mode (TD guest), the SMI causes VM exit to TDX module, then SEAMRET to KVM. Once it exits to KVM, SMI is delivered and handled by kernel handler right away. An SMI can be "I/O SMI" or "other SMI". For TDX, there will be no I/O SMI because I/O instructions inside TDX guest trigger #VE and TDX guest needs to use TDVMCALL to request VMM to do I/O emulation. For "other SMI", there are two cases: - MSMI case. When BIOS eMCA MCE-SMI morphing is enabled, the #MC occurs in TDX guest will be delivered as an MSMI. It causes an EXIT_REASON_OTHER_SMI VM exit with MSMI (bit 0) set in the exit qualification. On VM exit, TDX module checks whether the "other SMI" is caused by an MSMI or not. If so, TDX module marks TD as fatal, preventing further TD entries, and then completes the TD exit flow to KVM with the TDH.VP.ENTER outputs indicating TDX_NON_RECOVERABLE_TD. After TD exit, the MSMI is delivered and eventually handled by the kernel machine check handler (7911f14 x86/mce: Implement recovery for errors in TDX/SEAM non-root mode), i.e., the memory page is marked as poisoned and it won't be freed to the free list when the TDX guest is terminated. Since the TDX guest is dead, follow other non-recoverable cases, exit to userspace. - For non-MSMI case, KVM doesn't need to do anything, just continue TDX vCPU execution. 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> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-ID: <20250222014757.897978-17-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f30cb64 commit 6c441e4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

arch/x86/include/uapi/asm/vmx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define EXIT_REASON_TRIPLE_FAULT 2
3535
#define EXIT_REASON_INIT_SIGNAL 3
3636
#define EXIT_REASON_SIPI_SIGNAL 4
37+
#define EXIT_REASON_OTHER_SMI 6
3738

3839
#define EXIT_REASON_INTERRUPT_WINDOW 7
3940
#define EXIT_REASON_NMI_WINDOW 8

arch/x86/kvm/vmx/tdx.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,27 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
17581758
return tdx_emulate_io(vcpu);
17591759
case EXIT_REASON_EPT_MISCONFIG:
17601760
return tdx_emulate_mmio(vcpu);
1761+
case EXIT_REASON_OTHER_SMI:
1762+
/*
1763+
* Unlike VMX, SMI in SEAM non-root mode (i.e. when
1764+
* TD guest vCPU is running) will cause VM exit to TDX module,
1765+
* then SEAMRET to KVM. Once it exits to KVM, SMI is delivered
1766+
* and handled by kernel handler right away.
1767+
*
1768+
* The Other SMI exit can also be caused by the SEAM non-root
1769+
* machine check delivered via Machine Check System Management
1770+
* Interrupt (MSMI), but it has already been handled by the
1771+
* kernel machine check handler, i.e., the memory page has been
1772+
* marked as poisoned and it won't be freed to the free list
1773+
* when the TDX guest is terminated (the TDX module marks the
1774+
* guest as dead and prevent it from further running when
1775+
* machine check happens in SEAM non-root).
1776+
*
1777+
* - A MSMI will not reach here, it's handled as non_recoverable
1778+
* case above.
1779+
* - If it's not an MSMI, no need to do anything here.
1780+
*/
1781+
return 1;
17611782
default:
17621783
break;
17631784
}

0 commit comments

Comments
 (0)