]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
x86/virt/tdx: Pull kexec cache flush logic into arch/x86
authorRick Edgecombe <rick.p.edgecombe@intel.com>
Thu, 2 Apr 2026 06:32:02 +0000 (00:32 -0600)
committerDave Hansen <dave.hansen@linux.intel.com>
Mon, 27 Apr 2026 22:13:38 +0000 (15:13 -0700)
commit597bdf6e068e2c8f6e93f24bf39a34cdf017481f
treec55189198b2a5bc41bbe8d6b4f8ae295d5608c5a
parent53642715861e838f328a3fbef99a1d315955221a
x86/virt/tdx: Pull kexec cache flush logic into arch/x86

KVM tries to take care of some required cache flushing earlier in the
kexec path in order to be kind to some long standing races that can occur
later in the operation. Until recently, VMXOFF was handled within KVM.
Since VMX being enabled is required to make a SEAMCALL, it had the best
per-cpu scoped operation to plug the flushing into. So it is kicked off
from there.

This early kexec cache flushing in KVM happens via a syscore shutdown
callback. Now that VMX enablement control has moved to arch/x86, which has
grown its own syscore shutdown callback, it no longer make sense for it to
live in KVM. It fits better with the TDX enablement managing code.

In addition, future changes will add a SEAMCALL that happens immediately
before VMXOFF, which means the cache flush in KVM will be too late to
flush the cache before the last SEAMCALL. So move it to the newly added TDX
arch/x86 syscore shutdown handler.

Since tdx_cpu_flush_cache_for_kexec() is no longer needed by KVM, make it
static and remove the export. Since it is also not part of an operation
spread across disparate components, remove the redundant comments and
verbose naming.

In the existing KVM based code, CPU offline also funnels through
tdx_cpu_flush_cache_for_kexec(). Add an explicit WBINVD in
tdx_offline_cpu() as well, even though it may be redundant with WBINVD
done elsewhere during CPU offline (e.g. hlt_play_dead()). This avoids
relying on fragile code ordering for cache coherency safety.

[Vishal: add explicit WBINVD in tdx_offline_cpu()]

Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Chao Gao <chao.gao@intel.com>
Acked-by: Kai Huang <kai.huang@intel.com>
Acked-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Acked-by: Sean Christopherson <seanjc@google.com>
Link: https://patch.msgid.link/20260402-fuller_tdx_kexec_support-v3-2-34438d7094bf@intel.com
arch/x86/include/asm/tdx.h
arch/x86/kvm/vmx/tdx.c
arch/x86/virt/vmx/tdx/tdx.c