Re: [PATCH -tip] x86/mm: Use %RIP-relative address in untagged_addr()

From: H. Peter Anvin
Date: Fri Nov 17 2023 - 15:19:20 EST


On 11/17/23 11:43, Brian Gerst wrote:>>
Why don't we simply have %gs_base == 0 as an invariant for !SMP?

The reason is stack protector, which is still stuck at %gs:40. So
GSBASE has to point at fixed_percpu_data, even on a UP build. That is
corrected by the patch series I recently posted, though.


Right, that problem is gone.

If we
*REALLY* care to skip SWAPGS on !SMP systems, we could use alternativesYep, that is to patch out %gs: and lock (wouldn't even have to be explicit: this is
the kind of thing that objtool does really well.) We can use
alternatives without anything special, since it only matters after we
have entered user spae for the first time and would be concurrent with
patching out SWAPGS itself.

There is already support to patch out LOCK prefixes when running an
SMP build on a single CPU (.smp_locks section). Patching out the GS
prefix would only work if the initial percpu area is not freed.
Beyond that I don't think other optimizations are worth the effort,
and would get very little testing.

Yes, that is basically my point.

-hpa