From patchwork Thu Oct 17 11:17:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeepa Prabhu X-Patchwork-Id: 21090 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B9F0C25B8B for ; Thu, 17 Oct 2013 11:18:52 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id m17sf1892939oag.11 for ; Thu, 17 Oct 2013 04:18:52 -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=y6VF9qzzQ8nl4iuiq+z8yZr9ELw//3jeLuT2ihFIoIs=; b=i2d+gG1uU2O8nAFZ87ldV1YXGNjjkzESK3VDDMPt4PLgUGlb6P7rSzPiWJQ6izwQgb ukegDEprXnz9X0JxGBkIdESzFl6EXvROcvLoRIiCI/yqYI7DGPlcchzbRSfZ42DookEq fIcJhUzw3h3fN8+tvsWyMYuqBD6LKlHMiak0v6+Cc73wUwkQNnq9GQvFVcu/fn0ozrF5 FoQ3xkmBq/elD5d1Zn/T2ps4LLTS1bprcybg8fT+opIC5odARNSNQzYArM6B68V4BVNm CjLQNQJU3vkwXYxFGMjFRU5/7RjXC/afpfgB2joNIYkUWt64l8oc0VAUebdaZ8a/JtiU FCPw== X-Received: by 10.42.237.206 with SMTP id kp14mr117251icb.33.1382008732300; Thu, 17 Oct 2013 04:18:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.15.198 with SMTP id z6ls837532qec.63.gmail; Thu, 17 Oct 2013 04:18:52 -0700 (PDT) X-Received: by 10.52.33.147 with SMTP id r19mr82698vdi.37.1382008732130; Thu, 17 Oct 2013 04:18:52 -0700 (PDT) Received: from mail-vb0-f44.google.com (mail-vb0-f44.google.com [209.85.212.44]) by mx.google.com with ESMTPS id jb3si1511846vdb.14.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Oct 2013 04:18:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.44 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.44; Received: by mail-vb0-f44.google.com with SMTP id p14so1040188vbm.17 for ; Thu, 17 Oct 2013 04:18:52 -0700 (PDT) X-Gm-Message-State: ALoCoQlWE+lbK+rKU3GBRU0lo6cl+OpT09G/f/sdTxBwHRAeus0vWjIJ/BuwkbriXOTUFjfAvkWS X-Received: by 10.58.254.200 with SMTP id ak8mr6513393ved.12.1382008732029; Thu, 17 Oct 2013 04:18:52 -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 u4csp111884vcz; Thu, 17 Oct 2013 04:18:51 -0700 (PDT) X-Received: by 10.68.234.10 with SMTP id ua10mr7962525pbc.116.1382008730981; Thu, 17 Oct 2013 04:18:50 -0700 (PDT) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by mx.google.com with ESMTPS id gl1si4982331pac.111.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Oct 2013 04:18:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.170 is neither permitted nor denied by best guess record for domain of sandeepa.prabhu@linaro.org) client-ip=209.85.192.170; Received: by mail-pd0-f170.google.com with SMTP id x10so2548845pdj.15 for ; Thu, 17 Oct 2013 04:18:50 -0700 (PDT) X-Received: by 10.68.29.36 with SMTP id g4mr7861115pbh.145.1382008730557; Thu, 17 Oct 2013 04:18:50 -0700 (PDT) Received: from linaro-workstation.ban.broadcom.com ([202.122.18.226]) by mx.google.com with ESMTPSA id 7sm113711981paf.22.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Oct 2013 04:18:49 -0700 (PDT) From: Sandeepa Prabhu To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, steve.capper@linaro.org, nico@linaro.org, srikar@linux.vnet.ibm.com, rostedt@goodmis.org, masami.hiramatsu.pt@hitachi.com, dsaxena@linaro.org, jiang.liu@huawei.com, Vijaya.Kumar@caviumnetworks.com, Sandeepa Prabhu Subject: [PATCH RFC v4 1/6] arm64: support single-step and breakpoint handler hooks Date: Thu, 17 Oct 2013 16:47:46 +0530 Message-Id: <1382008671-4515-2-git-send-email-sandeepa.prabhu@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1382008671-4515-1-git-send-email-sandeepa.prabhu@linaro.org> References: <1382008671-4515-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.212.44 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 | 21 ++++++++ arch/arm64/kernel/debug-monitors.c | 86 ++++++++++++++++++++++++++++++++- arch/arm64/kernel/entry.S | 2 + 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h index a2232d0..6231479 100644 --- a/arch/arm64/include/asm/debug-monitors.h +++ b/arch/arm64/include/asm/debug-monitors.h @@ -62,6 +62,27 @@ struct task_struct; #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ +#define DBG_HOOK_HANDLED 0 +#define DBG_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..e42ad5f 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -188,6 +188,48 @@ static void clear_regs_spsr_ss(struct pt_regs *regs) regs->pstate = spsr; } +/* EL1 Single Step Handler hooks */ +static LIST_HEAD(step_hook); +DEFINE_RWLOCK(step_hook_lock); + +void register_step_hook(struct step_hook *hook) +{ + write_lock(&step_hook_lock); + list_add(&hook->node, &step_hook); + write_unlock(&step_hook_lock); +} + +void unregister_step_hook(struct step_hook *hook) +{ + write_lock(&step_hook_lock); + list_del(&hook->node); + write_unlock(&step_hook_lock); +} + +/* + * 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 = DBG_HOOK_ERROR; + + read_lock(&step_hook_lock); + + list_for_each_entry(hook, &step_hook, node) { + retval = hook->fn(regs, esr); + if (retval == DBG_HOOK_HANDLED) + break; + } + + read_unlock(&step_hook_lock); + + return retval; +} + static int single_step_handler(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -215,7 +257,10 @@ static int single_step_handler(unsigned long addr, unsigned int esr, */ user_rewind_single_step(current); } else { - /* TODO: route to KGDB */ + /* call registered single step handlers */ + if (call_step_hook(regs, esr) == DBG_HOOK_HANDLED) + return 0; + pr_warning("Unexpected kernel single-step exception at EL1\n"); /* * Re-enable stepping since we know that we will be @@ -227,11 +272,50 @@ static int single_step_handler(unsigned long addr, unsigned int esr, return 0; } + +static LIST_HEAD(break_hook); +DEFINE_RWLOCK(break_hook_lock); + +void register_break_hook(struct break_hook *hook) +{ + write_lock(&break_hook_lock); + list_add(&hook->node, &break_hook); + write_unlock(&break_hook_lock); +} + +void unregister_break_hook(struct break_hook *hook) +{ + write_lock(&break_hook_lock); + list_del(&hook->node); + write_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; + + read_lock(&break_hook_lock); + list_for_each_entry(hook, &break_hook, node) + if ((esr & hook->esr_mask) == hook->esr_val) + fn = hook->fn; + read_unlock(&break_hook_lock); + + return fn ? fn(regs, esr) : DBG_HOOK_ERROR; +} + static int brk_handler(unsigned long addr, unsigned int esr, struct pt_regs *regs) { siginfo_t info; + /* call the registered breakpoint handler */ + if (call_break_hook(regs, esr) == DBG_HOOK_HANDLED) + return 0; + + pr_warn("unexpected brk exception at %lx, esr=0x%x\n", + (long)instruction_pointer(regs), esr); + if (!user_mode(regs)) return -EFAULT; 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