* [PATCH 0/2] tracing: Fixes for filter
@ 2025-07-03 4:26 Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-07-03 4:26 UTC (permalink / raw)
To: Steven Rostedt, Shuah Khan
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel, linux-kselftest
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(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type
2025-07-03 4:26 [PATCH 0/2] tracing: Fixes for filter Masami Hiramatsu (Google)
@ 2025-07-03 4:26 ` Masami Hiramatsu (Google)
2025-07-08 1:06 ` Masami Hiramatsu
2025-07-03 4:26 ` [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter Masami Hiramatsu (Google)
2025-07-03 14:30 ` [PATCH 0/2] tracing: Fixes for filter Steven Rostedt
2 siblings, 1 reply; 8+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-07-03 4:26 UTC (permalink / raw)
To: Steven Rostedt, Shuah Khan
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel, linux-kselftest
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;
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter
2025-07-03 4:26 [PATCH 0/2] tracing: Fixes for filter Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
@ 2025-07-03 4:26 ` Masami Hiramatsu (Google)
2025-07-03 14:30 ` Steven Rostedt
2025-07-03 14:30 ` [PATCH 0/2] tracing: Fixes for filter Steven Rostedt
2 siblings, 1 reply; 8+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-07-03 4:26 UTC (permalink / raw)
To: Steven Rostedt, Shuah Khan
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel, linux-kselftest
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.
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] tracing: Fixes for filter
2025-07-03 4:26 [PATCH 0/2] tracing: Fixes for filter Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter Masami Hiramatsu (Google)
@ 2025-07-03 14:30 ` Steven Rostedt
2 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2025-07-03 14:30 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Shuah Khan, Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-kselftest
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(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter
2025-07-03 4:26 ` [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter Masami Hiramatsu (Google)
@ 2025-07-03 14:30 ` Steven Rostedt
2025-07-04 6:04 ` Masami Hiramatsu
0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2025-07-03 14:30 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Shuah Khan, Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-kselftest
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter
2025-07-03 14:30 ` Steven Rostedt
@ 2025-07-04 6:04 ` Masami Hiramatsu
2025-07-07 21:36 ` Shuah Khan
0 siblings, 1 reply; 8+ messages in thread
From: Masami Hiramatsu @ 2025-07-04 6:04 UTC (permalink / raw)
To: Shuah Khan, Steven Rostedt
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-kselftest
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
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter
2025-07-04 6:04 ` Masami Hiramatsu
@ 2025-07-07 21:36 ` Shuah Khan
0 siblings, 0 replies; 8+ messages in thread
From: Shuah Khan @ 2025-07-07 21:36 UTC (permalink / raw)
To: Masami Hiramatsu (Google), Shuah Khan, Steven Rostedt
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-kselftest, Shuah Khan
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
@ 2025-07-08 1:06 ` Masami Hiramatsu
0 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2025-07-08 1:06 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Steven Rostedt, Shuah Khan, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel, linux-kselftest
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;
> }
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-07-08 1:06 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 4:26 [PATCH 0/2] tracing: Fixes for filter Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
2025-07-08 1:06 ` Masami Hiramatsu
2025-07-03 4:26 ` [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter Masami Hiramatsu (Google)
2025-07-03 14:30 ` Steven Rostedt
2025-07-04 6:04 ` Masami Hiramatsu
2025-07-07 21:36 ` Shuah Khan
2025-07-03 14:30 ` [PATCH 0/2] tracing: Fixes for filter Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).