Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: constify arch_pick_mmap_layout() for improved const-correctness

This function only reads from the rlimit pointer (but writes to the
mm_struct pointer which is kept without `const`).

All callees are already const-ified or (internal functions) are being
constified by this patch.

Link: https://lkml.kernel.org/r/20250901205021.3573313-9-max.kellermann@ionos.com
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christian Zankel <chris@zankel.net>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Bottomley <james.bottomley@HansenPartnership.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jocelyn Falempe <jfalempe@redhat.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "Nysal Jan K.A" <nysal@linux.ibm.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russel King <linux@armlinux.org.uk>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Max Kellermann and committed by
Andrew Morton
a955cca3 e7f77876

+11 -11
+2 -2
arch/s390/mm/mmap.c
··· 47 47 } 48 48 49 49 static inline unsigned long mmap_base(unsigned long rnd, 50 - struct rlimit *rlim_stack) 50 + const struct rlimit *rlim_stack) 51 51 { 52 52 unsigned long gap = rlim_stack->rlim_cur; 53 53 unsigned long pad = stack_maxrandom_size() + stack_guard_gap; ··· 169 169 * This function, called very early during the creation of a new 170 170 * process VM image, sets up which VM layout function to use: 171 171 */ 172 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 172 + void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack) 173 173 { 174 174 unsigned long random_factor = 0UL; 175 175
+1 -1
arch/sparc/kernel/sys_sparc_64.c
··· 294 294 return rnd << PAGE_SHIFT; 295 295 } 296 296 297 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 297 + void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack) 298 298 { 299 299 unsigned long random_factor = mmap_rnd(); 300 300 unsigned long gap;
+3 -3
arch/x86/mm/mmap.c
··· 80 80 } 81 81 82 82 static unsigned long mmap_base(unsigned long rnd, unsigned long task_size, 83 - struct rlimit *rlim_stack) 83 + const struct rlimit *rlim_stack) 84 84 { 85 85 unsigned long gap = rlim_stack->rlim_cur; 86 86 unsigned long pad = stack_maxrandom_size(task_size) + stack_guard_gap; ··· 110 110 */ 111 111 static void arch_pick_mmap_base(unsigned long *base, unsigned long *legacy_base, 112 112 unsigned long random_factor, unsigned long task_size, 113 - struct rlimit *rlim_stack) 113 + const struct rlimit *rlim_stack) 114 114 { 115 115 *legacy_base = mmap_legacy_base(random_factor, task_size); 116 116 if (mmap_is_legacy()) ··· 119 119 *base = mmap_base(random_factor, task_size, rlim_stack); 120 120 } 121 121 122 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 122 + void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack) 123 123 { 124 124 if (mmap_is_legacy()) 125 125 mm_flags_clear(MMF_TOPDOWN, mm);
+2 -2
include/linux/sched/mm.h
··· 178 178 #endif 179 179 180 180 extern void arch_pick_mmap_layout(struct mm_struct *mm, 181 - struct rlimit *rlim_stack); 181 + const struct rlimit *rlim_stack); 182 182 183 183 unsigned long 184 184 arch_get_unmapped_area(struct file *filp, unsigned long addr, ··· 211 211 unsigned long flags, vm_flags_t vm_flags); 212 212 #else 213 213 static inline void arch_pick_mmap_layout(struct mm_struct *mm, 214 - struct rlimit *rlim_stack) {} 214 + const struct rlimit *rlim_stack) {} 215 215 #endif 216 216 217 217 static inline bool in_vfork(struct task_struct *tsk)
+3 -3
mm/util.c
··· 431 431 #define MIN_GAP (SZ_128M) 432 432 #define MAX_GAP (STACK_TOP / 6 * 5) 433 433 434 - static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) 434 + static unsigned long mmap_base(const unsigned long rnd, const struct rlimit *rlim_stack) 435 435 { 436 436 #ifdef CONFIG_STACK_GROWSUP 437 437 /* ··· 462 462 #endif 463 463 } 464 464 465 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 465 + void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack) 466 466 { 467 467 unsigned long random_factor = 0UL; 468 468 ··· 478 478 } 479 479 } 480 480 #elif defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT) 481 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 481 + void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack) 482 482 { 483 483 mm->mmap_base = TASK_UNMAPPED_BASE; 484 484 mm_flags_clear(MMF_TOPDOWN, mm);