diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/membarrier/Makefile | 7 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/membarrier_test.c | 5 | ||||
-rw-r--r-- | tools/testing/selftests/vm/Makefile | 9 | ||||
-rw-r--r-- | tools/testing/selftests/vm/userfaultfd.c | 52 |
4 files changed, 39 insertions, 34 deletions
diff --git a/tools/testing/selftests/membarrier/Makefile b/tools/testing/selftests/membarrier/Makefile index 877a50355d7f..a1a97085847d 100644 --- a/tools/testing/selftests/membarrier/Makefile +++ b/tools/testing/selftests/membarrier/Makefile | |||
@@ -1,11 +1,10 @@ | |||
1 | CFLAGS += -g -I../../../../usr/include/ | 1 | CFLAGS += -g -I../../../../usr/include/ |
2 | 2 | ||
3 | all: | ||
4 | $(CC) $(CFLAGS) membarrier_test.c -o membarrier_test | ||
5 | |||
6 | TEST_PROGS := membarrier_test | 3 | TEST_PROGS := membarrier_test |
7 | 4 | ||
5 | all: $(TEST_PROGS) | ||
6 | |||
8 | include ../lib.mk | 7 | include ../lib.mk |
9 | 8 | ||
10 | clean: | 9 | clean: |
11 | $(RM) membarrier_test | 10 | $(RM) $(TEST_PROGS) |
diff --git a/tools/testing/selftests/membarrier/membarrier_test.c b/tools/testing/selftests/membarrier/membarrier_test.c index dde312508007..535f0fef4d0b 100644 --- a/tools/testing/selftests/membarrier/membarrier_test.c +++ b/tools/testing/selftests/membarrier/membarrier_test.c | |||
@@ -1,9 +1,6 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | #define __EXPORTED_HEADERS__ | ||
3 | |||
4 | #include <linux/membarrier.h> | 2 | #include <linux/membarrier.h> |
5 | #include <asm-generic/unistd.h> | 3 | #include <syscall.h> |
6 | #include <sys/syscall.h> | ||
7 | #include <stdio.h> | 4 | #include <stdio.h> |
8 | #include <errno.h> | 5 | #include <errno.h> |
9 | #include <string.h> | 6 | #include <string.h> |
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index d36fab7d8ebd..3c53cac15de1 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # Makefile for vm selftests | 1 | # Makefile for vm selftests |
2 | 2 | ||
3 | CFLAGS = -Wall | 3 | CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) |
4 | BINARIES = compaction_test | 4 | BINARIES = compaction_test |
5 | BINARIES += hugepage-mmap | 5 | BINARIES += hugepage-mmap |
6 | BINARIES += hugepage-shm | 6 | BINARIES += hugepage-shm |
@@ -12,8 +12,11 @@ BINARIES += userfaultfd | |||
12 | all: $(BINARIES) | 12 | all: $(BINARIES) |
13 | %: %.c | 13 | %: %.c |
14 | $(CC) $(CFLAGS) -o $@ $^ -lrt | 14 | $(CC) $(CFLAGS) -o $@ $^ -lrt |
15 | userfaultfd: userfaultfd.c | 15 | userfaultfd: userfaultfd.c ../../../../usr/include/linux/kernel.h |
16 | $(CC) $(CFLAGS) -O2 -o $@ $^ -lpthread | 16 | $(CC) $(CFLAGS) -O2 -o $@ $< -lpthread |
17 | |||
18 | ../../../../usr/include/linux/kernel.h: | ||
19 | make -C ../../../.. headers_install | ||
17 | 20 | ||
18 | TEST_PROGS := run_vmtests | 21 | TEST_PROGS := run_vmtests |
19 | TEST_FILES := $(BINARIES) | 22 | TEST_FILES := $(BINARIES) |
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 2c7cca6f26a4..d77ed41b2094 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c | |||
@@ -64,17 +64,9 @@ | |||
64 | #include <sys/syscall.h> | 64 | #include <sys/syscall.h> |
65 | #include <sys/ioctl.h> | 65 | #include <sys/ioctl.h> |
66 | #include <pthread.h> | 66 | #include <pthread.h> |
67 | #include "../../../../include/uapi/linux/userfaultfd.h" | 67 | #include <linux/userfaultfd.h> |
68 | 68 | ||
69 | #ifdef __x86_64__ | 69 | #ifdef __NR_userfaultfd |
70 | #define __NR_userfaultfd 323 | ||
71 | #elif defined(__i386__) | ||
72 | #define __NR_userfaultfd 374 | ||
73 | #elif defined(__powewrpc__) | ||
74 | #define __NR_userfaultfd 364 | ||
75 | #else | ||
76 | #error "missing __NR_userfaultfd definition" | ||
77 | #endif | ||
78 | 70 | ||
79 | static unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; | 71 | static unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; |
80 | 72 | ||
@@ -430,7 +422,7 @@ static int userfaultfd_stress(void) | |||
430 | struct uffdio_register uffdio_register; | 422 | struct uffdio_register uffdio_register; |
431 | struct uffdio_api uffdio_api; | 423 | struct uffdio_api uffdio_api; |
432 | unsigned long cpu; | 424 | unsigned long cpu; |
433 | int uffd_flags; | 425 | int uffd_flags, err; |
434 | unsigned long userfaults[nr_cpus]; | 426 | unsigned long userfaults[nr_cpus]; |
435 | 427 | ||
436 | if (posix_memalign(&area, page_size, nr_pages * page_size)) { | 428 | if (posix_memalign(&area, page_size, nr_pages * page_size)) { |
@@ -473,6 +465,14 @@ static int userfaultfd_stress(void) | |||
473 | *area_mutex(area_src, nr) = (pthread_mutex_t) | 465 | *area_mutex(area_src, nr) = (pthread_mutex_t) |
474 | PTHREAD_MUTEX_INITIALIZER; | 466 | PTHREAD_MUTEX_INITIALIZER; |
475 | count_verify[nr] = *area_count(area_src, nr) = 1; | 467 | count_verify[nr] = *area_count(area_src, nr) = 1; |
468 | /* | ||
469 | * In the transition between 255 to 256, powerpc will | ||
470 | * read out of order in my_bcmp and see both bytes as | ||
471 | * zero, so leave a placeholder below always non-zero | ||
472 | * after the count, to avoid my_bcmp to trigger false | ||
473 | * positives. | ||
474 | */ | ||
475 | *(area_count(area_src, nr) + 1) = 1; | ||
476 | } | 476 | } |
477 | 477 | ||
478 | pipefd = malloc(sizeof(int) * nr_cpus * 2); | 478 | pipefd = malloc(sizeof(int) * nr_cpus * 2); |
@@ -499,6 +499,7 @@ static int userfaultfd_stress(void) | |||
499 | pthread_attr_init(&attr); | 499 | pthread_attr_init(&attr); |
500 | pthread_attr_setstacksize(&attr, 16*1024*1024); | 500 | pthread_attr_setstacksize(&attr, 16*1024*1024); |
501 | 501 | ||
502 | err = 0; | ||
502 | while (bounces--) { | 503 | while (bounces--) { |
503 | unsigned long expected_ioctls; | 504 | unsigned long expected_ioctls; |
504 | 505 | ||
@@ -579,20 +580,13 @@ static int userfaultfd_stress(void) | |||
579 | /* verification */ | 580 | /* verification */ |
580 | if (bounces & BOUNCE_VERIFY) { | 581 | if (bounces & BOUNCE_VERIFY) { |
581 | for (nr = 0; nr < nr_pages; nr++) { | 582 | for (nr = 0; nr < nr_pages; nr++) { |
582 | if (my_bcmp(area_dst, | ||
583 | area_dst + nr * page_size, | ||
584 | sizeof(pthread_mutex_t))) { | ||
585 | fprintf(stderr, | ||
586 | "error mutex 2 %lu\n", | ||
587 | nr); | ||
588 | bounces = 0; | ||
589 | } | ||
590 | if (*area_count(area_dst, nr) != count_verify[nr]) { | 583 | if (*area_count(area_dst, nr) != count_verify[nr]) { |
591 | fprintf(stderr, | 584 | fprintf(stderr, |
592 | "error area_count %Lu %Lu %lu\n", | 585 | "error area_count %Lu %Lu %lu\n", |
593 | *area_count(area_src, nr), | 586 | *area_count(area_src, nr), |
594 | count_verify[nr], | 587 | count_verify[nr], |
595 | nr); | 588 | nr); |
589 | err = 1; | ||
596 | bounces = 0; | 590 | bounces = 0; |
597 | } | 591 | } |
598 | } | 592 | } |
@@ -609,7 +603,7 @@ static int userfaultfd_stress(void) | |||
609 | printf("\n"); | 603 | printf("\n"); |
610 | } | 604 | } |
611 | 605 | ||
612 | return 0; | 606 | return err; |
613 | } | 607 | } |
614 | 608 | ||
615 | int main(int argc, char **argv) | 609 | int main(int argc, char **argv) |
@@ -618,8 +612,8 @@ int main(int argc, char **argv) | |||
618 | fprintf(stderr, "Usage: <MiB> <bounces>\n"), exit(1); | 612 | fprintf(stderr, "Usage: <MiB> <bounces>\n"), exit(1); |
619 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); | 613 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
620 | page_size = sysconf(_SC_PAGE_SIZE); | 614 | page_size = sysconf(_SC_PAGE_SIZE); |
621 | if ((unsigned long) area_count(NULL, 0) + sizeof(unsigned long long) > | 615 | if ((unsigned long) area_count(NULL, 0) + sizeof(unsigned long long) * 2 |
622 | page_size) | 616 | > page_size) |
623 | fprintf(stderr, "Impossible to run this test\n"), exit(2); | 617 | fprintf(stderr, "Impossible to run this test\n"), exit(2); |
624 | nr_pages_per_cpu = atol(argv[1]) * 1024*1024 / page_size / | 618 | nr_pages_per_cpu = atol(argv[1]) * 1024*1024 / page_size / |
625 | nr_cpus; | 619 | nr_cpus; |
@@ -637,3 +631,15 @@ int main(int argc, char **argv) | |||
637 | nr_pages, nr_pages_per_cpu); | 631 | nr_pages, nr_pages_per_cpu); |
638 | return userfaultfd_stress(); | 632 | return userfaultfd_stress(); |
639 | } | 633 | } |
634 | |||
635 | #else /* __NR_userfaultfd */ | ||
636 | |||
637 | #warning "missing __NR_userfaultfd definition" | ||
638 | |||
639 | int main(void) | ||
640 | { | ||
641 | printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n"); | ||
642 | return 0; | ||
643 | } | ||
644 | |||
645 | #endif /* __NR_userfaultfd */ | ||