Skip to content

Commit 17fca13

Browse files
arndbtorvalds
authored andcommitted
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/[email protected] Fixes: "mm: add a field to store names for private anonymous memory" Signed-off-by: Arnd Bergmann <[email protected]> Cc: Al Viro <[email protected]> Cc: Colin Cross <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Kees Cook <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Peter Xu <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 78db341 commit 17fca13

File tree

7 files changed

+55
-48
lines changed

7 files changed

+55
-48
lines changed

fs/proc/task_mmu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/pagewalk.h>
33
#include <linux/vmacache.h>
4+
#include <linux/mm_inline.h>
45
#include <linux/hugetlb.h>
56
#include <linux/huge_mm.h>
67
#include <linux/mount.h>

fs/userfaultfd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/sched/signal.h>
1616
#include <linux/sched/mm.h>
1717
#include <linux/mm.h>
18+
#include <linux/mm_inline.h>
1819
#include <linux/mmu_notifier.h>
1920
#include <linux/poll.h>
2021
#include <linux/slab.h>

include/linux/mm_inline.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/huge_mm.h>
66
#include <linux/swap.h>
7+
#include <linux/string.h>
78

89
/**
910
* folio_is_file_lru - Should the folio be on a file LRU or anon LRU?
@@ -135,4 +136,53 @@ static __always_inline void del_page_from_lru_list(struct page *page,
135136
{
136137
lruvec_del_folio(lruvec, page_folio(page));
137138
}
139+
140+
#ifdef CONFIG_ANON_VMA_NAME
141+
/*
142+
* mmap_lock should be read-locked when calling vma_anon_name() and while using
143+
* the returned pointer.
144+
*/
145+
extern const char *vma_anon_name(struct vm_area_struct *vma);
146+
147+
/*
148+
* mmap_lock should be read-locked for orig_vma->vm_mm.
149+
* mmap_lock should be write-locked for new_vma->vm_mm or new_vma should be
150+
* isolated.
151+
*/
152+
extern void dup_vma_anon_name(struct vm_area_struct *orig_vma,
153+
struct vm_area_struct *new_vma);
154+
155+
/*
156+
* mmap_lock should be write-locked or vma should have been isolated under
157+
* write-locked mmap_lock protection.
158+
*/
159+
extern void free_vma_anon_name(struct vm_area_struct *vma);
160+
161+
/* mmap_lock should be read-locked */
162+
static inline bool is_same_vma_anon_name(struct vm_area_struct *vma,
163+
const char *name)
164+
{
165+
const char *vma_name = vma_anon_name(vma);
166+
167+
/* either both NULL, or pointers to same string */
168+
if (vma_name == name)
169+
return true;
170+
171+
return name && vma_name && !strcmp(name, vma_name);
172+
}
173+
#else /* CONFIG_ANON_VMA_NAME */
174+
static inline const char *vma_anon_name(struct vm_area_struct *vma)
175+
{
176+
return NULL;
177+
}
178+
static inline void dup_vma_anon_name(struct vm_area_struct *orig_vma,
179+
struct vm_area_struct *new_vma) {}
180+
static inline void free_vma_anon_name(struct vm_area_struct *vma) {}
181+
static inline bool is_same_vma_anon_name(struct vm_area_struct *vma,
182+
const char *name)
183+
{
184+
return true;
185+
}
186+
#endif /* CONFIG_ANON_VMA_NAME */
187+
138188
#endif

include/linux/mm_types.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -890,52 +890,4 @@ typedef struct {
890890
unsigned long val;
891891
} swp_entry_t;
892892

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-
941893
#endif /* _LINUX_MM_TYPES_H */

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/mmu_notifier.h>
4343
#include <linux/fs.h>
4444
#include <linux/mm.h>
45+
#include <linux/mm_inline.h>
4546
#include <linux/vmacache.h>
4647
#include <linux/nsproxy.h>
4748
#include <linux/capability.h>

mm/madvise.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/fadvise.h>
1919
#include <linux/sched.h>
2020
#include <linux/sched/mm.h>
21+
#include <linux/mm_inline.h>
2122
#include <linux/string.h>
2223
#include <linux/uio.h>
2324
#include <linux/ksm.h>

mm/mmap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/slab.h>
1414
#include <linux/backing-dev.h>
1515
#include <linux/mm.h>
16+
#include <linux/mm_inline.h>
1617
#include <linux/vmacache.h>
1718
#include <linux/shm.h>
1819
#include <linux/mman.h>

0 commit comments

Comments
 (0)