From: Jim Cromie Date: Sun, 29 Nov 2026 00:44:19 -0700 Subject: [PATCH v2 6/7] dyndbg: Batch classmap param bit-changes into multi-query MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-jump-batch-261128-v2-6-b1829d2429f0@gmail.com> References: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com> In-Reply-To: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com> 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=3427; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=VkeUhK9sMNtwN/aRcl9onpI1TGJgqZR7TMKlqJ/3d5I=; b=WdIuUVWiYsXY9smNxJzuYNd2FptXlEVDtPq7U4GNDW9OMCLAQB42HPQSJBEFMy+VFRdQBAz7d itwR9hy46eOCzcYDZ6bkAS+8uw5GfqkheWoTAZvUMeRuO7QzM2N+W91 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 ddebug_apply_class_bitmap() currently runs ddebug_exec_queries() once per changed bit in a classmap parameter, re-acquiring locks and re-scanning ddebug_tables for every toggled class in the classmap on a single sysfs write. Assemble all changed class bits into one semicolon-separated multi-query buffer and submit them in a single ddebug_exec_queries() call: 0. Return early when *new_bits == *old_bits or ddebug_tables is empty. Built-in module parameters (e.g. drm.debug=0x1f with CONFIG_DRM=y) invoke param_set_dyndbg_classes() from parse_args() in start_kernel() before mm_core_init() initializes SLUB and before early_initcall(dynamic_debug_init) populates ddebug_tables; returning 0 preserves the existing empty-table no-op while avoiding pre-SLUB kmalloc(). 1. Allocate a PAGE_SIZE buffer via kmalloc(GFP_KERNEL) and format each toggled bit as "class %s %c%s;" via scnprintf(), trimming the final ';' before calling ddebug_exec_queries(). Each entry uses strlen(name) + strlen(flags) + 9 bytes (<= 15 bytes syntax overhead), so PAGE_SIZE (4096) fits up to 50-char names across 63 classes (and 113-char names across 32 classes) without chunked flushing, guarded by WARN_ON_ONCE(pos == PAGE_SIZE - 1). What's Unchanged: 0. Unchanged bitmap bits are skipped without generating queries. 1. Return value still reports total matched callsites or a negative errno on allocation or query failure. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 48f520a57b22..02dfe37aa834 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -609,11 +609,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); @@ -621,15 +630,18 @@ 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); + WARN_ON_ONCE(pos == PAGE_SIZE - 1); + if (pos) { + buf[pos - 1] = '\0'; /* trim trailing ';' */ + matches = ddebug_exec_queries(buf, NULL); } + + kfree(buf); return matches; } -- 2.56.1