Commit a5c6bc59 authored by John Hubbard's avatar John Hubbard Committed by Andrew Morton

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 e076eaca ("selftests: break the dependency upon local
header files")

Link: https://lkml.kernel.org/r/20240618022422.804305-7-jhubbard@nvidia.comSigned-off-by: default avatarJohn Hubbard <jhubbard@nvidia.com>
Acked-by: default avatarDavid 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d40f74ab
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <asm-generic/unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> /* Definition of O_* constants */ #include <fcntl.h> /* Definition of O_* constants */
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <asm-generic/unistd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
...@@ -369,7 +369,6 @@ static void test_unmerge_discarded(void) ...@@ -369,7 +369,6 @@ static void test_unmerge_discarded(void)
munmap(map, size); munmap(map, size);
} }
#ifdef __NR_userfaultfd
static void test_unmerge_uffd_wp(void) static void test_unmerge_uffd_wp(void)
{ {
struct uffdio_writeprotect uffd_writeprotect; struct uffdio_writeprotect uffd_writeprotect;
...@@ -430,7 +429,6 @@ static void test_unmerge_uffd_wp(void) ...@@ -430,7 +429,6 @@ static void test_unmerge_uffd_wp(void)
unmap: unmap:
munmap(map, size); munmap(map, size);
} }
#endif
/* Verify that KSM can be enabled / queried with prctl. */ /* Verify that KSM can be enabled / queried with prctl. */
static void test_prctl(void) static void test_prctl(void)
...@@ -686,9 +684,7 @@ int main(int argc, char **argv) ...@@ -686,9 +684,7 @@ int main(int argc, char **argv)
exit(test_child_ksm()); exit(test_child_ksm());
} }
#ifdef __NR_userfaultfd
tests++; tests++;
#endif
ksft_print_header(); ksft_print_header();
ksft_set_plan(tests); ksft_set_plan(tests);
...@@ -700,9 +696,7 @@ int main(int argc, char **argv) ...@@ -700,9 +696,7 @@ int main(int argc, char **argv)
test_unmerge(); test_unmerge();
test_unmerge_zero_pages(); test_unmerge_zero_pages();
test_unmerge_discarded(); test_unmerge_discarded();
#ifdef __NR_userfaultfd
test_unmerge_uffd_wp(); test_unmerge_uffd_wp();
#endif
test_prot_none(); test_prot_none();
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <asm-generic/unistd.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
#define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__) #define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__)
#define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__) #define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__)
#ifdef __NR_memfd_secret
#define PATTERN 0x55 #define PATTERN 0x55
static const int prot = PROT_READ | PROT_WRITE; static const int prot = PROT_READ | PROT_WRITE;
...@@ -334,13 +332,3 @@ int main(int argc, char *argv[]) ...@@ -334,13 +332,3 @@ int main(int argc, char *argv[])
ksft_finished(); ksft_finished();
} }
#else /* __NR_memfd_secret */
int main(int argc, char *argv[])
{
printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n");
return KSFT_SKIP;
}
#endif /* __NR_memfd_secret */
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
*/ */
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <asm-generic/unistd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -265,7 +265,6 @@ static void test_pte_mapped_thp(void) ...@@ -265,7 +265,6 @@ static void test_pte_mapped_thp(void)
munmap(mmap_mem, mmap_size); munmap(mmap_mem, mmap_size);
} }
#ifdef __NR_userfaultfd
static void test_uffdio_copy(void) static void test_uffdio_copy(void)
{ {
struct uffdio_register uffdio_register; struct uffdio_register uffdio_register;
...@@ -322,7 +321,6 @@ static void test_uffdio_copy(void) ...@@ -322,7 +321,6 @@ static void test_uffdio_copy(void)
munmap(dst, pagesize); munmap(dst, pagesize);
free(src); free(src);
} }
#endif /* __NR_userfaultfd */
int main(void) int main(void)
{ {
...@@ -335,9 +333,7 @@ int main(void) ...@@ -335,9 +333,7 @@ int main(void)
thpsize / 1024); thpsize / 1024);
tests += 3; tests += 3;
} }
#ifdef __NR_userfaultfd
tests += 1; tests += 1;
#endif /* __NR_userfaultfd */
ksft_print_header(); ksft_print_header();
ksft_set_plan(tests); ksft_set_plan(tests);
...@@ -367,9 +363,7 @@ int main(void) ...@@ -367,9 +363,7 @@ int main(void)
if (thpsize) if (thpsize)
test_pte_mapped_thp(); test_pte_mapped_thp();
/* Placing a fresh page via userfaultfd may set the PTE dirty. */ /* Placing a fresh page via userfaultfd may set the PTE dirty. */
#ifdef __NR_userfaultfd
test_uffdio_copy(); test_uffdio_copy();
#endif /* __NR_userfaultfd */
err = ksft_get_fail_cnt(); err = ksft_get_fail_cnt();
if (err) if (err)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <asm-generic/unistd.h>
static int mlock2_(void *start, size_t len, int flags) static int mlock2_(void *start, size_t len, int flags)
{ {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <math.h> #include <math.h>
#include <asm/unistd.h> #include <asm-generic/unistd.h>
#include <pthread.h> #include <pthread.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <assert.h> #include <assert.h>
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <asm-generic/unistd.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <setjmp.h> #include <setjmp.h>
......
...@@ -673,11 +673,7 @@ int uffd_open_dev(unsigned int flags) ...@@ -673,11 +673,7 @@ int uffd_open_dev(unsigned int flags)
int uffd_open_sys(unsigned int flags) int uffd_open_sys(unsigned int flags)
{ {
#ifdef __NR_userfaultfd
return syscall(__NR_userfaultfd, flags); return syscall(__NR_userfaultfd, flags);
#else
return -1;
#endif
} }
int uffd_open(unsigned int flags) int uffd_open(unsigned int flags)
......
...@@ -33,11 +33,9 @@ ...@@ -33,11 +33,9 @@
* pthread_mutex_lock will also verify the atomicity of the memory * pthread_mutex_lock will also verify the atomicity of the memory
* transfer (UFFDIO_COPY). * transfer (UFFDIO_COPY).
*/ */
#include <asm-generic/unistd.h>
#include "uffd-common.h" #include "uffd-common.h"
#ifdef __NR_userfaultfd
#define BOUNCE_RANDOM (1<<0) #define BOUNCE_RANDOM (1<<0)
#define BOUNCE_RACINGFAULTS (1<<1) #define BOUNCE_RACINGFAULTS (1<<1)
#define BOUNCE_VERIFY (1<<2) #define BOUNCE_VERIFY (1<<2)
...@@ -466,15 +464,3 @@ int main(int argc, char **argv) ...@@ -466,15 +464,3 @@ int main(int argc, char **argv)
nr_pages, nr_pages_per_cpu); nr_pages, nr_pages_per_cpu);
return userfaultfd_stress(); return userfaultfd_stress();
} }
#else /* __NR_userfaultfd */
#warning "missing __NR_userfaultfd definition"
int main(void)
{
printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n");
return KSFT_SKIP;
}
#endif /* __NR_userfaultfd */
...@@ -5,12 +5,11 @@ ...@@ -5,12 +5,11 @@
* Copyright (C) 2015-2023 Red Hat, Inc. * Copyright (C) 2015-2023 Red Hat, Inc.
*/ */
#include <asm-generic/unistd.h>
#include "uffd-common.h" #include "uffd-common.h"
#include "../../../../mm/gup_test.h" #include "../../../../mm/gup_test.h"
#ifdef __NR_userfaultfd
/* The unit test doesn't need a large or random size, make it 32MB for now */ /* The unit test doesn't need a large or random size, make it 32MB for now */
#define UFFD_TEST_MEM_SIZE (32UL << 20) #define UFFD_TEST_MEM_SIZE (32UL << 20)
...@@ -1554,14 +1553,3 @@ int main(int argc, char *argv[]) ...@@ -1554,14 +1553,3 @@ int main(int argc, char *argv[])
return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS;
} }
#else /* __NR_userfaultfd */
#warning "missing __NR_userfaultfd definition"
int main(void)
{
printf("Skipping %s (missing __NR_userfaultfd)\n", __file__);
return KSFT_SKIP;
}
#endif /* __NR_userfaultfd */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment