tracing: More updates for 4.7
Steven Rostedt
maintainercover tracing: More updates for 4.7
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 4afe6495e5cb3c352d95f07512cbb227e607e2ce
Dan Carpenter (1):
tracing: checking for NULL instead of IS_ERR()
Steven Rostedt (Red Hat) (1):
tracing: Do not inherit event-fork option for instances
Tom Zanussi (2):
tracing: Add check for NULL event field when creating hist field
tracing: Handle tracing_map_alloc_elts() error path correctly
Wang Xiaoqiang (1):
tracing: Don't use the address of the buffer array name in copy_from_user
----
kernel/trace/trace.c | 17 +++++++++++++---- kernel/trace/trace_events_hist.c | 3 +++ kernel/trace/tracing_map.c | 10 +++++++--- 3 files changed, 23 insertions(+), 7 deletions(-)
Steven Rostedt
maintainerPATCH 1/5 tracing: Do not inherit event-fork option for instances
From: "Steven Rostedt (Red Hat)" <[email protected]>
As the event-fork option requires doing work when enabled and disabled, it can not be passed down to created instances. The instance must clear this flag when it is created, and must clear it when its removed.
As more options may be created with this need, a macro ZEROED_TRACE_FLAGS is created that holds the flags that must not be inherited by the top level instance, and must be cleared on removal of instances.
--- kernel/trace/trace.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/trace/trace.c +10 -1
@@ -253,6 +253,9 @@ unsigned long long ns2usecs(cycle_t nsec)#define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK | \ TRACE_ITER_PRINTK_MSGONLY | TRACE_ITER_RECORD_CMD) +/* trace_flags that are default zero for instances */ +#define ZEROED_TRACE_FLAGS \ + TRACE_ITER_EVENT_FORK/* * The global_trace is the descriptor that holds the tracing
@@ -6710,7 +6713,7 @@ static int instance_mkdir(const char *name)if (!alloc_cpumask_var (&tr->tracing_cpumask,GFP_KERNEL )) goto out_free_tr; - tr->trace_flags = global_trace.trace_flags; + tr->trace_flags = global_trace.trace_flags & ~ZEROED_TRACE_FLAGS ;cpumask_copy (tr->tracing_cpumask, cpu_all_mask);
@@ -6784,6 +6787,12 @@ static int instance_rmdir(const char *name)list_del (&tr->list); +/* Disable all the flags that were enabled coming in */ +for (i =0 ; i <TRACE_FLAGS_MAX_SIZE ; i++) { +if ((1 << i) &ZEROED_TRACE_FLAGS ) +set_tracer_flag (tr,1 << i,0 ); + } +tracing_set_nop (tr);event_trace_del_tracer (tr);ftrace_destroy_function_files (tr);
Signature · 1 line
2.8.0.rc3
Steven Rostedt
maintainerPATCH 2/5 tracing: checking for NULL instead of IS_ERR()
In reply to Steven RostedtFrom: Dan Carpenter <[email protected]>
tracing_map_elt_alloc() returns ERR_PTRs on error, never NULL.
--- kernel/trace/tracing_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/tracing_map.c +1 -1
@@ -814,7 +814,7 @@ static struct tracing_map_elt *copy_elt(struct tracing_map_elt *elt)unsigned int i; dup_elt =tracing_map_elt_alloc (elt->map); -if (!dup_elt) +if (IS_ERR (dup_elt))return NULL ;if (elt->map->ops && elt->map->ops->elt_copy)
Signature · 1 line
2.8.0.rc3
Steven Rostedt
maintainerPATCH 3/5 tracing: Add check for NULL event field when creating hist field
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Smatch flagged create_hist_field() as possibly being able to dereference a NULL pointer, although the current code exits in all cases where the event field could be NULL, so it's not actually a problem.
Still, to prevent future changes to the code from overlooking new cases, make the NULL pointer check explicit and warn once in that case.
--- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
@@ -371,6 +371,9 @@ static struct hist_field *create_hist_field(struct ftrace_event_field *field, goto out; } +if (WARN_ON_ONCE (!field)) + goto out; +if (is_string_field (field)) { flags |=HIST_FIELD_FL_STRING ;
Signature · 1 line
2.8.0.rc3
Steven Rostedt
maintainerPATCH 4/5 tracing: Handle tracing_map_alloc_elts() error path correctly
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
If tracing_map_elt_alloc() fails, it will return ERR_PTR() instead of NULL, so change the check to IS_ERROR(). We also need to set the failed entry in the map->elts array to NULL instead of ERR_PTR() so tracing_map_free_elts() doesn't try freeing an ERR_PTR().
tracing_map_free_elts() should also zero out what it frees so a reentrant call won't find previously freed elements.
--- kernel/trace/tracing_map.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/trace/tracing_map.c +6 -2
@@ -366,10 +366,13 @@ static void tracing_map_free_elts(struct tracing_map *map)if (!map->elts)return ; -for (i =0 ; i < map->max_elts; i++) +for (i =0 ; i < map->max_elts; i++) {tracing_map_elt_free (*(TRACING_MAP_ELT (map->elts, i))); + *(TRACING_MAP_ELT (map->elts, i)) =NULL ; + }tracing_map_array_free (map->elts); + map->elts =NULL ; }static int tracing_map_alloc_elts (struct tracing_map *map)
@@ -383,7 +386,8 @@ static int tracing_map_alloc_elts(struct tracing_map *map)for (i =0 ; i < map->max_elts; i++) { *(TRACING_MAP_ELT (map->elts, i)) =tracing_map_elt_alloc (map); -if (!(*(TRACING_MAP_ELT (map->elts, i)))) { +if (IS_ERR (*(TRACING_MAP_ELT (map->elts, i)))) { + *(TRACING_MAP_ELT (map->elts, i)) =NULL ;tracing_map_free_elts (map);return -ENOMEM ;
Signature · 1 line
2.8.0.rc3
Steven Rostedt
maintainerPATCH 5/5 tracing: Dont use the address of the buffer array name in copy_from_user
In reply to Steven RostedtFrom: Wang Xiaoqiang <[email protected]>
With the following code snippet:
...
char buf[64];
...
if (copy_from_user(&buf, ubuf, cnt))
...Even though the value of "&buf" equals "buf", but there is no need to get the address of the "buf" again. Use "buf" instead of "&buf".
--- kernel/trace/trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
@@ -3664,7 +3664,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,if (cnt >=sizeof (buf))return -EINVAL ; -if (copy_from_user (&buf, ubuf, cnt)) +if (copy_from_user (buf, ubuf, cnt))return -EFAULT ; buf[cnt] =0 ;
@@ -4537,7 +4537,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,if (cnt >MAX_TRACER_SIZE ) cnt =MAX_TRACER_SIZE ; -if (copy_from_user (&buf, ubuf, cnt)) +if (copy_from_user (buf, ubuf, cnt))return -EFAULT ; buf[cnt] =0 ;
@@ -5327,7 +5327,7 @@ static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,if (cnt >=sizeof (buf))return -EINVAL ; -if (copy_from_user (&buf, ubuf, cnt)) +if (copy_from_user (buf, ubuf, cnt))return -EFAULT ; buf[cnt] =0 ;
Signature · 1 line
2.8.0.rc3