Skip to content

Commit a1f0dac

Browse files
ljskernelakpm00
authored andcommitted
tools/testing/vma: separate out vma_internal.h into logical headers
The vma_internal.h file is becoming entirely unmanageable. It combines duplicated kernel implementation logic that needs to be kept in-sync with the kernel, stubbed out declarations that we simply ignore for testing purposes and custom logic added to aid testing. If we separate each of the three things into separate headers it makes things far more manageable, so do so: * include/stubs.h contains the stubbed declarations, * include/dup.h contains the duplicated kernel declarations, and * include/custom.h contains declarations customised for testing. [lorenzo.stoakes@oracle.com: avoid a duplicate struct define] Link: https://lkml.kernel.org/r/1e032732-61c3-485c-9aa7-6a09016fefc1@lucifer.local Link: https://lkml.kernel.org/r/dd57baf5b5986cb96a167150ac712cbe804b63ee.1769097829.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Zi Yan <ziy@nvidia.com> Cc: Damien Le Moal <dlemoal@kernel.org> Cc: "Darrick J. Wong" <djwong@kernel.org> Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Yury Norov <ynorov@nvidia.com> Cc: Chris Mason <clm@fb.com> Cc: Pedro Falcato <pfalcato@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6aacab3 commit a1f0dac

5 files changed

Lines changed: 1873 additions & 1925 deletions

File tree

tools/testing/vma/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include ../shared/shared.mk
99
OFILES = $(SHARED_OFILES) main.o shared.o maple-shim.o
1010
TARGETS = vma
1111

12-
main.o: main.c shared.c shared.h vma_internal.h tests/merge.c tests/mmap.c tests/vma.c ../../../mm/vma.c ../../../mm/vma_init.c ../../../mm/vma_exec.c ../../../mm/vma.h
12+
main.o: main.c shared.c shared.h vma_internal.h tests/merge.c tests/mmap.c tests/vma.c ../../../mm/vma.c ../../../mm/vma_init.c ../../../mm/vma_exec.c ../../../mm/vma.h include/custom.h include/dup.h include/stubs.h
1313

1414
vma: $(OFILES)
1515
$(CC) $(CFLAGS) -o $@ $(OFILES) $(LDLIBS)

tools/testing/vma/include/custom.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
3+
#pragma once
4+
5+
/*
6+
* Contains declarations that exist in the kernel which have been CUSTOMISED for
7+
* testing purposes to faciliate userland VMA testing.
8+
*/
9+
10+
#ifdef CONFIG_MMU
11+
extern unsigned long mmap_min_addr;
12+
extern unsigned long dac_mmap_min_addr;
13+
#else
14+
#define mmap_min_addr 0UL
15+
#define dac_mmap_min_addr 0UL
16+
#endif
17+
18+
#define VM_WARN_ON(_expr) (WARN_ON(_expr))
19+
#define VM_WARN_ON_ONCE(_expr) (WARN_ON_ONCE(_expr))
20+
#define VM_WARN_ON_VMG(_expr, _vmg) (WARN_ON(_expr))
21+
#define VM_BUG_ON(_expr) (BUG_ON(_expr))
22+
#define VM_BUG_ON_VMA(_expr, _vma) (BUG_ON(_expr))
23+
24+
/* We hardcode this for now. */
25+
#define sysctl_max_map_count 0x1000000UL
26+
27+
#define TASK_SIZE ((1ul << 47)-PAGE_SIZE)
28+
29+
/*
30+
* The shared stubs do not implement this, it amounts to an fprintf(STDERR,...)
31+
* either way :)
32+
*/
33+
#define pr_warn_once pr_err
34+
35+
#define pgtable_supports_soft_dirty() 1
36+
37+
struct anon_vma {
38+
struct anon_vma *root;
39+
struct rb_root_cached rb_root;
40+
41+
/* Test fields. */
42+
bool was_cloned;
43+
bool was_unlinked;
44+
};
45+
46+
static inline void unlink_anon_vmas(struct vm_area_struct *vma)
47+
{
48+
/* For testing purposes, indicate that the anon_vma was unlinked. */
49+
vma->anon_vma->was_unlinked = true;
50+
}
51+
52+
static inline void vma_start_write(struct vm_area_struct *vma)
53+
{
54+
/* Used to indicate to tests that a write operation has begun. */
55+
vma->vm_lock_seq++;
56+
}
57+
58+
static inline __must_check
59+
int vma_start_write_killable(struct vm_area_struct *vma)
60+
{
61+
/* Used to indicate to tests that a write operation has begun. */
62+
vma->vm_lock_seq++;
63+
return 0;
64+
}
65+
66+
static inline int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src,
67+
enum vma_operation operation)
68+
{
69+
/* For testing purposes. We indicate that an anon_vma has been cloned. */
70+
if (src->anon_vma != NULL) {
71+
dst->anon_vma = src->anon_vma;
72+
dst->anon_vma->was_cloned = true;
73+
}
74+
75+
return 0;
76+
}
77+
78+
static inline int __anon_vma_prepare(struct vm_area_struct *vma)
79+
{
80+
struct anon_vma *anon_vma = calloc(1, sizeof(struct anon_vma));
81+
82+
if (!anon_vma)
83+
return -ENOMEM;
84+
85+
anon_vma->root = anon_vma;
86+
vma->anon_vma = anon_vma;
87+
88+
return 0;
89+
}
90+
91+
static inline int anon_vma_prepare(struct vm_area_struct *vma)
92+
{
93+
if (likely(vma->anon_vma))
94+
return 0;
95+
96+
return __anon_vma_prepare(vma);
97+
}
98+
99+
static inline void vma_lock_init(struct vm_area_struct *vma, bool reset_refcnt)
100+
{
101+
if (reset_refcnt)
102+
refcount_set(&vma->vm_refcnt, 0);
103+
}

0 commit comments

Comments
 (0)