Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers

From: Linus Torvalds
Date: Sun Oct 01 2023 - 16:37:20 EST


On Sun, 1 Oct 2023 at 13:21, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Sun, 1 Oct 2023 at 12:53, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> >
> > Regarding x86 target specific code, the same functionality used for
> > explicit address space is used internally to handle __thread
> > qualifier.
>
> Ok, that's interesting, in that __thread is certainly widely used so
> it will have seen testing.

.. but I just checked that the __thread case *does* work with my
stupid test-case, so clearly the "__thread" coverage ends up being
very different from something like __seg_fs.

The difference? For __thread, gcc and clang know how to get the
beginning of the thread area (the equivalent of our kernel
this_cpu_ptr() macro), so now the compiler knows how to turn a
__thread pointer into a "normal" pointer, and can just do memcpy.

But for __seg_fs and __seg_gs, the compiler doesn't know how to do
that, and then ends up just flailing wildly.

If the structure is small enough to be done as individual moves, both
gcc and clang do ok. But anything else is just a complete shit-show.

If they both errored out reliably and legibly, that would be one
thing. But gcc just silently generates garbage, and clang errors out
with 60+ lines of internal compiler backtrace.

Linus