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=1796408904; b=C0sn5ML5hLwq8esndOW2nEBrk321BK2NnQfxia/lfNvO0c4lKDOU9FGR6zH6gLfyDHI1 rMRdQ3i/LdlR55UZC/DuIPMeNeTfjRkoDpb6syfT3HS21rHLLFaK4oYVTAhvKpefyT3Ex oYgk26eDq4dp781ZGmfP9DlCX9iUz6g49f3XuSiUCkC7U+7a//vXq+4XN3YPSauvF7i1g uJ4Btk2YBfvBh6OLysl2rs+h38n6aaVKR0UrpDBAMS32OOlYWYCXB4yFlyA0MxdFLXbqs EC3r9A0RqBnMM+JwGsyOJfnepUPphNOOmdbpO2MNQ2st9ZBozU5zEAKxLvdoiv8bxYQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408904; 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=eff8tEMaIEavOqMSrzz90EtmSs50s3bZl8lU03blAxQ=; b=C9uqalA0/DFuF9xYNTQBACJC2nBVzFjDtf4MxWxPwjUKeObZT3KtvteRXUPYsTobFH/y g7yJhEPz5CcLoobIkpQqcCSJ5GrGWtSP7MnEWwZeeKfk23R+80qlwiz0Fnz0RQJQ4sgDW 2c3JRgrLd0UjOFG8fl1mhucWW7z+Ry2aQMzmeCh3NHtcT4EDgsQ3JDqv0IsWRWcOOSbVr f3Cm5bZz8ej11ga1stSQu5l2iaCAuz1SEDa/9r49LVHDG+bfsDkZl8QBZ74rG+pwOVuz+ 3qS4jH8C6YxSd96rRMxo9Oc8egi0VQ30bTY5UZDbByxBuYmL3fnT8GrGp1C3dkZ3cew== 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=Q2D9m7Q0; 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 C087E606A68B for ; Fri, 4 Dec 2026 18:28:24 +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=Q2D9m7Q0 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=1796408904; b=OdfLmNh0ia21AjJmMMWxV7C5Aqucqu36Kyn1Wp3I2Sa7YgsYQ7nyDDsLI7qvU4p5SdHe iu2a4AnHmDJjr5DkShCC7cI5rn2KzATJDiG7wOO2VhGYVt36yTeBIlKngImjikikmKj/Z M8pMPeK0pTuLH74ZuZ1425jASBSyN8q8K8tGg7gGEptkjR8aYuaT/pkWsJfFknl+N8r24 pWzrkmnn2Silf65Q2EXlMQHutKotd/WRRV28O/C5L5emJWBKewOjgDtqvbfnn+JvY14jB FGkdvfA/3ReIe3C9eN1hHsFXIYnCMLNxkY6n38Y6TREACdAvmIypcQbVvU8tK4mzK7Q== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796408904; 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=eff8tEMaIEavOqMSrzz90EtmSs50s3bZl8lU03blAxQ=; b=tubsMmBhphnXPJschm7kSzLmk9r8l3aloliGGp8gBClmtFoFZUC66x+3jMBa4WeR8oZm q+yq2CyhlcFOoMEdtEmEyVnT80Y+nxEYXmmmJpNHwH5QDxxM9wCg3V9W/FmpVFgRr95gQ sNtVgUeNL0AQcc9gZmvrt6/KkhU+RsfPWN6980zIw0QIs93nJmQXB/SSwuSfsYaI0+5Yr VJLUL9cjtv/nWNi9m73/e/62IbLbfw59rTTvog1uCzK1xNQFXDuiOqwL3HKS62jUicDp6 70QOF/P8/LbISdDGTLdSSNipIMwmZdSjkFGKTlRkTy4t5gm3IV9Xs7myQRblO+gPFKQ== 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 556951F00A10; Fri, 4 Dec 2026 18:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796408904; bh=eff8tEMaIEavOqMSrzz90EtmSs50s3bZl8lU03blAxQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=Q2D9m7Q04zPbHTrQogywGli2/8MuCtm2Y0kwUsdME2N1RkWxMwknj/jUIaB1sfaMb pXp6iKi01tqHlRF3tAQQE7fj/St5Y4yX5xU3ld/e2VC/JiyO9IsBL2xIJsBeOSFlq0 sGXFFbWQ22f4qkdG/79DArB6RJSHX5RgYQafmn/2q0Cu3qEk0BZvzEadwtfPQlz9ic tz9BDWKaskuZae2qFWZdUPEbAT6XUUlxBJgZ1wbqiFtinO7cdOKdmx0xAjfLgUms+t riHke8+9+frZTmmO1XASTScNHXfdjMmKkWfuyUvoiHYxxbk6EEKeR5LUxwpFg9Ca3B N3jdq05++PfkQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id D5A684DC1E; Fri, 4 Dec 2026 18:28:22 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Fri, 04 Dec 2026 11:27:55 -0700 Subject: [PATCH v3 4/5] dyndbg: Batch static branch updates 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: <20261204-jump-batch-261128-v3-4-2adda55a5d71@gmail.com> References: <20261204-jump-batch-261128-v3-0-2adda55a5d71@gmail.com> In-Reply-To: <20261204-jump-batch-261128-v3-0-2adda55a5d71@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=1796408901; l=3737; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=3nDQ8dGv6DiuAB8FPHMmWpoE3ZayR0ivy0+eNK9CmQ4=; b=6CIWy1n/IU7wcLMgULV6JGy+XHkB7IWdS9qD8kHaHNp3D13yhooj5wRG6+jWIBSSSkATalyLT du6atgGv7aOD8NT7vacuBEKFZMeHA4WJ0TcsFyyWPxf16dz6Me6Fo6H 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 Enabling or disabling pr_debug() callsites in ddebug_change() currently patches each callsite's static branch synchronously, triggering one cross-CPU text-poke IPI sequence per matched site. Because ddebug_change() also acquires and releases ddebug_lock on every query, semicolon-separated multi-queries cannot coalesce updates across sub-queries either. Hoist ddebug_lock and wrap the sub-query loop in static_key_batch inside ddebug_exec_queries(). Disjoint sub-queries (e.g. "class A +p; class B +p") coalesce into one shared text-poke batch, while overlapping toggles (e.g. "module foo +p; func bar -p" or "+p;-p") automatically flush the pending batch when revisiting a key so the first state settles before queuing the reverse transition. 1. Replace mutex_lock(&ddebug_lock) and mutex_unlock(&ddebug_lock) in ddebug_change() with lockdep_assert_held(&ddebug_lock). 2. Acquire ddebug_lock once in ddebug_exec_queries() and wrap the sub-query loop in scoped_guard(static_key_batch), flushing all queued static branch updates before releasing ddebug_lock. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 18a71a9108d3..1659c0604b18 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,8 +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); list_for_each_entry(dt, &ddebug_tables, link) { /* match against the module name */ @@ -263,7 +264,6 @@ static int ddebug_change(const struct ddebug_query *query, dp->flags = newflags; } } - mutex_unlock(&ddebug_lock); if (!nfound && verbose) pr_info("no matches for query\n"); @@ -573,26 +573,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