linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ftrace: Handle commands when closing set_ftrace_filter file
@ 2021-05-05 14:48 Steven Rostedt
  2021-05-13 20:24 ` Jiri Olsa
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2021-05-05 14:48 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Andrew Morton, Jiri Olsa

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

 # 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.

Cc: stable@vger.kernel.org
Fixes: eda1e32855656 ("tracing: handle broken names in ftrace filter")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 057e962ca5ce..c57508445faa 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -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);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ftrace: Handle commands when closing set_ftrace_filter file
  2021-05-05 14:48 [PATCH] ftrace: Handle commands when closing set_ftrace_filter file Steven Rostedt
@ 2021-05-13 20:24 ` Jiri Olsa
  2021-05-13 20:45   ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2021-05-13 20:24 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Ingo Molnar, Andrew Morton

On Wed, May 05, 2021 at 10:48:18AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
>  # 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.
> 
> Cc: stable@vger.kernel.org
> 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:

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  kernel/trace/ftrace.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 057e962ca5ce..c57508445faa 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -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);
> -- 
> 2.29.2
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ftrace: Handle commands when closing set_ftrace_filter file
  2021-05-13 20:24 ` Jiri Olsa
@ 2021-05-13 20:45   ` Steven Rostedt
  2021-05-13 20:58     ` Jiri Olsa
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2021-05-13 20:45 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: LKML, Ingo Molnar, Andrew Morton

On Thu, 13 May 2021 22:24:19 +0200
Jiri Olsa <jolsa@redhat.com> wrote:

> > 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"!

> 
> I saw the patch got already merged, FWIW:
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

I'm guessing you hit the bug too?

-- Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ftrace: Handle commands when closing set_ftrace_filter file
  2021-05-13 20:45   ` Steven Rostedt
@ 2021-05-13 20:58     ` Jiri Olsa
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2021-05-13 20:58 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Ingo Molnar, Andrew Morton

On Thu, May 13, 2021 at 04:45:04PM -0400, Steven Rostedt wrote:
> On Thu, 13 May 2021 22:24:19 +0200
> Jiri Olsa <jolsa@redhat.com> wrote:
> 
> > > 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"!
> 
> > 
> > I saw the patch got already merged, FWIW:
> > 
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> I'm guessing you hit the bug too?

no, I did not notice before, just reproduced based on your changelog

jirka


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-13 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 14:48 [PATCH] ftrace: Handle commands when closing set_ftrace_filter file Steven Rostedt
2021-05-13 20:24 ` Jiri Olsa
2021-05-13 20:45   ` Steven Rostedt
2021-05-13 20:58     ` Jiri Olsa

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).