[PATCH v4] x86/virt/tdx: Skip TDH.SYS.DISABLE if the TDX module is not initialized

From: Challvy Tee

Date: Mon Nov 02 2026 - 02:37:00 EST


Commit 5b25f249be32 ("x86/tdx: Disable the TDX module during kexec and
kdump") made native_machine_crash_shutdown() call tdx_sys_disable(),
whose only gate is compile time (CONFIG_INTEL_TDX_HOST). A kernel that
never initialized the TDX module therefore still issues
TDH.SYS.DISABLE.

In VMX non-root operation on a SEAM-capable host, SEAMCALL causes a VM
exit instead of a native #UD. KVM injects #UD only since
commit 9d7dfb95da2c ("KVM: VMX: Inject #UD if guest tries to execute
SEAMCALL or TDCALL"), first released in v6.18. On an older host the
VMM gets KVM_EXIT_INTERNAL_ERROR and the vCPU never resumes, so
machine_kexec() is never reached and no vmcore is written. Kdump is
thus broken only in guests on SEAM-capable hosts whose hypervisor does
not handle the exit; plain kexec is unaffected because tdx_shutdown()
only runs as a syscore op, registered after init_tdx_module() succeeds.

Gate the SEAMCALL on X86_FEATURE_TDX_HOST_PLATFORM before issuing it,
the way paddr_is_tdx_private() already guards its own SEAMCALL in this
file. Without that feature the module is never initialized, so there
is nothing to disable; on a TDX host the gate is a no-op.

It also decouples kdump from the host KVM version -- a guest cannot
require its host to inject the #UD.

Fixes: 5b25f249be32 ("x86/tdx: Disable the TDX module during kexec and kdump")
Suggested-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Challvy Tee <challvy.tee@xxxxxxxxx>
---
v3 -> v4:
- Gate on X86_FEATURE_TDX_HOST_PLATFORM instead of
tdx_module_state.initialized, guarding the SEAMCALL itself the way
paddr_is_tdx_private() already does, as suggested in review.
- Drop the v3 rationale about covering the syscore and future callers.
- Retested with this predicate: kdump produces a vmcore on the
Alibaba ECS Emerald Rapids guest (6.12.0-278.el10 base).
v3: https://lore.kernel.org/all/20261030154851.907726-1-challvy.tee@xxxxxxxxx/

Hypervisor -- KVM on all five (CPUID leaf 0x40000000), across three
clouds: Alibaba Cloud ECS, AWS EC2 and Tencent Cloud CVM.

Host log -- yes, from the Alibaba ECS host of the Emerald Rapids guest:

KVM internal error. Suberror: 4
extra data[0]: 4c
extra data[1]: 2f
RAX=0000000000000045 RDI=0000000000000045 RIP=ffffffff855422fe
R12=8000020300000000 R13=8000000300000000 R14=8000020200000000
Code=... 4c 8b 5e 28 <66> 0f 01 cf 72 05 ...
check runstate transition: 'running' -> 'internal-error'

Suberror 4 is KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON; the two data
words are the exit reason (0x4c = EXIT_REASON_SEAMCALL) and
last_vmentry_cpu, i.e. kvm_prepare_unexpected_reason_exit().

RAX and RDI hold 0x45 = TDH_SYS_DISABLE and RIP is at the '66 0f 01 cf'
SEAMCALL opcode in __seamcall. RAX still holds the input leaf rather
than a status code: the SEAMCALL never returned.

Reproduced with 'echo c > /proc/sysrq-trigger'. All five have
CONFIG_INTEL_TDX_HOST=y, kexec_crash_loaded=1, a kernel changelog
naming both backported commits, and "TDX not supported by the host
platform" in dmesg:

Microarch x86_vfm Cloud Kernel echo c
Sapphire Rapids 0x68F AWS EC2 6.12.0-278.el10 no vmcore
Granite Rapids 0x6AD AWS EC2 6.12.0-278.el10 no vmcore
Emerald Rapids 0x6CF Alibaba ECS 6.12.0-278.el10 no vmcore
Granite Rapids 0x6AD Alibaba ECS 6.12.0-278.el10 no vmcore
Granite Rapids 0x6AD Tencent CVM 6.12.0-278.el10 no vmcore

That dmesg line is printed by tdx_enable() when
X86_FEATURE_TDX_HOST_PLATFORM is clear, so the feature this patch tests
is absent on all five.

Controls, each producing a vmcore: the same platform on a kernel
without 5b25f249be32 (tdx_sys_disable absent from kallsyms), platforms
without SEAM support (Skylake, Cascade Lake, Ice Lake, AMD), and plain
kexec.

With the gate applied kdump produces a vmcore on the Alibaba ECS
Emerald Rapids guest, retested with this predicate. The Granite
Rapids guest was verified with the v3 predicate and not re-run; the
AWS and Tencent guests are reproduction evidence only. No TDX host was
available, so the no-op case is reasoned from the code, not measured.

arch/x86/virt/vmx/tdx/tdx.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 96ced0494b68..9b01131f7b7b 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -2321,6 +2321,9 @@ void tdx_sys_disable(void)
struct tdx_module_args args = {};
u64 ret;

+ if (!boot_cpu_has(X86_FEATURE_TDX_HOST_PLATFORM))
+ return;
+
/*
* Don't loop forever.
*
--
2.52.0