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

mm: move anon_vma declarations to linux/mm_inline.h

The patch to add anonymous vma names causes a build failure in some
configurations:

include/linux/mm_types.h: In function 'is_same_vma_anon_name':
include/linux/mm_types.h:924:37: error: implicit declaration of function 'strcmp' [-Werror=implicit-function-declaration]
924 | return name && vma_name && !strcmp(name, vma_name);
| ^~~~~~
include/linux/mm_types.h:22:1: note: 'strcmp' is defined in header '<string.h>'; did you forget to '#include <string.h>'?

This should not really be part of linux/mm_types.h in the first place,
as that header is meant to only contain structure defintions and need a
minimum set of indirect includes itself.

While the header clearly includes more than it should at this point,
let's not make it worse by including string.h as well, which would pull
in the expensive (compile-speed wise) fortify-string logic.

Move the new functions into a separate header that only needs to be
included in a couple of locations.

Link: https://lkml.kernel.org/r/20211207125710.2503446-1-arnd@kernel.org
Fixes: "mm: add a field to store names for private anonymous memory"
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Colin Cross <ccross@google.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Arnd Bergmann and committed by
Linus Torvalds
17fca131 78db3412

+55 -48
+1
fs/proc/task_mmu.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/pagewalk.h> 3 3 #include <linux/vmacache.h> 4 + #include <linux/mm_inline.h> 4 5 #include <linux/hugetlb.h> 5 6 #include <linux/huge_mm.h> 6 7 #include <linux/mount.h>
+1
fs/userfaultfd.c
··· 15 15 #include <linux/sched/signal.h> 16 16 #include <linux/sched/mm.h> 17 17 #include <linux/mm.h> 18 + #include <linux/mm_inline.h> 18 19 #include <linux/mmu_notifier.h> 19 20 #include <linux/poll.h> 20 21 #include <linux/slab.h>
+50
include/linux/mm_inline.h
··· 4 4 5 5 #include <linux/huge_mm.h> 6 6 #include <linux/swap.h> 7 + #include <linux/string.h> 7 8 8 9 /** 9 10 * folio_is_file_lru - Should the folio be on a file LRU or anon LRU? ··· 136 135 { 137 136 lruvec_del_folio(lruvec, page_folio(page)); 138 137 } 138 + 139 + #ifdef CONFIG_ANON_VMA_NAME 140 + /* 141 + * mmap_lock should be read-locked when calling vma_anon_name() and while using 142 + * the returned pointer. 143 + */ 144 + extern const char *vma_anon_name(struct vm_area_struct *vma); 145 + 146 + /* 147 + * mmap_lock should be read-locked for orig_vma->vm_mm. 148 + * mmap_lock should be write-locked for new_vma->vm_mm or new_vma should be 149 + * isolated. 150 + */ 151 + extern void dup_vma_anon_name(struct vm_area_struct *orig_vma, 152 + struct vm_area_struct *new_vma); 153 + 154 + /* 155 + * mmap_lock should be write-locked or vma should have been isolated under 156 + * write-locked mmap_lock protection. 157 + */ 158 + extern void free_vma_anon_name(struct vm_area_struct *vma); 159 + 160 + /* mmap_lock should be read-locked */ 161 + static inline bool is_same_vma_anon_name(struct vm_area_struct *vma, 162 + const char *name) 163 + { 164 + const char *vma_name = vma_anon_name(vma); 165 + 166 + /* either both NULL, or pointers to same string */ 167 + if (vma_name == name) 168 + return true; 169 + 170 + return name && vma_name && !strcmp(name, vma_name); 171 + } 172 + #else /* CONFIG_ANON_VMA_NAME */ 173 + static inline const char *vma_anon_name(struct vm_area_struct *vma) 174 + { 175 + return NULL; 176 + } 177 + static inline void dup_vma_anon_name(struct vm_area_struct *orig_vma, 178 + struct vm_area_struct *new_vma) {} 179 + static inline void free_vma_anon_name(struct vm_area_struct *vma) {} 180 + static inline bool is_same_vma_anon_name(struct vm_area_struct *vma, 181 + const char *name) 182 + { 183 + return true; 184 + } 185 + #endif /* CONFIG_ANON_VMA_NAME */ 186 + 139 187 #endif
-48
include/linux/mm_types.h
··· 890 890 unsigned long val; 891 891 } swp_entry_t; 892 892 893 - #ifdef CONFIG_ANON_VMA_NAME 894 - /* 895 - * mmap_lock should be read-locked when calling vma_anon_name() and while using 896 - * the returned pointer. 897 - */ 898 - extern const char *vma_anon_name(struct vm_area_struct *vma); 899 - 900 - /* 901 - * mmap_lock should be read-locked for orig_vma->vm_mm. 902 - * mmap_lock should be write-locked for new_vma->vm_mm or new_vma should be 903 - * isolated. 904 - */ 905 - extern void dup_vma_anon_name(struct vm_area_struct *orig_vma, 906 - struct vm_area_struct *new_vma); 907 - 908 - /* 909 - * mmap_lock should be write-locked or vma should have been isolated under 910 - * write-locked mmap_lock protection. 911 - */ 912 - extern void free_vma_anon_name(struct vm_area_struct *vma); 913 - 914 - /* mmap_lock should be read-locked */ 915 - static inline bool is_same_vma_anon_name(struct vm_area_struct *vma, 916 - const char *name) 917 - { 918 - const char *vma_name = vma_anon_name(vma); 919 - 920 - /* either both NULL, or pointers to same string */ 921 - if (vma_name == name) 922 - return true; 923 - 924 - return name && vma_name && !strcmp(name, vma_name); 925 - } 926 - #else /* CONFIG_ANON_VMA_NAME */ 927 - static inline const char *vma_anon_name(struct vm_area_struct *vma) 928 - { 929 - return NULL; 930 - } 931 - static inline void dup_vma_anon_name(struct vm_area_struct *orig_vma, 932 - struct vm_area_struct *new_vma) {} 933 - static inline void free_vma_anon_name(struct vm_area_struct *vma) {} 934 - static inline bool is_same_vma_anon_name(struct vm_area_struct *vma, 935 - const char *name) 936 - { 937 - return true; 938 - } 939 - #endif /* CONFIG_ANON_VMA_NAME */ 940 - 941 893 #endif /* _LINUX_MM_TYPES_H */
+1
kernel/fork.c
··· 42 42 #include <linux/mmu_notifier.h> 43 43 #include <linux/fs.h> 44 44 #include <linux/mm.h> 45 + #include <linux/mm_inline.h> 45 46 #include <linux/vmacache.h> 46 47 #include <linux/nsproxy.h> 47 48 #include <linux/capability.h>
+1
mm/madvise.c
··· 18 18 #include <linux/fadvise.h> 19 19 #include <linux/sched.h> 20 20 #include <linux/sched/mm.h> 21 + #include <linux/mm_inline.h> 21 22 #include <linux/string.h> 22 23 #include <linux/uio.h> 23 24 #include <linux/ksm.h>
+1
mm/mmap.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/backing-dev.h> 15 15 #include <linux/mm.h> 16 + #include <linux/mm_inline.h> 16 17 #include <linux/vmacache.h> 17 18 #include <linux/shm.h> 18 19 #include <linux/mman.h>