Hi,
Here is a patch series to fix some issues on the trace event and function filters.
The first patch fixes an issue that the event filter can not handle the string pointer with BTF attribute tag. This happens with CONFIG_DEBUG_INFO_BTF=y and PAHOLE_HAS_BTF_TAG=y.
The second patch fixes a selftest issue on the function glob filter. Since mutex_trylock() can be an inline function, it is not a good example for ftrace. This replaces it with mutex_unlock().
Thank you,
--- Masami Hiramatsu (Google) (2): tracing: Handle "(const) char __attribute() *" as string ptr type selftests: tracing: Use mutex_unlock for testing glob filter
kernel/trace/trace_events_filter.c | 5 +++++ tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
From: Masami Hiramatsu (Google) mhiramat@kernel.org
With CONFIG_DEBUG_INFO_BTF=y and PAHOLE_HAS_BTF_TAG=y, `__user` is converted to `__attribute((btf_type_tag("user")))`. In this case, some syscall events have `const char __attribute(...) *` for __user string, like below;
/sys/kernel/tracing # cat events/syscalls/sys_enter_openat/format name: sys_enter_openat ID: 720 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1;
field:int __syscall_nr; offset:8; size:4; signed:1; field:int dfd; offset:16; size:8; signed:0; field:const char __attribute__((btf_type_tag("user"))) * filename; offset:24; size:8; signed:0; field:int flags; offset:32; size:8; signed:0; field:umode_t mode; offset:40; size:8; signed:0;
Then the trace event filter failes to set string acceptable flag (FILTER_PTR_STRING) and rejects setting string filter;
# echo 'filename.ustring ~ "*ftracetest-dir.wbx24v*"' >> events/syscalls/sys_enter_openat/filter sh: write error: Invalid argument # cat error_log [ 723.743637] event filter parse error: error: Expecting numeric field Command: filename.ustring ~ "*ftracetest-dir.wbx24v*"
Handle "(const) char __attribute() *" also as string ptr type.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org --- kernel/trace/trace_events_filter.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 3885aadc434d..5e27190a0377 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1488,6 +1488,11 @@ int filter_assign_type(const char *type) if (strcmp(type, "char *") == 0 || strcmp(type, "const char *") == 0) return FILTER_PTR_STRING;
+ /* Ignore attributes */ + if (glob_match("char __attribute(*) \*", type) || + glob_match("const char __attribute(*) \*", type)) + return FILTER_PTR_STRING; + return FILTER_OTHER; }
On Thu, 3 Jul 2025 13:26:35 +0900 "Masami Hiramatsu (Google)" mhiramat@kernel.org wrote:
From: Masami Hiramatsu (Google) mhiramat@kernel.org
With CONFIG_DEBUG_INFO_BTF=y and PAHOLE_HAS_BTF_TAG=y, `__user` is converted to `__attribute((btf_type_tag("user")))`. In this case, some syscall events have `const char __attribute(...) *` for __user string, like below;
/sys/kernel/tracing # cat events/syscalls/sys_enter_openat/format name: sys_enter_openat ID: 720 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1;
field:int __syscall_nr; offset:8; size:4; signed:1; field:int dfd; offset:16; size:8; signed:0; field:const char __attribute__((btf_type_tag("user"))) * filename; offset:24;
Ahh, sorry, it was "__attribute__()" not "__attribute()".
Anyway, I think we should sanitize the __attribute__ from format.
Thank you,
size:8; signed:0;
field:int flags; offset:32; size:8; signed:0; field:umode_t mode; offset:40; size:8; signed:0;
Then the trace event filter failes to set string acceptable flag (FILTER_PTR_STRING) and rejects setting string filter;
# echo 'filename.ustring ~ "*ftracetest-dir.wbx24v*"' >> events/syscalls/sys_enter_openat/filter sh: write error: Invalid argument # cat error_log [ 723.743637] event filter parse error: error: Expecting numeric field Command: filename.ustring ~ "*ftracetest-dir.wbx24v*"
Handle "(const) char __attribute() *" also as string ptr type.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org
kernel/trace/trace_events_filter.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 3885aadc434d..5e27190a0377 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1488,6 +1488,11 @@ int filter_assign_type(const char *type) if (strcmp(type, "char *") == 0 || strcmp(type, "const char *") == 0) return FILTER_PTR_STRING;
- /* Ignore attributes */
- if (glob_match("char __attribute(*) \*", type) ||
glob_match("const char __attribute(*) \\*", type))
return FILTER_PTR_STRING;
- return FILTER_OTHER;
}
From: Masami Hiramatsu (Google) mhiramat@kernel.org
Since commit c5b6ababd21a ("locking/mutex: implement mutex_trylock_nested") makes mutex_trylock() as an inlined function if CONFIG_DEBUG_LOCK_ALLOC=y, we can not use mutex_trylock() for testing the glob filter of ftrace.
Use mutex_unlock instead.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org --- .../ftrace/test.d/ftrace/func-filter-glob.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc index 4b994b6df5ac..ed81eaf2afd6 100644 --- a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc +++ b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc @@ -29,7 +29,7 @@ ftrace_filter_check 'schedule*' '^schedule.*$' ftrace_filter_check '*pin*lock' '.*pin.*lock$'
# filter by start*mid* -ftrace_filter_check 'mutex*try*' '^mutex.*try.*' +ftrace_filter_check 'mutex*unl*' '^mutex.*unl.*'
# Advanced full-glob matching feature is recently supported. # Skip the tests if we are sure the kernel does not support it.
On Thu, 3 Jul 2025 13:26:43 +0900 "Masami Hiramatsu (Google)" mhiramat@kernel.org wrote:
From: Masami Hiramatsu (Google) mhiramat@kernel.org
Since commit c5b6ababd21a ("locking/mutex: implement mutex_trylock_nested") makes mutex_trylock() as an inlined function if CONFIG_DEBUG_LOCK_ALLOC=y, we can not use mutex_trylock() for testing the glob filter of ftrace.
Use mutex_unlock instead.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org
Acked-by: Steven Rostedt (Google) rostedt@goodmis.org
-- Steve
Shuah,
Can you take this patch (fix) to your tree since this is a fix for the selftest?
Thank you,
On Thu, 3 Jul 2025 10:30:39 -0400 Steven Rostedt rostedt@goodmis.org wrote:
On Thu, 3 Jul 2025 13:26:43 +0900 "Masami Hiramatsu (Google)" mhiramat@kernel.org wrote:
From: Masami Hiramatsu (Google) mhiramat@kernel.org
Since commit c5b6ababd21a ("locking/mutex: implement mutex_trylock_nested") makes mutex_trylock() as an inlined function if CONFIG_DEBUG_LOCK_ALLOC=y, we can not use mutex_trylock() for testing the glob filter of ftrace.
Use mutex_unlock instead.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org
Acked-by: Steven Rostedt (Google) rostedt@goodmis.org
-- Steve
On 7/4/25 00:04, Masami Hiramatsu (Google) wrote:
Shuah,
Can you take this patch (fix) to your tree since this is a fix for the selftest?
Thank you,
On Thu, 3 Jul 2025 10:30:39 -0400 Steven Rostedt rostedt@goodmis.org wrote:
On Thu, 3 Jul 2025 13:26:43 +0900 "Masami Hiramatsu (Google)" mhiramat@kernel.org wrote:
From: Masami Hiramatsu (Google) mhiramat@kernel.org
Since commit c5b6ababd21a ("locking/mutex: implement mutex_trylock_nested") makes mutex_trylock() as an inlined function if CONFIG_DEBUG_LOCK_ALLOC=y, we can not use mutex_trylock() for testing the glob filter of ftrace.
Use mutex_unlock instead.
Signed-off-by: Masami Hiramatsu (Google) mhiramat@kernel.org
Acked-by: Steven Rostedt (Google) rostedt@goodmis.org
-- Steve
Applied to linux-kselftest next
thanks, -- Shuah
On Thu, 3 Jul 2025 13:26:26 +0900 "Masami Hiramatsu (Google)" mhiramat@kernel.org wrote:
Hi,
Here is a patch series to fix some issues on the trace event and function filters.
The first patch fixes an issue that the event filter can not handle the string pointer with BTF attribute tag. This happens with CONFIG_DEBUG_INFO_BTF=y and PAHOLE_HAS_BTF_TAG=y.
The second patch fixes a selftest issue on the function glob filter. Since mutex_trylock() can be an inline function, it is not a good example for ftrace. This replaces it with mutex_unlock().
Thank you,
Masami Hiramatsu (Google) (2): tracing: Handle "(const) char __attribute() *" as string ptr type
I can take the first patch.
selftests: tracing: Use mutex_unlock for testing glob filter
This patch should go via Shuah's tree.
-- Steve
kernel/trace/trace_events_filter.c | 5 +++++ tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
linux-kselftest-mirror@lists.linaro.org