diff options
| author | Peter Xu <peterx@redhat.com> | 2023-04-12 12:42:54 -0400 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2023-04-18 16:30:05 -0700 |
| commit | 78391f6460ee2cb43f64bbdd7a7cf840e5a118a6 (patch) | |
| tree | b087843517f23c49f2d3ada5f0ec706dc64e85c7 /tools/testing/selftests/mm/vm_util.c | |
| parent | c4277cb6c8e5dc60d425f3a148b3e2bf40d8d778 (diff) | |
selftests/mm: uffd_open_{dev|sys}()
Provide two helpers to open an uffd handle. Drop the error checks around
SKIPs because it's inside an errexit() anyway, which IMHO doesn't really
help much if the test will not continue.
Link: https://lkml.kernel.org/r/20230412164254.328335-1-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests/mm/vm_util.c')
| -rw-r--r-- | tools/testing/selftests/mm/vm_util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index bb633d050d71..5ee6c4688a7c 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -3,6 +3,8 @@ #include <fcntl.h> #include <sys/ioctl.h> #include <linux/userfaultfd.h> +#include <sys/syscall.h> +#include <unistd.h> #include "../kselftest.h" #include "vm_util.h" @@ -230,3 +232,25 @@ int uffd_unregister(int uffd, void *addr, uint64_t len) return ret; } + +int uffd_open_dev(unsigned int flags) +{ + int fd, uffd; + + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); + if (fd < 0) + return fd; + uffd = ioctl(fd, USERFAULTFD_IOC_NEW, flags); + close(fd); + + return uffd; +} + +int uffd_open_sys(unsigned int flags) +{ +#ifdef __NR_userfaultfd + return syscall(__NR_userfaultfd, flags); +#else + return -1; +#endif +} |