Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933348AbbELNM5 (ORCPT ); Tue, 12 May 2015 09:12:57 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:60851 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932946AbbELNMz (ORCPT ); Tue, 12 May 2015 09:12:55 -0400 X-AuditID: cbfee68d-f79106d00000728c-41-5551fc55b2d8 Date: Tue, 12 May 2015 13:12:53 +0000 (GMT) From: Vaneet Narang Subject: Fwd: Re: Re: [EDT] [PATCH 1/1] Fix: hw watchpoint continually triggers callback To: Will Deacon , Maninder Singh Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux@arm.linux.org.uk" , AJEET YADAV , AKHILESH KUMAR , Amit Arora Reply-to: v.narang@samsung.com MIME-version: 1.0 X-MTR: 20150512130801583@v.narang Msgkey: 20150512130801583@v.narang X-EPLocale: en_US.windows-1252 X-Priority: 3 X-EPWebmail-Msg-Type: personal X-EPWebmail-Reply-Demand: 0 X-EPApproval-Locale: X-EPHeader: ML X-MLAttribute: X-RootMTR: 20150512124752312@v.narang X-ParentMTR: 20150512124752312@v.narang X-ArchiveUser: X-CPGSPASS: N X-ConfirmMail: N,general Content-type: text/plain; charset=windows-1252 MIME-version: 1.0 Message-id: <1609501084.68951431436373294.JavaMail.weblogic@ep2mlwas08a> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCIsWRmVeSWpSXmKPExsWyRsSkWjf0T2Cowbu3lhaXd81hc2D0+LxJ LoAxissmJTUnsyy1SN8ugStj1rGDbAU7FCoetnA1MJ6Q72Lk5BASUJbovHaNFcSWEDCRWPVg MwuELSZx4d56ti5GLqCapYwSa/e2M8EUbZi8hQkiMYdRYnZzGztIgkVAVWLui5dsIDabgLbE m3+9YJOEBSIkejYuAGsWEQiVeLvzLTtIM7PAESaJUycvsECcISfxd8EvZhCbV0BQ4uTMJ0Bx DqBtihKXHx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PEWg2JM30GMOW7Ti1n hll1f8tcqFYJia0tT8Dhwwx05ZTuh+wQtoHEkUVzWFF9AmJ7SKw6doxpAqPsLCSpWUjaZyFp R1azgJFlFaNoakFyQXFSeoWJXnFibnFpXrpecn7uJkZwEnq2ZAdjwwXrQ4wCHIxKPLwTngWG CrEmlhVX5h5ilOBgVhLhffAFKMSbklhZlVqUH19UmpNafIjRFBhpE5mlRJPzgQkyryTe0NjE 3NTY1MLA0NzcTEmc9/+53BAhgfTEktTs1NSC1CKYPiYOTqkGxhaZd/PXnf5UdSYtc2oZq8Ut wXfH3G41TVzEL1855bEnp3bHRott2x46uLPn7BIqv7fy1dacrB0CfIuY5007srgroK/iY7/I qt9SoQw9HdFLxb1X7du0xt/06dY5qV1HfH9yCCY+d7Lebzl7j8TXbZZO1f/XbPX8cVHH8Jry jnua2vd4UmYtW63EUpyRaKjFXFScCAARW1DlWAMAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id t4CDD1a1017603 Content-Length: 3118 Lines: 73 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 EP-2DAD0AFA905A4ACB804C4F82A001242F Hi Will, This fix is given for kernel developers who wants to use perf interface by registering callback using register_wide_hw_breakpoint API. On every callback trigger they have to unregister watchpoints otherwise callback gets called in a loop and now issue is "when to register watch point back ?". With this issue in place, it makes perf interface unusable. We didn't faced this issue with x86. For verification, we have used test code available at samples/hw_breakpoint/data_breakpoint.c Thanks & Regards, Vaneet Narang ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?