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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJHvVch2LJa57-Si2prKa-S3VUPpu3jYxW+3-+tcLMgSXkB69w@mail.gmail.com>
Date:   Wed, 2 Dec 2020 15:52:56 -0800
From:   Axel Rasmussen <axelrasmussen@...gle.com>
To:     Peter Xu <peterx@...hat.com>
Cc:     Shuah Khan <shuah@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Joe Perches <joe@...ches.com>,
        Mike Rapoport <rppt@...ux.vnet.ibm.com>,
        Andrea Arcangeli <aarcange@...hat.com>,
        David Alan Gilbert <dgilbert@...hat.com>,
        Greg Thelen <gthelen@...gle.com>,
        linux-kselftest@...r.kernel.org,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] userfaultfd: selftests: make __{s,u}64 format specifiers portable

On Wed, Dec 2, 2020 at 3:10 PM Peter Xu <peterx@...hat.com> wrote:
>
> Hi, Axel,
>
> Looks mostly good to me, but a few nitpickings below.
>
> On Wed, Dec 02, 2020 at 01:15:42PM -0800, Axel Rasmussen wrote:
>
> [...]
>
> > +static void uffd_error(const char *message, __s64 code)
> > +{
> > +     fprintf(stderr, "%s: %" PRId64 "\n", message, (int64_t)code);
> > +     exit(1);
> > +}
>
> IMHO a macro that can take arbitrary parameters would be nicer, but if it
> satisfy our need, definitely ok too.
>
> [...]
>
> > @@ -340,7 +348,8 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp)
> >       prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0;
> >
> >       if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) {
> > -             fprintf(stderr, "clear WP failed for address 0x%Lx\n", start);
> > +             fprintf(stderr, "clear WP failed for address 0x%" PRIx64 "\n",
> > +                     (uint64_t)start);
> >               exit(1);
>
> Is it intended to not use uffd_error() here?

Yes, this is intentional. This particular case prints the value in
hexadecimal, rather than decimal.

(Agree that uffd_error() could be made more general to cover cases
like this. I opted for the simplest thing which covers all but two
cases - this one, and one where we "return 1;" instead of "exit(1);" -
but I don't feel strongly.)

>
> >       }
> >  }
>
> [...]
>
> > @@ -979,26 +981,20 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
> >       if (ret) {
> >               /* real retval in ufdio_zeropage.zeropage */
> >               if (has_zeropage) {
> > -                     if (uffdio_zeropage.zeropage == -EEXIST) {
> > -                             fprintf(stderr, "UFFDIO_ZEROPAGE -EEXIST\n");
> > -                             exit(1);
> > -                     } else {
> > -                             fprintf(stderr, "UFFDIO_ZEROPAGE error %Ld\n",
> > -                                     uffdio_zeropage.zeropage);
> > -                             exit(1);
> > -                     }
> > +                     uffd_error(uffdio_zeropage.zeropage == -EEXIST ?
> > +                                              "UFFDIO_ZEROPAGE -EEXIST" :
> > +                                              "UFFDIO_ZEROPAGE error",
>
> Nit: The indents here are a bit odd..

This is what clang-format yields. Are you thinking it would be better
to line everything up with the ( in uffd_error( ?

Or, perhaps this case is a good reason to make uffd_error() a variadic
macro so we can insert "-EEXIST" || "error" with a "%s".

>
> Thanks,
>
> --
> Peter Xu
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ