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: <CAHk-=wjxtRUPLhMXvj7Y_RpMVyVEMSiLd8ZeoroQ+_A8M=BQqg@mail.gmail.com>
Date: Tue, 13 May 2025 14:28:37 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Peter Zijlstra <peterz@...radead.org>, dan.j.williams@...el.com, 
	linux-cxl@...r.kernel.org, linux-kernel@...r.kernel.org, 
	David Lechner <dlechner@...libre.com>, Ingo Molnar <mingo@...nel.org>, 
	"Fabio M. De Francesco" <fabio.maria.de.francesco@...ux.intel.com>, 
	Davidlohr Bueso <dave@...olabs.net>, Jonathan Cameron <jonathan.cameron@...wei.com>, 
	Dave Jiang <dave.jiang@...el.com>, Alison Schofield <alison.schofield@...el.com>, 
	Vishal Verma <vishal.l.verma@...el.com>, Ira Weiny <ira.weiny@...el.com>
Subject: Re: [PATCH 1/7] cleanup: Introduce DEFINE_ACQUIRE() a CLASS() for
 conditional locking

On Tue, 13 May 2025 at 13:31, Al Viro <viro@...iv.linux.org.uk> wrote:
>
> Nevermind - should've read back through the thread for context.

Well, your comment did make me test what I can make gcc generate..

I still can't get gcc to do

       cmpq $-4095,%rdi
        jns     .L189

for IS_ERR_OR_NULL() however hard I try.

The best I *can* get both gcc and clang to at least do

        movq    %rdi, %rcx
        addq    $4095, %rcx
        jns     .L189

which I suspect it much better than the "lea+cmpq", because a pure
register move is handled by the renaming and has no cost aside from
the front end (ie decoding).

So

  #define IS_ERR_OR_NULL(ptr) (MAX_ERRNO + (long)(ptr) >= 0)

does seem to be potentially something we could use, and maybe we could
push the compiler people to realize that their current code generation
is bad.

Of course, it doesn't actually *really* work for IS_ERR_OR_NULL(),
because it gets the wrong results for user pointers, and while the
*common* case for the kernel is to test various kernel pointers, the
user pointer case does happen (ie mmap() and friends).

IOW, it's not actually correct in that form, I just wanted to see what
we could do for some limited form of this common pattern.

Anyway, I am surprised that neither gcc nor clang seem to have
realized that you can turn an "add" that just checks the condition
codes for sign or equality into a "cmp" of the negative value.

It seems such a trivial and obvious thing to do. But maybe I'm
confused and am missing something.

            Linus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ