Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752448AbcLGCoB (ORCPT ); Tue, 6 Dec 2016 21:44:01 -0500 Received: from smtprelay0229.hostedemail.com ([216.40.44.229]:60947 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751064AbcLGCoA (ORCPT ); Tue, 6 Dec 2016 21:44:00 -0500 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3871:3872:4229:4605:5007:6119:6261:6742:6743:7875:7903:9040:10004:10400:10848:10967:11026:11232:11473:11658:11914:12043:12291:12295:12296:12438:12555:12663:12683:12740:12760:13439:13972:14110:14181:14659:14721:21080:21451:30012:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: toy78_5ca381a278856 X-Filterd-Recvd-Size: 3765 Date: Tue, 6 Dec 2016 21:43:55 -0500 From: Steven Rostedt To: Abel Vesa Cc: linux@armlinux.org.uk, jpoimboe@redhat.com, jeyu@redhat.com, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, mingo@redhat.com, gregkh@linuxfoundation.org, geert+renesas@glider.be, davem@davemloft.net, akpm@linux-foundation.org, emil.l.velikov@gmail.com, mchehab@kernel.org, linux@roeck-us.net, ard.biesheuvel@linaro.org, jens.wiklander@linaro.org, jean-philippe.brucker@arm.com, viro@zeniv.linux.org.uk, stefano.stabellini@eu.citrix.com, chris.brandt@renesas.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org Subject: Re: [PATCH 4/7] arm: Add ftrace with regs support Message-ID: <20161206214355.268d2791@grimm.local.home> In-Reply-To: <1481043967-15602-5-git-send-email-abelvesa@linux.com> References: <1481043967-15602-1-git-send-email-abelvesa@linux.com> <1481043967-15602-5-git-send-email-abelvesa@linux.com> X-Mailer: Claws Mail 3.14.1-26-gbac033 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2258 Lines: 95 On Tue, 6 Dec 2016 17:06:04 +0000 Abel Vesa wrote: > This adds __ftrace_regs_caller which, unlike __ftrace_caller, > adds register saving/restoring and livepatch handling if > the pc register gets modified by klp_ftrace_handler. > > Signed-off-by: Abel Vesa > --- > arch/arm/kernel/entry-ftrace.S | 49 > ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 > insertions(+) > > diff --git a/arch/arm/kernel/entry-ftrace.S > b/arch/arm/kernel/entry-ftrace.S index c73c403..b6ada5c 100644 > --- a/arch/arm/kernel/entry-ftrace.S > +++ b/arch/arm/kernel/entry-ftrace.S > @@ -92,6 +92,46 @@ > 2: mcount_exit > .endm > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > + > +.macro __ftrace_regs_caller suffix > + > + stmdb sp!, {r0-r15} > + mov r3, sp > + > + ldr r10, [sp, #60] > + > + mcount_get_lr r1 @ lr of instrumented > func > + mcount_adjust_addr r0, lr @ > instrumented function + > + .globl ftrace_regs_call\suffix > +ftrace_regs_call\suffix: > + bl ftrace_stub > + > +#ifdef CONFIG_FUNCTION_GRAPH_TRACER > + .globl ftrace_regs_graph_call\suffix > +ftrace_regs_graph_call\suffix: > + mov r0, r0 > +#endif So basically what the below does is to undo the mcount prologue and recall the new function as the old function is called. > +#ifdef CONFIG_LIVEPATCH > + ldr r0, [sp, #60] > + cmp r0, r10 > + beq ftrace_regs_caller_end > + ldmia sp!, {r0-r12} > + add sp, sp, #8 > + ldmia sp!, {r11} > + sub sp, r12, #16 > + str r11, [sp, #12] > + ldmia sp!, {r11, r12, lr, pc} But the above really could do with a lot of comments to explain exactly what it is doing. I don't condemn or condone this code. I'm just happy I don't have to maintain it. -- Steve > +#endif > +ftrace_regs_caller_end\suffix: > + ldmia sp!, {r0-r14} > + add sp, sp, #4 > + mov pc, lr > +.endm > + > +#endif > + > .macro __ftrace_caller suffix > mcount_enter > > @@ -212,6 +252,15 @@ UNWIND(.fnstart) > __ftrace_caller > UNWIND(.fnend) > ENDPROC(ftrace_caller) > + > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > +ENTRY(ftrace_regs_caller) > +UNWIND(.fnstart) > + __ftrace_regs_caller > +UNWIND(.fnend) > +ENDPROC(ftrace_regs_caller) > +#endif > + > #endif > > #ifdef CONFIG_FUNCTION_GRAPH_TRACER