Skip to content

Commit

Permalink
function tracing: fix wrong position computing of stack_trace
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Liming Wang authored and Ingo Molnar committed Nov 21, 2008
1 parent ed31348 commit 522a110
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions kernel/trace/trace_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ static struct file_operations stack_max_size_fops = {
static void *
t_next(struct seq_file *m, void *v, loff_t *pos)
{
long i = (long)m->private;
long i;

(*pos)++;

i++;
if (v == SEQ_START_TOKEN)
i = 0;
else {
i = *(long *)v;
i++;
}

if (i >= max_stack_trace.nr_entries ||
stack_dump_trace[i] == ULONG_MAX)
Expand All @@ -201,12 +206,15 @@ t_next(struct seq_file *m, void *v, loff_t *pos)

static void *t_start(struct seq_file *m, loff_t *pos)
{
void *t = &m->private;
void *t = SEQ_START_TOKEN;
loff_t l = 0;

local_irq_disable();
__raw_spin_lock(&max_stack_lock);

if (*pos == 0)
return SEQ_START_TOKEN;

for (; t && l < *pos; t = t_next(m, t, &l))
;

Expand Down Expand Up @@ -235,17 +243,19 @@ static int trace_lookup_stack(struct seq_file *m, long i)

static int t_show(struct seq_file *m, void *v)
{
long i = *(long *)v;
long i;
int size;

if (i < 0) {
if (v == SEQ_START_TOKEN) {
seq_printf(m, " Depth Size Location"
" (%d entries)\n"
" ----- ---- --------\n",
max_stack_trace.nr_entries);
return 0;
}

i = *(long *)v;

if (i >= max_stack_trace.nr_entries ||
stack_dump_trace[i] == ULONG_MAX)
return 0;
Expand Down Expand Up @@ -275,10 +285,6 @@ static int stack_trace_open(struct inode *inode, struct file *file)
int ret;

ret = seq_open(file, &stack_trace_seq_ops);
if (!ret) {
struct seq_file *m = file->private_data;
m->private = (void *)-1;
}

return ret;
}
Expand Down

0 comments on commit 522a110

Please sign in to comment.