From patchwork Thu Jan 12 14:30:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 9513333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E6EBB601E5 for ; Thu, 12 Jan 2017 14:32:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7A3E2679B for ; Thu, 12 Jan 2017 14:32:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAB5D286A4; Thu, 12 Jan 2017 14:32:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 756FE2679B for ; Thu, 12 Jan 2017 14:32:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cRgQ3-0000yB-T5; Thu, 12 Jan 2017 14:31:59 +0000 Received: from 6.mo3.mail-out.ovh.net ([188.165.43.173]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRgPy-0000rB-An for linux-arm-kernel@lists.infradead.org; Thu, 12 Jan 2017 14:31:57 +0000 Received: from player771.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 8392C719D2 for ; Thu, 12 Jan 2017 15:31:27 +0100 (CET) Received: from mail-qt0-f176.google.com (mail-qt0-f176.google.com [209.85.216.176]) (Authenticated sender: jjhiblot@traphandler.com) by player771.ha.ovh.net (Postfix) with ESMTPSA id 1BFC984006B for ; Thu, 12 Jan 2017 15:31:25 +0100 (CET) Received: by mail-qt0-f176.google.com with SMTP id x49so19174436qtc.2 for ; Thu, 12 Jan 2017 06:31:25 -0800 (PST) X-Gm-Message-State: AIkVDXJhdAHbVaGWmpwMUpVYSa0aLTk7CLmNPnImV5p7mngXgDz9ydqHL5bypCebIy8z0WKO5JAvFiYG0y46TQ== X-Received: by 10.200.51.26 with SMTP id t26mr14480171qta.106.1484231485108; Thu, 12 Jan 2017 06:31:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.164.162 with HTTP; Thu, 12 Jan 2017 06:30:44 -0800 (PST) In-Reply-To: <20170112001957.GA5458@nuc> References: <1481233595-22112-1-git-send-email-abelvesa@linux.com> <20161208224655.GA6319@gce> <20170110155112.GB14894@pathway.suse.cz> <20170112001957.GA5458@nuc> From: Jean-Jacques Hiblot Date: Thu, 12 Jan 2017 15:30:44 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS To: Abel Vesa X-Ovh-Tracer-Id: 10609917775534053628 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelgedrfedtgdeiiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceonhhonhgvqeenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170112_063154_530043_A4E4F796 X-CRM114-Status: GOOD ( 29.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , zhouchengming1@huawei.com, Jean-Jacques Hiblot , Russell King - ARM Linux , Steven Rostedt , Linux Kernel Mailing List , Abel Vesa , mingo@redhat.com, viro@zeniv.linux.org.uk, robin.murphy@arm.com, "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 2017-01-12 1:19 GMT+01:00 Abel Vesa : > On Tue, Jan 10, 2017 at 04:51:12PM +0100, Petr Mladek wrote: >> On Thu 2016-12-08 22:46:55, Abel Vesa wrote: >> > On Thu, Dec 08, 2016 at 09:46:35PM +0000, Abel Vesa wrote: >> > > From: Jean-Jacques Hiblot >> > > >> > > From: Jean-Jacques Hiblot >> > >> > >From statement twice in the commit message. Will resend. >> > > >> > > The DYNAMIC_FTRACE_WITH_REGS configuration makes it possible for a ftrace >> > > operation to specify if registers need to saved/restored by the ftrace handler. >> > > This is needed by kgraft and possibly other ftrace-based tools, and the ARM >> > > architecture is currently lacking this feature. It would also be the first step >> > > to support the "Kprobes-on-ftrace" optimization on ARM. >> > > >> > > This patch introduces a new ftrace handler that stores the registers on the >> > > stack before calling the next stage. The registers are restored from the stack >> > > before going back to the instrumented function. >> > > >> > > A side-effect of this patch is to activate the support for ftrace_modify_call() >> > > as it defines ARCH_SUPPORTS_FTRACE_OPS for the ARM architecture >> > > >> > > Signed-off-by: Jean-Jacques Hiblot >> > > Signed-off-by: Abel Vesa >> > > --- >> > > arch/arm/Kconfig | 2 ++ >> > > arch/arm/include/asm/ftrace.h | 4 +++ >> > > arch/arm/kernel/entry-ftrace.S | 78 ++++++++++++++++++++++++++++++++++++++++++ >> > > arch/arm/kernel/ftrace.c | 33 ++++++++++++++++++ >> > > 4 files changed, 117 insertions(+) >> > > >> > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig >> > > index b5d529f..87f1a9f 100644 >> > > --- a/arch/arm/Kconfig >> > > +++ b/arch/arm/Kconfig >> > > @@ -50,6 +50,7 @@ config ARM >> > > select HAVE_DMA_API_DEBUG >> > > select HAVE_DMA_CONTIGUOUS if MMU >> > > select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU >> > > + select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE >> > > select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU >> > > select HAVE_EXIT_THREAD >> > > select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) >> > > @@ -90,6 +91,7 @@ config ARM >> > > select PERF_USE_VMALLOC >> > > select RTC_LIB >> > > select SYS_SUPPORTS_APM_EMULATION >> > > + select FRAME_POINTER if DYNAMIC_FTRACE_WITH_REGS && FUNCTION_GRAPH_TRACER > Hi Petr, >> >> FRAME_POINTER is not for free. It takes space on the stack. Also there >> is a performance penalty. Do we really need to depend on it? If so, >> it might be worth a note in the commit message. > FRAME_POINTER is not needed. the dependency is wrong and should be removed. The code must be modified to not use fp register: ldr r1, [sp, #56] @ instrumented routine (func) @@ -139,8 +140,9 @@ ftrace_graph_regs_call: mov r2, fp @ frame pointer bl prepare_ftrace_return - ldr lr, [fp, #-4] @ restore lr from the stack - ldmia sp, {r0-r11, ip, sp} @ restore r0 through sp + ldr lr, [sp, #64] @ get the previous LR value from stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer ret ip .endm #endif Jean-Jacques > I was trying to create my own patch when I found this work done by > Jean-Jacques, so I haven't looked specifically for the FRAME_POINTER > part. I looked now at it and you seem to be right, FRAME_POINTER is > not needed. > > I will get rid of the FRAME_POINTER part, change the authorship and > send it again in the following days. >> >> I made only a quick look at the patch. It looks reasonable. But I do >> not have enough knowledge about the arm architecture, assembly, and >> ftrace-specifics. Also I cannot test it easily. So issues might >> be hidden to my eyes. >> >> Best Regards, >> Petr > Thanks, > Abel --- a/arch/arm/kernel/entry-ftrace.S +++ b/arch/arm/kernel/entry-ftrace.S @@ -130,7 +130,8 @@ ftrace_graph_regs_call: #ifdef CONFIG_FUNCTION_GRAPH_TRACER .macro __ftrace_graph_regs_caller - sub r0, fp, #4 @ lr of instrumented routine (parent) + add r0, sp, #64 @ r0 is now a pointer to lr of + @ instrumented routine @ called from __ftrace_regs_caller