From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756350Ab1ITMQ3 (ORCPT ); Tue, 20 Sep 2011 08:16:29 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:58404 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755447Ab1ITMQZ (ORCPT ); Tue, 20 Sep 2011 08:16:25 -0400 From: Srikar Dronamraju To: Peter Zijlstra , Ingo Molnar Cc: Steven Rostedt , Srikar Dronamraju , Linux-mm , Arnaldo Carvalho de Melo , Linus Torvalds , Andi Kleen , Hugh Dickins , Christoph Hellwig , Jonathan Corbet , Thomas Gleixner , Masami Hiramatsu , Oleg Nesterov , LKML , Jim Keniston , Roland McGrath , Ananth N Mavinakayanahalli , Andrew Morton Date: Tue, 20 Sep 2011 17:32:38 +0530 Message-Id: <20110920120238.25326.71868.sendpatchset@srdronam.in.ibm.com> In-Reply-To: <20110920115938.25326.93059.sendpatchset@srdronam.in.ibm.com> References: <20110920115938.25326.93059.sendpatchset@srdronam.in.ibm.com> Subject: [PATCH v5 3.1.0-rc4-tip 13/26] x86: define a x86 specific exception notifier. x-cbid: 11092003-3568-0000-0000-00000054BB26 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Uprobes uses notifier mechanism to get in control when an application encounters a breakpoint or a singlestep exception. Signed-off-by: Ananth N Mavinakayanahalli Signed-off-by: Srikar Dronamraju --- arch/x86/include/asm/uprobes.h | 4 ++++ arch/x86/kernel/signal.c | 14 ++++++++++++++ arch/x86/kernel/uprobes.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/asm/uprobes.h b/arch/x86/include/asm/uprobes.h index 35ac9d7..7d9d0a5 100644 --- a/arch/x86/include/asm/uprobes.h +++ b/arch/x86/include/asm/uprobes.h @@ -23,6 +23,8 @@ * Jim Keniston */ +#include + typedef u8 uprobe_opcode_t; #define MAX_UINSN_BYTES 16 #define UPROBES_XOL_SLOT_BYTES 128 /* to keep it cache aligned */ @@ -40,4 +42,6 @@ struct uprobe_arch_info {}; struct uprobe; extern int analyze_insn(struct task_struct *tsk, struct uprobe *uprobe); extern void set_instruction_pointer(struct pt_regs *regs, unsigned long vaddr); +extern int uprobe_exception_notify(struct notifier_block *self, + unsigned long val, void *data); #endif /* _ASM_UPROBES_H */ diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c index 54ddaeb..97fac33 100644 --- a/arch/x86/kernel/signal.c +++ b/arch/x86/kernel/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -820,6 +821,19 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) mce_notify_process(); #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ + if (thread_info_flags & _TIF_UPROBE) { + clear_thread_flag(TIF_UPROBE); +#ifdef CONFIG_X86_32 + /* + * On x86_32, do_notify_resume() gets called with + * interrupts disabled. Hence enable interrupts if they + * are still disabled. + */ + local_irq_enable(); +#endif + uprobe_notify_resume(regs); + } + /* deal with pending signal delivery */ if (thread_info_flags & _TIF_SIGPENDING) do_signal(regs); diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index e1c1dfe..8ec759a 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -393,3 +393,32 @@ void set_instruction_pointer(struct pt_regs *regs, unsigned long vaddr) { regs->ip = vaddr; } + +/* + * Wrapper routine for handling exceptions. + */ +int uprobe_exception_notify(struct notifier_block *self, + unsigned long val, void *data) +{ + struct die_args *args = data; + struct pt_regs *regs = args->regs; + int ret = NOTIFY_DONE; + + /* We are only interested in userspace traps */ + if (regs && !user_mode_vm(regs)) + return NOTIFY_DONE; + + switch (val) { + case DIE_INT3: + /* Run your handler here */ + if (uprobe_bkpt_notifier(regs)) + ret = NOTIFY_STOP; + break; + case DIE_DEBUG: + if (uprobe_post_notifier(regs)) + ret = NOTIFY_STOP; + default: + break; + } + return ret; +}