]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mm: consistently use current->mm in mm_get_unmapped_area()
authorRyan Roberts <ryan.roberts@arm.com>
Fri, 3 Oct 2025 15:53:04 +0000 (16:53 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 17 Nov 2025 01:27:57 +0000 (17:27 -0800)
commit9ac09bb9feaccc2f45e5606dc48a3f748d478dc4
tree112b8ef9515691a047d5db1356ad064c38d91117
parent0fdaa13ee93a068251d32ea7f60fd439b445adbe
mm: consistently use current->mm in mm_get_unmapped_area()

mm_get_unmapped_area() is a wrapper around arch_get_unmapped_area() /
arch_get_unmapped_area_topdown(), both of which search current->mm for
some free space.  Neither take an mm_struct - they implicitly operate on
current->mm.

But the wrapper takes an mm_struct and uses it to decide whether to search
bottom up or top down.  All callers pass in current->mm for this, so
everything is working consistently.  But it feels like an accident waiting
to happen; eventually someone will call that function with a different mm,
expecting to find free space in it, but what gets returned is free space
in the current mm.

So let's simplify by removing the parameter and have the wrapper use
current->mm to decide which end to start at.  Now everything is consistent
and self-documenting.

Link: https://lkml.kernel.org/r/20251003155306.2147572-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
14 files changed:
arch/sparc/kernel/sys_sparc_64.c
arch/x86/kernel/cpu/sgx/driver.c
drivers/char/mem.c
drivers/dax/device.c
fs/hugetlbfs/inode.c
fs/proc/inode.c
fs/ramfs/file-mmu.c
include/linux/sched/mm.h
io_uring/memmap.c
kernel/bpf/arena.c
kernel/bpf/syscall.c
mm/huge_memory.c
mm/mmap.c
mm/shmem.c