[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <59918204553304585345bffdf9816859ca60f0cb.camel@intel.com>
Date: Tue, 13 May 2025 23:24:01 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>
CC: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>, "seanjc@...gle.com"
<seanjc@...gle.com>, "bp@...en8.de" <bp@...en8.de>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>, "x86@...nel.org"
<x86@...nel.org>, "mingo@...hat.com" <mingo@...hat.com>, "Zhao, Yan Y"
<yan.y.zhao@...el.com>, "tglx@...utronix.de" <tglx@...utronix.de>,
"pbonzini@...hat.com" <pbonzini@...hat.com>, "kvm@...r.kernel.org"
<kvm@...r.kernel.org>, "linux-coco@...ts.linux.dev"
<linux-coco@...ts.linux.dev>, "Yamahata, Isaku" <isaku.yamahata@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [RFC, PATCH 02/12] x86/virt/tdx: Allocate reference counters for
PAMT memory
On Mon, 2025-05-12 at 12:53 +0300, kirill.shutemov@...ux.intel.com wrote:
> On Fri, May 09, 2025 at 01:06:05AM +0000, Huang, Kai wrote:
> > On Thu, 2025-05-08 at 16:03 +0300, kirill.shutemov@...ux.intel.com wrote:
> > > On Mon, May 05, 2025 at 11:05:12AM +0000, Huang, Kai wrote:
> > > >
> > > > > +static atomic_t *pamt_refcounts;
> > > > > +
> > > > > static enum tdx_module_status_t tdx_module_status;
> > > > > static DEFINE_MUTEX(tdx_module_lock);
> > > > >
> > > > > @@ -1035,9 +1038,108 @@ static int config_global_keyid(void)
> > > > > return ret;
> > > > > }
> > > > >
> > > > > +atomic_t *tdx_get_pamt_refcount(unsigned long hpa)
> > > > > +{
> > > > > + return &pamt_refcounts[hpa / PMD_SIZE];
> > > > > +}
> > > > > +EXPORT_SYMBOL_GPL(tdx_get_pamt_refcount);
> > > >
> > > > It's not quite clear why this function needs to be exported in this patch. IMO
> > > > it's better to move the export to the patch which actually needs it.
> > > >
> > > > Looking at patch 5, tdx_pamt_get()/put() use it, and they are in KVM code. But
> > > > I think we should just put them here in this file. tdx_alloc_page() and
> > > > tdx_free_page() should be in this file too.
> > > >
> > > > And instead of exporting tdx_get_pamt_refcount(), the TDX core code here can
> > > > export tdx_alloc_page() and tdx_free_page(), providing two high level helpers to
> > > > allow the TDX users (e.g., KVM) to allocate/free TDX private pages. How PAMT
> > > > pages are allocated is then hidden in the core TDX code.
> > >
> > > We would still need tdx_get_pamt_refcount() to handle case when we need to
> > > bump refcount for page allocated elsewhere.
> >
> > Hmm I am not sure I am following this. What "page allocated" are you referring
> > to? I am probably missing something, but if the caller wants a TDX page then it
> > should just call tdx_alloc_page() which handles refcount bumping internally.
> > No?
>
> Pages that get mapped to the guest is allocated externally via
> guest_memfd and we need bump refcount for them.
Oh right. TDX private pages can also be in page cache.
It's better to have a way to consolidate page allocation for TDX but with page
cache I don't see a simple straightforward way to do that.
For now, I think we can just export tdx_pamt_{get|put}() in the core TDX code.
We can also provide tdx_{alloc|free}_page() wrappers (e.g., static inline in
<asm/tdx.h>) for kernel TDX memory allocation so that they can be used for TDX
Connect too.
Powered by blists - more mailing lists