From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Brian Norris <briannorris@chromium.org>
Subject: [for-linus][PATCH 27/32] tracing: Add tests for globbing number-based strings
Date: Fri, 20 Nov 2026 12:39:19 -0500 [thread overview]
Message-ID: <20261120174119.088587233@kernel.org> (raw)
In-Reply-To: 20261120173852.687189370@kernel.org
From: Brian Norris <briannorris@chromium.org>
In "tracing: Properly match strings that start with numbers", we fixed
bugs related to string fields that start with a number and also use
globs instead of full matches.
Add some additional startup test cases for this.
For easy reproducible testing, I abused the kunit.py script to boot a
minimal kernel with FTRACE_STARTUP_TEST enabled:
./tools/testing/kunit/kunit.py run --arch=x86_64 \
--kconfig_add=CONFIG_FTRACE=y \
--kconfig_add=CONFIG_FUNCTION_TRACER=y \
--kconfig_add=CONFIG_DYNAMIC_FTRACE=y \
--kconfig_add=CONFIG_FTRACE_STARTUP_TEST=y \
--kconfig_add=CONFIG_EVENT_TRACE_STARTUP_TEST=n \
--raw_output=all deadbeef
Relevant line:
Testing ftrace filter: OK
Without "tracing: Properly match strings that start with numbers", the
test fails with:
Testing ftrace filter:
Failed to match filter 'str ~ "0001:*"', expected 1
Link: https://patch.msgid.link/20261116182710.2.Ic117871c2b1e94c5a2176903a5c3316a10584e61@changeid
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 74 ++++++++++++++++++++++++-
kernel/trace/trace_events_filter_test.h | 12 ++--
2 files changed, 80 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 6704ef3d9520..7018964c94fc 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -2856,6 +2856,8 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
#include <linux/types.h>
#include <linux/tracepoint.h>
+#include "trace_probe.h"
+
#define CREATE_TRACE_POINTS
#include "trace_events_filter_test.h"
@@ -2867,12 +2869,22 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
.match = m, \
.not_visited = nvisit, \
}
+
+#define DATA_STR(m, s) \
+{ \
+ .filter = FILTER, \
+ .str = s, \
+ .match = m, \
+ .not_visited = "", \
+}
+
#define YES 1
#define NO 0
static struct test_filter_data_t {
char *filter;
struct trace_event_raw_ftrace_test_filter rec;
+ const char *str;
int match;
char *not_visited;
} test_filter_data[] = {
@@ -2924,9 +2936,46 @@ static struct test_filter_data_t {
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, "bdfh"),
DATA_REC(YES, 0, 1, 0, 1, 0, 1, 0, 1, ""),
DATA_REC(YES, 1, 0, 1, 0, 1, 0, 1, 0, "bdfh"),
+#undef FILTER
+#define FILTER "str ~ \"0001:*\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(YES, "0001:"),
+ DATA_STR(NO, "0002:01:00.0"),
+ DATA_STR(NO, "pci:0001:01:00.0"),
+ DATA_STR(NO, "0001"),
+#undef FILTER
+#define FILTER "str ~ \"!0001:*\""
+ DATA_STR(NO, "0001:01:00.0"),
+ DATA_STR(YES, "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"0001:*:00.[0-9]\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(YES, "0001:ff:00.7"),
+ DATA_STR(NO, "0001:01:00.a"),
+ DATA_STR(NO, "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"0001:01:00.0\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(NO, "0001:01:00.1"),
+ DATA_STR(NO, "0001:01:00.00"),
+ DATA_STR(NO, "0001:01:00"),
+#undef FILTER
+#define FILTER "str == \"0001:01:00.0\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(NO, "0001:01:00.1"),
+#undef FILTER
+#define FILTER "str ~ \"*0001:*\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(YES, "pci:0001:01:00.0"),
+ DATA_STR(NO, "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"*:00.0\""
+ DATA_STR(YES, "0001:01:00.0"),
+ DATA_STR(NO, "0001:01:00.1"),
};
#undef DATA_REC
+#undef DATA_STR
#undef FILTER
#undef YES
#undef NO
@@ -2977,8 +3026,29 @@ static __init int ftrace_test_event_filter(void)
for (i = 0; i < DATA_CNT; i++) {
struct event_filter *filter = NULL;
struct test_filter_data_t *d = &test_filter_data[i];
+ union {
+ struct trace_event_raw_ftrace_test_filter rec;
+ /* Add some spare, to append the string contents. */
+ char buf[sizeof(struct trace_event_raw_ftrace_test_filter) + 32];
+ } event = { .rec = d->rec };
int err;
+ if (d->str) {
+ struct ftrace_event_field *field;
+ u32 offset = offsetof(typeof(event.rec), __data);
+ u32 len = strlen(d->str) + 1;
+ u32 *str_item;
+
+ field = trace_find_event_field(&event_ftrace_test_filter, "str");
+ if (WARN_ON_ONCE(!field))
+ break;
+ if (WARN_ON_ONCE(offset + len > sizeof(event.buf)))
+ break;
+ str_item = (u32 *)&event.buf[field->offset];
+ *str_item = make_data_loc(len, offset);
+ memcpy(&event.buf[offset], d->str, len);
+ }
+
err = create_filter(NULL, &event_ftrace_test_filter,
d->filter, false, &filter);
if (err) {
@@ -3000,7 +3070,7 @@ static __init int ftrace_test_event_filter(void)
update_pred_fn(filter, d->not_visited);
test_pred_visited = 0;
- err = filter_match_preds(filter, &d->rec);
+ err = filter_match_preds(filter, &event.rec);
preempt_enable();
mutex_unlock(&event_mutex);
@@ -3027,7 +3097,7 @@ static __init int ftrace_test_event_filter(void)
/* Need to call ftrace_test_filter to prevent a warning */
if (!trace_ftrace_test_filter_enabled())
- trace_ftrace_test_filter(1, 2, 3, 4, 5, 6, 7, 8);
+ trace_ftrace_test_filter(1, 2, 3, 4, 5, 6, 7, 8, "");
return 0;
}
diff --git a/kernel/trace/trace_events_filter_test.h b/kernel/trace/trace_events_filter_test.h
index e651dfbd345e..74a9dba91545 100644
--- a/kernel/trace/trace_events_filter_test.h
+++ b/kernel/trace/trace_events_filter_test.h
@@ -9,9 +9,10 @@
TRACE_EVENT(ftrace_test_filter,
- TP_PROTO(int a, int b, int c, int d, int e, int f, int g, int h),
+ TP_PROTO(int a, int b, int c, int d, int e, int f, int g, int h,
+ const char *str),
- TP_ARGS(a, b, c, d, e, f, g, h),
+ TP_ARGS(a, b, c, d, e, f, g, h, str),
TP_STRUCT__entry(
__field(int, a)
@@ -22,6 +23,7 @@ TRACE_EVENT(ftrace_test_filter,
__field(int, f)
__field(int, g)
__field(int, h)
+ __string(str, str)
),
TP_fast_assign(
@@ -33,11 +35,13 @@ TRACE_EVENT(ftrace_test_filter,
__entry->f = f;
__entry->g = g;
__entry->h = h;
+ __assign_str(str);
),
- TP_printk("a %d, b %d, c %d, d %d, e %d, f %d, g %d, h %d",
+ TP_printk("a %d, b %d, c %d, d %d, e %d, f %d, g %d, h %d, str %s",
__entry->a, __entry->b, __entry->c, __entry->d,
- __entry->e, __entry->f, __entry->g, __entry->h)
+ __entry->e, __entry->f, __entry->g, __entry->h,
+ __get_str(str))
);
#endif /* _TRACE_TEST_H || TRACE_HEADER_MULTI_READ */
--
2.53.0
next prev parent reply other threads:[~2026-11-20 17:41 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 17:38 Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 01/32] ring-buffer: Do not WARN when trace_rb_cpu_prepare() fails to allocate Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 02/32] tracing: Keep copying markers when one instance is stopped Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 03/32] tracing: Restrict perf filters that read kernel strings Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 04/32] tracing/filters: Treat zero-length dynamic strings as empty Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 05/32] tracing: Define common event fields before enabling boot events Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 06/32] tracing: Drop the synthetic event ref when clearing hist triggers Steven Rostedt
2026-11-20 17:38 ` [for-linus][PATCH 07/32] tracing: Avoid undefined shifts for zero histogram map size Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 08/32] tracing/filters: Fix MATCH_END_ONLY regex matching for fixed-size strings Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 09/32] tracing/filters: Handle out-of-range CPU for OP_NE in cpumask comparison Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 10/32] tracing/filters: Check for missing operand after operator in parse_pred() Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 11/32] tracing/filters: Fix false success return in process_system_preds() Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 12/32] tracing: Free tracer resources on instance creation failure Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 13/32] fgraph: Allocate shadow stacks inline with GFP_NOWAIT Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 14/32] fgraph: Use scoped_guard() for the task list walk Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 15/32] fgraph: Read the task->ret_stack with a smp_load_acquire() Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 16/32] tracing/osnoise: Dont start a kthread in timerlat user-space mode Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 17/32] tracing/user_events: Dont free an event that a dynamic event still references Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 18/32] tracing: Wait for marker writers when copy_trace_marker is cleared Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 19/32] tracing: Validate user addresses in faultable buffer copies Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 20/32] fgraph: Do not mark index 0 in every shadow stack frame Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 21/32] ring-buffer: Skip remote reader page swap when on tail Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 22/32] ring-buffer: Check remote reader page commit before meta entries Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 23/32] ring-buffer: Order remote page commit with data and timestamp Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 24/32] ring-buffer: Increment pages_read on remote ring buffer page swap Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 25/32] tracing/hwlat: Do the latency calculations in nanoseconds Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 26/32] tracing: Properly match strings that start with numbers Steven Rostedt
2026-11-20 17:39 ` Steven Rostedt [this message]
2026-11-20 17:39 ` [for-linus][PATCH 28/32] tracing: Take trace_access_lock() in tracing_buffers_ioctl() Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 29/32] tracing: Do not allow user events to add a system name Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 30/32] ring-buffer: Do not check si_mem_available() before deferred init completes Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 31/32] tracing: Add notrace to event functions that hook to ftrace Steven Rostedt
2026-11-20 17:39 ` [for-linus][PATCH 32/32] tracing: Ignore .function on the function trace event Steven Rostedt
2026-11-20 18:30 ` [PATCH 0/32] tracing: Fixes for v7.4 Steven Rostedt
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=20261120174119.088587233@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=briannorris@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@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