Re: [PATCH v3 08/16] x86/virt/tdx: Optimize tdx_alloc/free_page() helpers

Kiryl Shutsemau
2025-09-19T09:39:07Z

On Thu, Sep 18, 2025 at 04:22:16PM -0700, Rick Edgecombe wrote:
> + } else if (IS_TDX_HPA_RANGE_NOT_FREE(tdx_status)) {
> + /*
> + * Less obviously, another CPU's call to tdx_pamt_put() could have
> + * decremented the refcount before entering its lock section.
> + * In this case, the PAMT is not actually removed yet. Luckily
> + * TDX module tells about this case, so increment the refcount
> + * 0-1, so tdx_pamt_put() skips its pending PAMT.REMOVE.
> + *
> + * The call didn't need the pages though, so free them.
> + */
> atomic_inc(pamt_refcount);

It is still 0->1 transition. atomic_set(pamt_refcount, 1) would be
slightly faster here.

--
Kiryl Shutsemau / Kirill A. Shutemov