Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs

From: Steven Rostedt

Date: Mon Nov 30 2026 - 15:35:15 EST


On Mon, 30 Nov 2026 11:55:11 -0800
"Andy Lutomirski" <luto@xxxxxxxxxx> wrote:

> On Fri, Nov 27, 2026, at 12:12 PM, Valentin Schneider wrote:
> > Christmas comes early this year, here's v10!
> >
>
> > Approach
> > ========
> >
> > The heart of this series is the thought that while we cannot remove NOHZ_FULL
> > CPUs from the list of CPUs targeted by these IPIs, they may not have to execute
> > the callbacks immediately. Anything that only affects kernelspace can wait
> > until the next user->kernel transition, providing it can be executed "early
> > enough" in the entry code as a postponed operation.
>
> So I had a thought a while ago that I called "exact CT" (exact connection
> tracing). Basically the idea was to promote CT from a
> sort-of-specialized realtime/nohz feature to a core part of the entry and
> exit path. I probably sent some emails about it. The complexity (aside
> from rearranging a bunch of code) sort of boils down to needing a kind of
> unfortunate full barrier, and it goes like this:
>
> transition to user mode / quiescent:
>
> we set a percpu [0] quiescent flag saying "I promise that I'm on my way
> to userspace [1], and I will not access problematic mappings or rely on
> RCU (or, with your idea) run deferred-pokable code until I transition
> back". We need accesses that logically predate this to be logically
> synchronized with anything remote that reads this flag, so we make it a
> release. No big deal, I think.
>
> transition back from user mode / quiescent:
>
> This one is far trickier. We're going to clear the flag. But a remote
> CPU needs to be able to observe that the flag is clear and therefore not
> IPI us, which (on every architecture I'm familiar) requires smp_mb() or
> the equivalent.

Note, at least in our use case (and perhaps others), we do not need an
"exact" moment for not bothering NO_HZ full after it enters user space.
Heck, RCU needs a few ticks before it will stop bothering a NO_HZ CPU.

Could we take advantage of that? That is, we do not use smp_mb() until a
NO_HZ full CPU is fully registered after some time running in user space
(perhaps way for a RCU synchronization period?). Once a CPU has fully
registered that a task is running in NO_HZ full, then we can start doing
more invasive memory synchronizations from other CPUs when it needs to send
an IPI to this one.

As NO_HZ tasks tend to not want to ever go into the kernel, we do not care
if it is expensive when that task returns back from user space.

>
> So I think we clear the quiescent flag and then read the "did anything
> happen that we need to handle bit". This could literally be a write,
> smp_mb(), read, or it could be a CAS (and I haven't really contemplated
> whether it needs to be a sequentially consistent CAS on architectures
> (not x86) where this is a real distinction).
>
> And here's why I'm bringing this up. The unquiesce sequence is kind of
> expensive (tens of cycles! we used to care about this on syscall
> return!), but maybe it solves your problem too. After all, a deferred
> TLB flush looks a lot like a deferred serializing operation, and those
> two look at least a little bit like a remote CPU relying on us being
> RCU-quiescent. (Okay, RCU really is different, since we probably want to
> increment a *count* of quiescence too, but I think this can be made to
> fit in.)
>
> And one thing I hate about the current context tracking is that it's sort
> of glued on and RCU-specific instead of being a real part of the
> entry/exit sequence. But maybe it's actually time to change this.

+1

>
> I call my idea "exact" context tracking specifically because I think this
> stuff should change:
>
> void noinstr __ct_user_enter(enum ctx_state state)
> {
> struct context_tracking *ct = this_cpu_ptr(&context_tracking);
> lockdep_assert_irqs_disabled();
>
> /* Kernel threads aren't supposed to go to userspace */
> WARN_ON_ONCE(!current->mm);
>
> ^^^^^ excuse me, what is this doing here?
>
> if (!context_tracking_recursion_enter())
> return;
>
> ^^^^^^ the x86 and generic code do not have recursion confusion
> any more
>
> if (__ct_state() != state) {
>
>
> ^^^^^ the state transition really should be a foregone conclusion
>
> if (ct->active) {
>
> In the bad old days of the entry/exit code, we had lots of code paths
> that didn't really know the state that they were transitioning *from*.
> These days we keep extremely careful track of exactly what's going on,
> but CT never got updated.

Looks like this code could use some TLC!

>
>
> I would be absolutely delighted to help review this if you write it :)
>
>
> [0] We have a weird tradition of actually using per-task flags on the
> current task for this kind of thing. This particular use case might
> require either annoying remote acquisitions of the rq lock or actually
> using a percpu flag.

This should most definitely be per-cpu flags and not rely on tasks
themselves.

-- Steve


>
> [1] There's nothing wrong with aborting the transition as long as we
> still do the reverse transition.