Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753184AbbERNRT (ORCPT ); Mon, 18 May 2015 09:17:19 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:10496 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752283AbbERNRI (ORCPT ); Mon, 18 May 2015 09:17:08 -0400 X-AuditID: cbfee68e-f79c56d000006efb-e0-5559e6524a25 Date: Mon, 18 May 2015 13:17:06 +0000 (GMT) From: Vaneet Narang Subject: Re: [EDT] [PATCH 1/1] Fix: hw watchpoint continually triggers callback To: Will Deacon Cc: Maninder Singh , "linux@arm.linux.org.uk" , "linux-kernel@vger.kernel.org" , Amit Arora , AJEET YADAV , AKHILESH KUMAR , "linux-arm-kernel@lists.infradead.org" Reply-to: v.narang@samsung.com MIME-version: 1.0 X-MTR: 20150518120009905@v.narang Msgkey: 20150518120009905@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: 20150518120009905@v.narang X-ParentMTR: X-ArchiveUser: X-CPGSPASS: N X-ConfirmMail: N,general Content-type: text/plain; charset=windows-1252 MIME-version: 1.0 Message-id: <939613287.351841431955025734.JavaMail.weblogic@ep2mlwas08c> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRmVeSWpSXmKPExsWyRsSkWjfoWWSowat75haXd81hc2D0+LxJ LoAxissmJTUnsyy1SN8ugSvj3/8nzAX7dCpObXjL1sC4QruLkZNDSEBZovPaNVYQW0LARKL5 2082CFtM4sK99UA2F1DNUkaJvX+fMMIU7b24mgkiMYdR4vvST2AJFgFViWP7ZrGA2GwC2hJv /vWC2cIC/hJnvzxiBrFFBNQlGu6D2FwczAKfmCQ2tl1ihThDTuLvgl9gRbwCghInZz5hgdim KHH6bx8LRFxJ4svlHqi4nMSSqZeZIGxeiRnt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C1UjIbG15QnY/cxAd07pfsgOYRtIHFk0hxXdL7wCHhIXVk9lnMAoOwtJahaS9llI2pHV LGBkWcUomlqQXFCclF5hrFecmFtcmpeul5yfu4kRnIqeLd7B+P+89SFGAQ5GJR5eizcRoUKs iWXFlbmHGCU4mJVEeAVuRoYK8aYkVlalFuXHF5XmpBYfYjQFRttEZinR5HxgmswriTc0NjE3 NTa1MDA0NzdTEuf9fy43REggPbEkNTs1tSC1CKaPiYNTqoFx4sqf7M9MNQ1yI5eK5u15O3ez 134VefbvNS6dj8LSWOe3XFMJa9vJe3D7bBe5A167lKU+57J+rp6gfcM8uyjEx+ou+08L/X9M 3d+YJv4/NOf0Tc/jmwXk9XonrZiQbxxqkPclZLJwz6Npy+1eKZdYrMsvzM226Ejtmn5/l87z r1tXffgym6tCiaU4I9FQi7moOBEAEJ80cVsDAAA= 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 t4IDHNeE025513 Content-Length: 4237 Lines: 81 EP-2DAD0AFA905A4ACB804C4F82A001242F > >Ok, I have to ask: what on Earth is this number and what does [EDT] mean? This is auto generated from our editor. Kindly ignore its not relevant. Please find reply inline. >> >On Tue, May 12, 2015 at 02:12:54PM +0100, Vaneet Narang wrote: >> >> On Tue, May 12, 2015 at 12:48:13PM +0100, Maninder Singh wrote: >> >> 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 >> >> ?". >> >> >If you want to solve this, I think we need a better way to expose software >> >single-step/emulation to the overflow handler. If we try to do this in >> >the hw_breakpoint code itself, we run into problems: >> >> > - What if another thread hits the same instruction whilst we are trying >> > to step it? >> >> > - What if there are two breakpoints or a breakpoint + watchpoint >> > triggered by the same instruction? >> >> Thanks for you input. I am not sure, issues which you have mentioned with >> this implementation will actually come. >> To address the issues you have raised, I need to brief about kprobe. >> Kprobe follows 3 steps for breakpoint (BP) handling. >> 1. Decode BP instruction. >> 2. Replace BP instruction with new instruction that will generate SWI. >> 3. Execute instruction & move PC to next instruction. >> Kprobe follows step 1 & step 2 on addition of BP and 3rd step is followed >> when SWI gets triggered. >> >> For this fix we have used step 1 & step 3, we have skipped step 2. As we >> don't know the caller of watch point & also HW generates interrupt so step >> 2 is not required. The only difference is since we don't know the caller >> we can't decode instruction in advance. We have to follow step 1 and step >> 3 when HWI gets triggered. Since we are not replacing instruction from >> memory and I assume kprobe implementation for execution of instruction in >> interrupt context is tested and stable, so it shouldn't produce any of >> the above race condition issues. > >Ok, so my first point shouldn't be a problem if we're just emulating the >instruction. However, I still think there are corner cases. For example, >imagine hitting a breakpoint on a ldr pc, [&foo] instruction where we've >also got a watchpoint on foo. Even with emulation, it's going to be >difficult to ensure that watchpoint is safely delivered. > >As I say, I'd really rather have a kprobes-agnostic way of stepping an >instruction and let the debugger decide whether it wants to use that or >not. > 2 breakpoints will not be any issue but watchpoint + breakpoint is interesting scenario with ldr pc, [&foo] instruction in place. How would ARM will behave in this case without kprobe ? I think It will keep on generating Watch point interrupt only. With kprobe watchpoint interrupt gets triggered first and as soon as we execute ldr pc, [&foo] using kprobe it will trigger Breakpoint interrupt. This can be taken care with special handling for such instruction where PC gets changed. Can you please suggest what should be correct behavior in this case ? Is this scenario possible with any other instruction. ? I am not able to think other instructions. Is it possisble with push or pop ? >> > - What if the debugger didn't want to execute the instruction at all? >> >> if debugger doesn't want to execute instruction then debugger should use >> single step implementation without overflow handler. > >But the debugger might want to use the overflow handler to regain control >on the exception (like ptrace does for userspace). > I have tried same kernel module on x86, Linux 3.5. Behavior on x86 is to execute instruction. I am not sure how ptrace works on x86, if instruction gets executed without any control from overflow handler. Behavior on ARM should be same as x86. Since perf API interface is same on ARM as well as x86. >Will Regards, Vaneet Narang????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?