From: "Huang, Kai" <kai.huang@intel.com>
To: "tglx@kernel.org" <tglx@kernel.org>,
"Hansen, Dave" <dave.hansen@intel.com>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
"bp@alien8.de" <bp@alien8.de>, "kas@kernel.org" <kas@kernel.org>,
"seanjc@google.com" <seanjc@google.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"ackerleytng@google.com" <ackerleytng@google.com>,
"Gao, Chao" <chao.gao@intel.com>
Cc: "Verma, Vishal L" <vishal.l.verma@intel.com>
Subject: Re: [PATCH 2/4] x86/virt/tdx: Pull kexec cache flush logic into arch/x86
Date: Mon, 9 Mar 2026 00:23:25 +0000 [thread overview]
Message-ID: <d16e808b16d9c23f7db34e576c4dd82eb9772831.camel@intel.com> (raw)
In-Reply-To: <20260307010358.819645-3-rick.p.edgecombe@intel.com>
On Fri, 2026-03-06 at 17:03 -0800, Rick Edgecombe wrote:
> 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.
>
> 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 be
> helpful. So move it to the newly added TDX arch/x86 syscore shutdown
> handler.
Nit: I am not sure how to interpret "too late to be helpful". I think we
can just get rid of this paragraph.
>
> 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.
>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Feel free to add:
Acked-by: Kai Huang <kai.huang@intel.com>
Btw, there's a functional change here, and perhaps we should call out in
changelog:
- Currently tdx_cpu_flush_cache_for_kexec() is done in
kvm_disable_virtualization_cpu(), which is also called by KVM's CPUHP
offline() callback. So tdx_cpu_flush_cache_for_kexec() is explicitly done
in TDX code in CPU offline.
- With this change, tdx_cpu_flush_cache_for_kexec() is not explicitly done
in TDX code in CPU offline.
But AFAICT this is fine, since IIUC the WBINVD is always done when kernel
offlines one CPU (see [*]), i.e., the current
tdx_cpu_flush_cache_for_kexec() done in KVM's CPUHP is actually superfluous.
[*] See:
native_play_dead() ->
cpuidle_play_dead();
hlt_play_dead();
cpuidle_play_dead() can invoke different enter_dead() callbacks depending on
what idle driver is being used, but AFAICT eventually it ends up calling
either acpi_idle_play_dead() or mwait_play_dead(), both of which does WBINVD
before going to idle.
If cpuidle_play_dead() doesn't idle successfully, the hlt_play_dead() will
then WBINVD and hlt.
Actually, after looking at multiple commits around here, e.g.,
ea53069231f93 ("x86, hotplug: Use mwait to offline a processor, fix the
legacy case")
dfbba2518aac4 ("Revert "ACPI: processor: idle: Only flush cache on
entering C3")
... I believe it's a kernel policy to make sure cache is flushed when it
offlines a CPU (which makes sense anyway of course), I just couldn't find
the exact commit saying this (or I am not sure whether there's such commit).
Btw2, kinda related to this, could you help review:
https://lore.kernel.org/lkml/20260302102226.7459-1-kai.huang@intel.com/
next prev parent reply other threads:[~2026-03-09 0:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 1:03 [PATCH 0/4] Fuller TDX kexec support Rick Edgecombe
2026-03-07 1:03 ` [PATCH 1/4] x86/tdx: Move all TDX error defines into <asm/shared/tdx_errno.h> Rick Edgecombe
2026-03-08 23:47 ` Huang, Kai
2026-03-09 16:20 ` Edgecombe, Rick P
2026-03-07 1:03 ` [PATCH 2/4] x86/virt/tdx: Pull kexec cache flush logic into arch/x86 Rick Edgecombe
2026-03-09 0:23 ` Huang, Kai [this message]
2026-03-09 16:23 ` Edgecombe, Rick P
2026-03-07 1:03 ` [PATCH 3/4] x86/virt/tdx: Add SEAMCALL wrapper for TDH.SYS.DISABLE Rick Edgecombe
2026-03-16 11:51 ` Kiryl Shutsemau
2026-03-16 21:15 ` Edgecombe, Rick P
2026-03-17 9:47 ` Kiryl Shutsemau
2026-03-17 21:55 ` Edgecombe, Rick P
2026-03-07 1:03 ` [PATCH 4/4] KVM: x86: Disable the TDX module during kexec and kdump Rick Edgecombe
2026-03-09 8:15 ` Chao Gao
2026-03-09 16:24 ` Edgecombe, Rick P
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d16e808b16d9c23f7db34e576c4dd82eb9772831.camel@intel.com \
--to=kai.huang@intel.com \
--cc=ackerleytng@google.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=vishal.l.verma@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®