From: Jim Cromie via B4 Relay <devnull+jim.cromie.gmail.com@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Jason Baron <jbaron@akamai.com>,
Alice Ryhl <aliceryhl@google.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ard Biesheuvel <ardb@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH v3 5/5] dyndbg: Batch classmap param bit-changes into multi-query
Date: Fri, 04 Dec 2026 11:27:56 -0700 [thread overview]
Message-ID: <20261204-jump-batch-261128-v3-5-2adda55a5d71@gmail.com> (raw)
In-Reply-To: <20261204-jump-batch-261128-v3-0-2adda55a5d71@gmail.com>
From: Jim Cromie <jim.cromie@gmail.com>
ddebug_apply_class_bitmap() currently invokes ddebug_exec_queries()
once per changed bit in a classmap parameter, re-acquiring ddebug_lock,
flushing a separate static_key_batch, and re-scanning ddebug_tables for
every toggled class on a single sysfs write.
Now that ddebug_exec_queries() holds ddebug_lock and static_key_batch
across semicolon-separated sub-queries, formatting all toggled class
bits into one multi-query buffer lets a classmap bitmap write coalesce
all class updates into a single batched submission:
1. Return early when the new and old bitmaps match or ddebug_tables is
empty. Built-in module parameters invoke param_set_dyndbg_classes()
from parse_args() before SLUB is initialized and before
dynamic_debug_init() populates ddebug_tables; returning 0 preserves
the existing empty-table no-op while avoiding pre-SLUB kmalloc().
2. Allocate a PAGE_SIZE query buffer and format each toggled class bit
as a semicolon-separated class query, trimming the trailing
semicolon before passing the buffer to ddebug_exec_queries().
3. 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, so allocation or query failures do
not desynchronize cached state and turn retries into no-ops.
NB: The PAGE_SIZE query buffer cannot reasonably overflow: even with
32 classes toggling at once, it fits class names over ~111 characters
each -- well past anything readable or usable -- and still returns
-ENOSPC on WARN_ON_ONCE() defensively. A forthcoming classmaps-fixes
series will add compile time limits to ensure this.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
lib/dynamic_debug.c | 63 +++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 47 insertions(+), 16 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 1659c0604b18..f4516803f6e8 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -610,11 +610,20 @@ static int ddebug_exec_queries(char *query, const char *modname)
static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
unsigned long *new_bits, unsigned long *old_bits)
{
-#define QUERY_SIZE 128
- char query[QUERY_SIZE];
const struct ddebug_class_map *map = dcp->map;
- int matches = 0;
- int bi, ct;
+ int bi, pos = 0, matches = 0;
+ char *buf;
+
+ /*
+ * Short-circuit no-op writes and early-boot param parsing before
+ * dynamic_debug_init() populates ddebug_tables and SLUB is up.
+ */
+ if (*new_bits == *old_bits || list_empty(&ddebug_tables))
+ return 0;
+
+ buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
v2pr_info("apply: 0x%lx to: 0x%lx\n", *new_bits, *old_bits);
@@ -622,15 +631,21 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
if (test_bit(bi, new_bits) == test_bit(bi, old_bits))
continue;
- snprintf(query, QUERY_SIZE, "class %s %c%s", map->class_names[bi],
- test_bit(bi, new_bits) ? '+' : '-', dcp->flags);
-
- ct = ddebug_exec_queries(query, NULL);
- matches += ct;
+ pos += scnprintf(buf + pos, PAGE_SIZE - pos, "class %s %c%s;",
+ map->class_names[bi],
+ test_bit(bi, new_bits) ? '+' : '-', dcp->flags);
+ }
- v2pr_info("bit_%d: %d matches on class: %s -> 0x%lx\n", bi,
- ct, map->class_names[bi], *new_bits);
+ if (WARN_ON_ONCE(pos >= PAGE_SIZE - 1)) {
+ kfree(buf);
+ return -ENOSPC;
}
+ if (pos) {
+ buf[pos - 1] = '\0'; /* trim trailing ';' */
+ matches = ddebug_exec_queries(buf, NULL);
+ }
+
+ kfree(buf);
return matches;
}
@@ -646,7 +661,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
const struct ddebug_class_map *map = dcp->map;
unsigned long curr_bits, old_bits;
char *cl_str, *p, *tmp;
- int cls_id, totct = 0;
+ int cls_id, rc, totct = 0;
bool wanted;
cl_str = tmp = kstrdup_and_replace(instr, '\n', '\0', GFP_KERNEL);
@@ -685,7 +700,12 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
continue;
}
curr_bits ^= BIT(cls_id);
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits);
+ rc = ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits);
+ if (rc < 0) {
+ kfree(tmp);
+ return rc;
+ }
+ totct += rc;
*dcp->bits = curr_bits;
v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
map->class_names[cls_id]);
@@ -695,7 +715,12 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
curr_bits = CLASSMAP_BITMASK(cls_id + (wanted ? 1 : 0 ));
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits);
+ rc = ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits);
+ if (rc < 0) {
+ kfree(tmp);
+ return rc;
+ }
+ totct += rc;
*dcp->lvl = (cls_id + (wanted ? 1 : 0));
v2pr_info("%s: changed bit-%d: \"%s\" %lx->%lx\n", KP_NAME(kp), cls_id,
map->class_names[cls_id], old_bits, curr_bits);
@@ -758,7 +783,10 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
inrep &= CLASSMAP_BITMASK(map->length);
}
v2pr_info("bits:%lx > %s\n", inrep, KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits);
+ rc = ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits);
+ if (rc < 0)
+ return rc;
+ totct += rc;
*dcp->bits = inrep;
break;
case DD_CLASS_TYPE_LEVEL_NUM:
@@ -771,7 +799,10 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
new_bits = CLASSMAP_BITMASK(inrep);
v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &new_bits, &old_bits);
+ rc = ddebug_apply_class_bitmap(dcp, &new_bits, &old_bits);
+ if (rc < 0)
+ return rc;
+ totct += rc;
*dcp->lvl = inrep;
break;
default:
--
2.56.1
next prev parent reply other threads:[~2026-12-04 18:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jim Cromie via B4 Relay [this message]
2026-12-04 20:29 ` [PATCH v3 0/5] jump_label, x86, dyndbg: Batch multi-key static branch updates Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-jump-batch-261128-v3-5-2adda55a5d71@gmail.com \
--to=devnull+jim.cromie.gmail.com@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jbaron@akamai.com \
--cc=jim.cromie@gmail.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®