All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
@ 2008-12-04 22:47 Frederic Weisbecker
  2008-12-04 22:55 ` Steven Rostedt
  2008-12-05 13:48 ` Ingo Molnar
  0 siblings, 2 replies; 7+ messages in thread
From: Frederic Weisbecker @ 2008-12-04 22:47 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Steven Rostedt, Linux Kernel

Impact: fix tracer selfstests false results

After setting a ftrace_printk somewhere in th kernel, I saw the
Function tracer selftest failing.

When a selftest occurs, the ring buffer is lurked to see if
some entries were inserted. But concurrent insertion such as
ftrace_printk could occured at the same time and could give
false positive or negative results.

This patch prevent prevent from TRACE_PRINT entries insertion
during selftests.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ea38652..5dca6ef 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -44,6 +44,14 @@
 unsigned long __read_mostly	tracing_max_latency = (cycle_t)ULONG_MAX;
 unsigned long __read_mostly	tracing_thresh;
 
+/* We need to change this state when a selftest is running.
+ * A selftest will lurk into the ring-buffer to count the
+ * entries inserted during the selftest although some concurrent
+ * insertions into the ring-buffer such as ftrace_printk could occurred
+ * at the same time, giving false positive or negative results.
+ */
+static atomic_t tracing_selftest_running = ATOMIC_INIT(0);
+
 /* For tracers that don't implement custom flags */
 static struct tracer_opt dummy_tracer_opt[] = {
 	{ }
@@ -589,6 +597,8 @@ int register_tracer(struct tracer *type)
 		struct tracer *saved_tracer = current_trace;
 		struct trace_array *tr = &global_trace;
 		int i;
+
+		atomic_set(&tracing_selftest_running, 1);
 		/*
 		 * Run a selftest on this tracer.
 		 * Here we reset the trace buffer, and set the current
@@ -603,6 +613,7 @@ int register_tracer(struct tracer *type)
 		/* the test is responsible for initializing and enabling */
 		pr_info("Testing tracer %s: ", type->name);
 		ret = type->selftest(type, tr);
+		atomic_set(&tracing_selftest_running, 0);
 		/* the test is responsible for resetting too */
 		current_trace = saved_tracer;
 		if (ret) {
@@ -3594,7 +3605,7 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
 	unsigned long flags, irq_flags;
 	int cpu, len = 0, size, pc;
 
-	if (tracing_disabled)
+	if (tracing_disabled || atomic_read(&tracing_selftest_running))
 		return 0;
 
 	pc = preempt_count();
-- 
1.5.6.3


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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-04 22:47 [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests Frederic Weisbecker
@ 2008-12-04 22:55 ` Steven Rostedt
  2008-12-04 23:03   ` Frédéric Weisbecker
  2008-12-05 13:48 ` Ingo Molnar
  1 sibling, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2008-12-04 22:55 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: Ingo Molnar, Linux Kernel


On Thu, 4 Dec 2008, Frederic Weisbecker wrote:
> Impact: fix tracer selfstests false results
> 
> After setting a ftrace_printk somewhere in th kernel, I saw the
> Function tracer selftest failing.
> 
> When a selftest occurs, the ring buffer is lurked to see if
> some entries were inserted. But concurrent insertion such as
> ftrace_printk could occured at the same time and could give
> false positive or negative results.
> 
> This patch prevent prevent from TRACE_PRINT entries insertion
> during selftests.
> 
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> ---
>  kernel/trace/trace.c |   13 ++++++++++++-
>  1 files changed, 12 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index ea38652..5dca6ef 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -44,6 +44,14 @@
>  unsigned long __read_mostly	tracing_max_latency = (cycle_t)ULONG_MAX;
>  unsigned long __read_mostly	tracing_thresh;
>  
> +/* We need to change this state when a selftest is running.
> + * A selftest will lurk into the ring-buffer to count the
> + * entries inserted during the selftest although some concurrent
> + * insertions into the ring-buffer such as ftrace_printk could occurred
> + * at the same time, giving false positive or negative results.
> + */

The comment style should be:

/*
 * comment
 * comment
 * comment
 */


> +static atomic_t tracing_selftest_running = ATOMIC_INIT(0);

Do we need that is atomic? Also, it needs to be __read_mostly.

> +
>  /* For tracers that don't implement custom flags */
>  static struct tracer_opt dummy_tracer_opt[] = {
>  	{ }
> @@ -589,6 +597,8 @@ int register_tracer(struct tracer *type)
>  		struct tracer *saved_tracer = current_trace;
>  		struct trace_array *tr = &global_trace;
>  		int i;
> +
> +		atomic_set(&tracing_selftest_running, 1);

Enable this in the mutex lock, and we could make it a normal int.

>  		/*
>  		 * Run a selftest on this tracer.
>  		 * Here we reset the trace buffer, and set the current
> @@ -603,6 +613,7 @@ int register_tracer(struct tracer *type)
>  		/* the test is responsible for initializing and enabling */
>  		pr_info("Testing tracer %s: ", type->name);
>  		ret = type->selftest(type, tr);
> +		atomic_set(&tracing_selftest_running, 0);
>  		/* the test is responsible for resetting too */
>  		current_trace = saved_tracer;
>  		if (ret) {
> @@ -3594,7 +3605,7 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
>  	unsigned long flags, irq_flags;
>  	int cpu, len = 0, size, pc;
>  
> -	if (tracing_disabled)
> +	if (tracing_disabled || atomic_read(&tracing_selftest_running))
>  		return 0;
>  
>  	pc = preempt_count();
> -- 

-- Steve


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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-04 22:55 ` Steven Rostedt
@ 2008-12-04 23:03   ` Frédéric Weisbecker
  2008-12-04 23:04     ` Frédéric Weisbecker
  2008-12-04 23:26     ` Steven Rostedt
  0 siblings, 2 replies; 7+ messages in thread
From: Frédéric Weisbecker @ 2008-12-04 23:03 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Ingo Molnar, Linux Kernel

2008/12/4 Steven Rostedt <rostedt@goodmis.org>:
> The comment style should be:
>
> /*
>  * comment
>  * comment
>  * comment
>  */

Sorry, will fix it.

>
>> +static atomic_t tracing_selftest_running = ATOMIC_INIT(0);
>
> Do we need that is atomic? Also, it needs to be __read_mostly.


I thought it should be atomic to be sure the value is synchronized
on smp when read. But actually that should have been more likely an
int with smp_wb after writing it.

>> +
>>  /* For tracers that don't implement custom flags */
>>  static struct tracer_opt dummy_tracer_opt[] = {
>>       { }
>> @@ -589,6 +597,8 @@ int register_tracer(struct tracer *type)
>>               struct tracer *saved_tracer = current_trace;
>>               struct trace_array *tr = &global_trace;
>>               int i;
>> +
>> +             atomic_set(&tracing_selftest_running, 1);
>
> Enable this in the mutex lock, and we could make it a normal int.
>


But ftrace_printk can be called from interrupt context. I think we can loose
some TRACE_PRINT entries at the selftests time since the tracer are not enabled
by the user at this time, except the boot tracer...

>>               /*
>>                * Run a selftest on this tracer.
>>                * Here we reset the trace buffer, and set the current
>> @@ -603,6 +613,7 @@ int register_tracer(struct tracer *type)
>>               /* the test is responsible for initializing and enabling */
>>               pr_info("Testing tracer %s: ", type->name);
>>               ret = type->selftest(type, tr);
>> +             atomic_set(&tracing_selftest_running, 0);
>>               /* the test is responsible for resetting too */
>>               current_trace = saved_tracer;
>>               if (ret) {
>> @@ -3594,7 +3605,7 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
>>       unsigned long flags, irq_flags;
>>       int cpu, len = 0, size, pc;
>>
>> -     if (tracing_disabled)
>> +     if (tracing_disabled || atomic_read(&tracing_selftest_running))
>>               return 0;
>>
>>       pc = preempt_count();
>> --
>
> -- Steve
>
>

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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-04 23:03   ` Frédéric Weisbecker
@ 2008-12-04 23:04     ` Frédéric Weisbecker
  2008-12-04 23:26     ` Steven Rostedt
  1 sibling, 0 replies; 7+ messages in thread
From: Frédéric Weisbecker @ 2008-12-04 23:04 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Ingo Molnar, Linux Kernel

2008/12/5 Frédéric Weisbecker <fweisbec@gmail.com>:
> 2008/12/4 Steven Rostedt <rostedt@goodmis.org>:
>> The comment style should be:
>>
>> /*
>>  * comment
>>  * comment
>>  * comment
>>  */
>
> Sorry, will fix it.
>
>>
>>> +static atomic_t tracing_selftest_running = ATOMIC_INIT(0);
>>
>> Do we need that is atomic? Also, it needs to be __read_mostly.
>
>
> I thought it should be atomic to be sure the value is synchronized
> on smp when read. But actually that should have been more likely an
> int with smp_wb after writing it.
>
>>> +
>>>  /* For tracers that don't implement custom flags */
>>>  static struct tracer_opt dummy_tracer_opt[] = {
>>>       { }
>>> @@ -589,6 +597,8 @@ int register_tracer(struct tracer *type)
>>>               struct tracer *saved_tracer = current_trace;
>>>               struct trace_array *tr = &global_trace;
>>>               int i;
>>> +
>>> +             atomic_set(&tracing_selftest_running, 1);
>>
>> Enable this in the mutex lock, and we could make it a normal int.
>>
>
>
> But ftrace_printk can be called from interrupt context. I think we can loose
> some TRACE_PRINT entries at the selftests time since the tracer are not enabled
> by the user at this time, except the boot tracer...
>

But with the boot tracer enabled, there is no selftest actually :-)

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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-04 23:03   ` Frédéric Weisbecker
  2008-12-04 23:04     ` Frédéric Weisbecker
@ 2008-12-04 23:26     ` Steven Rostedt
  1 sibling, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2008-12-04 23:26 UTC (permalink / raw)
  To: Frédéric Weisbecker; +Cc: Ingo Molnar, Linux Kernel


On Fri, 5 Dec 2008, Fr?d?ric Weisbecker wrote:
> >
> > Enable this in the mutex lock, and we could make it a normal int.
> >
> 
> 
> But ftrace_printk can be called from interrupt context. I think we can loose
> some TRACE_PRINT entries at the selftests time since the tracer are not enabled
> by the user at this time, except the boot tracer...

I mean, move it down farther after we acquire the mutex. Should be fine.

-- Steve

> 
> >>               /*
> >>                * Run a selftest on this tracer.
> >>                * Here we reset the trace buffer, and set the current
> >> @@ -603,6 +613,7 @@ int register_tracer(struct tracer *type)
> >>               /* the test is responsible for initializing and enabling */
> >>               pr_info("Testing tracer %s: ", type->name);
> >>               ret = type->selftest(type, tr);
> >> +             atomic_set(&tracing_selftest_running, 0);
> >>               /* the test is responsible for resetting too */
> >>               current_trace = saved_tracer;
> >>               if (ret) {
> >> @@ -3594,7 +3605,7 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
> >>       unsigned long flags, irq_flags;
> >>       int cpu, len = 0, size, pc;
> >>
> >> -     if (tracing_disabled)
> >> +     if (tracing_disabled || atomic_read(&tracing_selftest_running))
> >>               return 0;
> >>
> >>       pc = preempt_count();
> >> --
> >
> > -- Steve
> >
> >
> 
> 

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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-04 22:47 [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests Frederic Weisbecker
  2008-12-04 22:55 ` Steven Rostedt
@ 2008-12-05 13:48 ` Ingo Molnar
  2008-12-05 14:01   ` Frédéric Weisbecker
  1 sibling, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2008-12-05 13:48 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: Steven Rostedt, Linux Kernel


* Frederic Weisbecker <fweisbec@gmail.com> wrote:

> Impact: fix tracer selfstests false results
> 
> After setting a ftrace_printk somewhere in th kernel, I saw the
> Function tracer selftest failing.
> 
> When a selftest occurs, the ring buffer is lurked to see if
> some entries were inserted. But concurrent insertion such as
> ftrace_printk could occured at the same time and could give
> false positive or negative results.
> 
> This patch prevent prevent from TRACE_PRINT entries insertion
> during selftests.
> 
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> ---
>  kernel/trace/trace.c |   13 ++++++++++++-
>  1 files changed, 12 insertions(+), 1 deletions(-)

applied to tip/tracing/ftrace, thanks.

I suspect you'll also fix the things Steve pointed out?

	Ingo

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

* Re: [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests
  2008-12-05 13:48 ` Ingo Molnar
@ 2008-12-05 14:01   ` Frédéric Weisbecker
  0 siblings, 0 replies; 7+ messages in thread
From: Frédéric Weisbecker @ 2008-12-05 14:01 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Steven Rostedt, Linux Kernel

2008/12/5 Ingo Molnar <mingo@elte.hu>:
>
> * Frederic Weisbecker <fweisbec@gmail.com> wrote:
>
>> Impact: fix tracer selfstests false results
>>
>> After setting a ftrace_printk somewhere in th kernel, I saw the
>> Function tracer selftest failing.
>>
>> When a selftest occurs, the ring buffer is lurked to see if
>> some entries were inserted. But concurrent insertion such as
>> ftrace_printk could occured at the same time and could give
>> false positive or negative results.
>>
>> This patch prevent prevent from TRACE_PRINT entries insertion
>> during selftests.
>>
>> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
>> ---
>>  kernel/trace/trace.c |   13 ++++++++++++-
>>  1 files changed, 12 insertions(+), 1 deletions(-)
>
> applied to tip/tracing/ftrace, thanks.
>
> I suspect you'll also fix the things Steve pointed out?


Yes of course :-)

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

end of thread, other threads:[~2008-12-05 14:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-04 22:47 [PATCH 1/3] tracing/ftrace: don't insert TRACE_PRINT during selftests Frederic Weisbecker
2008-12-04 22:55 ` Steven Rostedt
2008-12-04 23:03   ` Frédéric Weisbecker
2008-12-04 23:04     ` Frédéric Weisbecker
2008-12-04 23:26     ` Steven Rostedt
2008-12-05 13:48 ` Ingo Molnar
2008-12-05 14:01   ` Frédéric Weisbecker

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.