Re: [PATCH v4 5/8] x86/mm: Use pagetable_free()

Jason Gunthorpe
2025-09-05T18:41:20Z

On Fri, Sep 05, 2025 at 01:51:00PM +0800, Lu Baolu wrote:
> The kernel's memory management subsystem provides a dedicated interface,
> pagetable_free(), for freeing page table pages. Updates two call sites to
> use pagetable_free() instead of the lower-level __free_page() or
> free_pages(). This improves code consistency and clarity, and ensures the
> correct freeing mechanism is used.
>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
> arch/x86/mm/init_64.c | 2 +-
> arch/x86/mm/pat/set_memory.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
> index 76e33bd7c556..86b4297c1984 100644
> --- a/arch/x86/mm/init_64.c
> +++ b/arch/x86/mm/init_64.c
> @@ -1013,7 +1013,7 @@ static void __meminit free_pagetable(struct page *page, int order)
> free_reserved_pages(page, nr_pages);
> #endif
> } else {
> - free_pages((unsigned long)page_address(page), order);
> + pagetable_free(page_ptdesc(page));
> }
> }

Er.. So if bootmem happens to be under the table and we happen to free
it due to memory hotplug we don't go through the SVA fixing path?

Seems wrong??

Bootmem still has a ptdesc and a usable linked list, right?

So maybe this should be redone into an arch hook in/around
__pagetable_free() and all the above frees just use the normal ptdesc
free path, including the SVA work queue?

Jason