From patchwork Tue Aug 6 06:12:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeepa Prabhu X-Patchwork-Id: 18787 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f198.google.com (mail-ye0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CD0312486D for ; Tue, 6 Aug 2013 06:12:33 +0000 (UTC) Received: by mail-ye0-f198.google.com with SMTP id m12sf5002402yen.5 for ; Mon, 05 Aug 2013 23:12:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-removed-original-auth:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=BMKGrXW3It1y5b9slSK6PYAtq3ZOvAr9iVh7fFzbV0I=; b=YDLnjGrKXwsblC9LBHdSyYZGJqt80M6g8KyKDjAThfGBaFl2hkRx20yZatGB67uUdF p4ZRroavIlvN74Fz+x6gkzI2sPrdXGYShLMUvGPeyRjK2JlSSUBy8q0lOOvt7dYfAuED dDpsKzzmm6Rb7Kn09aMU5cXkrl3B+IgAPnfQXxqXJGEJfYJNTBMa5BMrHMddvQXEFa2C vm28JYYVYBbL3gQdvL36+oj5cyeiaZt8rHGRiMzZ8GQRUo4M6dQaxRLtZ4HI1uVULZw4 6jBdQ+8tBhswvIGdk8a9oi18N2GwDLC3ZX/cCFxj2+OJXHNDq5GHcgxxQSWSDdrdUO+t jr6g== X-Received: by 10.236.70.105 with SMTP id o69mr9504569yhd.53.1375769553247; Mon, 05 Aug 2013 23:12:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.231 with SMTP id n7ls90351qen.14.gmail; Mon, 05 Aug 2013 23:12:33 -0700 (PDT) X-Received: by 10.59.8.232 with SMTP id dn8mr7021603ved.8.1375769553049; Mon, 05 Aug 2013 23:12:33 -0700 (PDT) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id x9si610651vec.80.2013.08.05.23.12.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 23:12:33 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id i3so3730570vbh.12 for ; Mon, 05 Aug 2013 23:12:33 -0700 (PDT) X-Received: by 10.220.198.133 with SMTP id eo5mr6916577vcb.24.1375769552858; Mon, 05 Aug 2013 23:12:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.11.8 with SMTP id pc8csp129450vcb; Mon, 5 Aug 2013 23:12:32 -0700 (PDT) X-Received: by 10.68.96.133 with SMTP id ds5mr26238284pbb.169.1375769551387; Mon, 05 Aug 2013 23:12:31 -0700 (PDT) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by mx.google.com with ESMTPS id dw1si1722786pbc.336.2013.08.05.23.12.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 23:12:31 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.52 is neither permitted nor denied by best guess record for domain of sandeepa.prabhu@linaro.org) client-ip=209.85.220.52; Received: by mail-pa0-f52.google.com with SMTP id kq13so290014pab.11 for ; Mon, 05 Aug 2013 23:12:30 -0700 (PDT) X-Received: by 10.68.189.103 with SMTP id gh7mr25928653pbc.142.1375769550850; Mon, 05 Aug 2013 23:12:30 -0700 (PDT) Received: from linaro-workstation.ban.broadcom.com ([202.122.18.226]) by mx.google.com with ESMTPSA id eq5sm3148182pbc.15.2013.08.05.23.12.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 23:12:29 -0700 (PDT) From: Sandeepa Prabhu To: linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, Sandeepa Prabhu , Deepak Saxena Subject: [PATCH] AArch64: Add single-step and breakpoint handler hooks Date: Tue, 6 Aug 2013 11:42:06 +0530 Message-Id: <1375769526-3526-1-git-send-email-sandeepa.prabhu@linaro.org> X-Mailer: git-send-email 1.8.1.2 X-Gm-Message-State: ALoCoQkx6M1iKMk6JdzAnaz/TP7Hr2fN9TU589aAE1bT6hokpI5Fu82JgdX32NbTkPnpxlCQP36Y X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sandeepa.prabhu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , AArch64 Single Steping and Breakpoint debug exceptions will be used by multiple debug framworks like kprobes & kgdb. This patch implements the hooks for those frameworks to register their own handlers for handling breakpoint and single step events. Reworked the debug exception handler in entry.S: do_dbg to pass the correct break/step address to the handlers, i.e. FAR_EL1 if exception is watchpoint, ELR_EL1 for all other debug exceptions. Signed-off-by: Sandeepa Prabhu Signed-off-by: Deepak Saxena --- arch/arm64/include/asm/debug-monitors.h | 20 +++++++ arch/arm64/kernel/debug-monitors.c | 102 +++++++++++++++++++++++++++++++- arch/arm64/kernel/entry.S | 6 +- 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h index a2232d0..aff3a76 100644 --- a/arch/arm64/include/asm/debug-monitors.h +++ b/arch/arm64/include/asm/debug-monitors.h @@ -16,6 +16,8 @@ #ifndef __ASM_DEBUG_MONITORS_H #define __ASM_DEBUG_MONITORS_H +#include + #ifdef __KERNEL__ #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7) @@ -62,6 +64,24 @@ struct task_struct; #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ +struct step_hook { + struct list_head node; + int (*fn)(struct pt_regs *regs, unsigned int insn, unsigned long addr); +}; + +void register_step_hook(struct step_hook *hook); +void unregister_step_hook(struct step_hook *hook); + +struct break_hook { + struct list_head node; + u32 esr_magic; + u32 esr_mask; + int (*fn)(struct pt_regs *regs, unsigned int insn, unsigned long addr); +}; + +void register_break_hook(struct break_hook *hook); +void unregister_break_hook(struct break_hook *hook); + u8 debug_monitors_arch(void); void enable_debug_monitors(enum debug_el el); diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index cbfacf7..2846327 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -188,6 +188,54 @@ static void clear_regs_spsr_ss(struct pt_regs *regs) regs->pstate = spsr; } +/* EL1 Single Step Handler hooks */ +static LIST_HEAD(step_hook); +static DEFINE_RAW_SPINLOCK(step_lock); + +void register_step_hook(struct step_hook *hook) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&step_lock, flags); + list_add(&hook->node, &step_hook); + raw_spin_unlock_irqrestore(&step_lock, flags); +} + +void unregister_step_hook(struct step_hook *hook) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&step_lock, flags); + list_del(&hook->node); + raw_spin_unlock_irqrestore(&step_lock, flags); +} + +/* + * Call registered single step handers + * There is no Syndrome info to check for determining the handler. + * So we call all the registered handlers, until the right handler is + * found which returns zero. + */ +static int call_step_hook(struct pt_regs *regs, + unsigned int esr, unsigned long addr) +{ + struct step_hook *hook; + unsigned long flags; + + raw_spin_lock_irqsave(&step_lock, flags); + list_for_each_entry(hook, &step_hook, node) { + raw_spin_unlock_irqrestore(&step_lock, flags); + + if (hook->fn(regs, esr, addr) == 0) + return 0; + + raw_spin_lock_irqsave(&step_lock, flags); + } + raw_spin_unlock_irqrestore(&step_lock, flags); + + return 1; +} + static int single_step_handler(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -215,8 +263,11 @@ static int single_step_handler(unsigned long addr, unsigned int esr, */ user_rewind_single_step(current); } else { - /* TODO: route to KGDB */ - pr_warning("Unexpected kernel single-step exception at EL1\n"); + /* Call single step handlers for kgdb/kprobes */ + if (call_step_hook(regs, addr, esr) == 0) + return 0; + + pr_warn("unexpected single step exception at %lx!\n", addr); /* * Re-enable stepping since we know that we will be * returning to regs. @@ -227,11 +278,56 @@ static int single_step_handler(unsigned long addr, unsigned int esr, return 0; } + +static LIST_HEAD(break_hook); +static DEFINE_RAW_SPINLOCK(break_lock); + +void register_break_hook(struct break_hook *hook) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&break_lock, flags); + list_add(&hook->node, &break_hook); + raw_spin_unlock_irqrestore(&break_lock, flags); +} + +void unregister_break_hook(struct break_hook *hook) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&break_lock, flags); + list_del(&hook->node); + raw_spin_unlock_irqrestore(&break_lock, flags); +} + +static int call_break_hook(struct pt_regs *regs, + unsigned int esr, unsigned long addr) +{ + struct break_hook *hook; + unsigned long flags; + int (*fn)(struct pt_regs *regs, + unsigned int esr, unsigned long addr) = NULL; + + raw_spin_lock_irqsave(&break_lock, flags); + list_for_each_entry(hook, &break_hook, node) + if ((esr & hook->esr_mask) == hook->esr_magic) + fn = hook->fn; + raw_spin_unlock_irqrestore(&break_lock, flags); + + return fn ? fn(regs, esr, addr) : 1; +} + static int brk_handler(unsigned long addr, unsigned int esr, struct pt_regs *regs) { siginfo_t info; + /* Call single step handlers for kgdb/kprobes */ + if (call_break_hook(regs, esr, addr) == 0) + return 0; + + pr_warn("unexpected brk exception at %lx, esr=0x%x\n", addr, esr); + if (!user_mode(regs)) return -EFAULT; @@ -291,7 +387,7 @@ static int __init debug_traps_init(void) hook_debug_fault_code(DBG_ESR_EVT_HWSS, single_step_handler, SIGTRAP, TRAP_HWBKPT, "single-step handler"); hook_debug_fault_code(DBG_ESR_EVT_BRK, brk_handler, SIGTRAP, - TRAP_BRKPT, "ptrace BRK handler"); + TRAP_BRKPT, "AArch64 BRK handler"); return 0; } arch_initcall(debug_traps_init); diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 6ad781b..e7350bd 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -288,8 +288,12 @@ el1_dbg: /* * Debug exception handling */ + mrs x25, far_el1 //far for watchpt + cmp x24, #ESR_EL1_EC_WATCHPT_EL1 + csel x0, x25, x22, eq //addr: x25->far_el1, x22->elr_el1 + b.ge do_dbg tbz x24, #0, el1_inv // EL1 only - mrs x0, far_el1 +do_dbg: mov x2, sp // struct pt_regs bl do_debug_exception