aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
authorYe Liu <liuye@kylinos.cn>2026-05-11 10:54:07 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-05-28 21:30:59 -0700
commit4c4aa5c01332acdb577dd600256efc8abaa6a520 (patch)
tree64c40996d0d094fd2e87229276fb5c075a623df4 /mm
parent2ebc00cb506cee996b34038e08d8e2653c642f1e (diff)
downloadlinux-next-history-4c4aa5c01332acdb577dd600256efc8abaa6a520.tar.gz
mm/khugepaged: fix inconsistent MMF_VM_HUGEPAGE flag due to allocation failure order
__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. Link: https://lore.kernel.org/20260511025408.54035-1-ye.liu@linux.dev Fixes: 16618670276a ("mm: khugepaged: avoid pointless allocation for "struct mm_slot"") Signed-off-by: Ye Liu <liuye@kylinos.cn> Suggested-by: David Hildenbrand <david@kernel.org> Reviewed-by: Lance Yang <lance.yang@linux.dev> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Reviewed-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Lorenzo Stoakes <ljs@kernel.org> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Nico Pache <npache@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Xin Hao <xhao@linux.alibaba.com> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/khugepaged.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 28a843f30b32b..a4b97ec8ce56c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -437,13 +437,16 @@ void __khugepaged_enter(struct mm_struct *mm)
/* __khugepaged_exit() must not run from under us */
VM_BUG_ON_MM(collapse_test_exit(mm), mm);
- if (unlikely(mm_flags_test_and_set(MMF_VM_HUGEPAGE, mm)))
- return;
slot = mm_slot_alloc(mm_slot_cache);
if (!slot)
return;
+ if (unlikely(mm_flags_test_and_set(MMF_VM_HUGEPAGE, mm))) {
+ mm_slot_free(mm_slot_cache, slot);
+ return;
+ }
+
spin_lock(&khugepaged_mm_lock);
mm_slot_insert(mm_slots_hash, mm, slot);
/*