mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/5] jump_label, x86, dyndbg: Batch multi-key static branch updates
@ 2026-12-04 18:27 Jim Cromie via B4 Relay
  2026-12-04 18:27 ` [PATCH v3 1/5] x86/alternatives: Keep text-poke batch sorted on insert Jim Cromie via B4 Relay
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-12-04 18:27 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Peter Zijlstra, Josh Poimboeuf, Jason Baron,
	Alice Ryhl, Steven Rostedt, Ard Biesheuvel, Andrew Morton
  Cc: linux-kernel, Jim Cromie

Toggling many boolean static keys at once -- such as enabling or
disabling pr_debug() sites across vmlinux and loaded modules --
currently patches one static key at a time. Each toggle sends a full
set of cross-CPU text-poke IPIs (~39.7k CAL IPIs to flip 1,885 active
builtin keys across 8 CPUs on x86). Even if kernel/jump_label.c defers
arch_jump_label_transform_apply() across a batch of static-keys, x86's
smp_text_poke_batch_add() flushes whenever a poke address arrives below
the tail entry (~2 entries per batch in dyndbg descriptor order) and
hides its 256-entry flush boundaries from jump_label.c.

This series updates all three layers so a static_key_batch guard
transparently batches static_key_{enable,disable,slow_inc,slow_dec}()
calls while handling out-of-order poke addresses and same-batch state
reversals cleanly:

1. x86/alternatives (1/5): Keep text_poke_array.vec[] sorted on insert
   via binary search and memmove() so unordered multi-key callers fill
   the batch while pre-sorted ftrace pokes stay on the one-comparison
   tail-append fastpath. Reject already-queued addresses so the pending
   batch flushes first and the next batch starts with the new update
   (e.g. a "+p;-p" toggle by dyndbg, or a re-target by ftrace).

2. x86/jump_label (2/5): Add smp_text_poke_batch_try_add() and return
   its status from arch_jump_label_transform_queue() so jump_label.c
   flushes, finalizes completed keys, and starts a new batch in
   lockstep with text_poke_array.

3. jump_label (3/5): Add static_key_batch_begin/end() and
   DEFINE_LOCK_GUARD_0(static_key_batch, ...). Track the active batch
   task via batch_owner so static_key_{enable,disable,slow_inc,
   slow_dec}() calls coalesce their pokes, defer publishing 1 on newly
   enabled keys until __jump_label_finish(), and flush early if a batch
   revisits an already-queued key.

4. dyndbg (4/5..5/5): Hoist ddebug_lock and
   scoped_guard(static_key_batch) in ddebug_exec_queries() to coalesce
   static branch updates across sub-queries, and assemble changed
   classmap bitmap bits into one multi-query buffer.

Measured on an 8-vCPU x86_64 guest (v7.4-rc5, 1,997 builtin pr_debug
descriptors / 1,885 non-init keys / 1,964 jump sites,
CONFIG_PROVE_LOCKING=y):

  Workload                        master     v3 (5 patches)   Speedup
  -------------------------------------------------------------------
  echo "+p" > control             39,712          282 CAL      141x
  echo "-p" > control             39,674          255 CAL      156x
  "+p ; -p" (1x)                  79,256          424 CAL      187x
  "+p ; -p" (4x)                 316,773          756 CAL      419x

Bare-metal desktops (vmlinux + loaded modules incl. amdgpu):

  Host / CPUs / Sites          "module amdgpu +p"   "+p ; -p" (4x)
  ----------------------------------------------------------------
  Ryzen 9 6900HX, 16c, 8,484          615 CAL           12,524 CAL
  Ryzen 9 3900X,  24c, 8,197          909 CAL           18,243 CAL

Both match the theoretical floor ceil(N / 256) * 3 * (CPUs - 1) per
toggle within ~2% (~240-250x fewer CAL IPIs than unbatched master).

Two follow-up series have been prototyped on top of this work:

1. Pattern reuse (static_call_batch and tracepoint_batch): applies the
   same sorted text_poke_array (1/5) and batch_owner design to inline
   static calls and tracepoints, cutting 8-vCPU CAL IPIs on
   "echo 1/0 > /sys/kernel/tracing/events/enable" (1,553 events) from
   ~68.8k to ~850-890 (~77-81x fewer, passing 25/25 ftracetest tests).

2. Direct API reuse: wraps existing multi-key callers in
   static_key_batch / static_key_batch_cpuslocked (netfilter hook
   tables, sched_ext, sched/topology, mm/vmscan, net rps/xps, resctrl).

Verification & Tooling Disclosure:

1. Tested across 10 Kconfig build combinations in 8-vCPU virtme-ng
   (CONFIG_PROVE_LOCKING=y, CONFIG_KASAN=y, !CONFIG_MODULES,
   CONFIG_STATIC_KEYS_SELFTEST=y, CONFIG_TEST_STATIC_KEYS=m,
   CONFIG_TEST_DYNAMIC_DEBUG=m/y) and on 16-CPU and 24-CPU AMD Ryzen
   hosts; 0 lockdep, KASAN, or dmesg warnings.

2. Ran tools/testing/selftests/ftrace/ftracetest test.d/ftrace/ in
   4-vCPU virtme-ng to exercise ftrace_replace_code() on the shared
   smp_text_poke_batch_add() path: 25 passed, 0 failed, 0 unsupported
   (function and function-graph filters, profiling, event/traceon-off
   triggers, module tracing, CPU hotplug, and trace instances).

3. Peter Zijlstra suggested the batch_owner / static_key_batch guard
   design in 3/5. AI coding assistants (Gemini CLI / Antigravity)
   assisted with the commit split, the binary-search insertion sort in
   1/5, queue-limit sync in 2/5, and virtme-ng verification; all code
   and commit messages were reviewed and tested by the author.

---
Changes in v3:

1. Address Steven Rostedt's review on 1/5 (keep tpl assignment after
   declarations and drop untouched signature line breaks) and rewrite
   series changelogs in plain prose with 1.-indexed spaced lists and no
   "What's Unchanged" sections.

2. Rework jump_label batching per Peter Zijlstra: drop the separate
   @apply plumbing patch (v2 3/7), static_key_{enable,disable}_queued(),
   and STATIC_KEY_TRANS_DISABLE (-2). Track batch_owner (with nesting
   for _cpuslocked() callers) under cpus_read_batch_lock and
   jump_label_batch_lock guards so static_key_{enable,disable,
   slow_inc,slow_dec}() calls coalesce inside guard(static_key_batch)(),
   flushing when revisiting an already-queued key or loading a module.

3. Serialize static_key_disable() on jump_label_mutex when observing -1
   instead of firing a false WARN_ON_ONCE() and returning early
   (Sashiko review on v2 4/7).

4. Fold v2 5/7 and 7/7 into one dyndbg patch (4/5) that hoists
   ddebug_lock and scoped_guard(static_key_batch) directly to
   ddebug_exec_queries(), avoiding temporary batching churn in
   ddebug_change().

5. Bail out on negative returns from ddebug_apply_class_bitmap() in
   param_set_dyndbg_classnames() and param_set_dyndbg_classes() without
   updating *dcp->bits or *dcp->lvl (Sashiko review on v2 6/7).
- Link to v2: https://lore.kernel.org/r/20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com

Changes in v2:

1. CC x86, jump_label, ftrace, and dyndbg maintainers across the full
   series.

2. Split the combined v1 patch into single-purpose commits ordered
   x86 -> jump_label -> dyndbg, with mechanical @apply plumbing
   isolated in 3/7.

3. Drop all EXPORT_SYMBOL_GPL() exports on the queued static-key API
   (core-only).

4. Drop pr_debug() instrumentation from arch/x86/kernel/alternative.c.

5. Replace deferred sort() with binary-search insertion sort in
   smp_text_poke_batch_add() so vec[] stays sorted and duplicate-free
   at all times without touching smp_text_poke_batch_finish().

6. Propagate queue-full return from x86's
   arch_jump_label_transform_queue() so multi-site keys do not
   desynchronize the 256-site text_poke_array from the 256-key
   jump_label queue.
- Link to v1: https://lore.kernel.org/lkml/20260306015022.1940986-1-jim.cromie@gmail.com/

---
Jim Cromie (5):
      x86/alternatives: Keep text-poke batch sorted on insert
      x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit
      jump_label: Add static_key_batch API
      dyndbg: Batch static branch updates across queries
      dyndbg: Batch classmap param bit-changes into multi-query

 arch/x86/include/asm/text-patching.h |   1 +
 arch/x86/kernel/alternative.c        |  79 +++++++--
 arch/x86/kernel/jump_label.c         |   6 +-
 include/linux/jump_label.h           |  48 +++++-
 kernel/jump_label.c                  | 316 +++++++++++++++++++++++++----------
 lib/dynamic_debug.c                  | 105 ++++++++----
 6 files changed, 405 insertions(+), 150 deletions(-)
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261128-jump-batch-261128-1d89de6673f4

Best regards,
-- 
Jim Cromie <jim.cromie@gmail.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 20:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 18:27 [PATCH v3 0/5] jump_label, x86, dyndbg: Batch multi-key static branch updates Jim Cromie via B4 Relay
2026-12-04 18:27 ` [PATCH v3 1/5] x86/alternatives: Keep text-poke batch sorted on insert Jim Cromie via B4 Relay
2026-12-04 18:27 ` [PATCH v3 2/5] x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit Jim Cromie via B4 Relay
2026-12-04 18:27 ` [PATCH v3 3/5] jump_label: Add static_key_batch API Jim Cromie via B4 Relay
2026-12-04 18:27 ` [PATCH v3 4/5] dyndbg: Batch static branch updates across queries Jim Cromie via B4 Relay
2026-12-04 18:27 ` [PATCH v3 5/5] dyndbg: Batch classmap param bit-changes into multi-query Jim Cromie via B4 Relay
2026-12-04 20:29 ` [PATCH v3 0/5] jump_label, x86, dyndbg: Batch multi-key static branch updates Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®