From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Nick Desaulniers" <ndesaulniers@google.com>
Cc: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Bill Wendling" <morbo@google.com>,
"Ard Biesheuvel" <ardb+git@google.com>,
linux-kernel@vger.kernel.org,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Nathan Chancellor" <nathan@kernel.org>,
"Justin Stitt" <justinstitt@google.com>,
llvm@lists.linux.dev
Subject: Re: [PATCH] locking/local_lock: Don't evaluate the per-CPU lock pointer if unused
Date: Wed, 25 Nov 2026 09:03:42 +0100 [thread overview]
Message-ID: <c508e8c9-29ad-4157-bf64-40532b708067@app.fastmail.com> (raw)
In-Reply-To: <CAKwvOdn=FjiYgiB9wdut2=2FwivPUXiNOG2F=uOeEkycrtoVUw@mail.gmail.com>
On Tue, 24 Nov 2026, at 23:44, Nick Desaulniers wrote:
> On Tue, Nov 24, 2026 at 2:25 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>>
>>
>>
>> On Tue, 24 Nov 2026, at 20:32, Nick Desaulniers wrote:
>> > On Tue, Nov 24, 2026 at 8:39 AM Sebastian Andrzej Siewior
>> > <bigeasy@linutronix.de> wrote:
>> >>
>> >> On 2026-11-23 13:52:09 [-0800], Nick Desaulniers wrote:
>> >> > On Mon, Nov 23, 2026 at 1:23 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>> >> > >
>> >> > >
>> >> +/*
>> >> + * Only evaluate @lock if it is actually used, i.e., for local_trylock_t, or
>> >> + * when lock debugging is enabled (see local_lock_acquire() above).
>> >> + */
>> >> #define __local_lock_acquire(lock) \
>> >> do { \
>> >> - local_trylock_t *__tl; \
>> >> - local_lock_t *__l; \
>> >> - \
>> >> - __l = (local_lock_t *)(lock); \
>> >> - __tl = (local_trylock_t *)__l; \
>> >> _Generic((lock), \
>> >> local_trylock_t *: ({ \
>> >> + local_trylock_t *__tl = (local_trylock_t *)(lock); \
>> >> + \
>> >
>> > Why do we need the temporary?
>> >
>>
>> Because 'lock' is a macro argument that we should evaluate only once.
>
> Ah, right! Don't we have __auto_type or something for that though?
> Maybe cleaner than the cast? Ah, that also doesn't work for the same
> reason as below.
>
>>
>> >> lockdep_assert(__tl->acquired == 0); \
>> >> WRITE_ONCE(__tl->acquired, 1); \
>> >> + local_lock_acquire((local_lock_t *)__tl); \
>> >> }), \
>> >> - local_lock_t *: (void)0); \
>> >> - local_lock_acquire(__l); \
>> >> + local_lock_t *: ({ \
>> >> + local_lock_acquire((local_lock_t *)(lock)); \
>> >
>> > Is this cast necessary?
>> >
>>
>> Surprisingly, yes.
>>
>> https://godbolt.org/z/E8rGchfev
>
> What the f...
>
> Anyways, with the additional context (git trailers) linking to the
> clang bugs (and missed optimizations):
>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
It turns out we should be able to work around this treewide by using
__seg_gs only for __raw_cpu_read(). I'll send that out and we can
discuss there.
prev parent reply other threads:[~2026-11-25 8:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 10:56 Ard Biesheuvel
2026-11-23 19:12 ` Nick Desaulniers
2026-11-23 19:19 ` Nick Desaulniers
2026-11-23 21:23 ` Ard Biesheuvel
2026-11-23 21:52 ` Nick Desaulniers
2026-11-23 22:15 ` Ard Biesheuvel
2026-11-24 16:39 ` Sebastian Andrzej Siewior
2026-11-24 19:32 ` Nick Desaulniers
2026-11-24 22:24 ` Ard Biesheuvel
2026-11-24 22:44 ` Nick Desaulniers
2026-11-25 8:03 ` Ard Biesheuvel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c508e8c9-29ad-4157-bf64-40532b708067@app.fastmail.com \
--to=ardb@kernel.org \
--cc=ardb+git@google.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®