From: Jim Cromie Subject: [PATCH v2 0/7] jump_label, x86, dyndbg: Batch multi-key static branch updates Date: Sun, 29 Nov 2026 00:44:13 -0700 Message-Id: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAA/y3NQQ6CMBBA0as0s6akU7BCV97DsMAywBBLSYtEQ 7i7kbj9i/d3SBSZElixQ6SNE4cZrNCZADe280CSO7ACtNIGUVdyevlFPtrVjfJfsKvqjoy5Fn0 JmYAlUs/v07w3mYCR0xri51xs+KunpgplFF6U1jnWpaorI1FO7HMXg2e6Db7lZ+6Ch+Y4ji8UN fEfqQAAAA== X-Change-ID: 20261128-jump-batch-261128-1d89de6673f4 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Alice Ryhl , Steven Rostedt , Ard Biesheuvel , Andrew Morton Cc: linux-kernel@vger.kernel.org, Jim Cromie X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795938258; l=5863; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=L2mv8aqbBOSk0wJDzd9OFsBABTQsUl2hFs0qYHYV7gY=; b=6kGhBPd1vBgW5KPkMt92mO4yEHkCJQDQ0Pi25Dc4IOflakhVk2smv7jVDkuMl3Wbd955FAlX5 wRTYyWU5iOgBEXibL9IzEWEwCaCfTzFxpi3mqP1Af943CNe18E9pQuV X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= X-Endpoint-Received: by B4 Relay for jim.cromie@gmail.com/20260203 with auth_id=958 List-Id: B4 Relay Submissions 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, sending cross-CPU text-poke IPIs per site (~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 keys, x86's smp_text_poke_batch_add() finish()es whenever a patch address arrives below the tail entry (~2 entries per batch in dyndbg descriptor order) and hides its 256-entry queue limit from jump_label.c. This series fixes all three layers so multi-key static_key_batch updates fill x86's 256-entry text_poke_array cleanly: 0. x86/alternatives (1/7): keep text_poke_array.vec[] sorted on insert via lower-bound binary search and memmove() inside its 4 KB page, preserving the 1-comparison fastpath for pre-sorted callers (ftrace and single-key jump_label) while letting unordered multi-key callers fill the batch and rejecting duplicate @addr entries before queueing. 1. x86/jump_label (2/7): add smp_text_poke_batch_try_add() and return its bool status from arch_jump_label_transform_queue() so __jump_label_update() flushes at TEXT_POKE_ARRAY_MAX (256) in lockstep with text_poke_array when multi-site (e.g. inlined) keys fill the 256-site array ahead of MAX_QUEUED_KEYS (256). 2. jump_label (3/7..4/7): plumb @apply through jump_label_update_key() (no functional change in 3/7), then add core-only (unexported) static_key_batch_begin/end(), DEFINE_LOCK_GUARD_0(static_key_batch), and static_key_{enable,disable}_queued() using negative transitional markers (-1/-2) finalized via release stores after IPI completion. 3. dyndbg (5/7..7/7): switch ddebug_change() to queued static-key batching, assemble changed classmap parameter bits into one multi-query buffer, and hoist ddebug_lock and scoped_guard(static_key_batch) to ddebug_exec_queries(). Measured on an 8-vCPU x86_64 guest (v7.4-rc4, 1,997 builtin pr_debug descriptors / 1,885 non-init keys / 1,964 jump sites, CONFIG_PROVE_LOCKING=y): Workload master v2 (7 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 1,435 CAL 221x classmap bitmap 0x3ff (10 cls) 330 143 CAL 2.3x 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). Verification & Tooling Disclosure: 0. Tested on 16-CPU (CONFIG_PROVE_LOCKING=y, CONFIG_FTRACE_STARTUP_TEST=y, CONFIG_EVENT_TRACE_STARTUP_TEST=y) and 24-CPU AMD Ryzen hosts, plus 8-vCPU virtme-ng with CONFIG_STATIC_KEYS_SELFTEST=y (extended with batch + reversal cases), CONFIG_TEST_STATIC_KEYS=m, CONFIG_TEST_DYNAMIC_DEBUG=m, boot dyndbg= queries, and ftrace function tracer; 0 lockdep or dmesg warnings. 1. AI coding assistants (Gemini CLI / Antigravity) assisted with refactoring the commit split, designing the binary-search insertion sort in 1/7 and queue-limit sync in 2/7, and running virtme-ng and host IPI benchmarks; all code and commit messages were reviewed and tested by the author. Signed-off-by: Jim Cromie --- Changes in v2: 0. CC x86, jump_label, ftrace, and dyndbg maintainers across the full series. 1. Split the combined v1 patch into single-purpose commits ordered x86 -> jump_label -> dyndbg, with mechanical @apply plumbing isolated in 3/7. 2. Drop all EXPORT_SYMBOL_GPL() exports on the queued static-key API (core-only). 3. Drop pr_debug() instrumentation from arch/x86/kernel/alternative.c. 4. 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(). 5. 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 (7): x86/alternatives: Keep text-poke batch sorted on insert x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit jump_label: Plumb bool apply through jump_label_update_key() jump_label: Add batching API for queued static key updates dyndbg: Use queued static-key batching in ddebug_change() dyndbg: Batch classmap param bit-changes into multi-query dyndbg: Hoist lock and static_key_batch across queries arch/x86/include/asm/text-patching.h | 1 + arch/x86/kernel/alternative.c | 85 ++++++++--- arch/x86/kernel/jump_label.c | 6 +- include/linux/jump_label.h | 22 +++ kernel/jump_label.c | 282 ++++++++++++++++++++++++++++++----- lib/dynamic_debug.c | 81 ++++++---- 6 files changed, 387 insertions(+), 90 deletions(-) --- base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f change-id: 20261128-jump-batch-261128-1d89de6673f4 Best regards, -- Jim Cromie