All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>,
	linux-kernel@vger.kernel.org,
	clang-built-linux <llvm@lists.linux.dev>,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: [BUG] tracing: dynamic ftrace selftest detected failures
Date: Wed, 21 Aug 2024 09:21:47 +0900	[thread overview]
Message-ID: <20240821092147.ff26a09cb0a72b8621abe750@kernel.org> (raw)
In-Reply-To: <20240821084351.4b1c9d4d52b5aa7e07681d69@kernel.org>

On Wed, 21 Aug 2024 08:43:51 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:

> On Tue, 20 Aug 2024 18:11:09 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > On Wed, 21 Aug 2024 07:05:39 +0900
> > Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> > 
> > 
> > > Does the noinline attribute prevent embedding callsite too? I mean
> > > 
> > > extern callee()
> > > 
> > > noinline callee()
> > > {
> > > ...
> > > }
> > > 
> > > caller()
> > > {
> > > 	callee() // (*)
> > > }
> > > 
> > > In this case, does noinline prevent LTO to embed the callee at the callsite(*)
> > > or prevent LTO remove the callee() symbol?
> > >
> > 
> > Even though we have it passed as a parameter, I think the compiler and
> > linker is smart enough to see that and notice its use, and that the
> > function passed in is a nop, which doesn't break the flow.
> > 
> > Can you add the __used and see if it fixes it?
> 
> Adding __used to DYN_FTRACE_TEST_NAME() and DYN_FTRACE_TEST_NAME2() does
> not change, the test still fails. Hmm, what about makes the caller
> (trace_selftest_startup_dynamic_tracing()) called via a function pointer?
> In that case, wouldn't it be subject to constant propagetion?
> 
> Let me try.

OK, it is succeeded! Calling `caller` via global function pointer makes
it run as we expected. It passed the dynamic_ftrace test, but other tests
still fails. Those need to be called via function pointer too.
                             
[    1.851324] Testing dynamic ftrace: PASSED                                     
[    2.083329] Testing dynamic ftrace ops #1:                                     
[    2.173751] (0 0 0 0 0) FAILED!                                                
[    2.182337] ------------[ cut here ]------------                               
[    2.183323] WARNING: CPU: 0 PID: 1 at kernel/trace/trace.c:2143 run_tracer_sel0
[    2.184323] Modules linked in:                              

Anyway, here is what I did.

diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
index 97f1e4bc47dc..9663bc777888 100644
--- a/kernel/trace/trace_selftest.c
+++ b/kernel/trace/trace_selftest.c
@@ -353,9 +353,10 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)
 }
 
 /* Test dynamic code modification and ftrace filters */
-static int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
-						  struct trace_array *tr,
-						  int (*func)(void))
+static int noinline
+trace_selftest_startup_dynamic_tracing(struct tracer *trace,
+					struct trace_array *tr,
+					int (*func)(void))
 {
 	int save_ftrace_enabled = ftrace_enabled;
 	unsigned long count;
@@ -569,10 +570,22 @@ trace_selftest_function_recursion(void)
 	return ret;
 }
 #else
-# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
+static int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
+					struct trace_array *tr,
+					int (*func)(void))
+{
+	if (!trace || !tr || !func)
+		return -EINVAL;
+	return 0;
+}
 # define trace_selftest_function_recursion() ({ 0; })
 #endif /* CONFIG_DYNAMIC_FTRACE */
 
+int (*global_trace_selftest_startup_dynamic_tracing)(struct tracer *trace,
+					struct trace_array *tr,
+					int (*func)(void))
+	= trace_selftest_startup_dynamic_tracing;
+
 static enum {
 	TRACE_SELFTEST_REGS_START,
 	TRACE_SELFTEST_REGS_FOUND,
@@ -732,7 +745,7 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
 		goto out;
 	}
 
-	ret = trace_selftest_startup_dynamic_tracing(trace, tr,
+	ret = global_trace_selftest_startup_dynamic_tracing(trace, tr,
 						     DYN_FTRACE_TEST_NAME);
 	if (ret)
 		goto out;

-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  parent reply	other threads:[~2024-08-21  0:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19  8:11 [BUG] tracing: dynamic ftrace selftest detected failures Masami Hiramatsu
2024-08-19 15:29 ` Steven Rostedt
2024-08-19 15:56   ` Masami Hiramatsu
2024-08-19 16:02     ` Steven Rostedt
2024-08-19 23:34       ` Masami Hiramatsu
2024-08-20  1:03       ` Masami Hiramatsu
2024-08-20 10:48         ` Mark Rutland
2024-08-20 13:56           ` Steven Rostedt
2024-08-20 15:10           ` Sami Tolvanen
2024-08-20 15:20             ` Steven Rostedt
2024-08-20 22:05             ` Masami Hiramatsu
2024-08-20 22:11               ` Steven Rostedt
2024-08-20 23:43                 ` Masami Hiramatsu
2024-08-20 23:49                   ` Steven Rostedt
2024-08-21  0:15                     ` Masami Hiramatsu
2024-08-21  0:21                   ` Masami Hiramatsu [this message]
2024-08-21 15:06                     ` Sami Tolvanen
2024-08-21 15:32               ` Mark Rutland
2024-08-21 15:42                 ` Mark Rutland
2024-08-21 15:50                   ` Steven Rostedt
2024-08-23  0:04                     ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240821092147.ff26a09cb0a72b8621abe750@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=nathan@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.