| From: Axel Rasmussen <axelrasmussen@google.com> |
| Subject: userfaultfd: selftests: modify selftest to use /dev/userfaultfd |
| Date: Fri, 19 Aug 2022 13:51:59 -0700 |
| |
| modify selftest to exit with KSFT_SKIP *only* when features are |
| unsupported, exiting with 1 in other error cases, per Mike |
| |
| Link: https://lkml.kernel.org/r/20220819205201.658693-4-axelrasmussen@google.com |
| Signed-off-by: Axel Rasmussen <axelrasmussen@google.com> |
| Acked-by: Mike Rapoport <rppt@linux.ibm.com> |
| Acked-by: Peter Xu <peterx@redhat.com> |
| Cc: Al Viro <viro@zeniv.linux.org.uk> |
| Cc: Dave Hansen <dave.hansen@linux.intel.com> |
| Cc: Dmitry V. Levin <ldv@altlinux.org> |
| Cc: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org> |
| Cc: Hugh Dickins <hughd@google.com> |
| Cc: Jan Kara <jack@suse.cz> |
| Cc: Jonathan Corbet <corbet@lwn.net> |
| Cc: Mel Gorman <mgorman@techsingularity.net> |
| Cc: Mike Kravetz <mike.kravetz@oracle.com> |
| Cc: Mike Rapoport <rppt@kernel.org> |
| Cc: Nadav Amit <namit@vmware.com> |
| Cc: Shuah Khan <shuah@kernel.org> |
| Cc: Shuah Khan <skhan@linuxfoundation.org> |
| Cc: Suren Baghdasaryan <surenb@google.com> |
| Cc: Vlastimil Babka <vbabka@suse.cz> |
| Cc: Zhang Yi <yi.zhang@huawei.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| tools/testing/selftests/vm/userfaultfd.c | 15 ++++++++++----- |
| 1 file changed, 10 insertions(+), 5 deletions(-) |
| |
| --- a/tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-modify-selftest-to-use-dev-userfaultfd-v7 |
| +++ a/tools/testing/selftests/vm/userfaultfd.c |
| @@ -402,13 +402,16 @@ static void assert_expected_ioctls_prese |
| |
| static int __userfaultfd_open_dev(void) |
| { |
| - int fd, _uffd = -1; |
| + int fd, _uffd; |
| |
| fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); |
| if (fd < 0) |
| - return -1; |
| + errexit(KSFT_SKIP, "opening /dev/userfaultfd failed"); |
| |
| _uffd = ioctl(fd, USERFAULTFD_IOC_NEW, UFFD_FLAGS); |
| + if (_uffd < 0) |
| + errexit(errno == ENOTTY ? KSFT_SKIP : 1, |
| + "creating userfaultfd failed"); |
| close(fd); |
| return _uffd; |
| } |
| @@ -419,10 +422,12 @@ static void userfaultfd_open(uint64_t *f |
| |
| if (test_dev_userfaultfd) |
| uffd = __userfaultfd_open_dev(); |
| - else |
| + else { |
| uffd = syscall(__NR_userfaultfd, UFFD_FLAGS); |
| - if (uffd < 0) |
| - errexit(KSFT_SKIP, "creating userfaultfd failed"); |
| + if (uffd < 0) |
| + errexit(errno == ENOSYS ? KSFT_SKIP : 1, |
| + "creating userfaultfd failed"); |
| + } |
| uffd_flags = fcntl(uffd, F_GETFD, NULL); |
| |
| uffdio_api.api = UFFD_API; |
| _ |