Skip to content

Commit 08498be

Browse files
RichardWeiYangakpm00
authored andcommitted
mm/ksm: get mm_slot by mm_slot_entry() when slot is !NULL
Patch series "mm_slot: fix the usage of mm_slot_entry", v2. When using mm_slot in ksm, there is code like: slot = mm_slot_lookup(mm_slots_hash, mm); mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); if (mm_slot && ..) { } The mm_slot_entry() won't return a valid value if slot is NULL generally. But currently it works since slot is the first element of struct ksm_mm_slot. To reduce the ambiguity and make it robust, access mm_slot_entry() when slot is !NULL. Link: https://lkml.kernel.org/r/20250919071244.17020-1-richard.weiyang@gmail.com Link: https://lkml.kernel.org/r/20250919071244.17020-2-richard.weiyang@gmail.com Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Lance Yang <lance.yang@linux.dev> Cc: Kiryl Shutsemau <kirill@shutemov.name> Cc: xu xin <xu.xin16@zte.com.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 3dfd02c commit 08498be

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mm/ksm.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,15 +2936,17 @@ void __ksm_exit(struct mm_struct *mm)
29362936

29372937
spin_lock(&ksm_mmlist_lock);
29382938
slot = mm_slot_lookup(mm_slots_hash, mm);
2939-
mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
2940-
if (mm_slot && ksm_scan.mm_slot != mm_slot) {
2941-
if (!mm_slot->rmap_list) {
2942-
hash_del(&slot->hash);
2943-
list_del(&slot->mm_node);
2944-
easy_to_free = 1;
2945-
} else {
2946-
list_move(&slot->mm_node,
2947-
&ksm_scan.mm_slot->slot.mm_node);
2939+
if (slot) {
2940+
mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
2941+
if (ksm_scan.mm_slot != mm_slot) {
2942+
if (!mm_slot->rmap_list) {
2943+
hash_del(&slot->hash);
2944+
list_del(&slot->mm_node);
2945+
easy_to_free = 1;
2946+
} else {
2947+
list_move(&slot->mm_node,
2948+
&ksm_scan.mm_slot->slot.mm_node);
2949+
}
29482950
}
29492951
}
29502952
spin_unlock(&ksm_mmlist_lock);

0 commit comments

Comments
 (0)