Re: [PATCH v4 06/16] x86/virt/tdx: Improve PAMT refcounts allocation for sparse memory

From: Edgecombe, Rick P

Date: Wed Nov 26 2025 - 15:47:22 EST


On Tue, 2025-11-25 at 11:15 +0800, Binbin Wu wrote:
> On 11/21/2025 8:51 AM, Rick Edgecombe wrote:
> [...]
> > +
> > +/* Unmap a page from the PAMT refcount vmalloc region */
> > +static int pamt_refcount_depopulate(pte_t *pte, unsigned long addr, void *data)
> > +{
> > + struct page *page;
> > + pte_t entry;
> > +
> > + spin_lock(&init_mm.page_table_lock);
> > +
> > + entry = ptep_get(pte);
> > + /* refcount allocation is sparse, may not be populated */
>
> Not sure this comment about "sparse" is accurate since this function is called via
> apply_to_existing_page_range().
>
> And the check for not present just for sanity check?

Yes, I don't see what that comment is referring to. But we do need it, because
hypothetically the refcount mapping could have failed halfway. So we will have
pte_none()s for the ranges that didn't get populated. I'll use:

/* Refcount mapping could have failed part way, handle aborted mappings. */