Re: [PATCH -tip 1/3] x86/fsgsbase: Remove unnecessary "memory" clobbers from FS/GS base accessors

From: Peter Zijlstra

Date: Tue Mar 10 2026 - 10:31:57 EST


On Tue, Mar 10, 2026 at 02:11:04PM +0000, David Laight wrote:
> On Tue, 10 Mar 2026 11:27:42 +0100
> Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> > On Tue, Mar 10, 2026 at 09:21:22AM +0100, Uros Bizjak wrote:
> > > The rdfsbase() and rdgsbase() helpers currently include a "memory" clobber
> > > in their inline assembly definitions. However, the RDFSBASE and RDGSBASE
> > > instructions only read the FS/GS base MSRs into a general-purpose register
> > > and do not access memory. As such, the "memory" clobber is unnecessary.
> >
> > The point isn't that this accesses memory, but that prior or later
> > accesses would end up at different memory locations (as would happen
> > when setting the per-cpu segment.
>
> Don't they need a "memory" clobber to stop them being moved the other
> side of a request to set the relevant register?
> In effect the [fg]sbase register has to be treated like a memory location.

Its a read, it doesn't matter. And no, IIRC the compilers are not
allowed to re-order asm volatile, so as long as both the load and store
of the segments register are asm volatile, those cannot get reordered.