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

From: Valentin Schneider

Date: Tue Dec 01 2026 - 06:14:18 EST


On 30/11/26 11:55, Andy Lutomirski 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.
>
> 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.
>
> 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.
>
>
> I would be absolutely delighted to help review this if you write it :)
>

At a high level that sort of sounds like what Frederic had suggested and I
had implemented here:

https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@xxxxxxxxxx/

Although now I would just not store anything and have a single,
always-run-at-entry catchup sequence (like the CR3 RMW).