summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMike Rapoport <rppt@linux.vnet.ibm.com>2017-02-22 18:44:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-22 19:41:29 -0500
commit6228b8f2d15bc9a9b76d6b209a8b760a642fa996 (patch)
tree31ae498df52e5ee0a0123bc2608d929849da3da2 /tools
parent47dd924508f5fb10480afc69de04539fa3d14034 (diff)
userfaultfd: non-cooperative: selftest: introduce userfaultfd_open
userfaultfd_open will be needed by the non cooperative selftest. Link: http://lkml.kernel.org/r/20161216144821.5183-39-aarcange@redhat.com Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Hillf Danton <hillf.zj@alibaba-inc.com> Cc: Michael Rapoport <RAPOPORT@il.ibm.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/vm/userfaultfd.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index a5e5808c86cd..75540e770b82 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -81,7 +81,7 @@ static int huge_fd;
81static char *huge_fd_off0; 81static char *huge_fd_off0;
82#endif 82#endif
83static unsigned long long *count_verify; 83static unsigned long long *count_verify;
84static int uffd, finished, *pipefd; 84static int uffd, uffd_flags, finished, *pipefd;
85static char *area_src, *area_dst; 85static char *area_src, *area_dst;
86static char *zeropage; 86static char *zeropage;
87pthread_attr_t attr; 87pthread_attr_t attr;
@@ -512,23 +512,9 @@ static int stress(unsigned long *userfaults)
512 return 0; 512 return 0;
513} 513}
514 514
515static int userfaultfd_stress(void) 515static int userfaultfd_open(void)
516{ 516{
517 void *area;
518 char *tmp_area;
519 unsigned long nr;
520 struct uffdio_register uffdio_register;
521 struct uffdio_api uffdio_api; 517 struct uffdio_api uffdio_api;
522 unsigned long cpu;
523 int uffd_flags, err;
524 unsigned long userfaults[nr_cpus];
525
526 allocate_area((void **)&area_src);
527 if (!area_src)
528 return 1;
529 allocate_area((void **)&area_dst);
530 if (!area_dst)
531 return 1;
532 518
533 uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); 519 uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
534 if (uffd < 0) { 520 if (uffd < 0) {
@@ -549,6 +535,29 @@ static int userfaultfd_stress(void)
549 return 1; 535 return 1;
550 } 536 }
551 537
538 return 0;
539}
540
541static int userfaultfd_stress(void)
542{
543 void *area;
544 char *tmp_area;
545 unsigned long nr;
546 struct uffdio_register uffdio_register;
547 unsigned long cpu;
548 int err;
549 unsigned long userfaults[nr_cpus];
550
551 allocate_area((void **)&area_src);
552 if (!area_src)
553 return 1;
554 allocate_area((void **)&area_dst);
555 if (!area_dst)
556 return 1;
557
558 if (userfaultfd_open() < 0)
559 return 1;
560
552 count_verify = malloc(nr_pages * sizeof(unsigned long long)); 561 count_verify = malloc(nr_pages * sizeof(unsigned long long));
553 if (!count_verify) { 562 if (!count_verify) {
554 perror("count_verify"); 563 perror("count_verify");