On Mon, 2025-05-12 at 12:53 +0300, kirill.shutemov@xxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxx 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.