mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
tools/testing/vma: fix VMA flag tests
The VMA tests are incorrectly referencing NUM_VMA_FLAGS, which doesn't exist, rather they should reference NUM_VMA_FLAG_BITS. Additionally, remove the custom-written implementation of __mk_vma_flags() as this means we are not testing the code as present in the kernel, rather add the actual __mk_vma_flags() to dup.h and add #ifdef's to handle declarations differently depending on NUM_VMA_FLAG_BITS. Link: https://lkml.kernel.org/r/b19c63af3d5efdfe712bf5d5f89368a5360a60f7.1774034900.git.ljs@kernel.org Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com> Cc: "Borislav Petkov (AMD)" <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Christian Brauner <brauner@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jan Kara <jack@suse.cz> Cc: Jann Horn <jannh@google.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Kees Cook <kees@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Ondrej Mosnacek <omosnace@redhat.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Pedro Falcato <pfalcato@suse.de> Cc: Richard Weinberger <richard@nod.at> Cc: Russell King <linux@armlinux.org.uk> Cc: Stephen Smalley <stephen.smalley.work@gmail.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Vlastimil Babka (SUSE) <vbabka@kernel.org> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Will Deacon <will@kernel.org> Cc: xu xin <xu.xin16@zte.com.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
7ec1885a7e
commit
06531d2bf3
|
|
@ -29,8 +29,6 @@ extern unsigned long dac_mmap_min_addr;
|
|||
*/
|
||||
#define pr_warn_once pr_err
|
||||
|
||||
#define pgtable_supports_soft_dirty() 1
|
||||
|
||||
struct anon_vma {
|
||||
struct anon_vma *root;
|
||||
struct rb_root_cached rb_root;
|
||||
|
|
@ -99,23 +97,6 @@ static inline void vma_lock_init(struct vm_area_struct *vma, bool reset_refcnt)
|
|||
refcount_set(&vma->vm_refcnt, 0);
|
||||
}
|
||||
|
||||
static __always_inline vma_flags_t __mk_vma_flags(size_t count,
|
||||
const vma_flag_t *bits)
|
||||
{
|
||||
vma_flags_t flags;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* For testing purposes: allow invalid bit specification so we can
|
||||
* easily test.
|
||||
*/
|
||||
vma_flags_clear_all(&flags);
|
||||
for (i = 0; i < count; i++)
|
||||
if (bits[i] < NUM_VMA_FLAG_BITS)
|
||||
vma_flags_set_flag(&flags, bits[i]);
|
||||
return flags;
|
||||
}
|
||||
|
||||
static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
|
||||
{
|
||||
return PAGE_SIZE;
|
||||
|
|
|
|||
|
|
@ -854,10 +854,21 @@ static inline void vm_flags_clear(struct vm_area_struct *vma,
|
|||
vma_flags_clear_word(&vma->flags, flags);
|
||||
}
|
||||
|
||||
static inline vma_flags_t __mk_vma_flags(size_t count, const vma_flag_t *bits);
|
||||
static __always_inline vma_flags_t __mk_vma_flags(size_t count,
|
||||
const vma_flag_t *bits)
|
||||
{
|
||||
vma_flags_t flags;
|
||||
int i;
|
||||
|
||||
#define mk_vma_flags(...) __mk_vma_flags(COUNT_ARGS(__VA_ARGS__), \
|
||||
(const vma_flag_t []){__VA_ARGS__})
|
||||
vma_flags_clear_all(&flags);
|
||||
for (i = 0; i < count; i++)
|
||||
vma_flags_set_flag(&flags, bits[i]);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
#define mk_vma_flags(...) __mk_vma_flags(COUNT_ARGS(__VA_ARGS__), \
|
||||
(const vma_flag_t []){__VA_ARGS__})
|
||||
|
||||
static __always_inline bool vma_flags_test(const vma_flags_t *flags,
|
||||
vma_flag_t bit)
|
||||
|
|
@ -1390,3 +1401,7 @@ static inline int get_sysctl_max_map_count(void)
|
|||
{
|
||||
return READ_ONCE(sysctl_max_map_count);
|
||||
}
|
||||
|
||||
#ifndef pgtable_supports_soft_dirty
|
||||
#define pgtable_supports_soft_dirty() IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ static bool compare_legacy_flags(vm_flags_t legacy_flags, vma_flags_t flags)
|
|||
const unsigned long legacy_val = legacy_flags;
|
||||
/* The lower word should contain the precise same value. */
|
||||
const unsigned long flags_lower = flags.__vma_flags[0];
|
||||
#if NUM_VMA_FLAGS > BITS_PER_LONG
|
||||
#if NUM_VMA_FLAG_BITS > BITS_PER_LONG
|
||||
int i;
|
||||
|
||||
/* All bits in higher flag values should be zero. */
|
||||
for (i = 1; i < NUM_VMA_FLAGS / BITS_PER_LONG; i++) {
|
||||
for (i = 1; i < NUM_VMA_FLAG_BITS / BITS_PER_LONG; i++) {
|
||||
if (flags.__vma_flags[i] != 0)
|
||||
return false;
|
||||
}
|
||||
|
|
@ -116,6 +116,7 @@ static bool test_vma_flags_cleared(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
/*
|
||||
* Assert that VMA flag functions that operate at the system word level function
|
||||
* correctly.
|
||||
|
|
@ -124,10 +125,14 @@ static bool test_vma_flags_word(void)
|
|||
{
|
||||
vma_flags_t flags = EMPTY_VMA_FLAGS;
|
||||
const vma_flags_t comparison =
|
||||
mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 64, 65);
|
||||
mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT
|
||||
|
||||
, 64, 65
|
||||
);
|
||||
|
||||
/* Set some custom high flags. */
|
||||
vma_flags_set(&flags, 64, 65);
|
||||
|
||||
/* Now overwrite the first word. */
|
||||
vma_flags_overwrite_word(&flags, VM_READ | VM_WRITE);
|
||||
/* Ensure they are equal. */
|
||||
|
|
@ -158,12 +163,17 @@ static bool test_vma_flags_word(void)
|
|||
|
||||
return true;
|
||||
}
|
||||
#endif /* NUM_VMA_FLAG_BITS > 64 */
|
||||
|
||||
/* Ensure that vma_flags_test() and friends works correctly. */
|
||||
static bool test_vma_flags_test(void)
|
||||
{
|
||||
const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
struct vm_area_desc desc = {
|
||||
.vma_flags = flags,
|
||||
};
|
||||
|
|
@ -198,7 +208,11 @@ static bool test_vma_flags_test(void)
|
|||
static bool test_vma_flags_test_any(void)
|
||||
{
|
||||
const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
struct vm_area_struct vma;
|
||||
struct vm_area_desc desc;
|
||||
|
||||
|
|
@ -224,10 +238,12 @@ static bool test_vma_flags_test_any(void)
|
|||
do_test(VMA_READ_BIT, VMA_MAYREAD_BIT, VMA_SEQ_READ_BIT);
|
||||
/* However, the ...test_all() variant should NOT pass. */
|
||||
do_test_all_false(VMA_READ_BIT, VMA_MAYREAD_BIT, VMA_SEQ_READ_BIT);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
/* But should pass for flags present. */
|
||||
do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT, 64, 65);
|
||||
/* Also subsets... */
|
||||
do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT, 64);
|
||||
#endif
|
||||
do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT);
|
||||
do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT);
|
||||
do_test_all_true(VMA_READ_BIT);
|
||||
|
|
@ -291,8 +307,16 @@ static bool test_vma_flags_test_any(void)
|
|||
static bool test_vma_flags_clear(void)
|
||||
{
|
||||
vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
vma_flags_t mask = mk_vma_flags(VMA_EXEC_BIT, 64);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
vma_flags_t mask = mk_vma_flags(VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64
|
||||
#endif
|
||||
);
|
||||
struct vm_area_struct vma;
|
||||
struct vm_area_desc desc;
|
||||
|
||||
|
|
@ -303,6 +327,7 @@ static bool test_vma_flags_clear(void)
|
|||
vma_flags_clear_mask(&flags, mask);
|
||||
vma_flags_clear_mask(&vma.flags, mask);
|
||||
vma_desc_clear_flags_mask(&desc, mask);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
ASSERT_FALSE(vma_flags_test_any(&flags, VMA_EXEC_BIT, 64));
|
||||
ASSERT_FALSE(vma_flags_test_any(&vma.flags, VMA_EXEC_BIT, 64));
|
||||
ASSERT_FALSE(vma_desc_test_any(&desc, VMA_EXEC_BIT, 64));
|
||||
|
|
@ -310,6 +335,7 @@ static bool test_vma_flags_clear(void)
|
|||
vma_flags_set(&flags, VMA_EXEC_BIT, 64);
|
||||
vma_set_flags(&vma, VMA_EXEC_BIT, 64);
|
||||
vma_desc_set_flags(&desc, VMA_EXEC_BIT, 64);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Clear the flags and assert clear worked, then reset flags back to
|
||||
|
|
@ -330,20 +356,27 @@ static bool test_vma_flags_clear(void)
|
|||
do_test_and_reset(VMA_READ_BIT);
|
||||
do_test_and_reset(VMA_WRITE_BIT);
|
||||
do_test_and_reset(VMA_EXEC_BIT);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
do_test_and_reset(64);
|
||||
do_test_and_reset(65);
|
||||
#endif
|
||||
|
||||
/* Two flags, in different orders. */
|
||||
do_test_and_reset(VMA_READ_BIT, VMA_WRITE_BIT);
|
||||
do_test_and_reset(VMA_READ_BIT, VMA_EXEC_BIT);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
do_test_and_reset(VMA_READ_BIT, 64);
|
||||
do_test_and_reset(VMA_READ_BIT, 65);
|
||||
#endif
|
||||
do_test_and_reset(VMA_WRITE_BIT, VMA_READ_BIT);
|
||||
do_test_and_reset(VMA_WRITE_BIT, VMA_EXEC_BIT);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
do_test_and_reset(VMA_WRITE_BIT, 64);
|
||||
do_test_and_reset(VMA_WRITE_BIT, 65);
|
||||
#endif
|
||||
do_test_and_reset(VMA_EXEC_BIT, VMA_READ_BIT);
|
||||
do_test_and_reset(VMA_EXEC_BIT, VMA_WRITE_BIT);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
do_test_and_reset(VMA_EXEC_BIT, 64);
|
||||
do_test_and_reset(VMA_EXEC_BIT, 65);
|
||||
do_test_and_reset(64, VMA_READ_BIT);
|
||||
|
|
@ -354,6 +387,7 @@ static bool test_vma_flags_clear(void)
|
|||
do_test_and_reset(65, VMA_WRITE_BIT);
|
||||
do_test_and_reset(65, VMA_EXEC_BIT);
|
||||
do_test_and_reset(65, 64);
|
||||
#endif
|
||||
|
||||
/* Three flags. */
|
||||
|
||||
|
|
@ -367,7 +401,11 @@ static bool test_vma_flags_clear(void)
|
|||
static bool test_vma_flags_empty(void)
|
||||
{
|
||||
vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
|
||||
ASSERT_FLAGS_NONEMPTY(&flags);
|
||||
vma_flags_clear(&flags, VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT);
|
||||
|
|
@ -386,10 +424,19 @@ static bool test_vma_flags_empty(void)
|
|||
static bool test_vma_flags_diff(void)
|
||||
{
|
||||
vma_flags_t flags1 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
|
||||
vma_flags_t flags2 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, VMA_MAYWRITE_BIT,
|
||||
VMA_MAYEXEC_BIT, 64, 65, 66, 67);
|
||||
VMA_MAYEXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65, 66, 67
|
||||
#endif
|
||||
);
|
||||
vma_flags_t diff = vma_flags_diff_pair(&flags1, &flags2);
|
||||
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
|
|
@ -432,12 +479,23 @@ static bool test_vma_flags_diff(void)
|
|||
static bool test_vma_flags_and(void)
|
||||
{
|
||||
vma_flags_t flags1 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, 64, 65);
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
vma_flags_t flags2 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT, VMA_MAYWRITE_BIT,
|
||||
VMA_MAYEXEC_BIT, 64, 65, 66, 67);
|
||||
vma_flags_t flags3 = mk_vma_flags(VMA_IO_BIT, VMA_MAYBE_GUARD_BIT,
|
||||
68, 69);
|
||||
VMA_MAYEXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65, 66, 67
|
||||
#endif
|
||||
);
|
||||
vma_flags_t flags3 = mk_vma_flags(VMA_IO_BIT, VMA_MAYBE_GUARD_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 68, 69
|
||||
#endif
|
||||
);
|
||||
vma_flags_t and = vma_flags_and_mask(&flags1, flags2);
|
||||
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
|
|
@ -502,7 +560,9 @@ static void run_vma_tests(int *num_tests, int *num_fail)
|
|||
TEST(copy_vma);
|
||||
TEST(vma_flags_unchanged);
|
||||
TEST(vma_flags_cleared);
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
TEST(vma_flags_word);
|
||||
#endif
|
||||
TEST(vma_flags_test);
|
||||
TEST(vma_flags_test_any);
|
||||
TEST(vma_flags_clear);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user