lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 12 Apr 2023 11:25:03 -0700
From:   Axel Rasmussen <axelrasmussen@...gle.com>
To:     Peter Xu <peterx@...hat.com>
Cc:     linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andrea Arcangeli <aarcange@...hat.com>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Nadav Amit <nadav.amit@...il.com>,
        David Hildenbrand <david@...hat.com>,
        Mike Rapoport <rppt@...ux.vnet.ibm.com>,
        Leonardo Bras Soares Passos <lsoaresp@...hat.com>,
        Mike Rapoport <rppt@...nel.org>
Subject: Re: [PATCH v2 15/31] selftests/mm: uffd_open_{dev|sys}()

On Wed, Apr 12, 2023 at 9:43 AM Peter Xu <peterx@...hat.com> wrote:
>
> 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.
>
> Reviewed-by: David Hildenbrand <david@...hat.com>
> Reviewed-by: Mike Rapoport (IBM) <rppt@...nel.org>
> Signed-off-by: Peter Xu <peterx@...hat.com>

Reviewed-by: Axel Rasmussen <axelrasmussen@...gle.com>

> ---
>  tools/testing/selftests/mm/uffd-common.c | 28 +++++-------------------
>  tools/testing/selftests/mm/vm_util.c     | 24 ++++++++++++++++++++
>  tools/testing/selftests/mm/vm_util.h     |  2 ++
>  3 files changed, 31 insertions(+), 23 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
> index daa5b5781e7a..09ea24c5f02c 100644
> --- a/tools/testing/selftests/mm/uffd-common.c
> +++ b/tools/testing/selftests/mm/uffd-common.c
> @@ -192,34 +192,16 @@ void uffd_stats_report(struct uffd_stats *stats, int n_cpus)
>         printf("\n");
>  }
>
> -static int __userfaultfd_open_dev(void)
> -{
> -       int fd, _uffd;
> -
> -       fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC);
> -       if (fd < 0)
> -               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;
> -}
> -
>  void userfaultfd_open(uint64_t *features)
>  {
>         struct uffdio_api uffdio_api;
>
>         if (test_dev_userfaultfd)
> -               uffd = __userfaultfd_open_dev();
> -       else {
> -               uffd = syscall(__NR_userfaultfd, UFFD_FLAGS);
> -               if (uffd < 0)
> -                       errexit(errno == ENOSYS ? KSFT_SKIP : 1,
> -                               "creating userfaultfd failed");
> -       }
> +               uffd = uffd_open_dev(UFFD_FLAGS);
> +       else
> +               uffd = uffd_open_sys(UFFD_FLAGS);
> +       if (uffd < 0)
> +               err("uffd open failed (dev=%d)", test_dev_userfaultfd);
>         uffd_flags = fcntl(uffd, F_GETFD, NULL);
>
>         uffdio_api.api = UFFD_API;
> 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
> +}
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 3a9762022efd..481354141533 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -48,6 +48,8 @@ unsigned long default_huge_page_size(void);
>  int uffd_register(int uffd, void *addr, uint64_t len,
>                   bool miss, bool wp, bool minor);
>  int uffd_unregister(int uffd, void *addr, uint64_t len);
> +int uffd_open_dev(unsigned int flags);
> +int uffd_open_sys(unsigned int flags);
>
>  /*
>   * On ppc64 this will only work with radix 2M hugepage size
> --
> 2.39.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ