: bug fix, remove partial zero out
PATCH 1/6 : bug fix, remove partial zero out
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"
---
include/linux/ftrace_event.h +0 -1
@@ -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;
kernel/trace/trace.c +0 -11
@@ -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;
Quoted 35 lines · Lai Jiangshan
partial-zero-out a struct is very dangerous, we should zero out field by field directly when need.
partial-zero-out for struct
trace_iteratorexists 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_iteratorhas a bug now,cpumask_var_tstarted 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 <[email protected]>---
include/linux/ftrace_event.h +0
-1@@ -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;kernel/trace/trace.c +0
-0
kernel/trace/trace.c waitagain: · line 3132
Quoted 9 lines
kernel/trace/trace.c +0
-6@@ -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?
Quoted 51 lines · Frederic Weisbecker
Quoted 35 lines · Lai Jiangshan
partial-zero-out a struct is very dangerous, we should zero out field by field directly when need.
partial-zero-out for struct
trace_iteratorexists 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_iteratorhas a bug now,cpumask_var_tstarted 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 <[email protected]>---
include/linux/ftrace_event.h +0
-1@@ -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;kernel/trace/trace.c +0
-0kernel/trace/trace.c waitagain: · line 3132
Quoted 9 lines
kernel/trace/trace.c +0
-6@@ -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().
Quoted 6 lines
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_userreturns-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.
Quoted 4 lines
But concerning the need of setting
iter->posto -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.
Quoted 63 lines · Lai Jiangshan
Quoted 51 lines · Frederic Weisbecker
Quoted 35 lines · Lai Jiangshan
partial-zero-out a struct is very dangerous, we should zero out field by field directly when need.
partial-zero-out for struct
trace_iteratorexists 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_iteratorhas a bug now,cpumask_var_tstarted 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 <[email protected]>---
include/linux/ftrace_event.h +0
-1@@ -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;kernel/trace/trace.c +0
-0kernel/trace/trace.c waitagain: · line 3132
Quoted 9 lines
kernel/trace/trace.c +0
-6@@ -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().Quoted 6 lines
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_userreturns-EBUSY, we re-init the seq buffer, so it should be fine I guess.Yes,
-EBUSYis strange here.
but any way,trace_seq_init()is called.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
But concerning the need of setting
iter->posto -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.