From patchwork Wed Feb 14 12:28:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13556405 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 DA456C48BC1 for ; Wed, 14 Feb 2024 12:30:04 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=g33TRjpATMrD8lKMbrafI2FBwbCvsXE0gxQACk0lmGE=; b=rgzJfiK4Tppmx+/xBt6YJfXv6X 80PrenmR1za8R5T0eDw2mS6GpTokbBLmvdOARla9ubocwhPgyUZ7+1/QD7si6uY2BxHBrs/0rnII+ y0XiQoGBGz4diJprGKWF5ZXS6kl04Dl2yiRtE/aZ6jhS+i0ni0ujV90NNE9OfCxd3zjPK0c/WxRYh 2FdYYLti3/3IHVMLFt+pe2FYRkLJWcG/Y/cSCRkCzr+zDNiT7IFROBg2IZ1RZULkV0ngvspxsYQ9a /db2J3PQcOAUcmT/aRl7Xjp+koEF21zaSDpcJa05l9J5t31/0tiaVq3Wsu6C2ilpQjh/+1r4+mpIN 4AWn7K0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEOg-0000000CoHc-183R; Wed, 14 Feb 2024 12:29:54 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEOb-0000000CoDh-0s6Q for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 12:29:50 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-60753c3fab9so9177687b3.0 for ; Wed, 14 Feb 2024 04:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707913783; x=1708518583; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9CXAuLDgkE8EWQF/CV7t6ppGf8UwbT1/5PU84QU+uYE=; b=0csPODYbDWsflOMnhYSa9+nQikPHo7Zsts2FbbAWy+tJcwULPw8XxqGDgOCl1h1Lnh iwGu6OGcIjMD3cBIGWq+0cw/ZK73woUWTNx0kbAF4uMToXvcshVBSuYkc13JEkbHWbS4 +ULDIEwm4dtG8Lxba3Gpts/s0UIhDH41Iqf59NvFUHg9SDgwXXo8t88PxrcDDV5275mB H93zxIAxrQIEJEblyQ9tJyCNrBAEZx1MEAyPo/al2W12f9evy5C/tSpi2wh+4XE/Iqya akSAf2XdLfDbAotw9YP0IGSvbljTiNw5g+LcJKNJi77cH3yJGqzF7mMbeF8mt/umtId+ 7TkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707913783; x=1708518583; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9CXAuLDgkE8EWQF/CV7t6ppGf8UwbT1/5PU84QU+uYE=; b=j4C1Yi3n9IV4U5ylWXUnR8Cjq3w36i6Ru8uRRniZTImVd8A2jYHLqighta5mSuSDuO U0xh8Qw9mz/u4OAuk9aOrDJF7AsrDpPhLvO10M3DuJrKSOV7KUy7kylr6LPqk1h0++6V tOnepIfH+iLvrkgenvg+JY/aKTrKq5fNH+E2Ychi1plYCPukw5vTEETIvON+j70yI6C1 7uEybZaUa+kUbj/MeODX2PNDhgqOi7q2kLtYDvNUID3g3bTYfDY4G5tVvxtcFJHq3Chz NMoSAds4feIU678a6+oLeb43MNRXmIaLXCbVTonnkI06LWYsexQ5Kpy3TIDzVFsLEH2M lxKQ== X-Gm-Message-State: AOJu0Yw5vewhJyYuT0MmXe6wEHmrdswCKL4p6MJ3RgHFzwiW5lyo46oF HwsE7qIz6MN87/3ZTVtVw6d4+dJrnYKD2JSbCg4pqF+B88OyxEPKl/LcmTgpZ2JJI5xjOcSN3bM YozNrHmysQWb1XIB18iiHPiN1CzHs8NaUPTG91HNFl31CONyfPTkatRGpwsHakdCjinQLEHurOq FYnOQnYOEHJfgiHLgNGhz35bbAnUrvSFvWnUIDmutt X-Google-Smtp-Source: AGHT+IGSL7fmZPv+yVFJ/uwrxJPct0aIUZHbdTtaVWJ15ms+FsnCFKtHJ6Amo/l9SU4rjrbmFGIGJTvl X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:6cd8:0:b0:604:982c:3c26 with SMTP id h207-20020a816cd8000000b00604982c3c26mr337239ywc.3.1707913783476; Wed, 14 Feb 2024 04:29:43 -0800 (PST) Date: Wed, 14 Feb 2024 13:28:48 +0100 In-Reply-To: <20240214122845.2033971-45-ardb+git@google.com> Mime-Version: 1.0 References: <20240214122845.2033971-45-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3211; i=ardb@kernel.org; h=from:subject; bh=GT9VZCUTsUkmFmQ4vnPkMl0fh4kY3gseXy8jPjS7OR4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXMJoakydIMDCVy1+Rycy2ubxO7/nLriRTdd6w5T14Hr 8xYa9jWUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACai+pGR4ePN2fPbXa535q76 HMnZc9lj8YPcDS/3mEWsMnSMWPYuYxkjQ1/6uQeScwq+dT/9dGSj3Nt9Torvvb4+KVK+/Ol19LW TV/gB X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214122845.2033971-47-ardb+git@google.com> Subject: [PATCH v8 02/43] arm64: kernel: Don't rely on objcopy to make code under pi/ __init From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_042949_334300_C33621A8 X-CRM114-Status: GOOD ( 12.93 ) 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 From: Ard Biesheuvel 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 bc32a431fe35..2bbe866417d4 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 = $(cmd_objcopy) && $(obj)/relacheck $(@) $(<) $(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 b9e0bb4bc6a9..167081b30a15 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -17,7 +17,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; @@ -33,7 +33,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; @@ -41,7 +41,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; @@ -67,17 +67,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; @@ -86,7 +88,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, range;