From patchwork Fri Nov 11 17:11:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040637 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 6438DC433FE for ; Fri, 11 Nov 2022 17:25:02 +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=IhBmW5wIRMCoj1X3Qn00+m0kMQV2Am1dpi3VUIsDB8I=; b=tonEgVYINFZktc gZgwL9b3rlo5nIvkY69R+AP0oSGIOneD6sABnz+jZTNNPH1WUdt+Zn5WnfrF4hODVEZ+Xn0sUzbHW 2oPSTI5CIa/MWEpmjJ1MaKIPHeySBqE8pfGZ68mYJ/srC7lutqHXCd5S6BsPQ1Nj6YAOVhFiCYGoj eBvAt9AOzZLYDhXAHtBT4daO2udoiHML5UcvuEBD/77wNHGLkm+9VqdexrIp7OUiCUdpeS+EmJWnv 7meWNKAWFbLBERKAn7nU9xiYaoBGeG7sxH5VHjIXEtSot/JjnY4JzB5byDvcPLRS6XtDPPmS0jK8r bB4GT6VbsCpe7p9wiIWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXks-00HDfD-31; Fri, 11 Nov 2022 17:23:50 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXaO-00H7q4-BZ for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:13:02 +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 D7A50B82681; Fri, 11 Nov 2022 17:12:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4EAAC43143; Fri, 11 Nov 2022 17:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186777; bh=XcCalZgDu8W95+sS2ba5T6FJRehgpS6pDpztbl7asjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2OAGUM0oATDTDEa8yCEkMODhj+XAlTX7PL3vW2QU2nE9RwZXMm8PFIE6h1cSoShx Jmyza6lPX0Rp7CH6WU2byQTS2/T42QyKE3i0xDJZesopc9veOigi0xiy6nIO4IfXrZ FALsFWVFN8K9GMZiyrRjUSIO0Q/0b+7f2BqRXIqXpOPgxDxRk/aAY3Byqu4Dwc16ds 5fld2Ga3vdKGBCXiN05WsFPJEsPqIM3HS2Bb59IoyFhg1X8Y/lF9MHgYhJ8FGHbUpH gMBdF8W8w3LcGEG5W1etRtY7pTyDtxzKPcxT/F4gUMRqF8iS1xEiJlvRlZBhj+TKgf qxiNnuDp9tqIg== 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 17/33] arm64: idreg-override: Move to early mini C runtime Date: Fri, 11 Nov 2022 18:11:45 +0100 Message-Id: <20221111171201.2088501-18-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=6084; i=ardb@kernel.org; h=from:subject; bh=XcCalZgDu8W95+sS2ba5T6FJRehgpS6pDpztbl7asjk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboJFWD4sbYsFJ+cz2RpVyDwFbJ3WDantu4xZXnCF 5ggeV7uJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CRQAKCRDDTyI5ktmPJJhIC/ wNnBABmYHGxvJ9BqRzmL4Cvc5x7aWjegs+7MhOK4YZHaOSB0QLN6ZLSIgnlbhNLAlHBytCNPg5MVSZ +2pSy7yoXgGX8InKAN/L2Dai/vr0c0TstUyMKtfRSDCPomuRbyoJEp0J0Pm1KpVfuq/DMtiMK7I9Jh El9qWQQ7hJf2bGajiJpaywUhQmVIgSPIAskhXi1+hoE4Z5wn2FYjybh3Q+n4DzrviHd4vjoRg8DDaz R0uUtWXAk0D8/U3BX1JL02ca+zbziyXPl5xHWdX1mtQTCQhjUw83qZXijTy8Fhr4pDYfdQei4EwPlM wMbGMzOonCvbhlfTM4eS9iKFPmXd+xcMklAT+g6Zj3/NGG/S4ylcHUC6lP2qiZyN1RU8Dp6+gBH+rj KNyFRFHMi6bEPGlmABhySbeHuXoUeUtxN4yWT+Q9D2qBF7+g7OdDGLHl9jQQsVgGyRdJmaNPlm2MwG HIel2uLmC12fRbshtrju3omCJtJfHzkltyOv6Bixgp0jg= 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_091300_755564_02D3DB13 X-CRM114-Status: GOOD ( 16.33 ) 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 want to parse the ID register overrides even earlier, so that we can take them into account before creating the kernel mapping. So migrate the code and make it work in the context of the early C runtime. We will move the invocation to an earlier stage in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/Makefile | 4 +--- arch/arm64/kernel/head.S | 5 ++-- arch/arm64/kernel/image-vars.h | 10 ++++++++ arch/arm64/kernel/pi/Makefile | 5 ++-- arch/arm64/kernel/{ => pi}/idreg-override.c | 24 +++++++++++--------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index a8717865fee5c296..2b003834c320c20e 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -33,8 +33,7 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ smp.o smp_spin_table.o topology.o smccc-call.o \ - syscall.o proton-pack.o idreg-override.o idle.o \ - patching.o + syscall.o proton-pack.o idle.o patching.o pi/ targets += efi-entry.o @@ -65,7 +64,6 @@ obj-$(CONFIG_ACPI) += acpi.o obj-$(CONFIG_ACPI_NUMA) += acpi_numa.o obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o obj-$(CONFIG_PARAVIRT) += paravirt.o -obj-$(CONFIG_RELOCATABLE) += pi/ obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o obj-$(CONFIG_ELF_CORE) += elfcore.o diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 998a3e066b2fdf0a..786b7bd79a4026e9 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -458,10 +458,9 @@ SYM_FUNC_START_LOCAL(__primary_switched) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif - mov x0, x21 // pass FDT address in x0 - bl early_fdt_map // Try mapping the FDT early mov x0, x20 // pass the full boot status - bl init_feature_override // Parse cpu feature overrides + mov x1, x22 // pass the low FDT mapping + bl __pi_init_feature_override // Parse cpu feature overrides #ifdef CONFIG_UNWIND_PATCH_PAC_INTO_SCS bl scs_patch_vmlinux #endif diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 8151412653de209c..6ff6efbc1ce98ba6 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -41,6 +41,16 @@ PROVIDE(__pi___memcpy = __pi_memcpy); PROVIDE(__pi___memmove = __pi_memmove); PROVIDE(__pi___memset = __pi_memset); +PROVIDE(__pi_id_aa64isar1_override = id_aa64isar1_override); +PROVIDE(__pi_id_aa64isar2_override = id_aa64isar2_override); +PROVIDE(__pi_id_aa64mmfr1_override = id_aa64mmfr1_override); +PROVIDE(__pi_id_aa64pfr0_override = id_aa64pfr0_override); +PROVIDE(__pi_id_aa64pfr1_override = id_aa64pfr1_override); +PROVIDE(__pi_id_aa64smfr0_override = id_aa64smfr0_override); +PROVIDE(__pi_id_aa64zfr0_override = id_aa64zfr0_override); +PROVIDE(__pi_arm64_sw_feature_override = arm64_sw_feature_override); +PROVIDE(__pi__ctype = _ctype); + #ifdef CONFIG_KVM /* diff --git a/arch/arm64/kernel/pi/Makefile b/arch/arm64/kernel/pi/Makefile index e046c10606cb822e..47d3ffcff3ac9a03 100644 --- a/arch/arm64/kernel/pi/Makefile +++ b/arch/arm64/kernel/pi/Makefile @@ -38,6 +38,7 @@ $(obj)/lib-%.pi.o: OBJCOPYFLAGS += --prefix-alloc-sections=.init $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(call if_changed_rule,cc_o_c) -obj-y := relocate.pi.o -obj-$(CONFIG_RANDOMIZE_BASE) += kaslr_early.pi.o lib-fdt.pi.o lib-fdt_ro.pi.o +obj-y := idreg-override.pi.o lib-fdt.pi.o lib-fdt_ro.pi.o +obj-$(CONFIG_RELOCATABLE) += relocate.pi.o +obj-$(CONFIG_RANDOMIZE_BASE) += kaslr_early.pi.o extra-y := $(patsubst %.pi.o,%.o,$(obj-y)) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c similarity index 95% rename from arch/arm64/kernel/idreg-override.c rename to arch/arm64/kernel/pi/idreg-override.c index 7e3eb48f5c83d539..86d994424779bc0d 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -294,16 +294,11 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) } while (1); } -static __init const u8 *get_bootargs_cmdline(void) +static __init const u8 *get_bootargs_cmdline(const void *fdt) { const u8 *prop; - void *fdt; int node; - fdt = get_early_fdt_ptr(); - if (!fdt) - return NULL; - node = fdt_path_offset(fdt, "/chosen"); if (node < 0) return NULL; @@ -315,9 +310,9 @@ static __init const u8 *get_bootargs_cmdline(void) return strlen(prop) ? prop : NULL; } -static __init void parse_cmdline(void) +static __init void parse_cmdline(const void *fdt) { - const u8 *prop = get_bootargs_cmdline(); + const u8 *prop = get_bootargs_cmdline(fdt); if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop) __parse_cmdline(CONFIG_CMDLINE, true); @@ -327,9 +322,9 @@ static __init void parse_cmdline(void) } /* Keep checkers quiet */ -void init_feature_override(u64 boot_status); +void init_feature_override(u64 boot_status, const void *fdt); -asmlinkage void __init init_feature_override(u64 boot_status) +asmlinkage void __init init_feature_override(u64 boot_status, const void *fdt) { int i; @@ -340,7 +335,7 @@ asmlinkage void __init init_feature_override(u64 boot_status) __boot_status = boot_status; - parse_cmdline(); + parse_cmdline(fdt); for (i = 0; i < ARRAY_SIZE(regs); i++) { dcache_clean_inval_poc((unsigned long)reg_override(i), @@ -348,3 +343,10 @@ asmlinkage void __init init_feature_override(u64 boot_status) sizeof(struct arm64_ftr_override)); } } + +char * __init skip_spaces(const char *str) +{ + while (isspace(*str)) + ++str; + return (char *)str; +}