From patchwork Thu May 12 02:26:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Bin X-Patchwork-Id: 9076461 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8F80D9F1C3 for ; Thu, 12 May 2016 02:30:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 907E6201D3 for ; Thu, 12 May 2016 02:30:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 78BAE20148 for ; Thu, 12 May 2016 02:30:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0gNM-0007Jt-K9; Thu, 12 May 2016 02:29:20 +0000 Received: from szxga01-in.huawei.com ([58.251.152.64]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0gNH-0006qr-TG for linux-arm-kernel@lists.infradead.org; Thu, 12 May 2016 02:29:17 +0000 Received: from 172.24.1.47 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DKJ99924; Thu, 12 May 2016 10:26:57 +0800 (CST) Received: from [127.0.0.1] (10.177.23.78) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Thu, 12 May 2016 10:26:49 +0800 Subject: Re: [PATCH v12 00/10] arm64: Add kernel probes (kprobes) support To: James Morse , David Long References: <1461783185-9056-1-git-send-email-dave.long@linaro.org> <573350B2.4010701@arm.com> From: Li Bin Message-ID: <5733E9E0.1060504@huawei.com> Date: Thu, 12 May 2016 10:26:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <573350B2.4010701@arm.com> X-Originating-IP: [10.177.23.78] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.5733E9F4.00FA, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 89f182b37f23480c57ab1b944827e2de X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160511_192916_886320_9F31CB3C X-CRM114-Status: GOOD ( 15.66 ) X-Spam-Score: -5.6 (-----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Feng Kan , Catalin Marinas , Will Deacon , Yang Shi , John Blackwood , Pratyush Anand , Viresh Kumar , Zi Shen Lim , Dave P Martin , Petr Mladek , Vladimir Murzin , Steve Capper , Kees Cook , "Suzuki K. Poulose" , Marc Zyngier , Mark Brown , Sandeepa Prabhu , William Cohen , =?UTF-8?Q?Alex_Benn=c3=a9e?= , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Mark Salyzyn , Christoffer Dall , Andrew Morton , Robin Murphy , Jens Wiklander , Balamurugan Shanmugam Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP on 2016/5/11 23:33, James Morse wrote: > Hi David, > > On 27/04/16 19:52, David Long wrote: >> From: "David A. Long" >> >> This patchset is heavily based on Sandeepa Prabhu's ARM v8 kprobes patches, >> first seen in October 2013. This version attempts to address concerns raised by >> reviewers and also fixes problems discovered during testing. >> >> This patchset adds support for kernel probes(kprobes), jump probes(jprobes) >> and return probes(kretprobes) support for ARM64. >> >> The kprobes mechanism makes use of software breakpoint and single stepping >> support available in the ARM v8 kernel. > > I applied this series on v4.6-rc7, and built the sample kprobes. They work fine, > unless I throw ftrace into the mix too. > > I enabled the function_graph tracer, then tried to load the jprobe example module: > -------------------------%<------------------------- > root@ubuntu:/sys/kernel/debug/tracing# insmod /root/jprobe_example.ko > Planted jprobe at ffffff80080c8f20, handler addr ffffff8000bb3000 > root@ubuntu:/sys/kernel/debug/tracing# jprobe: clone_flags = 0x1200011, stack_st > art = 0x0 stack_size = 0x0 > Bad mode in Synchronous Abort handler detected, code 0x86000005 -- IABT (current > EL) > CPU: 5 PID: 1047 Comm: systemd-udevd Not tainted 4.6.0-rc7+ #4064 > Hardware name: ARM Juno development board (r1) (DT) > task: ffffffc975948300 ti: ffffffc974e4c000 task.ti: ffffffc974e4c000 > PC is at 0x0 > LR is at 0x0 > > pc : [<0000000000000000>] lr : [<0000000000000000>] pstate: 60000145 > sp : ffffffc974e4ff00 > x29: 0000000001200011 x28: ffffffc974e4c000 > x27: ffffff80088d0000 x26: 00000000000000dc > x25: 0000000000000120 x24: 0000000000000015 > x23: 0000000060000000 x22: 0000007fa1b40e60 > x21: 0000007fa1ce70d0 x20: 0000000000000000 > x19: 0000000000000000 x18: 0000000000000a03 > x17: 0000007fa1b40d90 x16: ffffff80080c9708 > x15: 003b9aca00000000 x14: 0000007fddb7e5c0 > x13: 0000007fa1b40e2c x12: 0000000000d00ff0 > x11: ffffff8009c4d000 x10: ffffff800920c000 > x9 : ffffff8008f5c000 x8 : ffffffc976c06800 > x7 : 000000000006daf2 x6 : 0000000000000015 > x5 : 0000000000000004 x4 : ffffffc96e8690a0 > x3 : 0000001ed7cbab74 x2 : ffffffc96e869000 > x1 : 0000000000000000 x0 : 0000000000000000 > > Internal error: Oops - bad mode: 0 [#1] PREEMPT SMP > Modules linked in: jprobe_example > CPU: 5 PID: 1047 Comm: systemd-udevd Not tainted 4.6.0-rc7+ #4064 > Hardware name: ARM Juno development board (r1) (DT) > task: ffffffc975948300 ti: ffffffc974e4c000 task.ti: ffffffc974e4c000 > PC is at 0x0 > LR is at 0x0 > > pc : [<0000000000000000>] lr : [<0000000000000000>] pstate: 60000145 > sp : ffffffc974e4ff00 > x29: 0000000001200011 x28: ffffffc974e4c000 > x27: ffffff80088d0000 x26: 00000000000000dc > x25: 0000000000000120 x24: 0000000000000015 > x23: 0000000060000000 x22: 0000007fa1b40e60 > x21: 0000007fa1ce70d0 x20: 0000000000000000 > x19: 0000000000000000 x18: 0000000000000a03 > x17: 0000007fa1b40d90 x16: ffffff80080c9708 > x15: 003b9aca00000000 x14: 0000007fddb7e5c0 > x13: 0000007fa1b40e2c x12: 0000000000d00ff0 > x11: ffffff8009c4d000 x10: ffffff800920c000 > x9 : ffffff8008f5c000 x8 : ffffffc976c06800 > x7 : 000000000006daf2 x6 : 0000000000000015 > x5 : 0000000000000004 x4 : ffffffc96e8690a0 > x3 : 0000001ed7cbab74 x2 : ffffffc96e869000 > x1 : 0000000000000000 x0 : 0000000000000000 > > Process systemd-udevd (pid: 1047, stack limit = 0xffffffc974e4c020) > Stack: (0xffffffc974e4ff00 to 0xffffffc974e50000) > ff00: 0000000000000417 0000007fa1ce76f0 00000000000000dc 0000000000000417 > ff20: 00000000ffffffff 0000007fddb7ecf8 0000000000000005 ffffffffffffffff > ff40: 00000000ff000001 003b9aca00000000 000000555b3868b0 0000007fa1b40d90 > ff60: 0000000000000a03 0000007fddb7e5c0 0000000000000000 0000007fddb7e5e0 > ff80: 000000555b358000 000000558f56f0e0 0000000000000000 000000558f574f00 > ffa0: 000000558f574f00 00000000000004fa 000000558f56f010 0000007fddb7e600 > ffc0: 0000007fa1b40e2c 0000007fddb7e5c0 0000007fa1b40e60 0000000060000000 > ffe0: 0000000001200011 00000000000000dc 0004000084000200 0800000002000000 > Call trace: > [< (null)>] (null) > Code: bad PC value > ---[ end trace 35d24aad799c2941 ]--- > -------------------------%<------------------------- > To solve this, it should pause function tracing before the jprobe handler is called and unpause it before it returns back to the function it probed. Li Bin > > Thanks, > > > James > > > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > . > diff --git a/arch/arm64/kernel/kprobes.c b/arch/arm64/kernel/kprobes.c index db2d95c..b21ed00 100644 --- a/arch/arm64/kernel/kprobes.c +++ b/arch/arm64/kernel/kprobes.c @@ -714,6 +714,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) instruction_pointer_set(regs, (long)jp->entry); preempt_disable(); + pause_graph_tracing(); return 1; } @@ -757,6 +758,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) show_regs(regs); BUG(); } + unpause_graph_tracing(); *regs = kcb->jprobe_saved_regs; memcpy((void *)stack_addr, kcb->jprobes_stack, MIN_STACK_SIZE(stack_addr));