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

selftests/mm: remove local __NR_* definitions

This continues the work on getting the selftests to build without
requiring people to first run "make headers" [1].

Now that the system call numbers are in the correct, checked-in locations
in the kernel tree (./tools/include/uapi/asm/unistd*.h), make sure that
the mm selftests include that file (indirectly).

Doing so provides guaranteed definitions at build time, so remove all of
the checks for "ifdef __NR_xxx" in the mm selftests, because they will
always be true (defined).

[1] commit e076eaca5906 ("selftests: break the dependency upon local
header files")

Link: https://lkml.kernel.org/r/20240618022422.804305-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Jeff Xu <jeffxu@chromium.org>
Cc: Andrei Vagin <avagin@google.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Rich Felker <dalias@libc.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

John Hubbard and committed by
Andrew Morton
a5c6bc59 d40f74ab

+9 -62
+1 -1
tools/testing/selftests/mm/hugepage-mremap.c
··· 15 15 #define _GNU_SOURCE 16 16 #include <stdlib.h> 17 17 #include <stdio.h> 18 - #include <unistd.h> 18 + #include <asm-generic/unistd.h> 19 19 #include <sys/mman.h> 20 20 #include <errno.h> 21 21 #include <fcntl.h> /* Definition of O_* constants */
+1 -7
tools/testing/selftests/mm/ksm_functional_tests.c
··· 11 11 #include <string.h> 12 12 #include <stdbool.h> 13 13 #include <stdint.h> 14 - #include <unistd.h> 14 + #include <asm-generic/unistd.h> 15 15 #include <errno.h> 16 16 #include <fcntl.h> 17 17 #include <sys/mman.h> ··· 369 369 munmap(map, size); 370 370 } 371 371 372 - #ifdef __NR_userfaultfd 373 372 static void test_unmerge_uffd_wp(void) 374 373 { 375 374 struct uffdio_writeprotect uffd_writeprotect; ··· 429 430 unmap: 430 431 munmap(map, size); 431 432 } 432 - #endif 433 433 434 434 /* Verify that KSM can be enabled / queried with prctl. */ 435 435 static void test_prctl(void) ··· 684 686 exit(test_child_ksm()); 685 687 } 686 688 687 - #ifdef __NR_userfaultfd 688 689 tests++; 689 - #endif 690 690 691 691 ksft_print_header(); 692 692 ksft_set_plan(tests); ··· 696 700 test_unmerge(); 697 701 test_unmerge_zero_pages(); 698 702 test_unmerge_discarded(); 699 - #ifdef __NR_userfaultfd 700 703 test_unmerge_uffd_wp(); 701 - #endif 702 704 703 705 test_prot_none(); 704 706
+1 -13
tools/testing/selftests/mm/memfd_secret.c
··· 17 17 18 18 #include <stdlib.h> 19 19 #include <string.h> 20 - #include <unistd.h> 20 + #include <asm-generic/unistd.h> 21 21 #include <errno.h> 22 22 #include <stdio.h> 23 23 #include <fcntl.h> ··· 27 27 #define fail(fmt, ...) ksft_test_result_fail(fmt, ##__VA_ARGS__) 28 28 #define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__) 29 29 #define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__) 30 - 31 - #ifdef __NR_memfd_secret 32 30 33 31 #define PATTERN 0x55 34 32 ··· 332 334 333 335 ksft_finished(); 334 336 } 335 - 336 - #else /* __NR_memfd_secret */ 337 - 338 - int main(int argc, char *argv[]) 339 - { 340 - printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n"); 341 - return KSFT_SKIP; 342 - } 343 - 344 - #endif /* __NR_memfd_secret */
+1 -7
tools/testing/selftests/mm/mkdirty.c
··· 9 9 */ 10 10 #include <fcntl.h> 11 11 #include <signal.h> 12 - #include <unistd.h> 12 + #include <asm-generic/unistd.h> 13 13 #include <string.h> 14 14 #include <errno.h> 15 15 #include <stdlib.h> ··· 265 265 munmap(mmap_mem, mmap_size); 266 266 } 267 267 268 - #ifdef __NR_userfaultfd 269 268 static void test_uffdio_copy(void) 270 269 { 271 270 struct uffdio_register uffdio_register; ··· 321 322 munmap(dst, pagesize); 322 323 free(src); 323 324 } 324 - #endif /* __NR_userfaultfd */ 325 325 326 326 int main(void) 327 327 { ··· 333 335 thpsize / 1024); 334 336 tests += 3; 335 337 } 336 - #ifdef __NR_userfaultfd 337 338 tests += 1; 338 - #endif /* __NR_userfaultfd */ 339 339 340 340 ksft_print_header(); 341 341 ksft_set_plan(tests); ··· 363 367 if (thpsize) 364 368 test_pte_mapped_thp(); 365 369 /* Placing a fresh page via userfaultfd may set the PTE dirty. */ 366 - #ifdef __NR_userfaultfd 367 370 test_uffdio_copy(); 368 - #endif /* __NR_userfaultfd */ 369 371 370 372 err = ksft_get_fail_cnt(); 371 373 if (err)
+1
tools/testing/selftests/mm/mlock2.h
··· 3 3 #include <errno.h> 4 4 #include <stdio.h> 5 5 #include <stdlib.h> 6 + #include <asm-generic/unistd.h> 6 7 7 8 static int mlock2_(void *start, size_t len, int flags) 8 9 {
+1 -1
tools/testing/selftests/mm/pagemap_ioctl.c
··· 15 15 #include <sys/ioctl.h> 16 16 #include <sys/stat.h> 17 17 #include <math.h> 18 - #include <asm/unistd.h> 18 + #include <asm-generic/unistd.h> 19 19 #include <pthread.h> 20 20 #include <sys/resource.h> 21 21 #include <assert.h>
+1 -1
tools/testing/selftests/mm/protection_keys.c
··· 42 42 #include <sys/wait.h> 43 43 #include <sys/stat.h> 44 44 #include <fcntl.h> 45 - #include <unistd.h> 45 + #include <asm-generic/unistd.h> 46 46 #include <sys/ptrace.h> 47 47 #include <setjmp.h> 48 48
-4
tools/testing/selftests/mm/uffd-common.c
··· 673 673 674 674 int uffd_open_sys(unsigned int flags) 675 675 { 676 - #ifdef __NR_userfaultfd 677 676 return syscall(__NR_userfaultfd, flags); 678 - #else 679 - return -1; 680 - #endif 681 677 } 682 678 683 679 int uffd_open(unsigned int flags)
+1 -15
tools/testing/selftests/mm/uffd-stress.c
··· 33 33 * pthread_mutex_lock will also verify the atomicity of the memory 34 34 * transfer (UFFDIO_COPY). 35 35 */ 36 - 36 + #include <asm-generic/unistd.h> 37 37 #include "uffd-common.h" 38 - 39 - #ifdef __NR_userfaultfd 40 38 41 39 #define BOUNCE_RANDOM (1<<0) 42 40 #define BOUNCE_RACINGFAULTS (1<<1) ··· 464 466 nr_pages, nr_pages_per_cpu); 465 467 return userfaultfd_stress(); 466 468 } 467 - 468 - #else /* __NR_userfaultfd */ 469 - 470 - #warning "missing __NR_userfaultfd definition" 471 - 472 - int main(void) 473 - { 474 - printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n"); 475 - return KSFT_SKIP; 476 - } 477 - 478 - #endif /* __NR_userfaultfd */
+1 -13
tools/testing/selftests/mm/uffd-unit-tests.c
··· 5 5 * Copyright (C) 2015-2023 Red Hat, Inc. 6 6 */ 7 7 8 + #include <asm-generic/unistd.h> 8 9 #include "uffd-common.h" 9 10 10 11 #include "../../../../mm/gup_test.h" 11 - 12 - #ifdef __NR_userfaultfd 13 12 14 13 /* The unit test doesn't need a large or random size, make it 32MB for now */ 15 14 #define UFFD_TEST_MEM_SIZE (32UL << 20) ··· 1553 1554 return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; 1554 1555 } 1555 1556 1556 - #else /* __NR_userfaultfd */ 1557 - 1558 - #warning "missing __NR_userfaultfd definition" 1559 - 1560 - int main(void) 1561 - { 1562 - printf("Skipping %s (missing __NR_userfaultfd)\n", __file__); 1563 - return KSFT_SKIP; 1564 - } 1565 - 1566 - #endif /* __NR_userfaultfd */