]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
userfaultfd: selftests: modify selftest to use /dev/userfaultfd
authorAxel Rasmussen <axelrasmussen@google.com>
Fri, 19 Aug 2022 20:51:59 +0000 (13:51 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 26 Aug 2022 05:02:46 +0000 (22:02 -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

index cae72867c1733b8bb1488db022f074e6038f4004..7be709d9eed07350260370b3d3b44e75ab4dc7fe 100644 (file)
@@ -402,13 +402,16 @@ static void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls)
 
 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 *features)
 
        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;