linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
       [not found]       ` <1252753957.12217.10.camel@ht.satnam>
@ 2009-09-14 15:16         ` Steven Rostedt
  2009-09-14 17:09           ` Christopher Li
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2009-09-14 15:16 UTC (permalink / raw)
  To: Jaswinder Singh Rajput
  Cc: Ingo Molnar, Stephen Rothwell, Thomas Gleixner, H. Peter Anvin,
	Peter Zijlstra, linux-next, linux-kernel, linux-sparse,
	Christopher Li, Josh Triplett

On Sat, 2009-09-12 at 16:42 +0530, Jaswinder Singh Rajput wrote:

> 
> Here are some more trace related warnings in current linus (as well as
> -tip) tree :
> 
>   CHECK   arch/x86/kernel/ptrace.c
> include/trace/events/syscalls.h:18:1: warning: symbol 'ftrace_raw_output_sys_enter' was not declared. Should it be static?
> include/trace/events/syscalls.h:42:1: warning: symbol 'ftrace_raw_output_sys_exit' was not declared. Should it be static?
> include/trace/events/syscalls.h:18:1: warning: symbol 'ftrace_define_fields_sys_enter' was not declared. Should it be static?
> include/trace/events/syscalls.h:42:1: warning: symbol 'ftrace_define_fields_sys_exit' was not declared. Should it be static?

I just wrote a patch to fix the above.

> include/trace/events/syscalls.h:18:1: error: bad constant expression
> include/trace/events/syscalls.h:42:1: error: bad constant expression

Not sure why sparse is failing on this. Looking at the sched.c code, I
ran "make kernel/sched.i" and then removed the CPP expressions and then
expanded the macros and here's where it is failing:

static void ftrace_profile_sched_kthread_stop(struct task_struct *t)
{
	struct ftrace_data_offsets_sched_kthread_stop __attribute__((unused)) __data_offsets;
	struct ftrace_event_call *event_call = &event_sched_kthread_stop;
	extern void perf_tpcounter_event(int, u64, u64, void *, int);
	struct ftrace_raw_sched_kthread_stop *entry;
	u64 __addr = 0, __count = 1;
	unsigned long irq_flags;
	
	int __entry_size;
	int __data_size;
	int pc;

	do { ({ unsigned long __dummy;
				typeof(irq_flags) __dummy2;
				(void)(&__dummy == &__dummy2);
				1;
			});
		do { (irq_flags) = __raw_local_save_flags();
		} while (0);
	} while (0);
	pc = (current_thread_info()->preempt_count);
	__data_size = ftrace_get_offsets_sched_kthread_stop(&__data_offsets, t);
	__entry_size = (((__data_size + sizeof(*entry) + sizeof(u32))+((typeof(__data_size + sizeof(*entry) + sizeof(u32)))(sizeof(u64))-1))&~((typeof(__data_size + sizeof(*entry) + sizeof(u32)))(sizeof(u64))-1));
	__entry_size -= sizeof(u32);
	do {
		char raw_data[__entry_size];   <<<<----------- FAILURE HERE
		struct trace_entry *ent;
		*(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
		entry = (struct ftrace_raw_sched_kthread_stop *)raw_data;
		ent = &entry->ent;
		tracing_generic_entry_update(ent, irq_flags, pc);
		ent->type = event_call->id;
		{ memcpy(entry->comm, t->comm, 16);
			entry->pid = t->pid;
			;
		} perf_tpcounter_event(event_call->id, __addr, __count, entry, __entry_size);
	} while (0);
};

Sure enough, sparse does not like the __entry_size. I replaced it with
"10" and sparse was happy with it. That is a perfectly legal entry, so
this looks more like a bug with sparse.

I just tested this too:

static void func(int size_me) {
	char array[size_me];

	memcpy(array, "hello", size);
};

and sparse failed on it as well. Note, you need to have something call
func, or sparse will ignore it.


-- Steve



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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 15:16         ` Warning from ring buffer code (Was: Re: linux-next: tip tree build warning) Steven Rostedt
@ 2009-09-14 17:09           ` Christopher Li
  2009-09-14 18:17             ` Steven Rostedt
  0 siblings, 1 reply; 9+ messages in thread
From: Christopher Li @ 2009-09-14 17:09 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Jaswinder Singh Rajput, Ingo Molnar, Stephen Rothwell,
	Thomas Gleixner, H. Peter Anvin, Peter Zijlstra, linux-next,
	linux-kernel, linux-sparse, Josh Triplett

On Mon, Sep 14, 2009 at 8:16 AM, Steven Rostedt <srostedt@redhat.com> wrote:
> static void func(int size_me) {
>        char array[size_me];
>
>        memcpy(array, "hello", size);
> };
>
> and sparse failed on it as well. Note, you need to have something call
> func, or sparse will ignore it.

Gcc allows variable size. Sparse expects the size of an array is constant.
For the kernel using variable array size is consider bad. Because the kernel
has very limited stack size. (8K if I remember correctly). Using dynamic array
is very easy to overflow the stack without realizing it.

It deserves a warning. I agree the warning message can use a better description
though.

Chris

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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 17:09           ` Christopher Li
@ 2009-09-14 18:17             ` Steven Rostedt
  2009-09-14 18:23               ` Peter Zijlstra
  2009-09-14 18:38               ` Frederic Weisbecker
  0 siblings, 2 replies; 9+ messages in thread
From: Steven Rostedt @ 2009-09-14 18:17 UTC (permalink / raw)
  To: Christopher Li
  Cc: Jaswinder Singh Rajput, Ingo Molnar, Stephen Rothwell,
	Thomas Gleixner, H. Peter Anvin, Peter Zijlstra, linux-next,
	linux-kernel, linux-sparse, Josh Triplett, Frederic Weisbecker

On Mon, 2009-09-14 at 10:09 -0700, Christopher Li wrote:
> On Mon, Sep 14, 2009 at 8:16 AM, Steven Rostedt <srostedt@redhat.com> wrote:
> > static void func(int size_me) {
> >        char array[size_me];
> >
> >        memcpy(array, "hello", size);
> > };
> >
> > and sparse failed on it as well. Note, you need to have something call
> > func, or sparse will ignore it.
> 
> Gcc allows variable size. Sparse expects the size of an array is constant.
> For the kernel using variable array size is consider bad. Because the kernel
> has very limited stack size. (8K if I remember correctly). Using dynamic array
> is very easy to overflow the stack without realizing it.
> 
> It deserves a warning. I agree the warning message can use a better description
> though.

Good point!

I've added Frederic to the Cc list, since he wrote the code.

Frederic, how big can one of those events get. The ring buffer (and
TRACE_EVENT) allow up to almost a page size, which is very hefty for the
stack. This code needs to either be rewritten or we need to set a limit
to the size of a profile entry.

We could add:

	if (__entry_size > 256)
		return;

Thoughts?

-- Steve




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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 18:17             ` Steven Rostedt
@ 2009-09-14 18:23               ` Peter Zijlstra
  2009-09-14 18:31                 ` Steven Rostedt
  2009-09-14 18:38               ` Frederic Weisbecker
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Zijlstra @ 2009-09-14 18:23 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Christopher Li, Jaswinder Singh Rajput, Ingo Molnar,
	Stephen Rothwell, Thomas Gleixner, H. Peter Anvin, linux-next,
	linux-kernel, linux-sparse, Josh Triplett, Frederic Weisbecker

On Mon, 2009-09-14 at 14:17 -0400, Steven Rostedt wrote:
> Frederic, how big can one of those events get. The ring buffer (and
> TRACE_EVENT) allow up to almost a page size, which is very hefty for the
> stack. This code needs to either be rewritten or we need to set a limit
> to the size of a profile entry.

Yeah, that needs to get a re-write.. I've complained about this when it
went in.

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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 18:23               ` Peter Zijlstra
@ 2009-09-14 18:31                 ` Steven Rostedt
  2009-09-14 18:41                   ` Frederic Weisbecker
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2009-09-14 18:31 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Christopher Li, Jaswinder Singh Rajput, Ingo Molnar,
	Stephen Rothwell, Thomas Gleixner, H. Peter Anvin, linux-next,
	linux-kernel, linux-sparse, Josh Triplett, Frederic Weisbecker

On Mon, 2009-09-14 at 20:23 +0200, Peter Zijlstra wrote:
> On Mon, 2009-09-14 at 14:17 -0400, Steven Rostedt wrote:
> > Frederic, how big can one of those events get. The ring buffer (and
> > TRACE_EVENT) allow up to almost a page size, which is very hefty for the
> > stack. This code needs to either be rewritten or we need to set a limit
> > to the size of a profile entry.
> 
> Yeah, that needs to get a re-write.. I've complained about this when it
> went in.

One answer is to create a per cpu buffer that is big enough to hold the
data needed. Then you can disable interrupts an use it without worry.

If you need to also handle NMIs, then create a per_cpu NMI buffer too,
and use that if "in_nmi()" is true.

-- Steve



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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 18:17             ` Steven Rostedt
  2009-09-14 18:23               ` Peter Zijlstra
@ 2009-09-14 18:38               ` Frederic Weisbecker
  1 sibling, 0 replies; 9+ messages in thread
From: Frederic Weisbecker @ 2009-09-14 18:38 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Christopher Li, Jaswinder Singh Rajput, Ingo Molnar,
	Stephen Rothwell, Thomas Gleixner, H. Peter Anvin, Peter Zijlstra,
	linux-next, linux-kernel, linux-sparse, Josh Triplett

On Mon, Sep 14, 2009 at 02:17:18PM -0400, Steven Rostedt wrote:
> On Mon, 2009-09-14 at 10:09 -0700, Christopher Li wrote:
> > On Mon, Sep 14, 2009 at 8:16 AM, Steven Rostedt <srostedt@redhat.com> wrote:
> > > static void func(int size_me) {
> > >        char array[size_me];
> > >
> > >        memcpy(array, "hello", size);
> > > };
> > >
> > > and sparse failed on it as well. Note, you need to have something call
> > > func, or sparse will ignore it.
> > 
> > Gcc allows variable size. Sparse expects the size of an array is constant.
> > For the kernel using variable array size is consider bad. Because the kernel
> > has very limited stack size. (8K if I remember correctly). Using dynamic array
> > is very easy to overflow the stack without realizing it.
> > 
> > It deserves a warning. I agree the warning message can use a better description
> > though.
> 
> Good point!
> 
> I've added Frederic to the Cc list, since he wrote the code.
> 
> Frederic, how big can one of those events get. The ring buffer (and
> TRACE_EVENT) allow up to almost a page size, which is very hefty for the
> stack. This code needs to either be rewritten or we need to set a limit
> to the size of a profile entry.
> 
> We could add:
> 
> 	if (__entry_size > 256)
> 		return;
> 
> Thoughts?
> 


Well it can be big, especially once we play with array fields or
__string().

I can manage the __string() that said, by only copying their
pointer and later delay the copy.

Well actually I would like to rewrite all that entirely to avoid
any stack allocation, especially for arrays and string.

Lemme think about a CPP magic way to directly interact with perf
buffer. I think it's possible.

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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 18:31                 ` Steven Rostedt
@ 2009-09-14 18:41                   ` Frederic Weisbecker
  2009-09-15  7:16                     ` Peter Zijlstra
  0 siblings, 1 reply; 9+ messages in thread
From: Frederic Weisbecker @ 2009-09-14 18:41 UTC (permalink / raw)
  To: Steven Rostedt, Peter Zijlstra
  Cc: Christopher Li, Jaswinder Singh Rajput, Ingo Molnar,
	Stephen Rothwell, Thomas Gleixner, H. Peter Anvin, linux-next,
	linux-kernel, linux-sparse, Josh Triplett

On Mon, Sep 14, 2009 at 02:31:16PM -0400, Steven Rostedt wrote:
> On Mon, 2009-09-14 at 20:23 +0200, Peter Zijlstra wrote:
> > On Mon, 2009-09-14 at 14:17 -0400, Steven Rostedt wrote:
> > > Frederic, how big can one of those events get. The ring buffer (and
> > > TRACE_EVENT) allow up to almost a page size, which is very hefty for the
> > > stack. This code needs to either be rewritten or we need to set a limit
> > > to the size of a profile entry.
> > 
> > Yeah, that needs to get a re-write.. I've complained about this when it
> > went in.
> 
> One answer is to create a per cpu buffer that is big enough to hold the
> data needed. Then you can disable interrupts an use it without worry.
> 
> If you need to also handle NMIs, then create a per_cpu NMI buffer too,
> and use that if "in_nmi()" is true.
> 
> -- Steve


Looks like a nice idea.

Peter, does that sound acceptable to you to disable interrupts during a
profiled tracepoint event?


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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-14 18:41                   ` Frederic Weisbecker
@ 2009-09-15  7:16                     ` Peter Zijlstra
  2009-09-15  9:01                       ` Frédéric Weisbecker
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Zijlstra @ 2009-09-15  7:16 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Steven Rostedt, Christopher Li, Jaswinder Singh Rajput,
	Ingo Molnar, Stephen Rothwell, Thomas Gleixner, H. Peter Anvin,
	linux-next, linux-kernel, linux-sparse, Josh Triplett

On Mon, 2009-09-14 at 20:41 +0200, Frederic Weisbecker wrote:
> On Mon, Sep 14, 2009 at 02:31:16PM -0400, Steven Rostedt wrote:
> > On Mon, 2009-09-14 at 20:23 +0200, Peter Zijlstra wrote:
> > > On Mon, 2009-09-14 at 14:17 -0400, Steven Rostedt wrote:
> > > > Frederic, how big can one of those events get. The ring buffer (and
> > > > TRACE_EVENT) allow up to almost a page size, which is very hefty for the
> > > > stack. This code needs to either be rewritten or we need to set a limit
> > > > to the size of a profile entry.
> > > 
> > > Yeah, that needs to get a re-write.. I've complained about this when it
> > > went in.
> > 
> > One answer is to create a per cpu buffer that is big enough to hold the
> > data needed. Then you can disable interrupts an use it without worry.
> > 
> > If you need to also handle NMIs, then create a per_cpu NMI buffer too,
> > and use that if "in_nmi()" is true.
> > 
> > -- Steve
> 
> 
> Looks like a nice idea.
> 
> Peter, does that sound acceptable to you to disable interrupts during a
> profiled tracepoint event?

It does anyway, a little further down the line, so sure.

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

* Re: Warning from ring buffer code (Was: Re: linux-next: tip tree build warning)
  2009-09-15  7:16                     ` Peter Zijlstra
@ 2009-09-15  9:01                       ` Frédéric Weisbecker
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Weisbecker @ 2009-09-15  9:01 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Steven Rostedt, Christopher Li, Jaswinder Singh Rajput,
	Ingo Molnar, Stephen Rothwell, Thomas Gleixner, H. Peter Anvin,
	linux-next, linux-kernel, linux-sparse, Josh Triplett

2009/9/15, Peter Zijlstra <peterz@infradead.org>:
> On Mon, 2009-09-14 at 20:41 +0200, Frederic Weisbecker wrote:
>> On Mon, Sep 14, 2009 at 02:31:16PM -0400, Steven Rostedt wrote:
>> > On Mon, 2009-09-14 at 20:23 +0200, Peter Zijlstra wrote:
>> > > On Mon, 2009-09-14 at 14:17 -0400, Steven Rostedt wrote:
>> > > > Frederic, how big can one of those events get. The ring buffer (and
>> > > > TRACE_EVENT) allow up to almost a page size, which is very hefty for
>> > > > the
>> > > > stack. This code needs to either be rewritten or we need to set a
>> > > > limit
>> > > > to the size of a profile entry.
>> > >
>> > > Yeah, that needs to get a re-write.. I've complained about this when
>> > > it
>> > > went in.
>> >
>> > One answer is to create a per cpu buffer that is big enough to hold the
>> > data needed. Then you can disable interrupts an use it without worry.
>> >
>> > If you need to also handle NMIs, then create a per_cpu NMI buffer too,
>> > and use that if "in_nmi()" is true.
>> >
>> > -- Steve
>>
>>
>> Looks like a nice idea.
>>
>> Peter, does that sound acceptable to you to disable interrupts during a
>> profiled tracepoint event?
>
> It does anyway, a little further down the line, so sure.


Ok I'll fix it soon using Steve's idea then.

Thanks.

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

end of thread, other threads:[~2009-09-15  9:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20090804161640.70817ee6.sfr@canb.auug.org.au>
     [not found] ` <1249403089.4634.139.camel@localhost.localdomain>
     [not found]   ` <20090912165300.9d257283.sfr@canb.auug.org.au>
     [not found]     ` <20090912073906.GA3972@elte.hu>
     [not found]       ` <1252753957.12217.10.camel@ht.satnam>
2009-09-14 15:16         ` Warning from ring buffer code (Was: Re: linux-next: tip tree build warning) Steven Rostedt
2009-09-14 17:09           ` Christopher Li
2009-09-14 18:17             ` Steven Rostedt
2009-09-14 18:23               ` Peter Zijlstra
2009-09-14 18:31                 ` Steven Rostedt
2009-09-14 18:41                   ` Frederic Weisbecker
2009-09-15  7:16                     ` Peter Zijlstra
2009-09-15  9:01                       ` Frédéric Weisbecker
2009-09-14 18:38               ` Frederic Weisbecker

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