linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest
@ 2022-04-18  7:39 Li Huafei
  2022-04-25 22:58 ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Li Huafei @ 2022-04-18  7:39 UTC (permalink / raw)
  To: jolsa; +Cc: rostedt, mingo, linux-kernel

The direct trampoline and graph coexistence test sets global_ops to
trace only 'trace_selftest_dynamic_test_func', but does not reset it
after the test is completed, resulting in the function filter being set
already after the system starts. Although it can be reset through the
tracefs interface, it is more or less confusing to the user, and we
should reset it to trace all functions after the trampoline/graph test
completes.

Fixes: 130c08065848 ("tracing: Add trampoline/graph selftest")
Signed-off-by: Li Huafei <lihuafei1@huawei.com>
---
 kernel/trace/trace_selftest.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
index abcadbe933bb..e89f72571f8e 100644
--- a/kernel/trace/trace_selftest.c
+++ b/kernel/trace/trace_selftest.c
@@ -866,12 +866,12 @@ trace_selftest_startup_function_graph(struct tracer *trace,
 	ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
 				     (unsigned long) trace_direct_tramp);
 	if (ret)
-		goto out;
+		goto reset_filter;
 
 	ret = register_ftrace_graph(&fgraph_ops);
 	if (ret) {
 		warn_failed_init_tracer(trace, ret);
-		goto out;
+		goto reset_filter;
 	}
 
 	DYN_FTRACE_TEST_NAME();
@@ -887,14 +887,18 @@ trace_selftest_startup_function_graph(struct tracer *trace,
 	ret = unregister_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
 				       (unsigned long) trace_direct_tramp);
 	if (ret)
-		goto out;
+		goto reset_filter;
 
 	tracing_start();
 
 	if (!ret && !count) {
 		ret = -1;
-		goto out;
+		goto reset_filter;
 	}
+
+reset_filter:
+	/* Enable tracing on all functions again */
+	ftrace_set_global_filter(NULL, 0, 1);
 #endif
 
 	/* Don't test dynamic tracing, the function tracer already did */
-- 
2.17.1


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

* Re: [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest
  2022-04-18  7:39 [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest Li Huafei
@ 2022-04-25 22:58 ` Steven Rostedt
  2022-04-26  8:00   ` Li Huafei
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-04-25 22:58 UTC (permalink / raw)
  To: Li Huafei; +Cc: jolsa, mingo, linux-kernel

On Mon, 18 Apr 2022 15:39:58 +0800
Li Huafei <lihuafei1@huawei.com> wrote:

> The direct trampoline and graph coexistence test sets global_ops to
> trace only 'trace_selftest_dynamic_test_func', but does not reset it
> after the test is completed, resulting in the function filter being set
> already after the system starts. Although it can be reset through the
> tracefs interface, it is more or less confusing to the user, and we
> should reset it to trace all functions after the trampoline/graph test
> completes.
> 
> Fixes: 130c08065848 ("tracing: Add trampoline/graph selftest")
> Signed-off-by: Li Huafei <lihuafei1@huawei.com>
> ---
>  kernel/trace/trace_selftest.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
> index abcadbe933bb..e89f72571f8e 100644
> --- a/kernel/trace/trace_selftest.c
> +++ b/kernel/trace/trace_selftest.c
> @@ -866,12 +866,12 @@ trace_selftest_startup_function_graph(struct tracer *trace,
>  	ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
>  				     (unsigned long) trace_direct_tramp);
>  	if (ret)
> -		goto out;
> +		goto reset_filter;
>  
>  	ret = register_ftrace_graph(&fgraph_ops);
>  	if (ret) {
>  		warn_failed_init_tracer(trace, ret);
> -		goto out;
> +		goto reset_filter;
>  	}
>  
>  	DYN_FTRACE_TEST_NAME();
> @@ -887,14 +887,18 @@ trace_selftest_startup_function_graph(struct tracer *trace,
>  	ret = unregister_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
>  				       (unsigned long) trace_direct_tramp);
>  	if (ret)
> -		goto out;
> +		goto reset_filter;
>  
>  	tracing_start();
>  
>  	if (!ret && !count) {
>  		ret = -1;
> -		goto out;
> +		goto reset_filter;

No need for all the 'goto reset_filter', if this function fails, then the
tracer is disabled, and there's no reason to clear the filter. In fact, it
may cause a crash (because something bad happened).

-- Steve


>  	}
> +
> +reset_filter:
> +	/* Enable tracing on all functions again */
> +	ftrace_set_global_filter(NULL, 0, 1);
>  #endif
>  
>  	/* Don't test dynamic tracing, the function tracer already did */


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

* Re: [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest
  2022-04-25 22:58 ` Steven Rostedt
@ 2022-04-26  8:00   ` Li Huafei
  2022-04-26 15:31     ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Li Huafei @ 2022-04-26  8:00 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: jolsa, mingo, linux-kernel

Hi Steve,

On 2022/4/26 6:58, Steven Rostedt wrote:
> On Mon, 18 Apr 2022 15:39:58 +0800
> Li Huafei <lihuafei1@huawei.com> wrote:
>
>> The direct trampoline and graph coexistence test sets global_ops to
>> trace only 'trace_selftest_dynamic_test_func', but does not reset it
>> after the test is completed, resulting in the function filter being set
>> already after the system starts. Although it can be reset through the
>> tracefs interface, it is more or less confusing to the user, and we
>> should reset it to trace all functions after the trampoline/graph test
>> completes.
>>
>> Fixes: 130c08065848 ("tracing: Add trampoline/graph selftest")
>> Signed-off-by: Li Huafei <lihuafei1@huawei.com>
>> ---
>>   kernel/trace/trace_selftest.c | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
>> index abcadbe933bb..e89f72571f8e 100644
>> --- a/kernel/trace/trace_selftest.c
>> +++ b/kernel/trace/trace_selftest.c
>> @@ -866,12 +866,12 @@ trace_selftest_startup_function_graph(struct tracer *trace,
>>   	ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
>>   				     (unsigned long) trace_direct_tramp);
>>   	if (ret)
>> -		goto out;
>> +		goto reset_filter;
>>   
>>   	ret = register_ftrace_graph(&fgraph_ops);
>>   	if (ret) {
>>   		warn_failed_init_tracer(trace, ret);
>> -		goto out;
>> +		goto reset_filter;
>>   	}
>>   
>>   	DYN_FTRACE_TEST_NAME();
>> @@ -887,14 +887,18 @@ trace_selftest_startup_function_graph(struct tracer *trace,
>>   	ret = unregister_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
>>   				       (unsigned long) trace_direct_tramp);
>>   	if (ret)
>> -		goto out;
>> +		goto reset_filter;
>>   
>>   	tracing_start();
>>   
>>   	if (!ret && !count) {
>>   		ret = -1;
>> -		goto out;
>> +		goto reset_filter;
> No need for all the 'goto reset_filter', if this function fails, then the
> tracer is disabled, and there's no reason to clear the filter. In fact, it
Thank you for the review. I see that we will disable function_graph tracer:

      /* Stop it if we failed */
      if (ret)
            ftrace_graph_stop();

But there is no function tracer disabled. Am I missing something that 
would disable the function tracer?


> may cause a crash (because something bad happened).

Yes, so should we kill ftrace when the function_graph test fails?

Thanks,
Huafei

>
> -- Steve
>
>
>>   	}
>> +
>> +reset_filter:
>> +	/* Enable tracing on all functions again */
>> +	ftrace_set_global_filter(NULL, 0, 1);
>>   #endif
>>   
>>   	/* Don't test dynamic tracing, the function tracer already did */
> .

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

* Re: [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest
  2022-04-26  8:00   ` Li Huafei
@ 2022-04-26 15:31     ` Steven Rostedt
  2022-04-27  1:39       ` Li Huafei
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-04-26 15:31 UTC (permalink / raw)
  To: Li Huafei; +Cc: jolsa, mingo, linux-kernel

On Tue, 26 Apr 2022 16:00:35 +0800
Li Huafei <lihuafei1@huawei.com> wrote:

> > No need for all the 'goto reset_filter', if this function fails, then the
> > tracer is disabled, and there's no reason to clear the filter. In fact, it  
> Thank you for the review. I see that we will disable function_graph tracer:
> 
>       /* Stop it if we failed */
>       if (ret)
>             ftrace_graph_stop();
> 
> But there is no function tracer disabled. Am I missing something that 
> would disable the function tracer?

No, but if we are triggering these, then something really bad has happened,
and function tracer is possibly corrupted too, or should not be trusted.

> 
> 
> > may cause a crash (because something bad happened).  
> 
> Yes, so should we kill ftrace when the function_graph test fails?

No, but the system should be fixed. These should never trigger on any
production system, because it means something really bad is happening and
we do not know what.

Not resetting the filters may even be useful in debugging it. So that's
another reason to not do so.

-- Steve

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

* Re: [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest
  2022-04-26 15:31     ` Steven Rostedt
@ 2022-04-27  1:39       ` Li Huafei
  0 siblings, 0 replies; 5+ messages in thread
From: Li Huafei @ 2022-04-27  1:39 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: jolsa, mingo, linux-kernel


On 2022/4/26 23:31, Steven Rostedt wrote:
> On Tue, 26 Apr 2022 16:00:35 +0800
> Li Huafei <lihuafei1@huawei.com> wrote:
>
>>> No need for all the 'goto reset_filter', if this function fails, then the
>>> tracer is disabled, and there's no reason to clear the filter. In fact, it
>> Thank you for the review. I see that we will disable function_graph tracer:
>>
>>        /* Stop it if we failed */
>>        if (ret)
>>              ftrace_graph_stop();
>>
>> But there is no function tracer disabled. Am I missing something that
>> would disable the function tracer?
> No, but if we are triggering these, then something really bad has happened,
> and function tracer is possibly corrupted too, or should not be trusted.
>
>>
>>> may cause a crash (because something bad happened).
>> Yes, so should we kill ftrace when the function_graph test fails?
> No, but the system should be fixed. These should never trigger on any
> production system, because it means something really bad is happening and
> we do not know what.
>
> Not resetting the filters may even be useful in debugging it. So that's
> another reason to not do so.


That makes sense.  I will remove all "goto reset_filter" from the error 
path and only reset the filter when the test passes.


Thanks,

Huafei


>
> -- Steve
> .

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

end of thread, other threads:[~2022-04-27  1:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18  7:39 [PATCH] tracing: Reset the function filter after completing trampoline/graph selftest Li Huafei
2022-04-25 22:58 ` Steven Rostedt
2022-04-26  8:00   ` Li Huafei
2022-04-26 15:31     ` Steven Rostedt
2022-04-27  1:39       ` Li Huafei

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