Re: [RFC PATCH 31/56] x86/alternative: Prepend nops with retpolines

Peter Zijlstra
2025-10-22T10:40:58Z

On Wed, Oct 22, 2025 at 09:41:05AM +0100, David Laight wrote:

> > > Ah, I found it, you freeze everything, which puts it at safe points.
> >
> > Yes. In fact, I think you were the one who pointed me in that direction :)
>
> Does that help?
> It'll stop the cpu prefetch queue containing garbage and let you flush the I-cache,
> but I don't see how it can stop the return address after the NOP3 being on the
> stack from an earlier interrupt, or even the nmi entry itself.
>
> I'm not sure, but if the kernel is pre-emptable could a sleeping thread have
> a stack that includes the address after the NOP3 - eg if an interrupt at
> that point is what caused the reschedule.

The thing is that freezing is only done at known safe points;
specifically schedule() calls that have TASK_FREEZABLE set.

Typically this is the return to userspace point and for kernel threads
somewhere in their main event loop.

This ensures tasks are not preempted at random points like in the middle
of an alternative.