On Fri, Jun 27, 2025 at 10:49:34AM +0300, Adrian Hunter wrote: > On 09/06/2025 22:13, Kirill A. Shutemov wrote: > > +static void tdx_pamt_put(struct page *page, enum pg_level level) > > +{ > > + unsigned long hpa = page_to_phys(page); > > + atomic_t *pamt_refcount; > > + LIST_HEAD(pamt_pages); > > + u64 err; > > + > > + if (!tdx_supports_dynamic_pamt(&tdx_sysinfo)) > > + return; > > + > > + if (level != PG_LEVEL_4K) > > + return; > > + > > + hpa = ALIGN_DOWN(hpa, PMD_SIZE); > > + > > + pamt_refcount = tdx_get_pamt_refcount(hpa); > > + if (!atomic_dec_and_test(pamt_refcount)) > > + return; > > + > > + scoped_guard(spinlock, &pamt_lock) { > > + /* Lost race against tdx_pamt_add()? */ > > + if (atomic_read(pamt_refcount) != 0) > > + return; > > + > > + err = tdh_phymem_pamt_remove(hpa | TDX_PS_2M, &pamt_pages); > > + > > + if (err) { > > + atomic_inc(pamt_refcount); > > + pr_err("TDH_PHYMEM_PAMT_REMOVE failed: %#llx\n", err); > > + return; > > + } > > + } > > + > > Won't any pages that have been used need to be cleared > before being freed. Good point. I missed that. -- Kiryl Shutsemau / Kirill A. Shutemov