updates for 2.6.31
Subsystems (2)
Steven Rostedt
maintainerHi Ingo,
This patch series are fixes that should get into 2.6.31 (maybe some of them even into stable?).
Please pull the latest tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tracing/ftrace
Li Zefan (4):
tracing: fix a typo in tracing_cpumask_write()
tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation tracing/filters: operand can be negative tracing/filters: strloc should be unsigned short
Rusty Russell (1):
cpumask: use new operators in kernel/trace
Steven Rostedt (1):
ring-buffer: prevent adding write in discarded area
Wu Zhangjin (1):
tracing: fix undeclared 'PAGE_SIZE' in include/linux/trace_seq.h
----
include/linux/trace_seq.h | 2 + kernel/trace/kmemtrace.c | 2 +- kernel/trace/ring_buffer.c | 72 +++++++++++++++++++++++++++++------- kernel/trace/trace.c | 8 ++-- kernel/trace/trace_events_filter.c | 9 +++- 5 files changed, 72 insertions(+), 21 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 cpumask: use new operators in kernel/trace
From: Rusty Russell <[email protected]>
LKML-Reference: <[email protected]>
--- kernel/trace/kmemtrace.c | 2 +- kernel/trace/ring_buffer.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/kmemtrace.c +1 -1
@@ -186,7 +186,7 @@ static int kmem_trace_init(struct trace_array *tr)int cpu; kmemtrace_array = tr; -for_each_cpu_mask (cpu, cpu_possible_map) +for_each_cpu (cpu, cpu_possible_mask)tracing_reset (tr, cpu);kmemtrace_start_probes ();
kernel/trace/ring_buffer.c +2 -2
@@ -3105,7 +3105,7 @@ static int rb_cpu_notify(struct notifier_block *self,switch (action) {case CPU_UP_PREPARE :case CPU_UP_PREPARE_FROZEN : -if (cpu_isset (cpu, *buffer->cpumask)) +if (cpumask_test_cpu (cpu, buffer->cpumask))return NOTIFY_OK ; buffer->buffers[cpu] =
@@ -3116,7 +3116,7 @@ static int rb_cpu_notify(struct notifier_block *self,return NOTIFY_OK ; }smp_wmb (); -cpu_set (cpu, *buffer->cpumask); +cpumask_set_cpu (cpu, buffer->cpumask);break ;case CPU_DOWN_PREPARE :case CPU_DOWN_PREPARE_FROZEN :
Signature · 3 lines
1.6.3.1 --
Steven Rostedt
maintainerPATCH 2/7 tracing: fix undeclared PAGE_SIZE in include/linux/trace_seq.h
In reply to Steven RostedtFrom: Wu Zhangjin <[email protected]>
when compiling linux-mips with kmemtrace enabled, there will be an error:
include/linux/trace_seq.h:12: error: 'PAGE_SIZE' undeclared here (not in
a function)
I checked the source code and found trace_seq.h used PAGE_SIZE but not included the relative header file, so, fix it via adding the header file <asm/page.h>
LKML-Reference: <[email protected]>
--- include/linux/trace_seq.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/trace_seq.h +2 -0
@@ -3,6 +3,8 @@#include <linux/fs.h> +#include <asm/page.h> +/* * Trace sequences are used to allow a function to call several other functions * to create a string of data to use (up to a max of PAGE_SIZE.
Signature · 3 lines
1.6.3.1 --
Steven Rostedt
maintainerPATCH 3/7 tracing: fix a typo in tracing_cpumask_write()
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
It's tracing_cpumask_new that should be kfree()ed.
This causes tracing_cpumask to be freed due to the typo:
# echo z > tracing_cpumask bash: echo: write error: Invalid argument
And subsequent reads/writes to tracing_cpuamsk will access this already-freed tracing_cpumask, thus may lead to crash.
[ Impact: fix leak and crash when writing invalid val to tracing_cpumask ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
@@ -2191,11 +2191,12 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,if (!alloc_cpumask_var (&tracing_cpumask_new,GFP_KERNEL ))return -ENOMEM ; -mutex_lock (&tracing_cpumask_update_lock); err =cpumask_parse_user (ubuf, count, tracing_cpumask_new);if (err) goto err_unlock; +mutex_lock (&tracing_cpumask_update_lock); +local_irq_disable ();__raw_spin_lock (&ftrace_max_lock);for_each_tracing_cpu (cpu) {
@@ -2223,8 +2224,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,return count; err_unlock: -mutex_unlock (&tracing_cpumask_update_lock); -free_cpumask_var (tracing_cpumask); +free_cpumask_var (tracing_cpumask_new);return err; }
Signature · 3 lines
1.6.3.1 --
Steven Rostedt
maintainerPATCH 4/7 tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Atomic allocation is not needed here.
[ Impact: clean up of memory alloction type ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace.c +1 -1
@@ -3627,7 +3627,7 @@ tracing_stats_read(struct file *filp, char __user *ubuf,struct trace_seq *s;unsigned long cnt; - s =kmalloc (sizeof (*s),GFP_ATOMIC ); + s =kmalloc (sizeof (*s),GFP_KERNEL );if (!s)return ENOMEM ;
Signature · 3 lines
1.6.3.1 --
Re: [PATCH 4/7] tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation
Quoted 5 lines · Steven Rostedt
From: Li Zefan <[email protected]>
Atomic allocation is not needed here.
[ Impact: clean up of memory alloction type ]
Note, the impact line was probably not needed here - and if we add one then the correct one would be:
[ Impact: use less failure-prone (non-atomic) allocations ]
Ingo
Steven Rostedt
maintainerPATCH 5/7 tracing/filters: operand can be negative
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
This should be a bug:
# cat format
name: foo_bar
ID: 71
format:
...
field:int bar; offset:24; size:4;
# echo 'bar < 0' > filter
# echo 'bar < -1' > filter
bash: echo: write error: Invalid argument[ Impact: fix to allow negative operand in filer expr ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events_filter.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +6 -1
@@ -546,6 +546,7 @@ static int filter_add_pred(struct filter_parse_state *ps,filter_pred_fn_t fn;unsigned long long val;int string_type; +int ret; pred->fn = filter_pred_none;
@@ -581,7 +582,11 @@ static int filter_add_pred(struct filter_parse_state *ps, pred->not =1 ;return filter_add_pred_fn (ps, call, pred, fn); }else { -if (strict_strtoull (pred->str_val,0 , &val)) { +if (field->is_signed) + ret =strict_strtoll (pred->str_val,0 , &val); +else + ret =strict_strtoull (pred->str_val,0 , &val); +if (ret) {parse_error (ps,FILT_ERR_ILLEGAL_INTVAL ,0 );return -EINVAL ; }
Signature · 3 lines
1.6.3.1 --
Steven Rostedt
maintainerPATCH 6/7 tracing/filters: strloc should be unsigned short
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
I forgot to update filter code accordingly in "tracing/events: change the type of __str_loc_item to unsigned short" (commt b0aae68cc5508f3c2fbf728988c954db4c8b8a53)
It can cause system crash:
# echo 1 > tracing/events/irq/irq_handler_entry/enable # echo 'name == eth0' > tracing/events/irq/irq_handler_entry/filter
[ Impact: fix crash while filtering on __string() field ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +1 -1
@@ -178,7 +178,7 @@ static int filter_pred_string(struct filter_pred *pred, void *event,static int filter_pred_strloc (struct filter_pred *pred,void *event,int val1,int val2) { -int str_loc = *(int *)(event + pred->offset); +unsigned short str_loc = *(unsigned short *)(event + pred->offset);char *addr = (char *)(event + str_loc);int cmp, match;
Signature · 3 lines
1.6.3.1 --
Steven Rostedt
maintainerPATCH 7/7 ring-buffer: prevent adding write in discarded area
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
This a very tight race where an interrupt could come in and not have enough data to put into the end of a buffer page, and that it would fail to write and need to go to the next page.
But if this happened when another writer was about to reserver their data, and that writer has smaller data to reserve, then it could succeed even though the interrupt moved the tail page.
To pervent that, if we fail to store data, and by subtracting the amount we reserved we still have room for smaller data, we need to fill that space with "discarded" data.
[ Impact: prevent race were buffer data may be lost ]
--- kernel/trace/ring_buffer.c | 68 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 56 insertions(+), 12 deletions(-)
kernel/trace/ring_buffer.c +56 -12
@@ -205,6 +205,7 @@ EXPORT_SYMBOL_GPL(tracing_is_on);#define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array))#define RB_ALIGNMENT 4U#define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) +#define RB_EVNT_MIN_SIZE 8U/* two 32bit words */ /* define RINGBUF_TYPE_DATA for 'case RINGBUF_TYPE_DATA:' */ #define RINGBUF_TYPE_DATA 0 ... RINGBUF_TYPE_DATA_TYPE_LEN_MAX
@@ -1170,6 +1171,59 @@ static unsigned rb_calculate_event_length(unsigned length)return length; } +static inline void +rb_reset_tail (struct ring_buffer_per_cpu *cpu_buffer, +struct buffer_page *tail_page, +unsigned long tail,unsigned long length) +{ +struct ring_buffer_event *event; + +/* +* Only the event that crossed the page boundary +* must fill the old tail_page with padding. +*/ +if (tail >=BUF_PAGE_SIZE ) { +local_sub (length, &tail_page->write); +return ; + } + + event =__rb_page_index (tail_page, tail); + +/* +* If this event is bigger than the minimum size, then +* we need to be careful that we don't subtract the +* write counter enough to allow another writer to slip +* in on this page. +* We put in a discarded commit instead, to make sure +* that this space is not used again. +* +* If we are less than the minimum size, we don't need to +* worry about it. +*/ +if (tail > (BUF_PAGE_SIZE -RB_EVNT_MIN_SIZE )) { +/* No room for any events */ + +/* Mark the rest of the page with padding */ +rb_event_set_padding (event); + +/* Set the write back to the previous setting */ +local_sub (length, &tail_page->write); +return ; + } + +/* Put in a discarded event */ + event->array[0 ] = (BUF_PAGE_SIZE - tail) -RB_EVNT_HDR_SIZE ; + event->type_len =RINGBUF_TYPE_PADDING ; +/* time delta must be non zero */ + event->time_delta =1 ; +/* Account for this as an entry */ +local_inc (&tail_page->entries); +local_inc (&cpu_buffer->entries); + +/* Set write to end of buffer */ + length = (tail + length) -BUF_PAGE_SIZE ; +local_sub (length, &tail_page->write); +}static struct ring_buffer_event * rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
@@ -1264,17 +1318,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, cpu_buffer->tail_page->page->time_stamp = *ts; } -/* -* The actual tail page has moved forward. -*/ -if (tail <BUF_PAGE_SIZE ) { -/* Mark the rest of the page with padding */ - event =__rb_page_index (tail_page, tail); -rb_event_set_padding (event); - } - -/* Set the write back to the previous setting */ -local_sub (length, &tail_page->write); +rb_reset_tail (cpu_buffer, tail_page, tail, length);/* * If this was a commit entry that failed,
@@ -1293,7 +1337,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, out_reset:/* reset write */ -local_sub (length, &tail_page->write); +rb_reset_tail (cpu_buffer, tail_page, tail, length);if (likely (lock_taken))__raw_spin_unlock (&cpu_buffer->lock);
Signature · 3 lines
1.6.3.1 --
Quoted 26 lines · Steven Rostedt
Hi Ingo,
This patch series are fixes that should get into 2.6.31 (maybe some of them even into stable?).
Please pull the latest tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tracing/ftraceLi Zefan (4):
tracing: fix a typo intracing_cpumask_write()
tracing: replace aGFP_ATOMICwithGFP_KERNELallocation tracing/filters: operand can be negative tracing/filters: strloc should be unsigned shortRusty Russell (1):
cpumask: use new operators in kernel/traceSteven Rostedt (1):
ring-buffer: prevent adding write in discarded areaWu Zhangjin (1):
tracing: fix undeclared 'PAGE_SIZE' ininclude/linux/trace_seq.h
Quoted 7 lines
----
include/linux/trace_seq.h | 2 + kernel/trace/kmemtrace.c | 2 +- kernel/trace/ring_buffer.c | 72 +++++++++++++++++++++++++++++------- kernel/trace/trace.c | 8 ++-- kernel/trace/trace_events_filter.c | 9 +++- 5 files changed, 72 insertions(+), 21 deletions(-)
Pulled into tracing/urgent - thanks Steve!
Ingo