From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Nick Desaulniers" <ndesaulniers@google.com>,
"Ard Biesheuvel" <ardb+git@google.com>
Cc: linux-kernel@vger.kernel.org,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Nathan Chancellor" <nathan@kernel.org>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
llvm@lists.linux.dev, x86@kernel.org,
"Alexander Potapenko" <glider@google.com>,
"Marco Elver" <elver@google.com>,
"Dmitry Vyukov" <dvyukov@google.com>,
"Uros Bizjak" <ubizjak@gmail.com>
Subject: Re: [PATCH] x86/percpu: Use address space loads for per-CPU reads when using Clang
Date: Thu, 26 Nov 2026 09:51:12 +0100 [thread overview]
Message-ID: <38ad4de5-1a41-4fa3-bd73-2f24d5578c41@app.fastmail.com> (raw)
In-Reply-To: <CAKwvOd=1u6d2Epp8MgkesknixWcB+JLKfAQq8g9kqYw5sDoLow@mail.gmail.com>
On Wed, 25 Nov 2026, at 20:05, Nick Desaulniers wrote:
> On Wed, Nov 25, 2026 at 2:50 AM Ard Biesheuvel <ardb+git@google.com> wrote:
>>
>> From: Ard Biesheuvel <ardb@kernel.org>
>>
>> Clang never discards inline asm with memory operands, even if its result
>> is unused [0]. This means unused per-CPU reads are always emitted,
>
> Ack on this missed optimization. I _just_ got beers with Bill last
> night, and forgot to bring this up!
>
>> including the load of this_cpu_off by this_cpu_ptr() in cases where the
>> resulting pointer is never dereferenced.
>>
>> Clang's support for the __seg_gs/__seg_fs named address space qualifiers
>> is insufficient for full CONFIG_USE_X86_SEG_SUPPORT, but works well
>> enough [1] for plain loads, and is present in all versions of Clang that
>> Linux still cares about. So use those to implement __raw_cpu_read() on
>> SMP, permitting the compiler to elide them when the result is unused.
>>
>> On a v7.4-rc1 defconfig build, this gets rid of 174 spurious per-CPU
>> loads, 136 of which are loads of this_cpu_off from this_cpu_ptr().
>>
>> [0] https://github.com/llvm/llvm-project/issues/245738
>> [1] Exclude KMSAN, which ignores the segment base when instrumenting
>> such loads.
>
> + Maintainers of KMSAN. Ard, can we get a formal bug report about that?
> https://github.com/llvm/llvm-project/issues
> With the report in hand, it would be handy to reference it below.
>
Posted a fix here:
https://github.com/llvm/llvm-project/pull/246269
Will add the reference to v2, and incorporate the rest of your feedback.
Thanks,
prev parent reply other threads:[~2026-11-26 8:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 10:49 Ard Biesheuvel
2026-11-25 19:05 ` Nick Desaulniers
2026-11-26 8:51 ` 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=38ad4de5-1a41-4fa3-bd73-2f24d5578c41@app.fastmail.com \
--to=ardb@kernel.org \
--cc=ardb+git@google.com \
--cc=bigeasy@linutronix.de \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=ubizjak@gmail.com \
--cc=x86@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®