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

Configure Feed

Select the types of activity you want to include in your feed.

mm: constify shmem related test functions for improved const-correctness

Patch series "mm: establish const-correctness for pointer parameters", v6.

This series is to improved const-correctness in the low-level
memory-management subsystem, which provides a basis for further
constification further up the call stack (e.g. filesystems).

I started this work when I tried to constify the Ceph filesystem code, but
found that to be impossible because many "mm" functions accept non-const
pointers, even though they modify nothing.


This patch (of 12):

We select certain test functions which either invoke each other, functions
that are already const-ified, or no further functions.

It is therefore relatively trivial to const-ify them, which provides a
basis for further const-ification further up the call stack.

Link: https://lkml.kernel.org/r/20250901205021.3573313-1-max.kellermann@ionos.com
Link: https://lkml.kernel.org/r/20250901205021.3573313-2-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
8eccb066 4fe2a810

+9 -9
+4 -4
include/linux/mm.h
··· 995 995 * The vma_is_shmem is not inline because it is used only by slow 996 996 * paths in userfault. 997 997 */ 998 - bool vma_is_shmem(struct vm_area_struct *vma); 999 - bool vma_is_anon_shmem(struct vm_area_struct *vma); 998 + bool vma_is_shmem(const struct vm_area_struct *vma); 999 + bool vma_is_anon_shmem(const struct vm_area_struct *vma); 1000 1000 #else 1001 - static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; } 1002 - static inline bool vma_is_anon_shmem(struct vm_area_struct *vma) { return false; } 1001 + static inline bool vma_is_shmem(const struct vm_area_struct *vma) { return false; } 1002 + static inline bool vma_is_anon_shmem(const struct vm_area_struct *vma) { return false; } 1003 1003 #endif 1004 1004 1005 1005 int vma_is_stack_for_current(struct vm_area_struct *vma);
+2 -2
include/linux/shmem_fs.h
··· 99 99 unsigned long len, unsigned long pgoff, unsigned long flags); 100 100 extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts); 101 101 #ifdef CONFIG_SHMEM 102 - bool shmem_mapping(struct address_space *mapping); 102 + bool shmem_mapping(const struct address_space *mapping); 103 103 #else 104 - static inline bool shmem_mapping(struct address_space *mapping) 104 + static inline bool shmem_mapping(const struct address_space *mapping) 105 105 { 106 106 return false; 107 107 }
+3 -3
mm/shmem.c
··· 275 275 static const struct vm_operations_struct shmem_anon_vm_ops; 276 276 static struct file_system_type shmem_fs_type; 277 277 278 - bool shmem_mapping(struct address_space *mapping) 278 + bool shmem_mapping(const struct address_space *mapping) 279 279 { 280 280 return mapping->a_ops == &shmem_aops; 281 281 } 282 282 EXPORT_SYMBOL_GPL(shmem_mapping); 283 283 284 - bool vma_is_anon_shmem(struct vm_area_struct *vma) 284 + bool vma_is_anon_shmem(const struct vm_area_struct *vma) 285 285 { 286 286 return vma->vm_ops == &shmem_anon_vm_ops; 287 287 } 288 288 289 - bool vma_is_shmem(struct vm_area_struct *vma) 289 + bool vma_is_shmem(const struct vm_area_struct *vma) 290 290 { 291 291 return vma_is_anon_shmem(vma) || vma->vm_ops == &shmem_vm_ops; 292 292 }