userfaultfd: non-cooperative: selftest: introduce userfaultfd_open
PATCH 85/142 userfaultfd: non-cooperative: selftest: introduce userfaultfd_open
From: Mike Rapoport <[email protected]>
Subject: userfaultfd: non-cooperative: selftest: introduce userfaultfd_open
userfaultfd_open will be needed by the non cooperative selftest.
Signed-off-by Mike Rapoport <[email protected]>
Signed-off-by Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Michael Rapoport <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
tools/testing/selftests/vm/userfaultfd.c | 41 ++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-non-cooperative-selftest-introduce-userfaultfd_open +25 -16
@@ -81,7 +81,7 @@ static int huge_fd;static char *huge_fd_off0;#endif static unsigned long long *count_verify; -static int uffd, finished, *pipefd; +static int uffd, uffd_flags, finished, *pipefd;static char *area_src, *area_dst;static char *zeropage;pthread_attr_t attr;
@@ -512,23 +512,9 @@ static int stress(unsigned long *userfaureturn 0 ; } -static int userfaultfd_stress (void ) +static int userfaultfd_open (void ) { -void *area; -char *tmp_area; -unsigned long nr; -struct uffdio_register uffdio_register;struct uffdio_api uffdio_api; -unsigned long cpu; -int uffd_flags, err; -unsigned long userfaults[nr_cpus]; - -allocate_area ((void **)&area_src); -if (!area_src) -return 1 ; -allocate_area ((void **)&area_dst); -if (!area_dst) -return 1 ; uffd =syscall (__NR_userfaultfd,O_CLOEXEC |O_NONBLOCK );if (uffd <0 ) {
@@ -549,6 +535,29 @@ static int userfaultfd_stress(void)return 1 ; } +return 0 ; +} + +static int userfaultfd_stress (void ) +{ +void *area; +char *tmp_area; +unsigned long nr; +struct uffdio_register uffdio_register; +unsigned long cpu; +int err; +unsigned long userfaults[nr_cpus]; + +allocate_area ((void **)&area_src); +if (!area_src) +return 1 ; +allocate_area ((void **)&area_dst); +if (!area_dst) +return 1 ; + +if (userfaultfd_open () <0 ) +return 1 ; + count_verify =malloc (nr_pages *sizeof (unsigned long long ));if (!count_verify) {perror ("count_verify" );
_