From: Jim Cromie <jim.cromie@gmail.com>
To: peterz@infradead.org, gregkh@linuxfoundation.org
Cc: jpoimboe@kernel.org, jbaron@akamai.com, aliceryhl@google.com,
rostedt@goodmis.org, ardb@kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 5/5] lib/dynamic_debug: add negation support to queries
Date: Fri, 3 Apr 2026 08:24:01 -0600 [thread overview]
Message-ID: <20260403142401.1387033-6-jim.cromie@gmail.com> (raw)
In-Reply-To: <20260403142401.1387033-1-jim.cromie@gmail.com>
This allow users to invert the selection of most keywords, excluding
lineno and class. For example:
echo "!module virtio* +p" > /proc/dynamic_debug/control
When testing a kernel running in virtme-ng, this cmd prevents flooding
the logs with virtio activity, and spoiling the the test scenario.
NOTE:
This is convenient, but not perfect; it cannot also avoid flooding
from pr_debugs in serial_core or other potential sources.
A more robust command is:
echo "!module virtio* +p % module serial -p" > /proc/dynamic_debug/control
It also "interferes" with evolution of the grammar; particularly
around and/or combinations. For example this could become meaningful,
though perhaps inadvisable:
echo " !module virtio* !module serial +p "
lineno is currently excluded, pending review of its usefulness vs
ambiguities, for example " !lineno 1-20 " has straightforward meaning.
!class FOO is unlikely to be justifiable; it defeats the "protection
thru specificity" that classes are designed for.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
lib/dynamic_debug.c | 81 +++++++++++++++++++++++++++++++--------------
1 file changed, 57 insertions(+), 24 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 0b13810b03db..3addfa06e54d 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -58,6 +58,10 @@ struct ddebug_query {
const char *format;
const char *class_string;
unsigned int first_lineno, last_lineno;
+ unsigned int filename_neg:1;
+ unsigned int module_neg:1;
+ unsigned int function_neg:1;
+ unsigned int format_neg:1;
};
struct ddebug_iter {
@@ -139,11 +143,12 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
fmtlen--;
}
- v3pr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u class=%s\n",
+ v3pr_info("%s: func%s=\"%s\" file%s=\"%s\" module%s=\"%s\" format%s=\"%.*s\" lineno=%u-%u class=%s\n",
msg,
- query->function ?: "",
- query->filename ?: "",
- query->module ?: "",
+ query->function_neg ? "!" : "", query->function ?: "",
+ query->filename_neg ? "!" : "", query->filename ?: "",
+ query->module_neg ? "!" : "", query->module ?: "",
+ query->format_neg ? "!" : "",
fmtlen, query->format ?: "",
query->first_lineno, query->last_lineno, query->class_string);
}
@@ -176,35 +181,38 @@ static bool ddebug_match_desc(const struct ddebug_query *query,
struct _ddebug *dp,
int valid_class)
{
+ bool match;
+
/* match site against query-class */
if (dp->class_id != valid_class)
return false;
/* match against the source filename */
- if (query->filename &&
- !match_wildcard(query->filename, dp->filename) &&
- !match_wildcard(query->filename,
- kbasename(dp->filename)) &&
- !match_wildcard(query->filename,
- trim_prefix(dp->filename)))
- return false;
+ if (query->filename) {
+ match = match_wildcard(query->filename, dp->filename) ||
+ match_wildcard(query->filename, kbasename(dp->filename)) ||
+ match_wildcard(query->filename, trim_prefix(dp->filename));
+ if (match == query->filename_neg)
+ return false;
+ }
/* match against the function */
- if (query->function &&
- !match_wildcard(query->function, dp->function))
- return false;
+ if (query->function) {
+ match = match_wildcard(query->function, dp->function);
+ if (match == query->function_neg)
+ return false;
+ }
/* match against the format */
if (query->format) {
if (*query->format == '^') {
- char *p;
/* anchored search. match must be at beginning */
- p = strstr(dp->format, query->format + 1);
- if (p != dp->format)
- return false;
- } else if (!strstr(dp->format, query->format)) {
- return false;
+ match = (strstr(dp->format, query->format + 1) == dp->format);
+ } else {
+ match = !!strstr(dp->format, query->format);
}
+ if (match == query->format_neg)
+ return false;
}
/* match against the line number range */
@@ -234,9 +242,11 @@ static int ddebug_change(const struct ddebug_query *query,
list_for_each_entry(dt, &ddebug_tables, link) {
/* match against the module name */
- if (query->module &&
- !match_wildcard(query->module, dt->mod_name))
- continue;
+ if (query->module) {
+ bool match = match_wildcard(query->module, dt->mod_name);
+ if (match == query->module_neg)
+ continue;
+ }
if (query->class_string) {
map = ddebug_find_valid_class(dt, query->class_string, &valid_class);
@@ -399,6 +409,16 @@ static int parse_linerange(struct ddebug_query *query, const char *first)
return 0;
}
+static char *check_neg(char *src, unsigned int *neg)
+{
+ if (*src == '!') {
+ *neg = 1;
+ return src + 1;
+ }
+ *neg = 0;
+ return src;
+}
+
static int check_set(const char **dest, char *src, char *name)
{
int rc = 0;
@@ -441,12 +461,15 @@ static int ddebug_parse_query(char *words[], int nwords,
}
for (i = 0; i < nwords; i += 2) {
- char *keyword = words[i];
+ unsigned int neg;
+ char *keyword = check_neg(words[i], &neg);
char *arg = words[i+1];
if (!strcmp(keyword, "func")) {
+ query->function_neg = neg;
rc = check_set(&query->function, arg, "func");
} else if (!strcmp(keyword, "file")) {
+ query->filename_neg = neg;
if (check_set(&query->filename, arg, "file"))
return -EINVAL;
@@ -464,16 +487,26 @@ static int ddebug_parse_query(char *words[], int nwords,
return -EINVAL;
}
} else if (!strcmp(keyword, "module")) {
+ query->module_neg = neg;
rc = check_set(&query->module, arg, "module");
} else if (!strcmp(keyword, "format")) {
string_unescape_inplace(arg, UNESCAPE_SPACE |
UNESCAPE_OCTAL |
UNESCAPE_SPECIAL);
+ query->format_neg = neg;
rc = check_set(&query->format, arg, "format");
} else if (!strcmp(keyword, "line")) {
+ if (neg) {
+ pr_err("negation not supported for \"line\"\n");
+ return -EINVAL;
+ }
if (parse_linerange(query, arg))
return -EINVAL;
} else if (!strcmp(keyword, "class")) {
+ if (neg) {
+ pr_err("negation not supported for \"class\"\n");
+ return -EINVAL;
+ }
rc = check_set(&query->class_string, arg, "class");
} else {
pr_err("unknown keyword \"%s\"\n", keyword);
--
2.53.0
prev parent reply other threads:[~2026-04-03 14:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 14:23 [PATCH 0/5] jump_label: mitigate dynamic-debug induced IPI storms Jim Cromie
2026-04-03 14:23 ` [PATCH 1/5] jump_label: add queueing API for batched static key updates Jim Cromie
2026-04-03 14:23 ` [PATCH 2/5] x86/alternative.c: sort text-pokes before flushing the queue Jim Cromie
2026-04-03 14:23 ` [PATCH 3/5] dyndbg: use static-key queueing API in dynamic-debug Jim Cromie
2026-04-03 14:24 ` [PATCH 4/5] dyndbg: factor ddebug_match_desc out from ddebug_change (for demonstration only) Jim Cromie
2026-04-03 14:24 ` Jim Cromie [this message]
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=20260403142401.1387033-6-jim.cromie@gmail.com \
--to=jim.cromie@gmail.com \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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®