From: Jim Cromie Date: Sun, 29 Nov 2026 00:44:20 -0700 Subject: [PATCH v2 7/7] dyndbg: Hoist lock and static_key_batch across queries MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-jump-batch-261128-v2-7-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=3923; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=NslrMHUPFZK6+KZCeDLJnk3HpLByU0WM8Z6tZH8/AfA=; b=p21Kzn3Ujyl3tZzoafP3GAZWDbmFdnMbPgoLd/QJodB6wKCgz54qHcd/PboeiGFOiHga5/Ish Rqlues8GocjDVp//jQReiSxDDCmEtbXE71ocOwQfKHUceQj6ZIKcYQd 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_change() acquires and releases ddebug_lock and flushes the static-key batch on every single query, forcing semicolon-separated multi-queries (such as ddebug_apply_class_bitmap() updates or echo "class A +p; class B +p" > control) to send a separate text-poke IPI per sub-query. Hoist both ddebug_lock and static_key_batch up to ddebug_exec_queries(): 0. Replace mutex_lock(&ddebug_lock) and static_branch_batch_begin/end() in ddebug_change() with lockdep_assert_held(&ddebug_lock). 1. Acquire ddebug_lock once around ddebug_exec_queries() and wrap the sub-query loop in scoped_guard(static_key_batch), coalescing static branch updates across all ';' and '\n' delimited sub-queries into a single batched flush before releasing ddebug_lock. What's Unchanged: 0. Same-batch key reversals (e.g. "module foo +p; func bar -p") remain safe: __static_key_set_queued() flushes the prior batch when a key is already in-flight in the opposite direction. 1. Lock hierarchy (ddebug_lock -> cpus_read_lock -> jump_label_mutex -> text_mutex) is unchanged, and queries that toggle no static keys skip text_mutex in static_key_batch_end(). Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 02dfe37aa834..9aedffe4938e 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -170,7 +170,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons * Search the tables for _ddebug's which match the given `query' and * apply the `flags' and `mask' to them. Returns number of matching * callsites, normally the same as number of changes. If verbose, - * logs the changes. Takes ddebug_lock. + * logs the changes. Caller must hold ddebug_lock. */ static int ddebug_change(const struct ddebug_query *query, struct flag_settings *modifiers) @@ -183,9 +183,9 @@ static int ddebug_change(const struct ddebug_query *query, struct ddebug_class_map *map = NULL; int __outvar valid_class; + lockdep_assert_held(&ddebug_lock); + /* search for matching ddebugs */ - mutex_lock(&ddebug_lock); - static_branch_batch_begin(); list_for_each_entry(dt, &ddebug_tables, link) { /* match against the module name */ @@ -264,8 +264,6 @@ static int ddebug_change(const struct ddebug_query *query, dp->flags = newflags; } } - static_branch_batch_end(); - mutex_unlock(&ddebug_lock); v2pr_info("applied %d queued updates to sites in total\n", nfound); if (!nfound && verbose) @@ -576,26 +574,30 @@ static int ddebug_exec_queries(char *query, const char *modname) char *split; int i, errs = 0, exitcode = 0, rc, nfound = 0; - for (i = 0; query; query = split) { - split = strpbrk(query, ";\n"); - if (split) - *split++ = '\0'; - - query = skip_spaces(query); - if (!query || !*query || *query == '#') - continue; + mutex_lock(&ddebug_lock); + scoped_guard(static_key_batch) { + for (i = 0; query; query = split) { + split = strpbrk(query, ";\n"); + if (split) + *split++ = '\0'; + + query = skip_spaces(query); + if (!query || !*query || *query == '#') + continue; - vpr_info("query %d: \"%s\" mod:%s\n", i, query, modname ?: "*"); + vpr_info("query %d: \"%s\" mod:%s\n", i, query, modname ?: "*"); - rc = ddebug_exec_query(query, modname); - if (rc < 0) { - errs++; - exitcode = rc; - } else { - nfound += rc; + rc = ddebug_exec_query(query, modname); + if (rc < 0) { + errs++; + exitcode = rc; + } else { + nfound += rc; + } + i++; } - i++; } + mutex_unlock(&ddebug_lock); if (i) v2pr_info("processed %d queries, with %d matches, %d errs\n", i, nfound, errs); -- 2.56.1