linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: ignore FTRACE_FL_DISABLED while walking dyn_ftrace records
@ 2016-11-07 23:14 Alexei Starovoitov
  2016-11-14 19:24 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2016-11-07 23:14 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Dave Jones, Martin KaFai Lau, linux-kernel, kernel-team

ftrace_shutdown() checks for sanity of ftrace records
and if dyn_ftrace->flags is not zero, it will warn.
It can happen that 'flags' are set to FTRACE_FL_DISABLED at this point,
since some module was loaded, but before ftrace_module_enable()
cleared the flags for this module.

In other words the module.c is doing:
ftrace_module_init(mod); // calls ftrace_update_code() that sets flags=FTRACE_FL_DISABLED
... // here ftrace_shutdown() is called that warns, since
err = prepare_coming_module(mod); // didn't have a chance to clear FTRACE_FL_DISABLED

Fix it by ignoring disabled records.
It's similar to what __ftrace_hash_rec_update() is already doing.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/trace/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 2050a7652a86..326498baab83 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2763,7 +2763,7 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
 		struct dyn_ftrace *rec;
 
 		do_for_each_ftrace_rec(pg, rec) {
-			if (FTRACE_WARN_ON_ONCE(rec->flags))
+			if (FTRACE_WARN_ON_ONCE(rec->flags & ~FTRACE_FL_DISABLED))
 				pr_warn("  %pS flags:%lx\n",
 					(void *)rec->ip, rec->flags);
 		} while_for_each_ftrace_rec();
-- 
2.8.0

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

* Re: [PATCH] tracing: ignore FTRACE_FL_DISABLED while walking dyn_ftrace records
  2016-11-07 23:14 [PATCH] tracing: ignore FTRACE_FL_DISABLED while walking dyn_ftrace records Alexei Starovoitov
@ 2016-11-14 19:24 ` Steven Rostedt
  2016-11-14 20:30   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2016-11-14 19:24 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Dave Jones, Martin KaFai Lau, linux-kernel, kernel-team

On Mon, 7 Nov 2016 15:14:20 -0800
Alexei Starovoitov <ast@fb.com> wrote:

> ftrace_shutdown() checks for sanity of ftrace records
> and if dyn_ftrace->flags is not zero, it will warn.
> It can happen that 'flags' are set to FTRACE_FL_DISABLED at this point,
> since some module was loaded, but before ftrace_module_enable()
> cleared the flags for this module.
> 
> In other words the module.c is doing:
> ftrace_module_init(mod); // calls ftrace_update_code() that sets flags=FTRACE_FL_DISABLED
> ... // here ftrace_shutdown() is called that warns, since
> err = prepare_coming_module(mod); // didn't have a chance to clear FTRACE_FL_DISABLED
> 
> Fix it by ignoring disabled records.
> It's similar to what __ftrace_hash_rec_update() is already doing.
> 

Alexei,

Do you have a clear reproducer of this bug?

-- Steve

> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
>  kernel/trace/ftrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 2050a7652a86..326498baab83 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2763,7 +2763,7 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
>  		struct dyn_ftrace *rec;
>  
>  		do_for_each_ftrace_rec(pg, rec) {
> -			if (FTRACE_WARN_ON_ONCE(rec->flags))
> +			if (FTRACE_WARN_ON_ONCE(rec->flags & ~FTRACE_FL_DISABLED))
>  				pr_warn("  %pS flags:%lx\n",
>  					(void *)rec->ip, rec->flags);
>  		} while_for_each_ftrace_rec();

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

* Re: [PATCH] tracing: ignore FTRACE_FL_DISABLED while walking dyn_ftrace records
  2016-11-14 19:24 ` Steven Rostedt
@ 2016-11-14 20:30   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2016-11-14 20:30 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Alexei Starovoitov, Dave Jones, Martin KaFai Lau, linux-kernel,
	kernel-team

On Mon, Nov 14, 2016 at 02:24:28PM -0500, Steven Rostedt wrote:
> On Mon, 7 Nov 2016 15:14:20 -0800
> Alexei Starovoitov <ast@fb.com> wrote:
> 
> > ftrace_shutdown() checks for sanity of ftrace records
> > and if dyn_ftrace->flags is not zero, it will warn.
> > It can happen that 'flags' are set to FTRACE_FL_DISABLED at this point,
> > since some module was loaded, but before ftrace_module_enable()
> > cleared the flags for this module.
> > 
> > In other words the module.c is doing:
> > ftrace_module_init(mod); // calls ftrace_update_code() that sets flags=FTRACE_FL_DISABLED
> > ... // here ftrace_shutdown() is called that warns, since
> > err = prepare_coming_module(mod); // didn't have a chance to clear FTRACE_FL_DISABLED
> > 
> > Fix it by ignoring disabled records.
> > It's similar to what __ftrace_hash_rec_update() is already doing.
> > 
> 
> Alexei,
> 
> Do you have a clear reproducer of this bug?

Nope. No reproducer. It's very rare. Only stack trace that I posted earlier.
Since it kills ftrace everything that depends on it later spews a ton
of other warnings. So it's an important fix.

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

end of thread, other threads:[~2016-11-14 20:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-07 23:14 [PATCH] tracing: ignore FTRACE_FL_DISABLED while walking dyn_ftrace records Alexei Starovoitov
2016-11-14 19:24 ` Steven Rostedt
2016-11-14 20:30   ` Alexei Starovoitov

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