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=1795938272; b=wDhZFZXLLkvTlIilxu/3rik108EEdUCYTjxQPBGvHdHPQCtWwUHjSEeNf2erK3zsW6EL q/odxKMgepk4tGD2K+/Lj2KdtMdYG1pUeRht6wA4U0fswslsvPJHyq5d44lDiFgxkyzGh uh8IvesQMGjngNCKS7T8fo3O8IC6+klnZNez+o9GfajvPjFE4jyLT57nDu0E0nlIQQTIL Pp638bf1IUpnHAScuAsHY8o1O8ZU4RQ/4I1uWCOh4CidgJaESLnrUuAazeShmNokpIWYu SInglg0IhVQtaqS6UHkOVlHRFB3gLUcF14tRSjsZQ4YiWJZbnTN7KrX+WIDq++ewhDA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795938272; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=M5EQqAl2G5lMS2cjDB/tY0YrAQ6OTW78fA+F7Ouc514=; b=5jLOvbXeNMcYY2A3qeAaUQEe7ITDPPZvVJdXyV0nPDYcffAPTSzYKYD1arI6DyXnVKKt oK7nQh2rN7xsS0uSEEzrlrMx7OEbkO1kHmH/x0YoDlATMPdg0BrNCv/LJbvW3hYgiN9D8 kH66/5WYx+Qi9xh5hZwK5o8N54/dwMTPiBM2Gsye16zOhg+T1fBVV4pQae9zeMFWe6riy zTXD2RBabzCwQMIPozQjZZPWXAhKFvUxH/ufHDomz3DwFtkGdjsW1BmpliREyQtyM/++O hnF5gRt8Kjz+gJqj+PwQ5z9WbLMJo20UK/889PjpLz5fgq0iQ5w7Izad1qYRK5MgTAg== 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=STBsUHFE; 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 E0B0F606A333 for ; Sun, 29 Nov 2026 07:44:31 +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=STBsUHFE 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=1795938271; b=HXV1l04+hv7ZGshLxFwfD19mPHxz77wh5zVSHmbl8kd7C2hVn3SrUFy+VXPvH13ScgSX 7f6Ln9FChaTWqaDZ2cPewqEVZkoidB3NZEMKMcPhWBvwYbq1/b4Y0Q7oJddoxLOzSgvkn cmIUrL4C7GSpJoDp64zbs/hYGegRRwUF+DKI9i//gsKGDDoNHNF5LHQwhoX922pnZTwv3 S86E9bemig1oiEtJxS24vsrq0FaurMf42921OuGCQwipkNRZOAmg+UaJbH2qJLXdd9kd+ SU2I9V2VmQIzxrH52mD0AOyif2vrtMMxwb3n+irtUnvbUBaY0hsoutJnfFdevcxFgGQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795938271; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=M5EQqAl2G5lMS2cjDB/tY0YrAQ6OTW78fA+F7Ouc514=; b=nlpt6YHqqB284qUPLNPqdg3rsDZtdfzvRsrJe+FI0vnrS9EnxCGmkz0MIDkuW3It1wq0 4gKainVQm/pk5S/HxRl8TJ9A+eDjxpxwuz9ZQkNILZrTVsljftyciE14y+mk7qoITNiq/ EU+M++aHjebSkQAnjgRMapNhnUtAw7eTvcQtfigdsOg/mukvRPDH9aG5F01dsUQb2ziLp RxFs2pz3K2LGHsfBu0VSgs6l1JssE31j5j73oRD/1Zoy2rrR480cJZLD8QbJpd7YdjSPC HUjV2VDmc2+FKGmi5gpeHGB2Y8ckDRtwhZevz5pU2KSJgWCN0WmGwI+qPPZV5U7jMSw== 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 366931F000C1; Sun, 29 Nov 2026 07:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795938271; bh=M5EQqAl2G5lMS2cjDB/tY0YrAQ6OTW78fA+F7Ouc514=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=STBsUHFECM4Dl3T2k8Zw9emzs/cZNnn+OHpYqw9DwDX0LuM6rGyBk4al4BQu2jVS1 ycp13wV0W8v8RMrPAZ4IVHv5Hq1H2HloMO/GpCp9utCubzuCept6bCV9BOSooEaabx IBDTtBDBvLQDKlg2rkRCiWsYxYJHhtNcKT/lgx55aRSc+x/twXrZKx2zTLdsi+GR1B bXdvLRaakNDiqtypMdxELgEjbSrXqgnE7hDKcW696DLw3igOmXg++EjHh97LngKzCv peOYUUxkx61Fn9P9a/WMkqX6qRDQM+sN/Xob0+saHsas4Mq4D58HvUkuMqhh7G+iQy kieQIcoBjkAFQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 8B2E64E3FC; Sun, 29 Nov 2026 07:44:19 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Sun, 29 Nov 2026 00:44:20 -0700 Subject: [PATCH v2 7/7] dyndbg: Hoist lock and static_key_batch across queries 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" 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 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com Content-Transfer-Encoding: 7bit From: Jim Cromie 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