Re: [PATCH v3] mm/khugepaged: fix inconsistent MMF_VM_HUGEPAGE flag due to allocation failure order

From: David Hildenbrand (Arm)

Date: Mon May 11 2026 - 01:42:07 EST


On 5/11/26 04:54, Ye Liu wrote:
> From: Ye Liu <liuye@xxxxxxxxxx>
>
> __khugepaged_enter() sets MMF_VM_HUGEPAGE before allocating the
> corresponding mm_slot. If mm_slot_alloc() fails, the function
> returns with the flag set but without inserting the mm into the
> khugepaged tracking structures, leaving the mm in an inconsistent
> state where future registration attempts are skipped.
>
> Fix this by reordering: allocate the mm_slot first, then check and
> set the flag. If the flag is already set, free the allocated slot
> and return. This ensures the flag is only set when the mm is
> successfully registered in the khugepaged tracking structures.
>
> Fixes: 16618670276a ("mm: khugepaged: avoid pointless allocation for "struct mm_slot"")
> Suggested-by: David Hildenbrand <david@xxxxxxxxxx>
> Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
> ---

Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David