Re: [PATCH v2 1/2] mm: free unused page table allocated by do_set_pmd()
From: David Hildenbrand (Arm)
Date: Mon Nov 09 2026 - 09:31:41 EST
On 11/6/26 16:34, Usama Arif wrote:
> On Fri, 06 Nov 2026 13:36:12 +0100 "David Hildenbrand (Arm)" <david@xxxxxxxxxx> 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>
>> ---
>> mm/memory.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>
> Acked-by: Usama Arif <usama.arif@xxxxxxxxx>
>
> Reminded me of lazy pagetable deposit series :)
Not just you. haha :)
--
Cheers,
David