From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796408903; b=flTpo28Qo3QdbKY6HPqMewnA2IzgrONnhLsq3gg5BisL/Qc7Vg3rnftAacoJxIWOE1ej tNaH2s1+aBunOaE/ZtFr5OBUylhFH4lEkjkNzsDaEPpxvfQsCA6ysuK5X5AxuZUu4Urik lLQu+6gPFnzH/KIY7uN2ea5r3mgjF8PLehfoY55DTYYo5dpaq5+JbMPmZUpnui1DI019D +NBjnALuWN9oLi2Kx47FREMJLW+gpJgAo64fC+7qLD8VUCX0CjsZHwnnqxz6yiyTg8oLO NSwW22GK7QuOuvSzEViBdM89RM0Ty2TNQvjvFntnt9RnE0TIwvni9tLYNNMNzPUPPDw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408903; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=zdwfA6uG9hrC3qg5WxVVq5FVm2Xo5vPi4NQxW2at//Q=; b=FKYvHe7iLdh+EPif7nxQiOGuo4J+1dGjq32SY2jjofou9BBvvctDYUW70DX65nOnuSQm k/OblQC3bz6nFhai7CIdOrqWCMyUAcK9gaT3jsG9bBVh8zX9oKmsUIn4DKNmSRAPQ7/gt CupD/T0s10zMB9aqFgA7qlBww/2WQBIleYTznr6QiiJeaBV931CzdW9h7MQFA7ojdVYOU uza+z/S7GIG7YVCDL1QpDXbHqB5m0MusuKOURuqpM4yF3MWfywhPlhqnwMq5aTJFCk2Bj a+715+HzsGQCtkycOJQRuKIAVpfFa/PplJtlHR0+MOCMfzHie3twsl1yZy/DylYod8w== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ltbcX7ra; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3F6606A32D for ; Fri, 4 Dec 2026 18:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ltbcX7ra Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796408903; b=s61ZI7KvRggjtRbXifIkKYEO6/xCnLP1OrBRm9/RVKUOxfEKQbGLrw7qQuVa6JzUFY+g Mgi77OSQaa10YLkBkgKLVUZLZlWsy9wDKziM08NRz1YGvGDyFUmelUWkMYP7W/oTnLyXb 7jEuqrsTInLvwLG8/0oIr7t12HId/Xr0x8uKbpu5fGzbE0ZCsZFX1Zzztxs0QHSRx0uy0 ZS+Fjlsc8Zb1Bd5xRzmJapv9nrKIVNArZGUQN0ORZzPYFa5mh2rpHvpCnpgZ9bGG7aRN5 ThUBMrYk+aTgVfkN++bU/znZ5HwjG/rq4CXTb0gPEfI2cJwGxHuDcaWz1FFkiGkKg+Q== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796408903; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=zdwfA6uG9hrC3qg5WxVVq5FVm2Xo5vPi4NQxW2at//Q=; b=cMQgRDuyp3LS8WQkzmnEuwxPinqA0snaz3aEbdCJ+CLuc0jzgivbiuDHl2MRHZSMN6Ng c1TbS03CSWxprKnL9o6P8egRWZ2tzN8SzRsARjH2ePcl87Gux5t3ybb/R/LPbEvJFIkza rMqXY/LmTfoPX4AJmIS1jYnbi9y96Efh/edat3s7WHTlkpresupsmJaPuCxvP5upE3HH4 YfRND/u9MkWVyUddMu6cnKwpJv/cBIvoYb2Ig6VnjIfH8+HuaPwPSzcFiXcntDZ341LWr +8d+wiVdtwvMgi7Xi9IOSCqUAf+puIjVDHuwdcOvkPnTiEIS2C3xBLrBs3D2kDIWW1Q== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 660EE1F0093B; Fri, 4 Dec 2026 18:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796408903; bh=zdwfA6uG9hrC3qg5WxVVq5FVm2Xo5vPi4NQxW2at//Q=; h=From:Subject:Date:To:Cc:Reply-To; b=ltbcX7raKJRLrdg4mGO4EEj6ojEpQXeoXVZV2n/YUUUQXE7Tk1sriPNV7Cmlt6j42 dGErKyXFoyTZwad4JnBN5X06ND6mq1SpeIz884dYq0/09KgqfKajAHJ7lMRzKflEYb 5oSKGNFt96Q1x1br+vciosJulwIJih4+KZSjRsqC0oKkGp0RYS0CrfTtSN3QcX5c8M Ug18xOWTRhst6FoqFSBBoBTkHsqYUTyRJDBRptlMwzT82WyyEDLN82R7DJ2wsdnOpo JMKJcH+CX0NQnKyYx4rLx2cXqboq9TsupP2K2etBIKteMJdkQrhpbKULkbfO8hXpwZ crZmTE4IAWMfw== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B83754DC13; Fri, 4 Dec 2026 18:28:21 +0000 (UTC) From: Jim Cromie via B4 Relay Subject: [PATCH v3 0/5] jump_label, x86, dyndbg: Batch multi-key static branch updates Date: Fri, 04 Dec 2026 11:27:51 -0700 Message-Id: <20261204-jump-batch-261128-v3-0-2adda55a5d71@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAA/23OzQqDMBAE4FcJezaSXW1qPPU9Sg/+RF1pjEQrL eK7F6WUHnodmG9mhckGthPkYoVgF57YD5CLJBJQdcXQWsk15AJIkUakTPYPN8qymKtOfhKsM1N brc9Jk0IkYAy24edhXm+RgI6n2YfXMbHgnh6aSpRWeFJEMZpUmUxLlD27uAresb20ruB7XHkHO 7LQt4hI5s+NhaSSJWZkakrJNOpX2LbtDahoelPrAAAA 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=1796408901; l=8101; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=JTuJTwWjeJps0zGoDfQ4F14hOBg5FvbUAh9Y352JJN0=; b=75uc4DIQK7XPxnC15rMWDqK+6FMbjWG3AxBVUbgbu2I9Z/u2oEDQO7i+vQGoQVfeVU2PNplm/ BJfKG5fpIoiDKO3mLWmBkQw/fJ86DXgyG6+xWrcmzHOp1hJ4Tq5CGtV 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 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com 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