From nobody Tue Apr 7 14:04:18 2026 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33FA03C5529 for ; Fri, 3 Apr 2026 14:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226256; cv=none; b=We8PkCHSwh1ZF8JrKEPYRrWQcTBo/E1bE1nhh7ixNEnx/JvK1aUEunUyMCI519FCDhhh2ZHLWxJaE0AO8kZ2orflvjwynHPPePC1IE6Msvn0fpB0vV5xgwqelmeAqfnCHU8JhPQL/LtyV0mUZPRWlM7g9yv7F6zG1TCZc5V782U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226256; c=relaxed/simple; bh=a5M7P5uLwE25ydXo7XlLk4Wdp4uQveWEuyZ/YP101ig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bXaFDuhySrfKn/rXPw/fnUaiyazvl/d5vNEPINIa3wh2U8C3+T0IN6ta8zErup08Rb5s2BnPzT73dZzkcHmvicBQgdDmmpdFdN9VZ9D9rKCAT/GB4bjT8XYm4/a9l2PZc5iwHxdmr80s98oSerjS5IIrtw+Kof9PIpoEJ2qTuWQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bAAMPQc9; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bAAMPQc9" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-4670676ba03so723426b6e.1 for ; Fri, 03 Apr 2026 07:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775226253; x=1775831053; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wWGJKqvINZ2eLx5DVOX+1vlZFIzp1jhj4sKSWhds1pY=; b=bAAMPQc9ELyEhYA5iOMEzgkZAweOHzoDxIa0x6mqcVCiiW4Bg2L9NysJf/9nTHLG2X +kNz1LSs8Ov1UfQ+LDa+e2X0okc8+uKEmYz9I5STCb1nGZbmVS5oNFb/QK2TvqastL9r JogZpOB+F3wT1bFjmB1YXyUxpyX30LEjVX8vLM4MM3u7SlogbB/0qEOLfwgsmqA+QTvz u6pyWm0CMVcpmZceKPMTaM/y7jtbAYDswwvtkTiHgvQH/50t07SZ4sQffPqaeP4tCgXV yjWeWh4Jo+nB8PPqJngwVsUuhmkGZYQa88xvFZ3NGtwD4Zn92Xro2MhlE4EQw7JresJl VhVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775226253; x=1775831053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wWGJKqvINZ2eLx5DVOX+1vlZFIzp1jhj4sKSWhds1pY=; b=Guydrf1sZvaUXb/XXarGlxCD+sst32qJgiewKaQ+Y+fAhhb9DF0iqdfK80MBeEjd+a DrDpQZ4Pf1CEOvVT4Vb40T4/7gw231O2H76Q+LhJwbutLCAgi22HeX9hvApoaI4yyhB0 ePzPzCXvx7STaPAny/vATqjHUccifCWnGXGpiOpqVpOEA94i+s9MQO0F/tzRsTDz6gkP Qg0p0ZxLBbLTAZJT2csSqb5F8YktEyfqu7OAM8AWbD5Ul0dtlgult9OgQR5CUWFkUFYH PCN7PXTiis2aVSNDPN2OC8VTYC6+J/USXOSU6IhSZkvdsiAsyiif2I0jpZv3wD+OBB7z K6ag== X-Forwarded-Encrypted: i=1; AJvYcCXjh6lHWINlhn9di0Xmlaw4J1C3NEK8Q7i+NDs3lYHy0Y/N69d9S9jEp+wy9Jc7gkeH7AiG0Rc8rPMN6t8=@vger.kernel.org X-Gm-Message-State: AOJu0YyaEx3Z5pDIr4RaGbNx3ZRoHZsJlISifry9bavKC2t0+7kB9ORw AezH7vA0ejxA5t4M8ge5pIWj9d5YRBxv/YIymFtFURoMLCGTuihEEvjy X-Gm-Gg: ATEYQzxz+I8YUiJmTsJOQSiftpzVzD+4DG/HlfPaW2qtLGhYNSalnmaz+sA1Xx2BU/j o+D+v2bCxtOPEV/N2xypELA65VtbuJX/Z3PRTZP65F4LhwzEBK5cqUP0BFrz9UTh3o3e0faazU1 2nO+ovWfI934lPw11njSjBoHUoSR9mkBy9Lyuo267bHe/KZGqvvzYos4VbRFFlFuRNh8VV3RpIE Pyd12s2HHfX+r3dvZOLHm3kOv1bA7CCSZummhiSPiX1HGOfTbWnZNCh9m6B73wpEIScqFvfCYLU UxwXPM9hXZLpH4tLKK8PWWcDeJki6FSJM5Wk3i5ie7awJqGQ8uWwue7wkVsvUaMY9mmXsAIIsMT Dp6ik2FRF73c51IHqonw+KZ3R8psLvkbJlVQKwW7OmGRP7AaFKMBGhXQr7c9ot02DJCrZFo8zfm N4amelhcLtM/+80H09KGVyapQ+n7opQ9bT1F852j1Uc5lBEA68kdp0RYYom/ET53yfWpXARlt/t Xs= X-Received: by 2002:a05:6808:f8e:b0:463:8a49:ca7a with SMTP id 5614622812f47-46ef871d0demr1694677b6e.52.1775226253040; Fri, 03 Apr 2026 07:24:13 -0700 (PDT) Received: from frodo.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 46e09a7af769-7dbb7c3a0c8sm1806671a34.12.2026.04.03.07.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 07:24:12 -0700 (PDT) From: Jim Cromie 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 Subject: [PATCH 5/5] lib/dynamic_debug: add negation support to queries Date: Fri, 3 Apr 2026 08:24:01 -0600 Message-ID: <20260403142401.1387033-6-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403142401.1387033-1-jim.cromie@gmail.com> References: <20260403142401.1387033-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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; }; =20 struct ddebug_iter { @@ -139,11 +143,12 @@ static void vpr_info_dq(const struct ddebug_query *qu= ery, const char *msg) fmtlen--; } =20 - v3pr_info("%s: func=3D\"%s\" file=3D\"%s\" module=3D\"%s\" format=3D\"%.*= s\" lineno=3D%u-%u class=3D%s\n", + v3pr_info("%s: func%s=3D\"%s\" file%s=3D\"%s\" module%s=3D\"%s\" format%s= =3D\"%.*s\" lineno=3D%u-%u class=3D%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_que= ry *query, struct _ddebug *dp, int valid_class) { + bool match; + /* match site against query-class */ if (dp->class_id !=3D valid_class) return false; =20 /* 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 =3D match_wildcard(query->filename, dp->filename) || + match_wildcard(query->filename, kbasename(dp->filename)) || + match_wildcard(query->filename, trim_prefix(dp->filename)); + if (match =3D=3D query->filename_neg) + return false; + } =20 /* match against the function */ - if (query->function && - !match_wildcard(query->function, dp->function)) - return false; + if (query->function) { + match =3D match_wildcard(query->function, dp->function); + if (match =3D=3D query->function_neg) + return false; + } =20 /* match against the format */ if (query->format) { if (*query->format =3D=3D '^') { - char *p; /* anchored search. match must be at beginning */ - p =3D strstr(dp->format, query->format + 1); - if (p !=3D dp->format) - return false; - } else if (!strstr(dp->format, query->format)) { - return false; + match =3D (strstr(dp->format, query->format + 1) =3D=3D dp->format); + } else { + match =3D !!strstr(dp->format, query->format); } + if (match =3D=3D query->format_neg) + return false; } =20 /* match against the line number range */ @@ -234,9 +242,11 @@ static int ddebug_change(const struct ddebug_query *qu= ery, list_for_each_entry(dt, &ddebug_tables, link) { =20 /* match against the module name */ - if (query->module && - !match_wildcard(query->module, dt->mod_name)) - continue; + if (query->module) { + bool match =3D match_wildcard(query->module, dt->mod_name); + if (match =3D=3D query->module_neg) + continue; + } =20 if (query->class_string) { map =3D 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; } =20 +static char *check_neg(char *src, unsigned int *neg) +{ + if (*src =3D=3D '!') { + *neg =3D 1; + return src + 1; + } + *neg =3D 0; + return src; +} + static int check_set(const char **dest, char *src, char *name) { int rc =3D 0; @@ -441,12 +461,15 @@ static int ddebug_parse_query(char *words[], int nwor= ds, } =20 for (i =3D 0; i < nwords; i +=3D 2) { - char *keyword =3D words[i]; + unsigned int neg; + char *keyword =3D check_neg(words[i], &neg); char *arg =3D words[i+1]; =20 if (!strcmp(keyword, "func")) { + query->function_neg =3D neg; rc =3D check_set(&query->function, arg, "func"); } else if (!strcmp(keyword, "file")) { + query->filename_neg =3D neg; if (check_set(&query->filename, arg, "file")) return -EINVAL; =20 @@ -464,16 +487,26 @@ static int ddebug_parse_query(char *words[], int nwor= ds, return -EINVAL; } } else if (!strcmp(keyword, "module")) { + query->module_neg =3D neg; rc =3D check_set(&query->module, arg, "module"); } else if (!strcmp(keyword, "format")) { string_unescape_inplace(arg, UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_SPECIAL); + query->format_neg =3D neg; rc =3D 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 =3D check_set(&query->class_string, arg, "class"); } else { pr_err("unknown keyword \"%s\"\n", keyword); --=20 2.53.0