From patchwork Fri Nov 11 17:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040627 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 B1F60C4332F for ; Fri, 11 Nov 2022 17:16:48 +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=C0pbF1h7/iB2P7a5JjbQA4s5kqHT8mOLxldA8U0HWXU=; b=okH5V7gIwF9jrZ L/akxypNG3QZ2kZK4+oWiAJEP9Md/bmIwroycQJEljTf9aOImFnvkzTqeuDtZu1x8Ud2uoZSN0/WL 2dPu5FsxJyPMgH41Lw3R2PcZP+AIETuae6U98prWvhGgdIRw2PVYQfHv56f5YwtGm5U9FY/G0oYBm lJGQvT6hOs31whbgVlgiSkemcgB6yphP9bWylske5IEYzb9uM0IDu+aQR/J6KkTDjRedr0C6VtkE7 ujrBjo5SRFc199V/jL4IzeFFRGG22b7Hpe1G3RFLB/YHGixR5IsAkYV2xGEERbqpbjH4cfYrbrHg9 qOvV0hO/9iuQtMIBF/Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXd2-00H9IL-TJ; Fri, 11 Nov 2022 17:15:45 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXa1-00H7bO-CS for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:12:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DB263B8266E; Fri, 11 Nov 2022 17:12:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC78FC4347C; Fri, 11 Nov 2022 17:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186754; bh=wcHghYDG8a1xGzC6B9oPbu4QgDzp6nE0raGQNLcDOmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqjjZjJ5oNf+wmSHfLkwZk0F+w6vmqLYZZWXUBmdduxEk/xWhjxEQuryhiADCrIm1 CnF4QIHaRE3a6ZR1yZG4Ovk86D3Np7D+wFYLfhF/CPZyYWwepDfPm+2lL8djn45rj7 yByUxr/wc/B88BlMzoWXG0gNlBPef1Ljr6MNYpxHsWFBcUZUN+ZP3zgJO35GmziQIq 3vb1OJZlZfZeiig4cBmJEfRzamV6Z+Ti/pK8+7TutVN4Hy/2Lu0EGFVPCwbvLi9V2V TwuRxOpwdVdJt9RMseeApaFQZyUNFm8v3S4ttfP1zR9D4cSb1JOg0PnV4ECuxg+8/T Dx9sPjAKsF2sQ== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v7 07/33] arm64: kernel: Don't rely on objcopy to make code under pi/ __init Date: Fri, 11 Nov 2022 18:11:35 +0100 Message-Id: <20221111171201.2088501-8-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org> References: <20221111171201.2088501-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3191; i=ardb@kernel.org; h=from:subject; bh=wcHghYDG8a1xGzC6B9oPbu4QgDzp6nE0raGQNLcDOmA=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboI0oB7buSyROeyNn4l+9zAXktPfPP4iGyVDR3qM Ysr6NxqJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CNAAKCRDDTyI5ktmPJHyiDA C6K1kep2IvhWjqB2tuKkwRFnfBt1FZwhzEqp1P8mnN6asEPOYGRF/64OKrbSQqbx1cZYmDFVuXYE+T SOfsnM393PTo7IbaXhkxul7ae6X6Lv7BiQeD83pOFk62Y3vEpxpNdExJltNSKM1UJsYgPbcR6xrZSE q1ZZzu/VHStmbzGYjFM+WWx6sW5wy0bKmXPh+Y5NcwT5+SQXbpyZU+UQqrjhal5itl8Up/DWtIwFXu AuSNmRYp2Q/zYwlSD03Q41lb0XDmYBqbKsFzFg8niRVCsscQDzmbcmsO3tFaUMxIz7lMD7FhQQM7AV 9SONCmZPisoeRER9yDR/BmgtT+hI7z0xYH0MWAeggxM3lOjsy6jeeepc7JMX73FEIg871WdwubELTq Y2JMA3YlcMAFcKfhPMSFjsuqiWTsU+Tq/hiqYeQzr8OXDdmPedsTv8eoYo228gP8VPZOTVkhZ8rYLU N6gG1mfZY03eia6BaKRWEEIdNX05H6819/L1FBvJ8AWXc= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221111_091237_764204_2FD59073 X-CRM114-Status: GOOD ( 13.80 ) 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 We will add some code under pi/ that contains global variables that should not end up in __initdata, as they will not be writable via the initial ID map. So only rely on objcopy for making the libfdt code __init, and use explicit annotations for the rest. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/pi/Makefile | 6 ++++-- arch/arm64/kernel/pi/kaslr_early.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/pi/Makefile b/arch/arm64/kernel/pi/Makefile index 810fdae897601e88..8aaf7cbac359ecdb 100644 --- a/arch/arm64/kernel/pi/Makefile +++ b/arch/arm64/kernel/pi/Makefile @@ -28,11 +28,13 @@ quiet_cmd_piobjcopy = $(quiet_cmd_objcopy) cmd_piobjcopy = $(obj)/relacheck $< && $(cmd_objcopy) $(obj)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_ \ - --remove-section=.note.gnu.property \ - --prefix-alloc-sections=.init + --remove-section=.note.gnu.property $(obj)/%.pi.o: $(obj)/%.o $(obj)/relacheck FORCE $(call if_changed,piobjcopy) +# ensure that all the lib- code ends up as __init code and data +$(obj)/lib-%.pi.o: OBJCOPYFLAGS += --prefix-alloc-sections=.init + $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(call if_changed_rule,cc_o_c) diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index 17bff6e399e46b0b..86ae0273c95016c6 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -16,7 +16,7 @@ #include /* taken from lib/string.c */ -static char *__strstr(const char *s1, const char *s2) +static char *__init __strstr(const char *s1, const char *s2) { size_t l1, l2; @@ -32,7 +32,7 @@ static char *__strstr(const char *s1, const char *s2) } return NULL; } -static bool cmdline_contains_nokaslr(const u8 *cmdline) +static bool __init cmdline_contains_nokaslr(const u8 *cmdline) { const u8 *str; @@ -40,7 +40,7 @@ static bool cmdline_contains_nokaslr(const u8 *cmdline) return str == cmdline || (str > cmdline && *(str - 1) == ' '); } -static bool is_kaslr_disabled_cmdline(void *fdt) +static bool __init is_kaslr_disabled_cmdline(void *fdt) { if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { int node; @@ -66,17 +66,19 @@ static bool is_kaslr_disabled_cmdline(void *fdt) return cmdline_contains_nokaslr(CONFIG_CMDLINE); } -static u64 get_kaslr_seed(void *fdt) +static u64 __init get_kaslr_seed(void *fdt) { + static char const chosen_str[] __initconst = "chosen"; + static char const seed_str[] __initconst = "kaslr-seed"; int node, len; fdt64_t *prop; u64 ret; - node = fdt_path_offset(fdt, "/chosen"); + node = fdt_path_offset(fdt, chosen_str); if (node < 0) return 0; - prop = fdt_getprop_w(fdt, node, "kaslr-seed", &len); + prop = fdt_getprop_w(fdt, node, seed_str, &len); if (!prop || len != sizeof(u64)) return 0; @@ -85,7 +87,7 @@ static u64 get_kaslr_seed(void *fdt) return ret; } -asmlinkage u64 kaslr_early_init(void *fdt) +asmlinkage u64 __init kaslr_early_init(void *fdt) { u64 seed;