Skip to contentSkip to conversation

tracing: Reset the function filter after completing trampoline/graph selftest

PATCH Superseded Li Huafei 2 participants 5 messages Apr 18, 2022 – Apr 27, 2022 Tracing

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Huafei

author
#0 lore raw

PATCH 1/1 tracing: Reset the function filter after completing trampoline/graph selftest

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")
---
 kernel/trace/trace_selftest.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
kernel/trace/trace_selftest.c +8 -4
index abcadbe933bb..e89f72571f8e 100644
@@ -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 */
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 36 lines · On Mon, 18 Apr 2022 15:39:58 +0800 Li Huafei <[email protected]> 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")
---
 kernel/trace/trace_selftest.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
kernel/trace/trace_selftest.c +2 -2
index abcadbe933bb..e89f72571f8e 100644
@@ -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);

kernel/trace/trace_selftest.c trace_selftest_startup_function_graph(struct tracer *trace, · line 896

Quoted 10 lines
kernel/trace/trace_selftest.c +2 -2
 	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

Quoted 8 lines
kernel/trace/trace_selftest.c +4 -0
 	}
+
+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 */
author
#2 lore raw

Hi Steve,

Quoted 43 lines · Steven Rostedt
Quoted 40 lines · On Mon, 18 Apr 2022 15:39:58 +0800 Li Huafei <[email protected]> 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")
---
  kernel/trace/trace_selftest.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
kernel/trace/trace_selftest.c +3 -3
index abcadbe933bb..e89f72571f8e 100644
@@ -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;
 
Quoted 8 lines

kernel/trace/trace_selftest.c trace_selftest_startup_function_graph(struct tracer *trace, · line 896

Quoted 6 lines
kernel/trace/trace_selftest.c +1 -1
  	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?

Quoted 1 line

may cause a crash (because something bad happened).

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

Thanks,
Huafei

Quoted 13 lines

-- Steve

kernel/trace/trace_selftest.c trace_selftest_startup_function_graph(struct tracer *trace, · line 904

Quoted 8 lines
kernel/trace/trace_selftest.c +4 -0
  	}
+
+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 */

.

maintainer
#3 lore raw
Quoted 10 lines · On Tue, 26 Apr 2022 16:00:35 +0800 Li Huafei <[email protected]> wrote:
Quoted 2 lines

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.

Quoted 5 lines
Quoted 3 lines

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

author
#4 lore raw
Quoted 17 lines · Steven Rostedt
Quoted 10 lines · On Tue, 26 Apr 2022 16:00:35 +0800 Li Huafei <[email protected]> wrote:
Quoted 2 lines

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.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 3 lines

-- Steve
.