From patchwork Tue Dec 6 17:06:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 9462953 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 771A260231 for ; Tue, 6 Dec 2016 17:10:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 603E92843B for ; Tue, 6 Dec 2016 17:10:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5519628480; Tue, 6 Dec 2016 17:10:59 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id E52852843B for ; Tue, 6 Dec 2016 17:10:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEJEt-0005zL-Fs; Tue, 06 Dec 2016 17:09:11 +0000 Received: from mail-wm0-f68.google.com ([74.125.82.68]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEJCn-00044X-0M for linux-arm-kernel@lists.infradead.org; Tue, 06 Dec 2016 17:07:08 +0000 Received: by mail-wm0-f68.google.com with SMTP id m203so22668640wma.3 for ; Tue, 06 Dec 2016 09:06:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bbUpcUQxPrnN2auHGtaZZELCwCTwVDBvdEBqQ0uaq30=; b=dMrOtksrpW8lgrFGwMabXpRUfv0JnNAAl4VsfODkaLQArfn+2AyG4+yt7M8bNGmtMX hBPxyuT9fyBSsJZc5FluKz0KzTV47Z8jdYD+XBTeWkAZdtG94UsGBGNMj2kxWEVA0RfB 5u10djpReK9fzy1q7Rjbn7JHjLLupRuzlkpytHIEGrciHpHXafQToSY3Rgbdmi0lIpFI 8hsuvyAtwbBJEVRsfygaw7xZCXswIQXRE74E5T1VeaWJtVpnu5a1ShHeGG7kRU3ZFwrm AC59vdiaCJoDPFzGte9WX+0yjkPN/uUdkmB4sUmPytzhNvd+k9zwMVzHWwnvh9OzeOj0 kPtQ== X-Gm-Message-State: AKaTC03MZmNmq6clWbyLwVKPGZ1ckirzKXvAZb20C6h31Jkp//LBMlNR5dJ+2COoSIEK2Q== X-Received: by 10.28.47.196 with SMTP id v187mr3460131wmv.75.1481043985201; Tue, 06 Dec 2016 09:06:25 -0800 (PST) Received: from gce.c.kernel-work.internal (115.57.155.104.bc.googleusercontent.com. [104.155.57.115]) by smtp.gmail.com with ESMTPSA id l67sm4942458wmf.20.2016.12.06.09.06.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 09:06:24 -0800 (PST) From: Abel Vesa To: linux@armlinux.org.uk, jpoimboe@redhat.com, jeyu@redhat.com, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com Subject: [PATCH 2/7] arm: ftrace: Add call modify mechanism Date: Tue, 6 Dec 2016 17:06:02 +0000 Message-Id: <1481043967-15602-3-git-send-email-abelvesa@linux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481043967-15602-1-git-send-email-abelvesa@linux.com> References: <1481043967-15602-1-git-send-email-abelvesa@linux.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161206_090701_774395_96585F27 X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. 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: linux-arm-kernel@lists.infradead.org, geert+renesas@glider.be, ard.biesheuvel@linaro.org, jean-philippe.brucker@arm.com, gregkh@linuxfoundation.org, stefano.stabellini@eu.citrix.com, emil.l.velikov@gmail.com, linux-kernel@vger.kernel.org, rostedt@goodmis.org, jens.wiklander@linaro.org, Abel Vesa , chris.brandt@renesas.com, mingo@redhat.com, viro@zeniv.linux.org.uk, live-patching@vger.kernel.org, akpm@linux-foundation.org, mchehab@kernel.org, davem@davemloft.net, linux@roeck-us.net MIME-Version: 1.0 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 Function ftrace_modify_call provides a way to replace ftrace_stub with the ftrace function. This helps the klp_ftrace_handler to be called via ftrace_ops_no_ops, which in turn will set the pc with the patched function's starting address. This is used for livepatching. Signed-off-by: Abel Vesa --- arch/arm/kernel/ftrace.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index 3f17594..cb4543a 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -139,6 +139,15 @@ int ftrace_update_ftrace_func(ftrace_func_t func) ret = ftrace_modify_code(pc, 0, new, false); +#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 + #ifdef CONFIG_OLD_MCOUNT if (!ret) { pc = (unsigned long)&ftrace_call_old; @@ -151,6 +160,18 @@ int ftrace_update_ftrace_func(ftrace_func_t func) return ret; } +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long pc = rec->ip; + u32 old, new; + + old = arm_gen_branch(pc, old_addr); + new = arm_gen_branch(pc, addr); + + return ftrace_modify_code(pc, old, new, true); +} + int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) { unsigned long new, old;