Re: [PATCH v2 1/2] mm: free unused page table allocated by do_set_pmd()
From: Baolin Wang
Date: Tue Nov 10 2026 - 01:38:24 EST
On 11/6/26 8:36 PM, David Hildenbrand (Arm) wrote:
do_set_pmd() can allocate vmf->prealloc_pte on architectures that need a
deposited page table, such as PowerPC with the hash MMU. If the PMD is
no longer empty when it takes the PMD lock, it returns VM_FAULT_FALLBACK
without consuming that table.
Since collapse_pte_mapped_thp() uses mmap_read_lock(), a concurrent
userfaultfd operation can install a PTE table before taking the folio
lock. If that races with set_huge_pmd(), the unused preallocated table
is lost when its local vm_fault goes out of scope.
Track whether do_set_pmd() allocated the table and free it after dropping
the PMD lock if it was not consumed. Preserve any preallocated table
supplied by the caller for PTE fallback. Successful PMD installation
consumes the table and clears the pointer.
Returning without a preallocated table matches the existing behavior on
architectures that do not need a deposited table. All callers
already handle that case.
Fixes: 1043173eb5eb ("mm/khugepaged: collapse_pte_mapped_thp() with mmap_read_lock()")
Cc: stable@xxxxxxxxxxxxxxx
Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>