From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26559 invoked by alias); 1 Apr 2011 14:44:34 -0000 Received: (qmail 26539 invoked by uid 22791); 1 Apr 2011 14:44:33 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e23smtp04.au.ibm.com (HELO e23smtp04.au.ibm.com) (202.81.31.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Apr 2011 14:44:27 +0000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp04.au.ibm.com (8.14.4/8.13.1) with ESMTP id p31Ecjpp013917 for ; Sat, 2 Apr 2011 01:38:45 +1100 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p31EiPN62080844 for ; Sat, 2 Apr 2011 01:44:25 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p31EiN53021088 for ; Sat, 2 Apr 2011 01:44:25 +1100 Received: from localhost6.localdomain6 ([9.124.31.43]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p31EiIEj021045; Sat, 2 Apr 2011 01:44:19 +1100 From: Srikar Dronamraju To: Peter Zijlstra , Ingo Molnar Cc: Steven Rostedt , Srikar Dronamraju , Linux-mm , Arnaldo Carvalho de Melo , Linus Torvalds , Masami Hiramatsu , Ananth N Mavinakayanahalli , Christoph Hellwig , Andi Kleen , Thomas Gleixner , Jonathan Corbet , Oleg Nesterov , LKML , Jim Keniston , Roland McGrath , SystemTap , Andrew Morton Date: Fri, 01 Apr 2011 14:44:00 -0000 Message-Id: <20110401143442.15455.10508.sendpatchset@localhost6.localdomain6> In-Reply-To: <20110401143223.15455.19844.sendpatchset@localhost6.localdomain6> References: <20110401143223.15455.19844.sendpatchset@localhost6.localdomain6> Subject: [PATCH v3 2.6.39-rc1-tip 11/26] 11: uprobes: task specific information. X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2011-q2/txt/msg00019.txt.bz2 Uprobes needs to maintain some task specific information include if a task is currently uprobed, the currently handing uprobe, any arch specific information (for example to handle rip relative instructions), the per-task slot where the original instruction is copied to before single-stepping. Provides routines to create/manage and free the task specific information. Signed-off-by: Srikar Dronamraju --- include/linux/sched.h | 3 +++ include/linux/uprobes.h | 25 +++++++++++++++++++++++++ kernel/fork.c | 4 ++++ kernel/uprobes.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 0 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 83bd2e2..d4dcd23 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1534,6 +1534,9 @@ struct task_struct { unsigned long memsw_nr_pages; /* uncharged mem+swap usage */ } memcg_batch; #endif +#ifdef CONFIG_UPROBES + struct uprobe_task *utask; +#endif }; /* Future-safe accessor for struct task_struct's cpus_allowed. */ diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 27496c6..8da993c 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -26,12 +26,14 @@ #include #ifdef CONFIG_ARCH_SUPPORTS_UPROBES #include +struct uprobe_task_arch_info; /* arch specific task info */ #else /* * ARCH_SUPPORTS_UPROBES is not defined. */ typedef u8 uprobe_opcode_t; struct uprobe_arch_info {}; /* arch specific info*/ +struct uprobe_task_arch_info {}; /* arch specific task info */ #endif /* CONFIG_ARCH_SUPPORTS_UPROBES */ /* Post-execution fixups. Some architectures may define others. */ @@ -77,6 +79,27 @@ struct uprobe { int copy; }; +enum uprobe_task_state { + UTASK_RUNNING, + UTASK_BP_HIT, + UTASK_SSTEP +}; + +/* + * uprobe_utask -- not a user-visible struct. + * Corresponds to a thread in a probed process. + * Guarded by uproc->mutex. + */ +struct uprobe_task { + unsigned long xol_vaddr; + unsigned long vaddr; + + enum uprobe_task_state state; + struct uprobe_task_arch_info tskinfo; + + struct uprobe *active_uprobe; +}; + /* * Most architectures can use the default versions of @read_opcode(), * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn(); @@ -111,6 +134,7 @@ extern int register_uprobe(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer); extern void unregister_uprobe(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer); +extern void uprobe_free_utask(struct task_struct *tsk); struct vm_area_struct; extern int uprobe_mmap(struct vm_area_struct *vma); @@ -133,5 +157,6 @@ static inline int uprobe_mmap(struct vm_area_struct *vma) { return 0; } +static inline void uprobe_free_utask(struct task_struct *tsk) {} #endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */ diff --git a/kernel/fork.c b/kernel/fork.c index 2f1a16d..e25c29e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -197,6 +197,7 @@ void __put_task_struct(struct task_struct *tsk) delayacct_tsk_free(tsk); put_signal_struct(tsk->signal); + uprobe_free_utask(tsk); if (!profile_handoff_task(tsk)) free_task(tsk); } @@ -1218,6 +1219,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, INIT_LIST_HEAD(&p->pi_state_list); p->pi_state_cache = NULL; #endif +#ifdef CONFIG_UPROBES + p->utask = NULL; +#endif /* * sigaltstack should be cleared when sharing the same VM */ diff --git a/kernel/uprobes.c b/kernel/uprobes.c index 8cf38d6..f9fb7c2 100644 --- a/kernel/uprobes.c +++ b/kernel/uprobes.c @@ -955,3 +955,41 @@ mmap_out: down_write(&mm->mmap_sem); return ret; } + +/* + * Called with no locks held. + * Called in context of a exiting or a exec-ing thread. + */ +void uprobe_free_utask(struct task_struct *tsk) +{ + struct uprobe_task *utask = tsk->utask; + + if (!utask) + return; + + if (utask->active_uprobe) + put_uprobe(utask->active_uprobe); + kfree(utask); + tsk->utask = NULL; +} + +/* + * Allocate a uprobe_task object for the task. + * Called when the thread hits a breakpoint for the first time. + * + * Returns: + * - pointer to new uprobe_task on success + * - negative errno otherwise + */ +static struct uprobe_task *add_utask(void) +{ + struct uprobe_task *utask; + + utask = kzalloc(sizeof *utask, GFP_KERNEL); + if (unlikely(utask == NULL)) + return ERR_PTR(-ENOMEM); + + utask->active_uprobe = NULL; + current->utask = utask; + return utask; +}