public inbox for linux-coco@lists.linux.dev
 help / color / mirror / Atom feed
From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "seanjc@google.com" <seanjc@google.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"kas@kernel.org" <kas@kernel.org>, "bp@alien8.de" <bp@alien8.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"tglx@kernel.org" <tglx@kernel.org>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"Annapurve, Vishal" <vannapurve@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Huang, Kai" <kai.huang@intel.com>,
	"Zhao, Yan Y" <yan.y.zhao@intel.com>,
	"ackerleytng@google.com" <ackerleytng@google.com>
Subject: Re: [PATCH] x86/tdx: Use pg_level in TDX APIs, not the TDX-Module's 0-based level
Date: Tue, 20 Jan 2026 22:38:07 +0000	[thread overview]
Message-ID: <7a33ca7002696a666e2b51fc80ce01bac1381e3f.camel@intel.com> (raw)
In-Reply-To: <20260120203937.1447592-1-seanjc@google.com>

On Tue, 2026-01-20 at 12:39 -0800, Sean Christopherson wrote:
> > Rework the TDX APIs to take the kernel's 1-based pg_level enum, not the
> > TDX-Module's 0-based level.  The APIs are _kernel_ APIs, not TDX-Module
> > APIs, and the kernel (and KVM) uses "enum pg_level" literally everywhere.
> > 
> > Using "enum pg_level" eliminates ambiguity when looking at the APIs (it's
> > NOT clear that "int level" refers to the TDX-Module's level), and will
> > allow for using existing helpers like page_level_size() when support for
> > hugepages is added to the S-EPT APIs.
> > 
> > No functional change intended.

Makes sense.

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>

> > 
> > Cc: Kai Huang <kai.huang@intel.com>
> > Cc: Dave Hansen <dave.hansen@linux.intel.com>
> > Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
> > Cc: Yan Zhao <yan.y.zhao@intel.com>
> > Cc: Vishal Annapurve <vannapurve@google.com>
> > Cc: Ackerley Tng <ackerleytng@google.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> > 
> > Compile-tested only.  Came across this when looking at the S-EPT hugepage
> > series, specifically this code:
> >   
> >    unsigned long npages = 1 << (level * PTE_SHIFT);
> > 
> > which I was _sure_ was broken, until I realized @level wasn't what I thought
> > it was.
> >  
> >  arch/x86/include/asm/tdx.h  | 14 ++++----------
> >  arch/x86/kvm/vmx/tdx.c      | 11 ++++-------
> >  arch/x86/virt/vmx/tdx/tdx.c | 26 ++++++++++++++++++--------
> >  3 files changed, 26 insertions(+), 25 deletions(-)

The line increase is just from wrapped lines, so it's kinda less code.

> > 
> > diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> > index 6b338d7f01b7..bc0d03e70fd6 100644
> > --- a/arch/x86/include/asm/tdx.h
> > +++ b/arch/x86/include/asm/tdx.h
> > @@ -189,19 +189,13 @@ static inline u64 mk_keyed_paddr(u16 hkid, struct page *page)
> >  	return ret;
> >  }
> >  
> > -static inline int pg_level_to_tdx_sept_level(enum pg_level level)
> > -{
> > -        WARN_ON_ONCE(level == PG_LEVEL_NONE);
> > -        return level - 1;
> > -}
> > -
> >  u64 tdh_vp_enter(struct tdx_vp *vp, struct tdx_module_args *args);
> >  u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page);
> >  u64 tdh_mem_page_add(struct tdx_td *td, u64 gpa, struct page *page, struct page *source, u64 *ext_err1, u64 *ext_err2);
> > -u64 tdh_mem_sept_add(struct tdx_td *td, u64 gpa, int level, struct page *page, u64 *ext_err1, u64 *ext_err2);
> > +u64 tdh_mem_sept_add(struct tdx_td *td, u64 gpa, enum pg_level level, struct page *page, u64 *ext_err1, u64 *ext_err2);
> >  u64 tdh_vp_addcx(struct tdx_vp *vp, struct page *tdcx_page);
> > -u64 tdh_mem_page_aug(struct tdx_td *td, u64 gpa, int level, struct page *page, u64 *ext_err1, u64 *ext_err2);
> > -u64 tdh_mem_range_block(struct tdx_td *td, u64 gpa, int level, u64 *ext_err1, u64 *ext_err2);
> > +u64 tdh_mem_page_aug(struct tdx_td *td, u64 gpa, enum pg_level level, struct page *page, u64 *ext_err1, u64 *ext_err2);
> > +u64 tdh_mem_range_block(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *ext_err1, u64 *ext_err2);
> >  u64 tdh_mng_key_config(struct tdx_td *td);
> >  u64 tdh_mng_create(struct tdx_td *td, u16 hkid);
> >  u64 tdh_vp_create(struct tdx_td *td, struct tdx_vp *vp);
> > @@ -217,7 +211,7 @@ u64 tdh_vp_rd(struct tdx_vp *vp, u64 field, u64 *data);
> >  u64 tdh_vp_wr(struct tdx_vp *vp, u64 field, u64 data, u64 mask);
> >  u64 tdh_phymem_page_reclaim(struct page *page, u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size);
> >  u64 tdh_mem_track(struct tdx_td *tdr);
> > -u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, u64 level, u64 *ext_err1, u64 *ext_err2);
                                                         ^WTH, oops.
> > +u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *ext_err1, u64 *ext_err2);
> >  u64 tdh_phymem_cache_wb(bool resume);
> >  u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td);
> >  u64 tdh_phymem_page_wbinvd_hkid(u64 hkid, struct page *page);


  reply	other threads:[~2026-01-20 22:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 20:39 [PATCH] x86/tdx: Use pg_level in TDX APIs, not the TDX-Module's 0-based level Sean Christopherson
2026-01-20 22:38 ` Edgecombe, Rick P [this message]
2026-01-20 23:31 ` Huang, Kai
2026-01-21 12:32 ` Kiryl Shutsemau
2026-01-22  7:54 ` Yan Zhao

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=7a33ca7002696a666e2b51fc80ce01bac1381e3f.camel@intel.com \
    --to=rick.p.edgecombe@intel.com \
    --cc=ackerleytng@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kai.huang@intel.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=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=vannapurve@google.com \
    --cc=x86@kernel.org \
    --cc=yan.y.zhao@intel.com \
    /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