Skip to content

Commit 0a7565e

Browse files
johnhubbardakpm00
authored andcommitted
Revert "selftests/mm: remove local __NR_* definitions"
This reverts commit a5c6bc5. The general approach described in commit e076eac ("selftests: break the dependency upon local header files") was taken one step too far here: it should not have been extended to include the syscall numbers. This is because doing so would require per-arch support in tools/include/uapi, and no such support exists. This revert fixes two separate reports of test failures, from Dave Hansen[1], and Li Wang[2]. An excerpt of Dave's report: Before this commit (a5c6bc5) things are fine. But after, I get: running PKEY tests for unsupported CPU/OS An excerpt of Li's report: I just found that mlock2_() return a wrong value in mlock2-test [1] https://lore.kernel.org/[email protected] [2] https://lore.kernel.org/CAEemH2eW=UMu9+turT2jRie7+6ewUazXmA6kL+VBo3cGDGU6RA@mail.gmail.com Link: https://lkml.kernel.org/r/[email protected] Fixes: a5c6bc5 ("selftests/mm: remove local __NR_* definitions") Signed-off-by: John Hubbard <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Li Wang <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jeff Xu <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Muhammad Usama Anjum <[email protected]> Cc: Peter Xu <[email protected]> Cc: Rich Felker <[email protected]> Cc: Shuah Khan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8344017 commit 0a7565e

File tree

9 files changed

+60
-8
lines changed

9 files changed

+60
-8
lines changed

tools/testing/selftests/mm/hugepage-mremap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define _GNU_SOURCE
1616
#include <stdlib.h>
1717
#include <stdio.h>
18-
#include <asm-generic/unistd.h>
18+
#include <unistd.h>
1919
#include <sys/mman.h>
2020
#include <errno.h>
2121
#include <fcntl.h> /* Definition of O_* constants */

tools/testing/selftests/mm/ksm_functional_tests.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <string.h>
1212
#include <stdbool.h>
1313
#include <stdint.h>
14-
#include <asm-generic/unistd.h>
14+
#include <unistd.h>
1515
#include <errno.h>
1616
#include <fcntl.h>
1717
#include <sys/mman.h>
@@ -369,6 +369,7 @@ static void test_unmerge_discarded(void)
369369
munmap(map, size);
370370
}
371371

372+
#ifdef __NR_userfaultfd
372373
static void test_unmerge_uffd_wp(void)
373374
{
374375
struct uffdio_writeprotect uffd_writeprotect;
@@ -429,6 +430,7 @@ static void test_unmerge_uffd_wp(void)
429430
unmap:
430431
munmap(map, size);
431432
}
433+
#endif
432434

433435
/* Verify that KSM can be enabled / queried with prctl. */
434436
static void test_prctl(void)
@@ -684,7 +686,9 @@ int main(int argc, char **argv)
684686
exit(test_child_ksm());
685687
}
686688

689+
#ifdef __NR_userfaultfd
687690
tests++;
691+
#endif
688692

689693
ksft_print_header();
690694
ksft_set_plan(tests);
@@ -696,7 +700,9 @@ int main(int argc, char **argv)
696700
test_unmerge();
697701
test_unmerge_zero_pages();
698702
test_unmerge_discarded();
703+
#ifdef __NR_userfaultfd
699704
test_unmerge_uffd_wp();
705+
#endif
700706

701707
test_prot_none();
702708

tools/testing/selftests/mm/memfd_secret.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <stdlib.h>
1919
#include <string.h>
20-
#include <asm-generic/unistd.h>
20+
#include <unistd.h>
2121
#include <errno.h>
2222
#include <stdio.h>
2323
#include <fcntl.h>
@@ -28,6 +28,8 @@
2828
#define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__)
2929
#define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__)
3030

31+
#ifdef __NR_memfd_secret
32+
3133
#define PATTERN 0x55
3234

3335
static const int prot = PROT_READ | PROT_WRITE;
@@ -332,3 +334,13 @@ int main(int argc, char *argv[])
332334

333335
ksft_finished();
334336
}
337+
338+
#else /* __NR_memfd_secret */
339+
340+
int main(int argc, char *argv[])
341+
{
342+
printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n");
343+
return KSFT_SKIP;
344+
}
345+
346+
#endif /* __NR_memfd_secret */

tools/testing/selftests/mm/mkdirty.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
#include <fcntl.h>
1111
#include <signal.h>
12-
#include <asm-generic/unistd.h>
12+
#include <unistd.h>
1313
#include <string.h>
1414
#include <errno.h>
1515
#include <stdlib.h>
@@ -265,6 +265,7 @@ static void test_pte_mapped_thp(void)
265265
munmap(mmap_mem, mmap_size);
266266
}
267267

268+
#ifdef __NR_userfaultfd
268269
static void test_uffdio_copy(void)
269270
{
270271
struct uffdio_register uffdio_register;
@@ -322,6 +323,7 @@ static void test_uffdio_copy(void)
322323
munmap(dst, pagesize);
323324
free(src);
324325
}
326+
#endif /* __NR_userfaultfd */
325327

326328
int main(void)
327329
{
@@ -334,7 +336,9 @@ int main(void)
334336
thpsize / 1024);
335337
tests += 3;
336338
}
339+
#ifdef __NR_userfaultfd
337340
tests += 1;
341+
#endif /* __NR_userfaultfd */
338342

339343
ksft_print_header();
340344
ksft_set_plan(tests);
@@ -364,7 +368,9 @@ int main(void)
364368
if (thpsize)
365369
test_pte_mapped_thp();
366370
/* Placing a fresh page via userfaultfd may set the PTE dirty. */
371+
#ifdef __NR_userfaultfd
367372
test_uffdio_copy();
373+
#endif /* __NR_userfaultfd */
368374

369375
err = ksft_get_fail_cnt();
370376
if (err)

tools/testing/selftests/mm/mlock2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <errno.h>
44
#include <stdio.h>
55
#include <stdlib.h>
6-
#include <asm-generic/unistd.h>
76

87
static int mlock2_(void *start, size_t len, int flags)
98
{

tools/testing/selftests/mm/protection_keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <sys/wait.h>
4343
#include <sys/stat.h>
4444
#include <fcntl.h>
45-
#include <asm-generic/unistd.h>
45+
#include <unistd.h>
4646
#include <sys/ptrace.h>
4747
#include <setjmp.h>
4848

tools/testing/selftests/mm/uffd-common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,11 @@ int uffd_open_dev(unsigned int flags)
673673

674674
int uffd_open_sys(unsigned int flags)
675675
{
676+
#ifdef __NR_userfaultfd
676677
return syscall(__NR_userfaultfd, flags);
678+
#else
679+
return -1;
680+
#endif
677681
}
678682

679683
int uffd_open(unsigned int flags)

tools/testing/selftests/mm/uffd-stress.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
* pthread_mutex_lock will also verify the atomicity of the memory
3434
* transfer (UFFDIO_COPY).
3535
*/
36-
#include <asm-generic/unistd.h>
36+
3737
#include "uffd-common.h"
3838

3939
uint64_t features;
40+
#ifdef __NR_userfaultfd
4041

4142
#define BOUNCE_RANDOM (1<<0)
4243
#define BOUNCE_RACINGFAULTS (1<<1)
@@ -471,3 +472,15 @@ int main(int argc, char **argv)
471472
nr_pages, nr_pages_per_cpu);
472473
return userfaultfd_stress();
473474
}
475+
476+
#else /* __NR_userfaultfd */
477+
478+
#warning "missing __NR_userfaultfd definition"
479+
480+
int main(void)
481+
{
482+
printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n");
483+
return KSFT_SKIP;
484+
}
485+
486+
#endif /* __NR_userfaultfd */

tools/testing/selftests/mm/uffd-unit-tests.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
* Copyright (C) 2015-2023 Red Hat, Inc.
66
*/
77

8-
#include <asm-generic/unistd.h>
98
#include "uffd-common.h"
109

1110
#include "../../../../mm/gup_test.h"
1211

12+
#ifdef __NR_userfaultfd
13+
1314
/* The unit test doesn't need a large or random size, make it 32MB for now */
1415
#define UFFD_TEST_MEM_SIZE (32UL << 20)
1516

@@ -1558,3 +1559,14 @@ int main(int argc, char *argv[])
15581559
return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS;
15591560
}
15601561

1562+
#else /* __NR_userfaultfd */
1563+
1564+
#warning "missing __NR_userfaultfd definition"
1565+
1566+
int main(void)
1567+
{
1568+
printf("Skipping %s (missing __NR_userfaultfd)\n", __file__);
1569+
return KSFT_SKIP;
1570+
}
1571+
1572+
#endif /* __NR_userfaultfd */

0 commit comments

Comments
 (0)