]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: VMX: Handle #MCs on VM-Enter/TD-Enter outside of the fastpath
authorSean Christopherson <seanjc@google.com>
Tue, 18 Nov 2025 22:23:26 +0000 (14:23 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 19 Nov 2025 13:40:52 +0000 (05:40 -0800)
commit63669bd1d50f0b5cdb7bb390a0955b7b26821152
tree492ce84fd7328aacbdce73f7bcd46216211aa1f0
parentebd1a336550096bf7543699bab2e89fa401deac6
KVM: VMX: Handle #MCs on VM-Enter/TD-Enter outside of the fastpath

Handle Machine Checks (#MC) that happen on VM-Enter (VMX or TDX) outside
of KVM's fastpath so that as much host state as possible is re-loaded
before invoking the kernel's #MC handler.  The only requirement is that
KVM invokes the #MC handler before enabling IRQs (and even that could
_probably_ be related to handling #MCs before enabling preemption).

Waiting to handle #MCs until "more" host state is loaded hardens KVM
against flaws in the #MC handler, which has historically been quite
brittle. E.g. prior to commit 5567d11c21a1 ("x86/mce: Send #MC singal from
task work"), the #MC code could trigger a schedule() with IRQs and
preemption disabled.  That led to a KVM hack-a-fix in commit 1811d979c716
("x86/kvm: move kvm_load/put_guest_xcr0 into atomic context").

Note, vmx_handle_exit_irqoff() is common to VMX and TDX guests.

Cc: Tony Lindgren <tony.lindgren@linux.intel.com>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: Jon Kohler <jon@nutanix.com>
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Link: https://patch.msgid.link/20251118222328.2265758-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/tdx.c
arch/x86/kvm/vmx/vmx.c