From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Nick Desaulniers" <ndesaulniers@google.com>,
"Ard Biesheuvel" <ardb+git@google.com>,
"Bill Wendling" <morbo@google.com>
Cc: linux-kernel@vger.kernel.org,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"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: Mon, 23 Nov 2026 22:23:16 +0100 [thread overview]
Message-ID: <73d50ff0-36db-4dcc-ad1e-c34bf3ebbce6@app.fastmail.com> (raw)
In-Reply-To: <CAKwvOdkOjGkGajGMKtqcHpRSrpXC9UZrH9XPsiv5Rpcdte5tJQ@mail.gmail.com>
On Mon, 23 Nov 2026, at 20:12, Nick Desaulniers wrote:
> On Sun, Nov 22, 2026 at 2:56 AM Ard Biesheuvel <ardb+git@google.com> wrote:
>>
>> From: Ard Biesheuvel <ardb@kernel.org>
>>
>> When lock debugging is disabled, local_lock_acquire() and friends are
>> empty, and so the per-CPU lock pointer that is passed to them, which is
>> usually computed using this_cpu_ptr(), is not used at all.
>>
>> However, on x86, when the compiler does not support named address spaces
>> (i.e., Clang), this_cpu_ptr() is based on inline asm with a memory
>
> I had to look this one up ("named address spaces").
>
> https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html#x86-Named-Address-Spaces
>
> So __seg_fs / __seg_gs ?
>
> CC_HAS_NAMED_AS : arch/x86/Kconfig#2331
>
> Weird, clang _does_ seem to support these, since clang-11 (clang-17 is
> the current minimum supported default).
> https://godbolt.org/z/cfhj8r69E
>
> commit 47ff30cc1be7 ("x86/percpu: Enable named address spaces for all
> capable GCC versions")
> added a
>
> depends on CC_IS_GCC
>
> What happens if you turn that off?
>
> Ah, a week after that commit was authored, the same author filed
> https://github.com/llvm/llvm-project/issues/93449
>
> (currently assigned to Bill; Bill, can you PTAL?)
>
> They also filed
> https://github.com/llvm/llvm-project/issues/93449
>
> https://github.com/llvm/llvm-project/issues/187893 looks like possible
> a dup of one of the above. Bill, can you please take a look at those
> 3?
>
>> operand, and Clang does not discard such inline asm even if its result
>> is unused. So the computation of the per-CPU address of the lock is
>> emitted regardless, e.g., on every local_lock_nested_bh() in
>> process_backlog() and on every local_lock() in the folio batching code.
>
> I'm more so curious how you even noticed this problem? Was there a
> thread? Were you looking at some assembler and wondering what was
> going on here? Or was there another thread about this?
>
No it manifested in local testing of my fgkaslr implementation.
I'm doing some very detailed profiling to ensure it does not regress
performance.
> Very detailed commit message, but you kind of bury the lede here on
> what the actual problem this patch is fixing *is*.
>
Apologies. I'll trim it down,
The TL;DR is that non-volatile asm() statements with memory input
operands are not elided by Clang if their output is never used.
next prev parent reply other threads:[~2026-11-23 21:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 10:56 [PATCH] locking/local_lock: Don't evaluate the per-CPU lock pointer if unused Ard Biesheuvel
2026-11-23 19:12 ` Nick Desaulniers
2026-11-23 19:19 ` Nick Desaulniers
2026-11-23 21:23 ` Ard Biesheuvel [this message]
2026-11-23 21:52 ` Nick Desaulniers
2026-11-23 22:15 ` Ard Biesheuvel
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=73d50ff0-36db-4dcc-ad1e-c34bf3ebbce6@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