ftrace: Handle commands when closing set_ftrace_filter file
Steven Rostedt
maintainerPATCH 1/1 ftrace: Handle commands when closing set_ftrace_filter file
From: "Steven Rostedt (VMware)" <[email protected]>
# echo switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter
will cause switch_mm to stop tracing by the traceoff command.
# echo -n switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter
does nothing.
The reason is that the parsing in the write function only processes commands if it finished parsing (there is white space written after the command). That's to handle:
write(fd, "switch_mm:", 10);
write(fd, "traceoff", 8);
cases, where the command is broken over multiple writes.
The problem is if the file descriptor is closed, then the write call is not processed, and the command needs to be processed in the release code. The release code can handle matching of functions, but does not handle commands.
--- kernel/trace/ftrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +4 -1
@@ -5591,7 +5591,10 @@ int ftrace_regex_release(struct inode *inode, struct file *file) parser = &iter->parser;if (trace_parser_loaded (parser)) { -ftrace_match_records (iter->hash, parser->buffer, parser->idx); +int enable = !(iter->flags &FTRACE_ITER_NOTRACE ); + +ftrace_process_regex (iter, parser->buffer, + parser->idx, enable); }trace_parser_put (parser);
Signature · 1 line
2.29.2
Quoted 19 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
# echo switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filterwill cause
switch_mmto stop tracing by the traceoff command.# echo -n switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filterdoes nothing.
The reason is that the parsing in the write function only processes commands if it finished parsing (there is white space written after the command). That's to handle:
write(fd, "switch_mm:", 10);
write(fd, "traceoff", 8);cases, where the command is broken over multiple writes.
Quoted 7 lines
The problem is if the file descriptor is closed, then the write call is not processed, and the command needs to be processed in the release code. The release code can handle matching of functions, but does not handle commands.
Fixes eda1e32855656 ("tracing: handle broken names in ftrace filter")
nice, breaking kernel since 2009.. I'll put that on t-shirt ;-)
I saw the patch got already merged, FWIW:
jirka
Quoted 24 lines
Signed-off-by Steven Rostedt (VMware) <[email protected]>--- kernel/trace/ftrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/trace/ftrace.c +4
-1@@ -5591,7 +5591,10 @@ int ftrace_regex_release(struct inode *inode, struct file *file) parser = &iter->parser;if (trace_parser_loaded (parser)) { -ftrace_match_records (iter->hash, parser->buffer, parser->idx); +int enable = !(iter->flags &FTRACE_ITER_NOTRACE ); + +ftrace_process_regex (iter, parser->buffer, + parser->idx, enable); }trace_parser_put (parser);Signature · 1 line
2.29.2
Steven Rostedt
maintainerQuoted 3 lines · On Thu, 13 May 2021 22:24:19 +0200 Jiri Olsa <[email protected]> wrote:
Quoted 1 line
Fixes eda1e32855656 ("tracing: handle broken names in ftrace filter")nice, breaking kernel since 2009.. I'll put that on t-shirt ;-)
Hmm, maybe I'll recommend that for the Linux Plumber's t-shirt ;-)
"Breaking kernel's since 2009"!
Quoted 4 lines
I saw the patch got already merged, FWIW:
Acked-by Jiri Olsa <[email protected]>
I'm guessing you hit the bug too?
-- Steve
Quoted 9 lines · Steven Rostedt
Quoted 3 lines · On Thu, 13 May 2021 22:24:19 +0200 Jiri Olsa <[email protected]> wrote:
Quoted 1 line
Fixes eda1e32855656 ("tracing: handle broken names in ftrace filter")nice, breaking kernel since 2009.. I'll put that on t-shirt ;-)
Hmm, maybe I'll recommend that for the Linux Plumber's t-shirt ;-)
Quoted 8 lines
"Breaking kernel's since 2009"!
Quoted 4 lines
I saw the patch got already merged, FWIW:
Acked-by Jiri Olsa <[email protected]>I'm guessing you hit the bug too?
no, I did not notice before, just reproduced based on your changelog
jirka