From patchwork Mon Sep 9 06:47:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13795962 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCA6CD4F4C for ; Mon, 9 Sep 2024 06:49:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E5F56B011C; Mon, 9 Sep 2024 02:49:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96FB46B011E; Mon, 9 Sep 2024 02:49:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 810576B011F; Mon, 9 Sep 2024 02:49:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 622C26B011C for ; Mon, 9 Sep 2024 02:49:14 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DFFB4A82B2 for ; Mon, 9 Sep 2024 06:49:13 +0000 (UTC) X-FDA: 82544272986.28.86F4B9E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf22.hostedemail.com (Postfix) with ESMTP id 4972CC000F for ; Mon, 9 Sep 2024 06:49:12 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gE5rHksS; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725864439; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E/8oKQWQ1fglLyTxHETDdJztnkJGSyY84+n1OIbt7tI=; b=A3Ddkksw4FtJr9BoOnkcZUrLpAEcaYi/QpDANNEo26f4YY0IF5JcrDaO0d434ZIBpfV0U9 TXHAiB+ecsQ1XRyVndCPgPAitFslZ0//3n0VXnVT3f/aXts8LkKdBy5PU3bEd5TdvKmYiD HngiSK2VvdX07Y6MKLxwo3/r0oep3r4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725864439; a=rsa-sha256; cv=none; b=sE/4HhLkFd39N3VuHUDMU7Gk27P1RBwiAL6jWnop6RFPurmOMH5Z7Q/yDMH7pZrtxhqxMZ 5zRS+y8G6UlNVpxBDBVSnfTXS9oeLCbznMh0RbffSB9WQbiJ5zmusuYQ0NfnSN9PBIRUXz DJ2OxkY3TJjTWBjHklPnpppLMjIfJBU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gE5rHksS; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 225E9A4272E; Mon, 9 Sep 2024 06:49:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4244C4CECA; Mon, 9 Sep 2024 06:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725864551; bh=X9sfhUFgPK5V3fglnGNo5sHB9wMPevyPr+qKgRxwoik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gE5rHksSDO3uZ8d+BpxC3iCqxZ+t+kYtAmK8ij3ReKzOLwADAXD1KPV81Gv59cLJB QeffyMC9I/10+jXBXTc3t+0L43Q/5LUUYAuSWRRkqMF1qUTuLgE0CHJfsn1QJzpnCc vpbE4JzC9jBNebxwgUnNlq4/NCkpYAMAlNBdq0T9QBn3F+30lZRo0AKiT/LUxF50CU ovqI5rDJnLv1Xkn6214K1cbtBxdD6gx3ThLFeZUH9qVKkVoE+XrXj8aDCwlWIX7+qy pjaJ4YltFeHWHyE9MeOm4kT8zBk9Qw94w2NQP5QJetbV7d9rtaQpBgupHNkhqraFay cord90B6KD2bQ== From: Mike Rapoport To: Andrew Morton Cc: Andreas Larsson , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Brian Cain , Catalin Marinas , Christoph Hellwig , Christophe Leroy , Dave Hansen , Dinh Nguyen , Geert Uytterhoeven , Guo Ren , Helge Deller , Huacai Chen , Ingo Molnar , Johannes Berg , John Paul Adrian Glaubitz , Kent Overstreet , "Liam R. Howlett" , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Mike Rapoport , Oleg Nesterov , Palmer Dabbelt , Peter Zijlstra , Richard Weinberger , Russell King , Song Liu , Stafford Horne , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Uladzislau Rezki , Vineet Gupta , Will Deacon , bpf@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v3 5/8] ftrace: Add swap_func to ftrace_process_locs() Date: Mon, 9 Sep 2024 09:47:27 +0300 Message-ID: <20240909064730.3290724-6-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240909064730.3290724-1-rppt@kernel.org> References: <20240909064730.3290724-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4972CC000F X-Stat-Signature: umn3i4x3hoy8xyg56r9dxx6hx7imoypd X-Rspam-User: X-HE-Tag: 1725864552-552710 X-HE-Meta: U2FsdGVkX1+405CJ+e9Kp7gBi6RNByTO55xhc5UOyhfcK+I3Q7tj4WV5soQlUcaqjFCW3Q0FUCJYAqbg+LkZg7WhjYe8UykDQzvau2bBeZRtq6d5l0CY+VwbuOR/MyxktkMsyQuBjYVnQkigk0f3FhRx86j6Kw61vHmOEwfh8rk1X5Eb4+gqwY4IyW6YO+qnCejg2n0t2upYZUSjslZwzFA88OE2AVrgwq2xpdiQDcNb31WFP5xO/XFSBIM5nyVvu8QhMemuJ0mvLJb6HVF/JhJBj+x5xR2H6v0cCdw97RS0dlQ6OLXnA99LZSyCSq5GETFZ/DWVdBMUXg6tuHSXzwsroQEyy91NLyp+bwgTVAHkc1u7yl5QBpgeN2Gt/EHeqzwwVvCkV8ChJFdpB/rfhaSR4kYQn+ijVAr92exH2EjhkSekYfSF2pU6BT1XaULP5OyLu7czODla4Tua1tP8bQFctydwVPSqw7d2sem6TuRaATnftg0H19bzDOXmCufbLQZNDcBoP0vGR9JYmo+DGulRplusY1aCw+2PQHVNQO9CVDPfeiXQUlCPRij30TDXMPKnjUzK0r34YMKlxSxuCJsoRSebbsU2C+BAxRR6PaXkEtPeOzVf41vqkDXkuYe5optsxldZImQOK2ouP0J+3I1mysmfV3mj+BHwLy/uKLcoZoKbIVzlcyofXpxx4/G+3LvKAplGzULxK8ipID13DGVS/6FNAZ+4QOuy0jY+BxJrSAh7aUVpK565YBETSNJoIalb20nI4T33+5SaD0pcnWLCz0Ltg4seiWbqtiRKD8pJCqR5StcW9CgdvlgvRyw8z0dK4eldPhiDj71rqEACh11xeNgNfc2VYTvx57Isjl/FlLpIkQjz9qSh6MLRUH8zuaj0fQmZ9u6G8/f0PMXLk1n57ckiUpOtJavP0YurvbD4gmAXCucWgfvJT5wkFpag3PhC60K82qO1DR5/dhe iumIfurA pX195OkMIgP3gP/qvuaEJvgAhevIKlLyLlW4kSqaw0qeWdTTYamO2FLoBUahkw3RmvkRv/lFeB1V1I6FmFVy4vgu5PhHUfl/7oyKqPw7/ADfbBcgd+y3jEuntzNlu17blR6ouBbIzttGPiDkgOBtgvtGa4FUYdwbKZNnEAIiqvn48QrGcgczEBT6N4hGZfH6uJg16Jlh4M3Vn70aZzlxOFvAhDyO6Dty6OxUPzASVL0Z35Wy/uog4lIwnrY8eFFasWVBXLm+Jz5oLIbAPo6kYc5aHcQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Song Liu ftrace_process_locs sorts module mcount, which is inside RO memory. Add a ftrace_swap_func so that archs can use RO-memory-poke function to do the sorting. Signed-off-by: Song Liu Signed-off-by: Mike Rapoport (Microsoft) --- include/linux/ftrace.h | 2 ++ kernel/trace/ftrace.c | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index fd5e84d0ec47..b794dcb7cae8 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -1188,4 +1188,6 @@ unsigned long arch_syscall_addr(int nr); #endif /* CONFIG_FTRACE_SYSCALLS */ +void ftrace_swap_func(void *a, void *b, int n); + #endif /* _LINUX_FTRACE_H */ diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 4c28dd177ca6..95bb9b52ab36 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6989,6 +6989,23 @@ static void test_is_sorted(unsigned long *start, unsigned long count) } #endif +/* + * ftrace_process_locs sorts module mcount, which might be inside RO + * memory. + * ftrace_swap_func allows architectures to use RO-memory-poke function to + * do the sorting. + */ +void __weak ftrace_swap_func(void *a, void *b, int n) +{ + unsigned long t; + + WARN_ON_ONCE(n != sizeof(t)); + + t = *((unsigned long *)a); + *(unsigned long *)a = *(unsigned long *)b; + *(unsigned long *)b = t; +} + static int ftrace_process_locs(struct module *mod, unsigned long *start, unsigned long *end) @@ -7016,7 +7033,7 @@ static int ftrace_process_locs(struct module *mod, */ if (!IS_ENABLED(CONFIG_BUILDTIME_MCOUNT_SORT) || mod) { sort(start, count, sizeof(*start), - ftrace_cmp_ips, NULL); + ftrace_cmp_ips, ftrace_swap_func); } else { test_is_sorted(start, count); }