Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757036AbXJZTht (ORCPT ); Fri, 26 Oct 2007 15:37:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751001AbXJZThm (ORCPT ); Fri, 26 Oct 2007 15:37:42 -0400 Received: from tomts13-srv.bellnexxia.net ([209.226.175.34]:61850 "EHLO tomts13-srv.bellnexxia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750815AbXJZThl (ORCPT ); Fri, 26 Oct 2007 15:37:41 -0400 Date: Fri, 26 Oct 2007 15:37:38 -0400 From: Mathieu Desnoyers To: Andi Kleen Cc: linux-kernel@vger.kernel.org Subject: Adding TIF_TRACE_KERNEL to x86_64 Message-ID: <20071026193738.GA1591@Krystal> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Editor: vi X-Info: http://krystal.dyndns.org:8080 X-Operating-System: Linux/2.6.21.3-grsec (i686) X-Uptime: 15:29:41 up 88 days, 19:48, 6 users, load average: 0.95, 0.45, 0.44 User-Agent: Mutt/1.5.13 (2006-08-11) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6102 Lines: 161 Hi Andi, I am trying to add a TIF_TRACE_KERNEL to each architectures to have a system-wide activation of syscall_trace. However, I get the following issue on x86_64 : a few processes segfault and others get a GPF when I enable the flag on all processes. I am starting to think that it might be caused by an incorrect top of stack when we return from a syscall/interrupt in these processes. It would happen if we get into the following race: 1 - process A enters in a syscall, TIF_KERNEL_TRACE is cleared 2 - we activate TIF_KERNEL_TRACE 3 - process A returns from syscall (with wrong top of stack ?) -> segfault. Am I on the right track ? Can this be a concern with TIF_SYSCALL_TRACE also ? (potential race in ptrace ?) Thanks for you input, Mathieu My x86_64 flags patch for 2.6.23.1 looks like this: --- include/asm-x86_64/thread_info.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) Index: linux-2.6-lttng/include/asm-x86_64/thread_info.h =================================================================== --- linux-2.6-lttng.orig/include/asm-x86_64/thread_info.h 2007-07-30 18:46:16.000000000 -0400 +++ linux-2.6-lttng/include/asm-x86_64/thread_info.h 2007-07-30 19:13:03.000000000 -0400 @@ -107,6 +107,7 @@ static inline struct thread_info *stack_ * Warning: layout of LSW is hardcoded in entry.S */ #define TIF_SYSCALL_TRACE 0 /* syscall trace active */ +#define TIF_KERNEL_TRACE 1 /* kernel trace active */ #define TIF_SIGPENDING 2 /* signal pending */ #define TIF_NEED_RESCHED 3 /* rescheduling necessary */ #define TIF_SINGLESTEP 4 /* reenable singlestep on user return*/ @@ -125,6 +126,7 @@ static inline struct thread_info *stack_ #define TIF_FREEZE 23 /* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1<real_parent = current->real_parent; Index: linux-2.6-lttng/kernel/sched.c =================================================================== --- linux-2.6-lttng.orig/kernel/sched.c 2007-10-12 12:02:17.000000000 -0400 +++ linux-2.6-lttng/kernel/sched.c 2007-10-12 12:11:55.000000000 -0400 @@ -7032,3 +7032,45 @@ struct cgroup_subsys cpu_cgroup_subsys = }; #endif /* CONFIG_FAIR_CGROUP_SCHED */ + +/** + * clear_kernel_trace_flag_all_tasks - clears all TIF_KERNEL_TRACE thread flags. + * + * This function iterates on all threads in the system to clear their + * TIF_KERNEL_TRACE flag. Setting the TIF_KERNEL_TRACE flag with the + * tasklist_lock held in copy_process() makes sure that once we finish clearing + * the thread flags, all threads have their flags cleared. + */ +void clear_kernel_trace_flag_all_tasks(void) +{ + struct task_struct *p; + struct task_struct *t; + + read_lock(&tasklist_lock); + do_each_thread(p, t) { + clear_tsk_thread_flag(t, TIF_KERNEL_TRACE); + } while_each_thread(p, t); + read_unlock(&tasklist_lock); +} +EXPORT_SYMBOL_GPL(clear_kernel_trace_flag_all_tasks); + +/** + * set_kernel_trace_flag_all_tasks - sets all TIF_KERNEL_TRACE thread flags. + * + * This function iterates on all threads in the system to set their + * TIF_KERNEL_TRACE flag. Setting the TIF_KERNEL_TRACE flag with the + * tasklist_lock held in copy_process() makes sure that once we finish setting + * the thread flags, all threads have their flags set. + */ +void set_kernel_trace_flag_all_tasks(void) +{ + struct task_struct *p; + struct task_struct *t; + + read_lock(&tasklist_lock); + do_each_thread(p, t) { + set_tsk_thread_flag(t, TIF_KERNEL_TRACE); + } while_each_thread(p, t); + read_unlock(&tasklist_lock); +} +EXPORT_SYMBOL_GPL(set_kernel_trace_flag_all_tasks); -- Mathieu Desnoyers Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/