Link: https://lkml.kernel.org/r/20251007182504440BJgK8VXRHh8TD7IGSUIY4@zte.com.cn Link: https://lkml.kernel.org/r/20251007182821572h_SoFqYZXEP1mvWI4n9VL@zte.com.cn Fixes: 3c6f33b7273a ("mm/ksm: support fork/exec for prctl") Fixes: d7597f59d1d3 ("mm: add new api to enable ksm per process") Signed-off-by: xu xin xu.xin16@zte.com.cn Cc: Stefan Roesch shr@devkernel.io Cc: David Hildenbrand david@redhat.com Cc: Jinjiang Tu tujinjiang@huawei.com Cc: Wang Yaxin wang.yaxin@zte.com.cn Cc: Yang Yang yang.yang29@zte.com.cn Cc: stable@vger.kernel.org Signed-off-by: Andrew Morton akpm@linux-foundation.org [ changed mm_flags_test() and mm_flags_clear() calls to test_bit() and clear_bit() ] Signed-off-by: Sasha Levin sashal@kernel.org
mm/ksm.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c index 2e4cd681622d..96a0feb19c09 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2451,8 +2451,14 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) spin_unlock(&ksm_mmlist_lock); mm_slot_free(mm_slot_cache, mm_slot);
/** Only clear MMF_VM_MERGEABLE. We must not clear* MMF_VM_MERGE_ANY, because for those MMF_VM_MERGE_ANY process,* perhaps their mm_struct has just been added to ksm_mm_slot* list, and its process has not yet officially started running* or has not yet performed mmap/brk to allocate anonymous VMAS. clear_bit(MMF_VM_MERGEABLE, &mm->flags);*/
mmap_read_unlock(mm); mmdrop(mm); } else {clear_bit(MMF_VM_MERGE_ANY, &mm->flags);@@ -2567,8 +2573,16 @@ void ksm_add_vma(struct vm_area_struct *vma) { struct mm_struct *mm = vma->vm_mm;
- if (test_bit(MMF_VM_MERGE_ANY, &mm->flags))
- if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) { __ksm_add_vma(vma);
/** Generally, the flags here always include MMF_VM_MERGEABLE.* However, in rare cases, this flag may be cleared by ksmd who* scans a cycle without finding any mergeable vma.*/if (unlikely(!test_bit(MMF_VM_MERGEABLE, &mm->flags)))__ksm_enter(mm);- }
}
Acked-by: xu xin xu.xin16@zte.com.cn
Thanks!