diff options
author | Liming Wang <liming.wang@windriver.com> | 2008-11-20 22:00:18 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-11-21 02:49:52 -0500 |
commit | 522a110b42b306d696cf84e34c677ed0e7080194 (patch) | |
tree | a77d238aed14185cb5662daae5f01f0da405a834 /kernel/trace | |
parent | ed313489badef16d700f5a3be50e8fd8f8294bc8 (diff) |
function tracing: fix wrong position computing of stack_trace
Impact: make output of stack_trace complete if buffer overruns
When read buffer overruns, the output of stack_trace isn't complete.
When printing records with seq_printf in t_show, if the read buffer
has overruned by the current record, then this record won't be
printed to user space through read buffer, it will just be dropped in
this printing.
When next printing, t_start should return the "*pos"th record, which
is the one dropped by previous printing, but it just returns
(m->private + *pos)th record.
Here we use a more sane method to implement seq_operations which can
be found in kernel code. Thus we needn't initialize m->private.
About testing, it's not easy to overrun read buffer, but we can use
seq_printf to print more padding bytes in t_show, then it's easy to
check whether or not records are lost.
This commit has been tested on both condition of overrun and non
overrun.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | kernel/trace/trace_stack.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index be682b62fe58..3bdb44bde4b7 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c | |||
@@ -184,11 +184,16 @@ static struct file_operations stack_max_size_fops = { | |||
184 | static void * | 184 | static void * |
185 | t_next(struct seq_file *m, void *v, loff_t *pos) | 185 | t_next(struct seq_file *m, void *v, loff_t *pos) |
186 | { | 186 | { |
187 | long i = (long)m->private; | 187 | long i; |
188 | 188 | ||
189 | (*pos)++; | 189 | (*pos)++; |
190 | 190 | ||
191 | i++; | 191 | if (v == SEQ_START_TOKEN) |
192 | i = 0; | ||
193 | else { | ||
194 | i = *(long *)v; | ||
195 | i++; | ||
196 | } | ||
192 | 197 | ||
193 | if (i >= max_stack_trace.nr_entries || | 198 | if (i >= max_stack_trace.nr_entries || |
194 | stack_dump_trace[i] == ULONG_MAX) | 199 | stack_dump_trace[i] == ULONG_MAX) |
@@ -201,12 +206,15 @@ t_next(struct seq_file *m, void *v, loff_t *pos) | |||
201 | 206 | ||
202 | static void *t_start(struct seq_file *m, loff_t *pos) | 207 | static void *t_start(struct seq_file *m, loff_t *pos) |
203 | { | 208 | { |
204 | void *t = &m->private; | 209 | void *t = SEQ_START_TOKEN; |
205 | loff_t l = 0; | 210 | loff_t l = 0; |
206 | 211 | ||
207 | local_irq_disable(); | 212 | local_irq_disable(); |
208 | __raw_spin_lock(&max_stack_lock); | 213 | __raw_spin_lock(&max_stack_lock); |
209 | 214 | ||
215 | if (*pos == 0) | ||
216 | return SEQ_START_TOKEN; | ||
217 | |||
210 | for (; t && l < *pos; t = t_next(m, t, &l)) | 218 | for (; t && l < *pos; t = t_next(m, t, &l)) |
211 | ; | 219 | ; |
212 | 220 | ||
@@ -235,10 +243,10 @@ static int trace_lookup_stack(struct seq_file *m, long i) | |||
235 | 243 | ||
236 | static int t_show(struct seq_file *m, void *v) | 244 | static int t_show(struct seq_file *m, void *v) |
237 | { | 245 | { |
238 | long i = *(long *)v; | 246 | long i; |
239 | int size; | 247 | int size; |
240 | 248 | ||
241 | if (i < 0) { | 249 | if (v == SEQ_START_TOKEN) { |
242 | seq_printf(m, " Depth Size Location" | 250 | seq_printf(m, " Depth Size Location" |
243 | " (%d entries)\n" | 251 | " (%d entries)\n" |
244 | " ----- ---- --------\n", | 252 | " ----- ---- --------\n", |
@@ -246,6 +254,8 @@ static int t_show(struct seq_file *m, void *v) | |||
246 | return 0; | 254 | return 0; |
247 | } | 255 | } |
248 | 256 | ||
257 | i = *(long *)v; | ||
258 | |||
249 | if (i >= max_stack_trace.nr_entries || | 259 | if (i >= max_stack_trace.nr_entries || |
250 | stack_dump_trace[i] == ULONG_MAX) | 260 | stack_dump_trace[i] == ULONG_MAX) |
251 | return 0; | 261 | return 0; |
@@ -275,10 +285,6 @@ static int stack_trace_open(struct inode *inode, struct file *file) | |||
275 | int ret; | 285 | int ret; |
276 | 286 | ||
277 | ret = seq_open(file, &stack_trace_seq_ops); | 287 | ret = seq_open(file, &stack_trace_seq_ops); |
278 | if (!ret) { | ||
279 | struct seq_file *m = file->private_data; | ||
280 | m->private = (void *)-1; | ||
281 | } | ||
282 | 288 | ||
283 | return ret; | 289 | return ret; |
284 | } | 290 | } |