From patchwork Tue Oct 1 15:57:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeepa Prabhu X-Patchwork-Id: 20720 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 D2C1125E05 for ; Tue, 1 Oct 2013 15:59:37 +0000 (UTC) Received: by mail-ye0-f198.google.com with SMTP id m11sf7353630yen.5 for ; Tue, 01 Oct 2013 08:59:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=n9kIGbgyfHDDmDC3hmrwmTMzEwc77SerksLgV5JyQn0=; b=A29MiSxwi8r7JbF8IkhaFdcG9B8FdGVRxXG0C4g7IXcwHLwKxdADa4ue5BGd4hjbhh 5aZF6jmke/oc5CFwXSu8yGzJ93o0UqtgyoVbzP+JiB6LzDheae6/6h+4dhxPN7QGQwIo YPxA77pHAgTOcgOJtteBtRHAdlsO2VVyZUbCeF2a6V30txY0qwvphhbFESYn8Sxejp5x 6Nrx9e9y2ry1MU8HfLlWJmopH3uPsgD9UAsFYyn/jldEd4p0eaHbA6A+iz8dHZ5gRQby 7tuzkvn/42SQD1gh/WfxEoP354SXiE0mnWSTBl7J0bjKiTAJhcXGmT7gBvA5y4QTYV60 +tSg== X-Received: by 10.236.227.165 with SMTP id d35mr9204276yhq.51.1380643177590; Tue, 01 Oct 2013 08:59:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.5.9 with SMTP id o9ls114722qeo.49.gmail; Tue, 01 Oct 2013 08:59:37 -0700 (PDT) X-Received: by 10.220.1.203 with SMTP id 11mr28393216vcg.15.1380643177492; Tue, 01 Oct 2013 08:59:37 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id zw10si1464282vdb.70.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:37 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jy13so5293938veb.6 for ; Tue, 01 Oct 2013 08:59:37 -0700 (PDT) X-Gm-Message-State: ALoCoQkJ9FXumHP5AGsFh4d8ukiubrVrMjerlgsuuI9lj9f7KXK9p06jredeBNHU2VcB9bZdNbII X-Received: by 10.220.10.194 with SMTP id q2mr28275960vcq.2.1380643177392; Tue, 01 Oct 2013 08:59:37 -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.220.174.196 with SMTP id u4csp28268vcz; Tue, 1 Oct 2013 08:59:36 -0700 (PDT) X-Received: by 10.68.179.161 with SMTP id dh1mr9108913pbc.160.1380643176308; Tue, 01 Oct 2013 08:59:36 -0700 (PDT) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id ql10si5173661pbb.10.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:36 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.169 is neither permitted nor denied by best guess record for domain of sandeepa.prabhu@linaro.org) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id r10so7504257pdi.28 for ; Tue, 01 Oct 2013 08:59:35 -0700 (PDT) X-Received: by 10.66.191.5 with SMTP id gu5mr34195024pac.126.1380643175870; Tue, 01 Oct 2013 08:59:35 -0700 (PDT) Received: from linaro-workstation.ban.broadcom.com ([202.122.18.226]) by mx.google.com with ESMTPSA id nj9sm7593660pbc.13.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:34 -0700 (PDT) From: Sandeepa Prabhu To: linux-arm-kernel@lists.infradead.org Cc: deepak.saxena@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, tixy@linaro.org, linaro-kernel@lists.linaro.org, patches@linaro.org, Sandeepa Prabhu , Deepak Saxena Subject: [PATCH RFC v3 1/5] AArch64: Add single-step and breakpoint handler hooks Date: Tue, 1 Oct 2013 21:27:56 +0530 Message-Id: <1380643080-8984-2-git-send-email-sandeepa.prabhu@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380643080-8984-1-git-send-email-sandeepa.prabhu@linaro.org> References: <1380643080-8984-1-git-send-email-sandeepa.prabhu@linaro.org> 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.128.175 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 route software breakpoint (BRK64) exception to do_debug_exception() Signed-off-by: Sandeepa Prabhu Signed-off-by: Deepak Saxena --- arch/arm64/include/asm/debug-monitors.h | 23 +++++++++ arch/arm64/kernel/debug-monitors.c | 85 +++++++++++++++++++++++++++++++-- arch/arm64/kernel/entry.S | 2 + 3 files changed, 107 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h index a2232d0..8e354b3 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,27 @@ struct task_struct; #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ +#define DEBUG_HOOK_HANDLED 0 +#define DEBUG_HOOK_ERROR 1 + +struct step_hook { + struct list_head node; + int (*fn)(struct pt_regs *regs, unsigned int esr); +}; + +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_val; + u32 esr_mask; + int (*fn)(struct pt_regs *regs, unsigned int esr); +}; + +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..fbbf824 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -188,6 +188,43 @@ static void clear_regs_spsr_ss(struct pt_regs *regs) regs->pstate = spsr; } +/* EL1 Single Step Handler hooks */ +static LIST_HEAD(step_hook); + +void register_step_hook(struct step_hook *hook) +{ + list_add_rcu(&hook->node, &step_hook); +} + +void unregister_step_hook(struct step_hook *hook) +{ + list_del_rcu(&hook->node); +} + +/* + * 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) +{ + struct step_hook *hook; + int retval = DEBUG_HOOK_ERROR; + + rcu_read_lock(); + + list_for_each_entry_rcu(hook, &step_hook, node) { + retval = hook->fn(regs, esr); + if (retval == DEBUG_HOOK_HANDLED) + break; + } + + rcu_read_unlock(); + + return retval; +} + static int single_step_handler(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -215,8 +252,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, esr) == DEBUG_HOOK_HANDLED) + 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 +267,50 @@ static int single_step_handler(unsigned long addr, unsigned int esr, return 0; } + +static LIST_HEAD(break_hook); +static DEFINE_RAW_SPINLOCK(break_hook_lock); + +void register_break_hook(struct break_hook *hook) +{ + raw_spin_lock(&break_hook_lock); + list_add(&hook->node, &break_hook); + raw_spin_unlock(&break_hook_lock); +} + +void unregister_break_hook(struct break_hook *hook) +{ + raw_spin_lock(&break_hook_lock); + list_del(&hook->node); + raw_spin_unlock(&break_hook_lock); +} + +static int call_break_hook(struct pt_regs *regs, unsigned int esr) +{ + struct break_hook *hook; + int (*fn)(struct pt_regs *regs, unsigned int esr) = NULL; + + raw_spin_lock(&break_hook_lock); + list_for_each_entry(hook, &break_hook, node) + if ((esr & hook->esr_mask) == hook->esr_val) + fn = hook->fn; + raw_spin_unlock(&break_hook_lock); + + return fn ? fn(regs, esr) : DEBUG_HOOK_ERROR; +} + 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) == DEBUG_HOOK_HANDLED) + return 0; + + pr_warn("unexpected brk exception at %llx, esr=0x%x\n", + instruction_pointer(regs), esr); + if (!user_mode(regs)) return -EFAULT; @@ -291,7 +370,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 3881fd1..7fbc510 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -288,6 +288,8 @@ el1_dbg: /* * Debug exception handling */ + cmp x24, #ESR_EL1_EC_BRK64 // if BRK64 + cinc x24, x24, eq // set bit '0' tbz x24, #0, el1_inv // EL1 only mrs x0, far_el1 mov x2, sp // struct pt_regs