* [PATCH 1/6] : bug fix, remove partial zero out
@ 2010-01-19 7:33 Lai Jiangshan
2010-01-20 17:52 ` Frederic Weisbecker
0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2010-01-19 7:33 UTC (permalink / raw)
To: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton,
Frederic Weisbecker
partial-zero-out a struct is very dangerous, we should zero out
field by field directly when need.
partial-zero-out for struct trace_iterator exists when ftrace
was first introduced into mainline kernel. But in this few years,
the code of ftrace is changed a lot, and:
1) partial-zero-out for struct trace_iterator has a bug now,
cpumask_var_t started should not be zeroed out.
2) I viewed the codes and found that fields below
"/* The below is zeroed out in pipe_read */"
don't need to be zeroed out or initialized now.
So, we remove the code of "partial zero out"
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 3ca9485..c6d0e1a 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -54,7 +54,6 @@ struct trace_iterator {
struct ring_buffer_iter *buffer_iter[NR_CPUS];
unsigned long iter_flags;
- /* The below is zeroed out in pipe_read */
struct trace_seq seq;
struct trace_entry *ent;
int leftover;
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5314c90..27fecf8 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3124,12 +3124,6 @@ waitagain:
if (cnt >= PAGE_SIZE)
cnt = PAGE_SIZE - 1;
- /* reset all but tr, trace, and overruns */
- memset(&iter->seq, 0,
- sizeof(struct trace_iterator) -
- offsetof(struct trace_iterator, seq));
- iter->pos = -1;
-
trace_event_read_lock();
trace_access_lock(iter->cpu_file);
while (find_next_entry_inc(iter) != NULL) {
@@ -4398,12 +4392,7 @@ static void __ftrace_dump(bool disable_tracing)
cnt++;
- /* reset all but tr, trace, and overruns */
- memset(&iter.seq, 0,
- sizeof(struct trace_iterator) -
- offsetof(struct trace_iterator, seq));
iter.iter_flags |= TRACE_FILE_LAT_FMT;
- iter.pos = -1;
if (find_next_entry_inc(&iter) != NULL) {
int ret;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/6] : bug fix, remove partial zero out
2010-01-19 7:33 [PATCH 1/6] : bug fix, remove partial zero out Lai Jiangshan
@ 2010-01-20 17:52 ` Frederic Weisbecker
2010-01-26 3:31 ` Lai Jiangshan
0 siblings, 1 reply; 4+ messages in thread
From: Frederic Weisbecker @ 2010-01-20 17:52 UTC (permalink / raw)
To: Lai Jiangshan; +Cc: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton
On Tue, Jan 19, 2010 at 03:33:56PM +0800, Lai Jiangshan wrote:
> partial-zero-out a struct is very dangerous, we should zero out
> field by field directly when need.
>
> partial-zero-out for struct trace_iterator exists when ftrace
> was first introduced into mainline kernel. But in this few years,
> the code of ftrace is changed a lot, and:
>
> 1) partial-zero-out for struct trace_iterator has a bug now,
> cpumask_var_t started should not be zeroed out.
>
> 2) I viewed the codes and found that fields below
> "/* The below is zeroed out in pipe_read */"
> don't need to be zeroed out or initialized now.
>
> So, we remove the code of "partial zero out"
>
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
> index 3ca9485..c6d0e1a 100644
> --- a/include/linux/ftrace_event.h
> +++ b/include/linux/ftrace_event.h
> @@ -54,7 +54,6 @@ struct trace_iterator {
> struct ring_buffer_iter *buffer_iter[NR_CPUS];
> unsigned long iter_flags;
>
> - /* The below is zeroed out in pipe_read */
> struct trace_seq seq;
> struct trace_entry *ent;
> int leftover;
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 5314c90..27fecf8 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3124,12 +3124,6 @@ waitagain:
> if (cnt >= PAGE_SIZE)
> cnt = PAGE_SIZE - 1;
>
> - /* reset all but tr, trace, and overruns */
> - memset(&iter->seq, 0,
> - sizeof(struct trace_iterator) -
> - offsetof(struct trace_iterator, seq));
> - iter->pos = -1;
> -
I'm not sure exaclty why we needed to zero the seq here.
We already reset it in trace_seq_init().
We might do it again on waitagain. I lost track how we could
ever need to goto waitagain. It was about a tricky bug to fix
but I'm don't remember exactly the details.
That said, if trace_seq_to_user returns -EBUSY, we
re-init the seq buffer, so it should be fine I guess.
But concerning the need of setting iter->pos to -1, I'm not
sure we need to remove it. Shouldn't it be set to 0 btw?
Steve?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/6] : bug fix, remove partial zero out
2010-01-20 17:52 ` Frederic Weisbecker
@ 2010-01-26 3:31 ` Lai Jiangshan
2010-01-30 21:26 ` Frederic Weisbecker
0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2010-01-26 3:31 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton
Frederic Weisbecker wrote:
> On Tue, Jan 19, 2010 at 03:33:56PM +0800, Lai Jiangshan wrote:
>> partial-zero-out a struct is very dangerous, we should zero out
>> field by field directly when need.
>>
>> partial-zero-out for struct trace_iterator exists when ftrace
>> was first introduced into mainline kernel. But in this few years,
>> the code of ftrace is changed a lot, and:
>>
>> 1) partial-zero-out for struct trace_iterator has a bug now,
>> cpumask_var_t started should not be zeroed out.
>>
>> 2) I viewed the codes and found that fields below
>> "/* The below is zeroed out in pipe_read */"
>> don't need to be zeroed out or initialized now.
>>
>> So, we remove the code of "partial zero out"
>>
>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>> ---
>> diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
>> index 3ca9485..c6d0e1a 100644
>> --- a/include/linux/ftrace_event.h
>> +++ b/include/linux/ftrace_event.h
>> @@ -54,7 +54,6 @@ struct trace_iterator {
>> struct ring_buffer_iter *buffer_iter[NR_CPUS];
>> unsigned long iter_flags;
>>
>> - /* The below is zeroed out in pipe_read */
>> struct trace_seq seq;
>> struct trace_entry *ent;
>> int leftover;
>> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
>> index 5314c90..27fecf8 100644
>> --- a/kernel/trace/trace.c
>> +++ b/kernel/trace/trace.c
>> @@ -3124,12 +3124,6 @@ waitagain:
>> if (cnt >= PAGE_SIZE)
>> cnt = PAGE_SIZE - 1;
>>
>> - /* reset all but tr, trace, and overruns */
>> - memset(&iter->seq, 0,
>> - sizeof(struct trace_iterator) -
>> - offsetof(struct trace_iterator, seq));
>> - iter->pos = -1;
>> -
>
>
>
> I'm not sure exaclty why we needed to zero the seq here.
> We already reset it in trace_seq_init().
>
> We might do it again on waitagain. I lost track how we could
> ever need to goto waitagain. It was about a tricky bug to fix
> but I'm don't remember exactly the details.
>
> That said, if trace_seq_to_user returns -EBUSY, we
> re-init the seq buffer, so it should be fine I guess.
Yes, -EBUSY is strange here.
but any way, trace_seq_init() is called.
>
> But concerning the need of setting iter->pos to -1, I'm not
> sure we need to remove it. Shouldn't it be set to 0 btw?
>
->pos is not used here, ->idx is just increased here,
so we don't need to initialize them.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/6] : bug fix, remove partial zero out
2010-01-26 3:31 ` Lai Jiangshan
@ 2010-01-30 21:26 ` Frederic Weisbecker
0 siblings, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2010-01-30 21:26 UTC (permalink / raw)
To: Lai Jiangshan; +Cc: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton
On Tue, Jan 26, 2010 at 11:31:58AM +0800, Lai Jiangshan wrote:
> Frederic Weisbecker wrote:
> > On Tue, Jan 19, 2010 at 03:33:56PM +0800, Lai Jiangshan wrote:
> >> partial-zero-out a struct is very dangerous, we should zero out
> >> field by field directly when need.
> >>
> >> partial-zero-out for struct trace_iterator exists when ftrace
> >> was first introduced into mainline kernel. But in this few years,
> >> the code of ftrace is changed a lot, and:
> >>
> >> 1) partial-zero-out for struct trace_iterator has a bug now,
> >> cpumask_var_t started should not be zeroed out.
> >>
> >> 2) I viewed the codes and found that fields below
> >> "/* The below is zeroed out in pipe_read */"
> >> don't need to be zeroed out or initialized now.
> >>
> >> So, we remove the code of "partial zero out"
> >>
> >> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> >> ---
> >> diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
> >> index 3ca9485..c6d0e1a 100644
> >> --- a/include/linux/ftrace_event.h
> >> +++ b/include/linux/ftrace_event.h
> >> @@ -54,7 +54,6 @@ struct trace_iterator {
> >> struct ring_buffer_iter *buffer_iter[NR_CPUS];
> >> unsigned long iter_flags;
> >>
> >> - /* The below is zeroed out in pipe_read */
> >> struct trace_seq seq;
> >> struct trace_entry *ent;
> >> int leftover;
> >> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> >> index 5314c90..27fecf8 100644
> >> --- a/kernel/trace/trace.c
> >> +++ b/kernel/trace/trace.c
> >> @@ -3124,12 +3124,6 @@ waitagain:
> >> if (cnt >= PAGE_SIZE)
> >> cnt = PAGE_SIZE - 1;
> >>
> >> - /* reset all but tr, trace, and overruns */
> >> - memset(&iter->seq, 0,
> >> - sizeof(struct trace_iterator) -
> >> - offsetof(struct trace_iterator, seq));
> >> - iter->pos = -1;
> >> -
> >
> >
> >
> > I'm not sure exaclty why we needed to zero the seq here.
> > We already reset it in trace_seq_init().
> >
> > We might do it again on waitagain. I lost track how we could
> > ever need to goto waitagain. It was about a tricky bug to fix
> > but I'm don't remember exactly the details.
> >
> > That said, if trace_seq_to_user returns -EBUSY, we
> > re-init the seq buffer, so it should be fine I guess.
>
> Yes, -EBUSY is strange here.
> but any way, trace_seq_init() is called.
>
> >
> > But concerning the need of setting iter->pos to -1, I'm not
> > sure we need to remove it. Shouldn't it be set to 0 btw?
> >
>
> ->pos is not used here, ->idx is just increased here,
> so we don't need to initialize them.
Ok.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-01-30 21:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19 7:33 [PATCH 1/6] : bug fix, remove partial zero out Lai Jiangshan
2010-01-20 17:52 ` Frederic Weisbecker
2010-01-26 3:31 ` Lai Jiangshan
2010-01-30 21:26 ` Frederic Weisbecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox