From patchwork Thu Sep 29 09:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Huafei X-Patchwork-Id: 12993870 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3E5DC433F5 for ; Thu, 29 Sep 2022 09:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Tmi/F1ybntirBzBqiw24qiW/ZzTUnayKEjoE+e2Vssk=; b=32l00cGgNbVh73 q7Xq7HITkdB1ytOg1AwmYUmgBmbRH4ykhvFIhaJG3qmCdtJp0OfUMNqC+akjRd3sm/3f/Gb+OYeLm 1gdjPTZeAcTT7vs6jCe3sfzB9aERgjxXp4dCvAP6g/z7ut4TpJSTztCWwbgx1eQwpoVsIywveP7Rs nT+rlk3k/AMGpyMRAIMmG66cEyDgyfSb+a8pp812I8dSL0HYpwqJ29TgRRPzWkk4Q6xe6NNThSCQK 6zv4VoZZqTpcJ52JNZtlV0nlplkCfzcQ3Jmq/AlaFxDCYvaIq5tGMp2gtMDjXSrXrT7KTREoHvTkj eqZe/MyCgylJigLBTv3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq7A-002C2c-Jd; Thu, 29 Sep 2022 09:45:56 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq6l-002Bp4-IN for linux-arm-kernel@lists.infradead.org; Thu, 29 Sep 2022 09:45:33 +0000 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MdSzN62cxz1P6wg; Thu, 29 Sep 2022 17:41:04 +0800 (CST) Received: from kwepemm600010.china.huawei.com (7.193.23.86) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:22 +0800 Received: from ubuntu1804.huawei.com (10.67.174.174) by kwepemm600010.china.huawei.com (7.193.23.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:21 +0800 From: Li Huafei To: , , CC: , , , , , , , , , , , Subject: [PATCH 1/3] arm64: module: Make plt_equals_entry() static Date: Thu, 29 Sep 2022 17:41:32 +0800 Message-ID: <20220929094134.99512-2-lihuafei1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929094134.99512-1-lihuafei1@huawei.com> References: <20220929094134.99512-1-lihuafei1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.174] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600010.china.huawei.com (7.193.23.86) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220929_024531_794435_5F9C2EED X-CRM114-Status: UNSURE ( 9.95 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since commit 4e69ecf4da1e ("arm64/module: ftrace: deal with place relative nature of PLTs"), plt_equals_entry() is not used outside of module-plts.c, so make it static. Signed-off-by: Li Huafei Acked-by: Mark Rutland --- arch/arm64/include/asm/module.h | 1 - arch/arm64/kernel/module-plts.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/module.h b/arch/arm64/include/asm/module.h index 4e7fa2623896..28514b989a0b 100644 --- a/arch/arm64/include/asm/module.h +++ b/arch/arm64/include/asm/module.h @@ -58,7 +58,6 @@ static inline bool is_forbidden_offset_for_adrp(void *place) } struct plt_entry get_plt_entry(u64 dst, void *pc); -bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b); static inline bool plt_entry_is_initialized(const struct plt_entry *e) { diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c index a3d0494f25a9..5a0a8f552a61 100644 --- a/arch/arm64/kernel/module-plts.c +++ b/arch/arm64/kernel/module-plts.c @@ -37,7 +37,8 @@ struct plt_entry get_plt_entry(u64 dst, void *pc) return plt; } -bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b) +static bool plt_entries_equal(const struct plt_entry *a, + const struct plt_entry *b) { u64 p, q; From patchwork Thu Sep 29 09:41:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Huafei X-Patchwork-Id: 12993868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80B22C433F5 for ; Thu, 29 Sep 2022 09:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CSpr9ihdyT9G0t0SUSzlnJFF/HvYR4MIW60l9x4SJ3U=; b=c88KG7U720qtUl amrLMZ4j7n5n+eJzmG1RLeUZYjZwezWT+KMaHDtLd7/eo8U6+cJFZ9gtbzqDzqfOIh/w6oXURwclm St/8r75tdTjPKjY6DSyPMGCJ2QTzOWc8x1qX2lleG1fL6Ic+CePLUYLswphjlZQ01zU5qzDGGq05R TGZNmtUSOvL5yH5IRfBZeRc9t3g/tfDrvcX1KhC+FFprvYyob9gstAGxQ9S09ZyRlEsRr9XKx6R6J 1zZxlkij2ktHi1TooZ+lvxgZOYxjUs4715VwHfDZQUvkT8H3wIhHOK21vLBMmdyL3M0/2Pwd+YGv6 xw3F6ji0tfuKm73N6r3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq6p-002BuB-Nd; Thu, 29 Sep 2022 09:45:35 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq6l-002Bp5-Lj for linux-arm-kernel@lists.infradead.org; Thu, 29 Sep 2022 09:45:33 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MdSyq0PLPzHtnC; Thu, 29 Sep 2022 17:40:35 +0800 (CST) Received: from kwepemm600010.china.huawei.com (7.193.23.86) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:22 +0800 Received: from ubuntu1804.huawei.com (10.67.174.174) by kwepemm600010.china.huawei.com (7.193.23.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:21 +0800 From: Li Huafei To: , , CC: , , , , , , , , , , , Subject: [PATCH 2/3] arm64: module: Remove unused plt_entry_is_initialized() Date: Thu, 29 Sep 2022 17:41:33 +0800 Message-ID: <20220929094134.99512-3-lihuafei1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929094134.99512-1-lihuafei1@huawei.com> References: <20220929094134.99512-1-lihuafei1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.174] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600010.china.huawei.com (7.193.23.86) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220929_024531_901756_11AE9B69 X-CRM114-Status: UNSURE ( 7.17 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since commit f1a54ae9af0d ("arm64: module/ftrace: intialize PLT at load time"), plt_entry_is_initialized() is unused anymore , so remove it. Signed-off-by: Li Huafei Acked-by: Mark Rutland --- arch/arm64/include/asm/module.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/arm64/include/asm/module.h b/arch/arm64/include/asm/module.h index 28514b989a0b..8096d30c5e39 100644 --- a/arch/arm64/include/asm/module.h +++ b/arch/arm64/include/asm/module.h @@ -59,9 +59,4 @@ static inline bool is_forbidden_offset_for_adrp(void *place) struct plt_entry get_plt_entry(u64 dst, void *pc); -static inline bool plt_entry_is_initialized(const struct plt_entry *e) -{ - return e->adrp || e->add || e->br; -} - #endif /* __ASM_MODULE_H */ From patchwork Thu Sep 29 09:41:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Huafei X-Patchwork-Id: 12993871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9874C4332F for ; Thu, 29 Sep 2022 09:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RMIfzeGcapS5EWeCCt4583C43DgLMk7Fk0uoZePXz1Q=; b=be6pU5M6Z9w7Yd gBjc8ZH/G0xjcqlotCgFzUjBj2ldo31QxqErSGr21XfzhHBwcU464CwdjeShd364jmvvbqX8X2yfy 1evFW3HCMWtOmDh70L7zXEfPgJ+lCfRkpVP7UgQIN4C7Kr68BFaKB2InOQywGOQ6DqTMj27EovfD1 RYvdcB2WFgZEkSvMrUSo1mB487n0vd9tBxsHkrbLg6pgnjsQuc0YVja79rale1s8GPlU/Dr6OAdqK ollRLSZy1bGNsIYDjte2uiU+isk0Hdn8TuQNCbqvOveLkDLOy+sN2gaq/6WijVGU+zlvcxjeyfNeD tndTjYaZOXJFNRpKjT6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq7O-002C5v-Dq; Thu, 29 Sep 2022 09:46:10 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1odq6l-002Bp3-Hi for linux-arm-kernel@lists.infradead.org; Thu, 29 Sep 2022 09:45:34 +0000 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MdSzP6smwz1P6yq; Thu, 29 Sep 2022 17:41:05 +0800 (CST) Received: from kwepemm600010.china.huawei.com (7.193.23.86) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:23 +0800 Received: from ubuntu1804.huawei.com (10.67.174.174) by kwepemm600010.china.huawei.com (7.193.23.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 17:45:22 +0800 From: Li Huafei To: , , CC: , , , , , , , , , , , Subject: [PATCH 3/3] arm64: module/ftrace: Fix mcount-based ftrace initialization failure Date: Thu, 29 Sep 2022 17:41:34 +0800 Message-ID: <20220929094134.99512-4-lihuafei1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929094134.99512-1-lihuafei1@huawei.com> References: <20220929094134.99512-1-lihuafei1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.174] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600010.china.huawei.com (7.193.23.86) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220929_024531_948909_3C22DDC0 X-CRM114-Status: GOOD ( 22.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The commit a6253579977e ("arm64: ftrace: consistently handle PLTs.") makes ftrace_make_nop() always validate the 'old' instruction that will be replaced. However, in the mcount-based implementation, ftrace_init_nop() also calls ftrace_make_nop() to do the initialization, and the 'old' target address is MCOUNT_ADDR at this time. with CONFIG_MODULE_PLT support, the distance between MCOUNT_ADDR and callsite may exceed 128M, at which point ftrace_find_callable_addr() will fail because it cannot find an available PLT. We can reproduce this problem by forcing the module to alloc memory away from the kernel: ftrace_test: loading out-of-tree module taints kernel. ftrace: no module PLT for _mcount ------------[ ftrace bug ]------------ ftrace failed to modify [] 0xffff800029180014 actual: 44:00:00:94 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffff80000802eb3c ------------[ cut here ]------------ WARNING: CPU: 3 PID: 157 at kernel/trace/ftrace.c:2120 ftrace_bug+0x94/0x270 Modules linked in: CPU: 3 PID: 157 Comm: insmod Tainted: G O 6.0.0-rc6-00151-gcd722513a189-dirty #22 Hardware name: linux,dummy-virt (DT) pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : ftrace_bug+0x94/0x270 lr : ftrace_bug+0x21c/0x270 sp : ffff80000b2bbaf0 x29: ffff80000b2bbaf0 x28: 0000000000000000 x27: ffff0000c4d38000 x26: 0000000000000001 x25: ffff800009d7e000 x24: ffff0000c4d86e00 x23: 0000000002000000 x22: ffff80000a62b000 x21: ffff8000098ebea8 x20: ffff0000c4d38000 x19: ffff80000aa24158 x18: ffffffffffffffff x17: 0000000000000000 x16: 0a0d2d2d2d2d2d2d x15: ffff800009aa9118 x14: 0000000000000000 x13: 6333626532303830 x12: 3030303866666666 x11: 203a706d61727420 x10: 6465746365707865 x9 : 3362653230383030 x8 : c0000000ffffefff x7 : 0000000000017fe8 x6 : 000000000000bff4 x5 : 0000000000057fa8 x4 : 0000000000000000 x3 : 0000000000000001 x2 : ad2cb14bb5438900 x1 : 0000000000000000 x0 : 0000000000000022 Call trace: ftrace_bug+0x94/0x270 ftrace_process_locs+0x308/0x430 ftrace_module_init+0x44/0x60 load_module+0x15b4/0x1ce8 __do_sys_init_module+0x1ec/0x238 __arm64_sys_init_module+0x24/0x30 invoke_syscall+0x54/0x118 el0_svc_common.constprop.4+0x84/0x100 do_el0_svc+0x3c/0xd0 el0_svc+0x1c/0x50 el0t_64_sync_handler+0x90/0xb8 el0t_64_sync+0x15c/0x160 ---[ end trace 0000000000000000 ]--- ---------test_init----------- In fact, in .init.plt or .plt or both of them, we have the mcount PLT. If we save the mcount PLT entry address, we can determine what the 'old' instruction should be when initializing the nop instruction. Fixes: a6253579977e ("arm64: ftrace: consistently handle PLTs.") Signed-off-by: Li Huafei --- arch/arm64/include/asm/module.h | 7 +++++++ arch/arm64/kernel/ftrace.c | 29 ++++++++++++++++++++++++++++- arch/arm64/kernel/module-plts.c | 16 ++++++++++++++++ arch/arm64/kernel/module.c | 11 +++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/module.h b/arch/arm64/include/asm/module.h index 8096d30c5e39..943d37d66c10 100644 --- a/arch/arm64/include/asm/module.h +++ b/arch/arm64/include/asm/module.h @@ -20,6 +20,11 @@ struct mod_arch_specific { /* for CONFIG_DYNAMIC_FTRACE */ struct plt_entry *ftrace_trampolines; + +#if defined(CONFIG_DYNAMIC_FTRACE) && !defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) + struct plt_entry *mcount_plt_init; + struct plt_entry *mcount_plt; +#endif }; #endif @@ -58,5 +63,7 @@ static inline bool is_forbidden_offset_for_adrp(void *place) } struct plt_entry get_plt_entry(u64 dst, void *pc); +struct plt_entry *find_plt_entry(struct module *mod, const Elf_Shdr *sechdrs, + u64 dest, bool init_sec); #endif /* __ASM_MODULE_H */ diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index ea5dc7c90f46..a61f41fa8e73 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -77,6 +77,17 @@ static struct plt_entry *get_ftrace_plt(struct module *mod, unsigned long addr) return NULL; } +static struct plt_entry *get_mcount_plt(struct module *mod, unsigned long addr, + unsigned long loc) +{ +#if defined(CONFIG_ARM64_MODULE_PLTS) && !defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) + if (addr == MCOUNT_ADDR) + return !within_module_init(loc, mod) ? mod->arch.mcount_plt : + mod->arch.mcount_plt_init; +#endif + return NULL; +} + /* * Find the address the callsite must branch to in order to reach '*addr'. * @@ -127,7 +138,22 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec, if (WARN_ON(!mod)) return false; + plt = get_ftrace_plt(mod, *addr); + if (plt) { + *addr = (unsigned long)plt; + return true; + } + + /* + * For the mcount-based implementation, we might call from + * ftrace_init_nop(), and '*addr' should be MCOUNT_ADDR. We have saved + * the mcount PLT entry address, see module_set_mcount_plt(). So here + * we can still find the appropriate PLT based on whether the 'pc' is + * in the init section or core section to make the 'old' instructions + * that need to be replaced. + */ + plt = get_mcount_plt(mod, *addr, pc); if (!plt) { pr_err("ftrace: no module PLT for %ps\n", (void *)*addr); return false; @@ -209,7 +235,8 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec) #endif /* - * Turn off the call to ftrace_caller() in instrumented function + * Turn off the call to ftrace_caller() in instrumented function, or initialize + * the _mcount call to nop. */ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr) diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c index 5a0a8f552a61..5e553a1bf2a8 100644 --- a/arch/arm64/kernel/module-plts.c +++ b/arch/arm64/kernel/module-plts.c @@ -70,6 +70,22 @@ static bool in_init(const struct module *mod, void *loc) return (u64)loc - (u64)mod->init_layout.base < mod->init_layout.size; } +struct plt_entry *find_plt_entry(struct module *mod, const Elf_Shdr *sechdrs, + u64 dest, bool init_sec) +{ + struct mod_plt_sec *pltsec = !init_sec ? &mod->arch.core : + &mod->arch.init; + struct plt_entry *plts = (struct plt_entry *)sechdrs[pltsec->plt_shndx].sh_addr; + struct plt_entry plt = get_plt_entry(dest, &plt); + int i; + + for (i = 0; i < pltsec->plt_num_entries; i++) + if (plt_entries_equal(&plt, &plts[i])) + return &plts[i]; + + return 0; +} + u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs, void *loc, const Elf64_Rela *rela, Elf64_Sym *sym) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index f2d4bb14bfab..9ed0909e2729 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -520,6 +520,15 @@ static int module_init_ftrace_plt(const Elf_Ehdr *hdr, return 0; } +static void module_set_mcount_plt(const Elf_Shdr *sechdrs, struct module *mod) +{ +#if defined(CONFIG_ARM64_MODULE_PLTS) && defined(CONFIG_DYNAMIC_FTRACE) && \ + !defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) + mod->arch.mcount_plt_init = find_plt_entry(mod, sechdrs, MCOUNT_ADDR, true); + mod->arch.mcount_plt = find_plt_entry(mod, sechdrs, MCOUNT_ADDR, false); +#endif +} + int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *me) @@ -529,5 +538,7 @@ int module_finalize(const Elf_Ehdr *hdr, if (s) apply_alternatives_module((void *)s->sh_addr, s->sh_size); + module_set_mcount_plt(sechdrs, me); + return module_init_ftrace_plt(hdr, sechdrs, me); }