Re: [PATCH v3 06/16] x86/virt/tdx: Improve PAMT refcounters allocation for sparse memory
From: Huang, Kai
Date: Wed Oct 01 2025 - 16:50:07 EST
On Wed, 2025-10-01 at 19:00 +0000, Edgecombe, Rick P wrote:
> I guess we are really doing two separate calculations. First calculate the range
> of refcounts we need, and then calculate the range of vmalloc space we need. How
> about this, is it clearer to you? It is very specific about what/why we actually
> are doing, but at the expense of minimizing operations. In this slow path, I
> think clarity is the priority.
>
> static int alloc_pamt_refcount(unsigned long start_pfn, unsigned long end_pfn)
> {
> unsigned long refcount_first, refcount_last;
> unsigned long mapping_start, mapping_end;
>
> /*
> * 'start_pfn' is inclusive and 'end_pfn' is exclusive. Find the
> * range of refcounts the pfn range will need.
> */
> refcount_first = (unsigned long)tdx_find_pamt_refcount(start_pfn);
> refcount_last = (unsigned long)tdx_find_pamt_refcount(end_pfn - 1);
>
> /*
> * Calculate the page aligned range that includes the refcounts. The
> * teardown logic needs to handle potentially overlapping refcount
> * mappings resulting from the alignments.
> */
> mapping_start = round_down(refcount_first, PAGE_SIZE);
> mapping_end = round_up(refcount_last + sizeof(*pamt_refcounts),
> PAGE_SIZE);
>
>
> return apply_to_page_range(&init_mm, mapping_start, mapping_end -
> mapping_start,
> pamt_refcount_populate, NULL);
> }
Yeah it's better and clearer. LGTM. Thanks.