Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932879AbbELMpa (ORCPT ); Tue, 12 May 2015 08:45:30 -0400 Received: from foss.arm.com ([217.140.101.70]:60516 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932469AbbELMp1 (ORCPT ); Tue, 12 May 2015 08:45:27 -0400 Date: Tue, 12 May 2015 13:45:23 +0100 From: Will Deacon To: Maninder Singh Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux@arm.linux.org.uk" , "v.narang@samsung.com" , AJEET YADAV , AKHILESH KUMAR , Amit Arora Subject: Re: [EDT] [PATCH 1/1] Fix: hw watchpoint continually triggers callback Message-ID: <20150512124523.GB2062@arm.com> References: <1010527489.65391431431292840.JavaMail.weblogic@ep2mlwas02a> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1010527489.65391431431292840.JavaMail.weblogic@ep2mlwas02a> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2576 Lines: 65 On Tue, May 12, 2015 at 12:48:13PM +0100, Maninder Singh wrote: > EP-2DAD0AFA905A4ACB804C4F82A001242F > > On ARM, when a watchpoint is registered using register_wide_hw_breakpoint, > the callback handler endlessly runs until the watchpoint is unregistered. > The reason for this issue is debug interrupts gets raised before executing the instruction, > and after interrupt handling ARM tries to execute the same instruction again , which results > in interrupt getting raised again. > > This patch fixes this issue by using KPROBES (getting the instruction executed and incrementing PC > to next instruction). > > Signed-off-by: Vaneet Narang > Signed-off-by: Maninder Singh > Reviewed-by: Amit Arora > Reviewed-by: Ajeet Yadav > --- > arch/arm/kernel/hw_breakpoint.c | 18 ++++++++++++++++++ > 1 files changed, 18 insertions(+), 0 deletions(-) > > diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c > index dc7d0a9..ec72f86 100644 > --- a/arch/arm/kernel/hw_breakpoint.c > +++ b/arch/arm/kernel/hw_breakpoint.c > @@ -37,6 +37,9 @@ > #include > #include > #include > +#ifdef CONFIG_KPROBES > +#include > +#endif > > /* Breakpoint currently in use for each BRP. */ > static DEFINE_PER_CPU(struct perf_event *, bp_on_reg[ARM_MAX_BRP]); > @@ -757,6 +760,21 @@ static void watchpoint_handler(unsigned long addr, unsigned int fsr, > */ > if (!wp->overflow_handler) > enable_single_step(wp, instruction_pointer(regs)); > +#ifdef CONFIG_KPROBES > + else { > + struct kprobe kp; > + unsigned long flags; > + > + arch_uninstall_hw_breakpoint(wp); > + kp.addr = (kprobe_opcode_t *)instruction_pointer(regs); > + if (!arch_prepare_kprobe(&kp)) { > + local_irq_save(flags); > + kp.ainsn.insn_singlestep(&kp, regs); > + local_irq_restore(flags); > + } > + arch_install_hw_breakpoint(wp); > + } > +#endif I don't think this is the right thing to do at all; the kernel already handles step exceptions using mismatched breakpoints when there is no overflow handler specified (e.g. using perf mem events). If you register a handler (e.g. gdb via ptrace) then you have to handle the step yourself. Will -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/