From: Matthew Wilcox (Oracle) Date: Wed, 20 Jul 2022 02:17:59 +0000 (+0000) Subject: fork: use VMA iterator X-Git-Tag: howlett/maple/20220816~20 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5432094bf7f569125e2ba8efeb77df879b2a3fd1;p=users%2Fjedix%2Flinux-maple.git fork: use VMA iterator The VMA iterator is faster than the linked list and removing the linked list will shrink the vm_area_struct. Link: https://lkml.kernel.org/r/20220504011345.662299-34-Liam.Howlett@oracle.com Link: https://lkml.kernel.org/r/20220621204632.3370049-50-Liam.Howlett@oracle.com Link: https://lkml.kernel.org/r/20220720021727.17018-50-Liam.Howlett@oracle.com Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Liam R. Howlett Acked-by: Vlastimil Babka Cc: Catalin Marinas Cc: David Howells Cc: SeongJae Park Cc: Will Deacon Cc: Davidlohr Bueso Cc: David Hildenbrand Cc: Hulk Robot Cc: Lukas Bulwahn Cc: Sven Schnelle Cc: Yang Yingliang Signed-off-by: Andrew Morton --- diff --git a/kernel/fork.c b/kernel/fork.c index da4d77b81853..16b593f6e103 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1299,13 +1299,16 @@ int replace_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) /* Forbid mm->exe_file change if old file still mapped. */ old_exe_file = get_mm_exe_file(mm); if (old_exe_file) { + VMA_ITERATOR(vmi, mm, 0); mmap_read_lock(mm); - for (vma = mm->mmap; vma && !ret; vma = vma->vm_next) { + for_each_vma(vmi, vma) { if (!vma->vm_file) continue; if (path_equal(&vma->vm_file->f_path, - &old_exe_file->f_path)) + &old_exe_file->f_path)) { ret = -EBUSY; + break; + } } mmap_read_unlock(mm); fput(old_exe_file);