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.

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>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
06531d2b 7ec1885a

+92 -36
-19
tools/testing/vma/include/custom.h
··· 29 29 */ 30 30 #define pr_warn_once pr_err 31 31 32 - #define pgtable_supports_soft_dirty() 1 33 - 34 32 struct anon_vma { 35 33 struct anon_vma *root; 36 34 struct rb_root_cached rb_root; ··· 95 97 { 96 98 if (reset_refcnt) 97 99 refcount_set(&vma->vm_refcnt, 0); 98 - } 99 - 100 - static __always_inline vma_flags_t __mk_vma_flags(size_t count, 101 - const vma_flag_t *bits) 102 - { 103 - vma_flags_t flags; 104 - int i; 105 - 106 - /* 107 - * For testing purposes: allow invalid bit specification so we can 108 - * easily test. 109 - */ 110 - vma_flags_clear_all(&flags); 111 - for (i = 0; i < count; i++) 112 - if (bits[i] < NUM_VMA_FLAG_BITS) 113 - vma_flags_set_flag(&flags, bits[i]); 114 - return flags; 115 100 } 116 101 117 102 static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+18 -3
tools/testing/vma/include/dup.h
··· 854 854 vma_flags_clear_word(&vma->flags, flags); 855 855 } 856 856 857 - static inline vma_flags_t __mk_vma_flags(size_t count, const vma_flag_t *bits); 857 + static __always_inline vma_flags_t __mk_vma_flags(size_t count, 858 + const vma_flag_t *bits) 859 + { 860 + vma_flags_t flags; 861 + int i; 858 862 859 - #define mk_vma_flags(...) __mk_vma_flags(COUNT_ARGS(__VA_ARGS__), \ 860 - (const vma_flag_t []){__VA_ARGS__}) 863 + vma_flags_clear_all(&flags); 864 + for (i = 0; i < count; i++) 865 + vma_flags_set_flag(&flags, bits[i]); 866 + 867 + return flags; 868 + } 869 + 870 + #define mk_vma_flags(...) __mk_vma_flags(COUNT_ARGS(__VA_ARGS__), \ 871 + (const vma_flag_t []){__VA_ARGS__}) 861 872 862 873 static __always_inline bool vma_flags_test(const vma_flags_t *flags, 863 874 vma_flag_t bit) ··· 1401 1390 { 1402 1391 return READ_ONCE(sysctl_max_map_count); 1403 1392 } 1393 + 1394 + #ifndef pgtable_supports_soft_dirty 1395 + #define pgtable_supports_soft_dirty() IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) 1396 + #endif
+74 -14
tools/testing/vma/tests/vma.c
··· 5 5 const unsigned long legacy_val = legacy_flags; 6 6 /* The lower word should contain the precise same value. */ 7 7 const unsigned long flags_lower = flags.__vma_flags[0]; 8 - #if NUM_VMA_FLAGS > BITS_PER_LONG 8 + #if NUM_VMA_FLAG_BITS > BITS_PER_LONG 9 9 int i; 10 10 11 11 /* All bits in higher flag values should be zero. */ 12 - for (i = 1; i < NUM_VMA_FLAGS / BITS_PER_LONG; i++) { 12 + for (i = 1; i < NUM_VMA_FLAG_BITS / BITS_PER_LONG; i++) { 13 13 if (flags.__vma_flags[i] != 0) 14 14 return false; 15 15 } ··· 116 116 return true; 117 117 } 118 118 119 + #if NUM_VMA_FLAG_BITS > 64 119 120 /* 120 121 * Assert that VMA flag functions that operate at the system word level function 121 122 * correctly. ··· 125 124 { 126 125 vma_flags_t flags = EMPTY_VMA_FLAGS; 127 126 const vma_flags_t comparison = 128 - mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 64, 65); 127 + mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT 128 + 129 + , 64, 65 130 + ); 129 131 130 132 /* Set some custom high flags. */ 131 133 vma_flags_set(&flags, 64, 65); 134 + 132 135 /* Now overwrite the first word. */ 133 136 vma_flags_overwrite_word(&flags, VM_READ | VM_WRITE); 134 137 /* Ensure they are equal. */ ··· 163 158 164 159 return true; 165 160 } 161 + #endif /* NUM_VMA_FLAG_BITS > 64 */ 166 162 167 163 /* Ensure that vma_flags_test() and friends works correctly. */ 168 164 static bool test_vma_flags_test(void) 169 165 { 170 166 const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 171 - VMA_EXEC_BIT, 64, 65); 167 + VMA_EXEC_BIT 168 + #if NUM_VMA_FLAG_BITS > 64 169 + , 64, 65 170 + #endif 171 + ); 172 172 struct vm_area_desc desc = { 173 173 .vma_flags = flags, 174 174 }; ··· 208 198 static bool test_vma_flags_test_any(void) 209 199 { 210 200 const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 211 - VMA_EXEC_BIT, 64, 65); 201 + VMA_EXEC_BIT 202 + #if NUM_VMA_FLAG_BITS > 64 203 + , 64, 65 204 + #endif 205 + ); 212 206 struct vm_area_struct vma; 213 207 struct vm_area_desc desc; 214 208 ··· 238 224 do_test(VMA_READ_BIT, VMA_MAYREAD_BIT, VMA_SEQ_READ_BIT); 239 225 /* However, the ...test_all() variant should NOT pass. */ 240 226 do_test_all_false(VMA_READ_BIT, VMA_MAYREAD_BIT, VMA_SEQ_READ_BIT); 227 + #if NUM_VMA_FLAG_BITS > 64 241 228 /* But should pass for flags present. */ 242 229 do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT, 64, 65); 243 230 /* Also subsets... */ 244 231 do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT, 64); 232 + #endif 245 233 do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT); 246 234 do_test_all_true(VMA_READ_BIT, VMA_WRITE_BIT); 247 235 do_test_all_true(VMA_READ_BIT); ··· 307 291 static bool test_vma_flags_clear(void) 308 292 { 309 293 vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 310 - VMA_EXEC_BIT, 64, 65); 311 - vma_flags_t mask = mk_vma_flags(VMA_EXEC_BIT, 64); 294 + VMA_EXEC_BIT 295 + #if NUM_VMA_FLAG_BITS > 64 296 + , 64, 65 297 + #endif 298 + ); 299 + vma_flags_t mask = mk_vma_flags(VMA_EXEC_BIT 300 + #if NUM_VMA_FLAG_BITS > 64 301 + , 64 302 + #endif 303 + ); 312 304 struct vm_area_struct vma; 313 305 struct vm_area_desc desc; 314 306 ··· 327 303 vma_flags_clear_mask(&flags, mask); 328 304 vma_flags_clear_mask(&vma.flags, mask); 329 305 vma_desc_clear_flags_mask(&desc, mask); 306 + #if NUM_VMA_FLAG_BITS > 64 330 307 ASSERT_FALSE(vma_flags_test_any(&flags, VMA_EXEC_BIT, 64)); 331 308 ASSERT_FALSE(vma_flags_test_any(&vma.flags, VMA_EXEC_BIT, 64)); 332 309 ASSERT_FALSE(vma_desc_test_any(&desc, VMA_EXEC_BIT, 64)); ··· 335 310 vma_flags_set(&flags, VMA_EXEC_BIT, 64); 336 311 vma_set_flags(&vma, VMA_EXEC_BIT, 64); 337 312 vma_desc_set_flags(&desc, VMA_EXEC_BIT, 64); 313 + #endif 338 314 339 315 /* 340 316 * Clear the flags and assert clear worked, then reset flags back to ··· 356 330 do_test_and_reset(VMA_READ_BIT); 357 331 do_test_and_reset(VMA_WRITE_BIT); 358 332 do_test_and_reset(VMA_EXEC_BIT); 333 + #if NUM_VMA_FLAG_BITS > 64 359 334 do_test_and_reset(64); 360 335 do_test_and_reset(65); 336 + #endif 361 337 362 338 /* Two flags, in different orders. */ 363 339 do_test_and_reset(VMA_READ_BIT, VMA_WRITE_BIT); 364 340 do_test_and_reset(VMA_READ_BIT, VMA_EXEC_BIT); 341 + #if NUM_VMA_FLAG_BITS > 64 365 342 do_test_and_reset(VMA_READ_BIT, 64); 366 343 do_test_and_reset(VMA_READ_BIT, 65); 344 + #endif 367 345 do_test_and_reset(VMA_WRITE_BIT, VMA_READ_BIT); 368 346 do_test_and_reset(VMA_WRITE_BIT, VMA_EXEC_BIT); 347 + #if NUM_VMA_FLAG_BITS > 64 369 348 do_test_and_reset(VMA_WRITE_BIT, 64); 370 349 do_test_and_reset(VMA_WRITE_BIT, 65); 350 + #endif 371 351 do_test_and_reset(VMA_EXEC_BIT, VMA_READ_BIT); 372 352 do_test_and_reset(VMA_EXEC_BIT, VMA_WRITE_BIT); 353 + #if NUM_VMA_FLAG_BITS > 64 373 354 do_test_and_reset(VMA_EXEC_BIT, 64); 374 355 do_test_and_reset(VMA_EXEC_BIT, 65); 375 356 do_test_and_reset(64, VMA_READ_BIT); ··· 387 354 do_test_and_reset(65, VMA_WRITE_BIT); 388 355 do_test_and_reset(65, VMA_EXEC_BIT); 389 356 do_test_and_reset(65, 64); 357 + #endif 390 358 391 359 /* Three flags. */ 392 360 ··· 401 367 static bool test_vma_flags_empty(void) 402 368 { 403 369 vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 404 - VMA_EXEC_BIT, 64, 65); 370 + VMA_EXEC_BIT 371 + #if NUM_VMA_FLAG_BITS > 64 372 + , 64, 65 373 + #endif 374 + ); 405 375 406 376 ASSERT_FLAGS_NONEMPTY(&flags); 407 377 vma_flags_clear(&flags, VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT); ··· 424 386 static bool test_vma_flags_diff(void) 425 387 { 426 388 vma_flags_t flags1 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 427 - VMA_EXEC_BIT, 64, 65); 389 + VMA_EXEC_BIT 390 + #if NUM_VMA_FLAG_BITS > 64 391 + , 64, 65 392 + #endif 393 + ); 394 + 428 395 vma_flags_t flags2 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 429 396 VMA_EXEC_BIT, VMA_MAYWRITE_BIT, 430 - VMA_MAYEXEC_BIT, 64, 65, 66, 67); 397 + VMA_MAYEXEC_BIT 398 + #if NUM_VMA_FLAG_BITS > 64 399 + , 64, 65, 66, 67 400 + #endif 401 + ); 431 402 vma_flags_t diff = vma_flags_diff_pair(&flags1, &flags2); 432 403 433 404 #if NUM_VMA_FLAG_BITS > 64 ··· 479 432 static bool test_vma_flags_and(void) 480 433 { 481 434 vma_flags_t flags1 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 482 - VMA_EXEC_BIT, 64, 65); 435 + VMA_EXEC_BIT 436 + #if NUM_VMA_FLAG_BITS > 64 437 + , 64, 65 438 + #endif 439 + ); 483 440 vma_flags_t flags2 = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, 484 441 VMA_EXEC_BIT, VMA_MAYWRITE_BIT, 485 - VMA_MAYEXEC_BIT, 64, 65, 66, 67); 486 - vma_flags_t flags3 = mk_vma_flags(VMA_IO_BIT, VMA_MAYBE_GUARD_BIT, 487 - 68, 69); 442 + VMA_MAYEXEC_BIT 443 + #if NUM_VMA_FLAG_BITS > 64 444 + , 64, 65, 66, 67 445 + #endif 446 + ); 447 + vma_flags_t flags3 = mk_vma_flags(VMA_IO_BIT, VMA_MAYBE_GUARD_BIT 448 + #if NUM_VMA_FLAG_BITS > 64 449 + , 68, 69 450 + #endif 451 + ); 488 452 vma_flags_t and = vma_flags_and_mask(&flags1, flags2); 489 453 490 454 #if NUM_VMA_FLAG_BITS > 64 ··· 560 502 TEST(copy_vma); 561 503 TEST(vma_flags_unchanged); 562 504 TEST(vma_flags_cleared); 505 + #if NUM_VMA_FLAG_BITS > 64 563 506 TEST(vma_flags_word); 507 + #endif 564 508 TEST(vma_flags_test); 565 509 TEST(vma_flags_test_any); 566 510 TEST(vma_flags_clear);