[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <oyagitkaefceadeqoqgycqhubw4hnlsjxf6lytazxpjnzueb4k@bmcvegkzrycq>
Date: Wed, 10 Sep 2025 17:06:53 +0100
From: Kiryl Shutsemau <kas@...nel.org>
To: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, Rick Edgecombe <rick.p.edgecombe@...el.com>,
Sean Christopherson <seanjc@...gle.com>, Paolo Bonzini <pbonzini@...hat.com>,
Kai Huang <kai.huang@...el.com>, Isaku Yamahata <isaku.yamahata@...el.com>,
Vishal Annapurve <vannapurve@...gle.com>, Thomas Huth <thuth@...hat.com>,
Adrian Hunter <adrian.hunter@...el.com>, linux-coco@...ts.linux.dev, kvm@...r.kernel.org,
Farrah Chen <farrah.chen@...el.com>
Subject: Re: [PATCH] x86/virt/tdx: Use precalculated TDVPR page physical
address
On Wed, Sep 10, 2025 at 07:44:53AM -0700, Dave Hansen wrote:
> From: Kai Huang <kai.huang@...el.com>
>
> All of the x86 KVM guest types (VMX, SEV and TDX) do some special context
> tracking when entering guests. This means that the actual guest entry
> sequence must be noinstr.
>
> Part of entering a TDX guest is passing a physical address to the TDX
> module. Right now, that physical address is stored as a 'struct page'
> and converted to a physical address at guest entry. That page=>phys
> conversion can be complicated, can vary greatly based on kernel
> config, and it is definitely _not_ a noinstr path today.
>
> There have been a number of tinkering approaches to try and fix this
> up, but they all fall down due to some part of the page=>phys
> conversion infrastructure not being noinstr friendly.
>
> Precalculate the page=>phys conversion and store it in the existing
> 'tdx_vp' structure. Use the new field at every site that needs a
> tdvpr physical address. Remove the now redundant tdx_tdvpr_pa().
> Remove the __flatten remnant from the tinkering.
>
> Note that only one user of the new field is actually noinstr. All
> others can use page_to_phys(). But, they might as well save the effort
> since there is a pre-calculated value sitting there for them.
>
> [ dhansen: rewrite all the text ]
>
> Signed-off-by: Kai Huang <kai.huang@...el.com>
> Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
> Tested-by: Farrah Chen <farrah.chen@...el.com>
Reviewed-by: Kiryl Shutsemau <kas@...nel.org>
One nitpick is below.
> ---
> arch/x86/include/asm/tdx.h | 2 ++
> arch/x86/kvm/vmx/tdx.c | 9 +++++++++
> arch/x86/virt/vmx/tdx/tdx.c | 21 ++++++++-------------
> 3 files changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> index 6120461bd5ff3..6b338d7f01b7d 100644
> --- a/arch/x86/include/asm/tdx.h
> +++ b/arch/x86/include/asm/tdx.h
> @@ -171,6 +171,8 @@ struct tdx_td {
> struct tdx_vp {
> /* TDVP root page */
> struct page *tdvpr_page;
> + /* precalculated page_to_phys(tdvpr_page) for use in noinstr code */
> + phys_addr_t tdvpr_pa;
Missing newline above the new field?
--
Kiryl Shutsemau / Kirill A. Shutemov
Powered by blists - more mailing lists