tracing: Fixes to syscall tracing
Subsystems (4)
Steven Rostedt
maintainercover tracing: Fixes to syscall tracing
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 72fa1a896d8ef355e81270667803ceb16a3dd13f
Oleg Nesterov (3):
tracing: Fix syscall_*regfunc() vs copy_process() race
tracing: Change syscall_*regfunc() to check PF_KTHREAD and use for_each_process_thread()
tracing: syscall_regfunc() should not skip kernel threads
----
include/trace/syscall.h | 15 +++++++++++++++ kernel/fork.c | 2 ++ kernel/tracepoint.c | 26 +++++++++++--------------- 3 files changed, 28 insertions(+), 15 deletions(-)
Steven Rostedt
maintainerPATCH 1/3 tracing: Fix syscall_*regfunc() vs copy_process() race
From: Oleg Nesterov <[email protected]>
syscall_regfunc() and syscall_unregfunc() should set/clear TIF_SYSCALL_TRACEPOINT system-wide, but do_each_thread() can race with copy_process() and miss the new child which was not added to the process/thread lists yet.
Change copy_process() to update the child's TIF_SYSCALL_TRACEPOINT under tasklist.
--- include/trace/syscall.h | 15 +++++++++++++++ kernel/fork.c | 2 ++ 2 files changed, 17 insertions(+)
include/trace/syscall.h +15 -0
@@ -4,6 +4,7 @@#include <linux/tracepoint.h> #include <linux/unistd.h> #include <linux/ftrace_event.h> +#include <linux/thread_info.h> #include <asm/ptrace.h>
@@ -32,4 +33,18 @@ struct syscall_metadata { struct ftrace_event_call *exit_event; }; +#ifdef CONFIG_TRACEPOINTS +static inline void syscall_tracepoint_update (struct task_struct *p) +{ +if (test_thread_flag (TIF_SYSCALL_TRACEPOINT )) +set_tsk_thread_flag (p,TIF_SYSCALL_TRACEPOINT ); +else +clear_tsk_thread_flag (p,TIF_SYSCALL_TRACEPOINT ); +} +#else +static inline void syscall_tracepoint_update (struct task_struct *p) +{ +} +#endif +#endif /* _TRACE_SYSCALL_H */
kernel/fork.c +2 -0
@@ -1487,7 +1487,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, total_forks++;spin_unlock (¤t->sighand->siglock); +syscall_tracepoint_update (p);write_unlock_irq (&tasklist_lock); +proc_fork_connector (p);cgroup_post_fork (p);if (clone_flags &CLONE_THREAD )
Signature · 1 line
2.0.0.rc2
Steven Rostedt
maintainerPATCH 2/3 tracing: Change syscall_*regfunc() to check PF_KTHREAD and use for_each_process_thread()
In reply to Steven RostedtFrom: Oleg Nesterov <[email protected]>
1. Remove _irqsafe from syscall_regfunc/syscall_unregfunc, read_lock(tasklist) doesn't need to disable irqs.
2. Change this code to avoid the deprecated do_each_thread() and use for_each_process_thread() (stolen from the patch from Frederic).
3. Change syscall_regfunc() to check PF_KTHREAD to skip the kernel threads, ->mm != NULL is the common mistake.
Note: probably this check should be simply removed, needs another patch.
--- kernel/tracepoint.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
kernel/tracepoint.c +11 -13
@@ -492,33 +492,31 @@ static int sys_tracepoint_refcount;void syscall_regfunc (void ) { -unsigned long flags; -struct task_struct *g, *t; +struct task_struct *p, *t;if (!sys_tracepoint_refcount) { -read_lock_irqsave (&tasklist_lock, flags); - do_each_thread(g, t) { +read_lock (&tasklist_lock); +for_each_process_thread (p, t) {/* Skip kernel threads. */ -if (t->mm) +if (!(t->flags &PF_KTHREAD ))set_tsk_thread_flag (t,TIF_SYSCALL_TRACEPOINT ); - }while_each_thread (g, t); -read_unlock_irqrestore (&tasklist_lock, flags); + } +read_unlock (&tasklist_lock); } sys_tracepoint_refcount++; }void syscall_unregfunc (void ) { -unsigned long flags; -struct task_struct *g, *t; +struct task_struct *p, *t; sys_tracepoint_refcount--;if (!sys_tracepoint_refcount) { -read_lock_irqsave (&tasklist_lock, flags); - do_each_thread(g, t) { +read_lock (&tasklist_lock); +for_each_process_thread (p, t) {clear_tsk_thread_flag (t,TIF_SYSCALL_TRACEPOINT ); - }while_each_thread (g, t); -read_unlock_irqrestore (&tasklist_lock, flags); + } +read_unlock (&tasklist_lock); } }#endif
Signature · 1 line
2.0.0.rc2
Steven Rostedt
maintainerPATCH 3/3 tracing: syscall_regfunc() should not skip kernel threads
In reply to Steven RostedtFrom: Oleg Nesterov <[email protected]>
syscall_regfunc() ignores the kernel threads because "it has no effect", see cc3b13c1 "Don't trace kernel thread syscalls" which added this check.
However, this means that a user-space task spawned by call_usermodehelper() will run without TIF_SYSCALL_TRACEPOINT if sys_tracepoint_refcount != 0.
Remove this check. The unnecessary report from ret_from_fork path mentioned by cc3b13c1 is no longer possible, see See commit fb45550d76bb5 "make sure that kernel_thread() callbacks call do_exit() themselves".
A kernel_thread() callback can only return and take the int_ret_from_sys_call path after do_execve() succeeds, otherwise the kernel will crash. But in this case it is no longer a kernel thread and thus is needs TIF_SYSCALL_TRACEPOINT.
--- kernel/tracepoint.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/tracepoint.c +1 -3
@@ -497,9 +497,7 @@ void syscall_regfunc(void)if (!sys_tracepoint_refcount) {read_lock (&tasklist_lock);for_each_process_thread (p, t) { -/* Skip kernel threads. */ -if (!(t->flags &PF_KTHREAD )) -set_tsk_thread_flag (t,TIF_SYSCALL_TRACEPOINT ); +set_tsk_thread_flag (t,TIF_SYSCALL_TRACEPOINT ); }read_unlock (&tasklist_lock); }
Signature · 1 line
2.0.0.rc2