Re: [Patch v6 08/22] x86/fpu: Ensure TIF_NEED_FPU_LOAD is set after saving FPU state

From: Peter Zijlstra

Date: Wed Feb 25 2026 - 08:02:46 EST


On Wed, Feb 11, 2026 at 11:55:10AM -0800, Dave Hansen wrote:

> This:
>
> > /* Swap fpstate */
> > if (enter_guest) {
> > - fpu->__task_fpstate = cur_fps;
> > + WRITE_ONCE(fpu->__task_fpstate, cur_fps);
> > + barrier();
> > fpu->fpstate = guest_fps;
> > guest_fps->in_use = true;
> > } else {
> > guest_fps->in_use = false;
> > fpu->fpstate = fpu->__task_fpstate;
> > - fpu->__task_fpstate = NULL;
> > + barrier();
> > + WRITE_ONCE(fpu->__task_fpstate, NULL);
> > }
>
> also urgently needs comments.
>
> I also can't help but think that there might be a nicer way to do that
> without the barrier(). I _think_ two correctly-ordered WRITE_ONCE()'s
> would make the compiler do the same thing as the barrier().
>
> But I'm not fully understanding what the barrier() is doing anyway, so
> take that with a grain of salt.

barrier() restricts load/store movement by the compiler. A load/store
cannot be moved across barrier().