Re: [PATCH v4 06/16] x86/virt/tdx: Improve PAMT refcounts allocation for sparse memory
From: Kiryl Shutsemau
Date: Thu Nov 27 2025 - 10:57:47 EST
On Wed, Nov 26, 2025 at 08:47:19PM +0000, Edgecombe, Rick P wrote:
> 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. */
It is possible that we can have holes in physical address space between
0 and max_pfn. You need the check even outside of "failed halfway"
scenario.
--
Kiryl Shutsemau / Kirill A. Shutemov