Re: [PATCH v2 4/7] jump_label: Add batching API for queued static key updates

From: jim . cromie

Date: Fri Dec 04 2026 - 20:18:09 EST


On Fri, Dec 4, 2026 at 4:27 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Fri, Dec 04, 2026 at 12:18:30PM -0700, jim.cromie@xxxxxxxxx wrote:
>
> > Yes, that worked well -- I just posted v3 built around your
> > batch_owner / static_key_batch guard design, dropping the @apply
> > plumbing, *_queued() helpers, and STATIC_KEY_TRANS_DISABLE (-2).
> >
> > A few edge cases came up while wiring it up and testing with lockdep:
> >
> > 1. Added batch_depth and a batch_owner == current fastpath before
> > cpus_read_lock() so nested batch guards and _cpuslocked() wrappers
> > don't self-deadlock or drop the outer batch early.
>
> Urgh, that gets us firmly in recursive locking territory -- and that has
> proven to be a painful place time and time again.
>
> What sites actually 'need' this; and can't we fix that differently?
>

Agreed -- no real caller needs nested batches. The only thing that forced
it was turning static_key_*_cpuslocked() into inline wrappers around
guard(static_key_batch_cpuslocked)(), which nested whenever a batched
caller invoked a *_cpuslocked() helper (e.g. jump_label_test() or
sched/mm callers).

Those inline wrappers also broke EXPORT_SYMBOL_GPL() for
static_key_{enable,disable}_cpuslocked() and bypassed the lockless fast
paths on unbatched *_cpuslocked() calls (both flagged by Sashiko on v3).

Keeping static_key_*_cpuslocked() out-of-line as thin wrappers that
assert cpus_held and call shared __static_key_*() helpers (lockless fast
path -> guard(jump_label_batch_lock)()) fixes all three:

- static_key_batch becomes strictly non-recursive (no batch_depth, no
batch_owner check before cpus_read_lock());
- *_cpuslocked() still coalesces when called inside
guard(static_key_batch_cpuslocked)();
- existing exports and lockless fast paths stay intact.

> > 2. Moved key queueing to jump_label_queue_key() (handling 0-site keys)
> > with jump_label_flush_key() on revisits (e.g. "+p;-p"), plus
> > static_key_disable() falling through on -1 onto jump_label_mutex.
>
> Its not immediately clear what you mean here; did you force a flush when
> a second operation on a previously queued key arrives?

Yes -- jump_label_flush_key() scans jump_label_queue[] and calls
__jump_label_finish() before modifying key->enabled or queueing new
pokes if the key is already queued in the current batch.

Three reasons:
1. x86 __jump_label_patch() verifies live kernel text before queuing and
BUG()s on mismatch, so queuing a second transition (e.g. "+p;-p")
before the first poke lands in text panics.
2. Flushing settles an in-batch enable's -1 -> 1 first, so a follow-on
disable, slow_inc (1 -> 2), or slow_dec (1 -> 0) sees the normal
settled state.
3. Queueing in jump_label_update() via jump_label_queue_key() (rather
than only inside __jump_label_update()'s site loop) ensures a 0-site
key (e.g. __init-only) still transitions -1 -> 1 at
__jump_label_finish() instead of staying stuck at -1.

And in static_key_disable(), checking (val == 0 || WARN_ON_ONCE(val > 1))
instead of (val != 1) lets val == -1 fall through onto jump_label_mutex
(both for an in-batch revisit before jump_label_flush_key() and for a
concurrent disable racing an enable).

I'll drop the recursive batching and find better wording for that in v4.