tracing: Check all tasks on each CPU when filtering pids
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>
Wed, 21 Oct 2015 19:27:36 +0000 (15:27 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Mon, 26 Oct 2015 01:33:56 +0000 (21:33 -0400)
My tests found that if a task is running but not filtered when set_event_pid
is modified, then it can still be traced.

Call on_each_cpu() to check if the current running task should be filtered
and update the per cpu flags of tr->data appropriately.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_events.c

index ab07058e27c1d3f9d188387abd51bb2bec9ce86e..2b7fccd499c665d92069497f4b976be0e43f50dd 100644 (file)
@@ -1549,6 +1549,22 @@ static int max_pids(struct trace_pid_list *pid_list)
        return (PAGE_SIZE << pid_list->order) / sizeof(pid_t);
 }
 
+static void ignore_task_cpu(void *data)
+{
+       struct trace_array *tr = data;
+       struct trace_pid_list *pid_list;
+
+       /*
+        * This function is called by on_each_cpu() while the
+        * event_mutex is held.
+        */
+       pid_list = rcu_dereference_protected(tr->filtered_pids,
+                                            mutex_is_locked(&event_mutex));
+
+       this_cpu_write(tr->trace_buffer.data->ignore_pid,
+                      check_ignore_pid(pid_list, current));
+}
+
 static ssize_t
 ftrace_event_pid_write(struct file *filp, const char __user *ubuf,
                       size_t cnt, loff_t *ppos)
@@ -1711,6 +1727,12 @@ ftrace_event_pid_write(struct file *filp, const char __user *ubuf,
                                                 tr, INT_MAX);
                register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
                                                 tr, 0);
+
+               /*
+                * Ignoring of pids is done at task switch. But we have to
+                * check for those tasks that are currently running.
+                */
+               on_each_cpu(ignore_task_cpu, tr, 1);
        }
 
        mutex_unlock(&event_mutex);