From patchwork Mon Nov 10 08:56:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 5264791 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6EA639F2ED for ; Mon, 10 Nov 2014 09:04:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 126932013A for ; Mon, 10 Nov 2014 09:04:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C793320158 for ; Mon, 10 Nov 2014 09:04:23 +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 1Xnkra-0000Z5-AK; Mon, 10 Nov 2014 09:02:18 +0000 Received: from mail-wg0-f54.google.com ([74.125.82.54]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XnkrO-0000QD-L7 for linux-arm-kernel@lists.infradead.org; Mon, 10 Nov 2014 09:02:07 +0000 Received: by mail-wg0-f54.google.com with SMTP id n12so8165708wgh.13 for ; Mon, 10 Nov 2014 01:01:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g4jOkaThgmAd2LVF3dGIf+/dlxB+zmRi8iXDO8l1wsQ=; b=OqcNWBneMmqUuFTEtEGwVxxc676DatNn1BktqJ4aHyGUHtub0eFSeMCAcvME2B24d0 mpWaMw2Tmkw7kzA4f9mCYkrUqfD9Iovx9Th0m03PL/TWUue3ODdISlcPusX86c2jmkQI okH/pp51k9crwtlm0Sbv7zMHTNMfiA2OKybk5o2R7RGjkk6VkXwyyqd6aszLXm3BGQec KpbhT+slTFOhb846h0Zdyg/AfpbCS3BmyMoSoB5mwzn5F2TpsCRxSmBo6tCbv8BO6izd 0TLmAqwEx/V5eLMvkm3TWWuOww+FEKp7viTn6ausMij3Vhs61pkO5sBwB2Jz0PwKmXZe EmgA== X-Received: by 10.194.158.193 with SMTP id ww1mr15401794wjb.65.1415610104240; Mon, 10 Nov 2014 01:01:44 -0800 (PST) Received: from laptrap.localdomain (sch42-5-78-217-165-73.fbx.proxad.net. [78.217.165.73]) by mx.google.com with ESMTPSA id t16sm16799091wjr.28.2014.11.10.01.01.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Nov 2014 01:01:43 -0800 (PST) From: Jean-Jacques Hiblot To: jslaby@suse.cz, linux@arm.linux.org.uk, rostedt@goodmis.org, mingo@redhat.com, nsekhar@ti.com, stefano.stabellini@eu.citrix.com, christoffer.dall@linaro.org Subject: [PATCH v2 01/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS Date: Mon, 10 Nov 2014 09:56:17 +0100 Message-Id: <1415609777-18525-2-git-send-email-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1415609777-18525-1-git-send-email-jjhiblot@traphandler.com> References: <20141107115225.72bc6cbf@gandalf.local.home> <1415609777-18525-1-git-send-email-jjhiblot@traphandler.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141110_010206_858872_6D191C34 X-CRM114-Status: GOOD ( 20.57 ) X-Spam-Score: -0.7 (/) Cc: Jean-Jacques Hiblot , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 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 --- arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 32cbbd5..6f928ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) + 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_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) @@ -72,6 +73,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 # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 39eb16b..d8e9bea 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -10,6 +10,9 @@ extern void mcount(void); extern void __gnu_mcount_nc(void); #ifdef CONFIG_DYNAMIC_FTRACE + +#define ARCH_SUPPORTS_FTRACE_OPS 1 + struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..9594fe2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -197,7 +197,10 @@ ENDPROC(ret_from_fork) mcount_get_lr r1 @ lr of instrumented func mcount_adjust_addr r0, lr @ instrumented function - + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + mov r3, #0 @ regs is NULL .globl ftrace_call\suffix ftrace_call\suffix: bl ftrace_stub @@ -211,6 +214,38 @@ ftrace_graph_call\suffix: mcount_exit .endm +.macro __ftrace_regs_caller + + add ip, sp, #4 @ move in IP the value of SP as it was + @ before the push {lr} of the mcount mechanism + stmdb sp!, {ip,lr,pc} + stmdb sp!, {r0-r11,lr} + @ stack content at this point: + @ 0 4 44 48 52 56 60 64 + @ RO | R1 | ... | R11 | LR | SP + 4 | LR | PC | previous LR | + + mov r3, sp @ struct pt_regs* + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + ldr r1, [sp, #64] @ lr of instrumented func + mcount_adjust_addr r0, lr @ instrumented function + + .globl ftrace_regs_call +ftrace_regs_call: + bl ftrace_stub + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_regs_call +ftrace_graph_regs_call: + mov r0, r0 +#endif + 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 + .macro __ftrace_graph_caller sub r0, fp, #4 @ &lr of instrumented routine (&parent) #ifdef CONFIG_DYNAMIC_FTRACE @@ -226,6 +261,24 @@ ftrace_graph_call\suffix: mcount_exit .endm + +.macro __ftrace_graph_regs_caller + + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + + @ called from __ftrace_regs_caller + ldr r1, [sp, #56] @ instrumented routine (func) + mcount_adjust_addr r1, r1 + + mov r2, fp @ frame pointer + bl prepare_ftrace_return + + ldr lr, [fp, #-4] @ restore LR from the stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + #ifdef CONFIG_OLD_MCOUNT /* * mcount @@ -312,14 +365,27 @@ UNWIND(.fnstart) __ftrace_caller UNWIND(.fnend) ENDPROC(ftrace_caller) + +ENTRY(ftrace_regs_caller) +UNWIND(.fnstart) + __ftrace_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_regs_caller) #endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(ftrace_graph_caller) UNWIND(.fnstart) __ftrace_graph_caller UNWIND(.fnend) ENDPROC(ftrace_graph_caller) + +ENTRY(ftrace_graph_regs_caller) +UNWIND(.fnstart) + __ftrace_graph_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_graph_regs_caller) #endif .purgem mcount_enter diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index af9a8a9..35c5743 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -130,6 +130,16 @@ int ftrace_update_ftrace_func(ftrace_func_t func) } #endif + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) { + pc = (unsigned long)&ftrace_regs_call; + new = ftrace_call_replace(pc, (unsigned long)func); + + ret = ftrace_modify_code(pc, 0, new, false); + } +#endif + return ret; } @@ -139,6 +149,20 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) unsigned long ip = rec->ip; old = ftrace_nop_replace(rec); + + new = ftrace_call_replace(ip, adjust_address(rec, addr)); + + return ftrace_modify_code(rec->ip, old, new, true); +} + +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long new, old; + unsigned long ip = rec->ip; + + old = ftrace_call_replace(ip, adjust_address(rec, old_addr)); + new = ftrace_call_replace(ip, adjust_address(rec, addr)); return ftrace_modify_code(rec->ip, old, new, true); @@ -211,6 +235,9 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, extern unsigned long ftrace_graph_call; extern unsigned long ftrace_graph_call_old; extern void ftrace_graph_caller_old(void); +extern unsigned long ftrace_graph_regs_call; +extern void ftrace_graph_regs_caller(void); + static int __ftrace_modify_caller(unsigned long *callsite, void (*func) (void), bool enable) @@ -240,6 +267,13 @@ static int ftrace_modify_graph_caller(bool enable) enable); #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) + ret = __ftrace_modify_caller(&ftrace_graph_regs_call, + ftrace_graph_regs_caller, + enable); +#endif + return ret; }