From patchwork Tue Jan 23 14:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527718 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 3FA3CC47258 for ; Tue, 23 Jan 2024 16:01:00 +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=HRqhzlevYNdvjTvnX8jZxSntVkCSCri3fWhqSr262OU=; b=puiqPFs6GjZLkJDtJTOSTqB0MW l14FmXA0f8bxt2DzPr9nyCBupAuOiYAsPE3x/FU7UVXLoxJ0nk0goc/w/jPgbAk6FZ0VVg8NG0/WN lz91WvmUnYIbA5CCvDjtVD4POuGmDBoGd9Zmc4Rx8jpIa/11VwmO3CWqWzZe6ImO+AC65HJ2Z3KP5 aWiGlqIKFaRHFMaCfarw/nBCBzAlS8UPQOoD6vyHKFx7YD5zbF3BwdomRv2b1e1g/hhPNbMwFDTY5 0aZodIPA0XvKHN/BxxMOrbsLjilCnyGnbTySlcMhnR2aUIcwymvcdSx8gAgguw0I4hiHNcptR2Zs1 S9LHdEeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSJCQ-00HAqT-0N; Tue, 23 Jan 2024 16:00:30 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIAq-00Gtj7-0X for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:54:50 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc223d528cfso6626754276.0 for ; Tue, 23 Jan 2024 06:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021687; x=1706626487; 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=12uRlojCIuYdKr6dT1QfLTLFhbPXNVqaaRvgxwtReCo=; b=YFSNAblgu08pPOEvxRNGjJHXcFBhGc+PF3Sjb757JcpIiob55TXtbdZvodrE7q3WAg 3UFIRzPdHBvc8eQYbWLbRyHvQL2eKtrhXmb9FoEaAq6Znt/cmm4fIJmDgYvpjr2bZ/b6 5Dh6UxSKXsPR19supr9aTKgCb+LbhagXUEtXOuIrAt3z47XuYcFV8VpeD62JKUD2Qs3X seOH4mwgP/tdHSxMnIjSeP+zcBwWiNm58eXOb1h8fYhor+KzZaOiBoaeDiQaEZENnJTR T46Fv85yfieMp/BOn1ojW/jqCHudEzkLgyV44cdZ1d4o50Jp6vnCUpbn5CdVqlEsjw7C sXkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021687; x=1706626487; 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=12uRlojCIuYdKr6dT1QfLTLFhbPXNVqaaRvgxwtReCo=; b=Ju4dDwzoXf2jE9Wh3qtSYHBmpGr+3NR8OTQZ40gINXAjubehpvwNFIVss/0A5L5PSM x1m9wYer7aDWHW3SMe6WHnRtsA5wHhM6Uu3NS6aAQ9b8YFLLIxuwImCZ/znqgoxjMn+Z f+vZ4NyVK1I670CLxRQ6Oij1+92JzSo2pUn8PpQKqNW8hnhFAASxpJ00p0l/SSD0Cqe3 7Ql8mCn8epRhn6yClQIqwl1cOKLSb6H0ql2FNJP3FoMVNOE3/5TgOTwdrJPTE3zBVS2R ZevgDJtN2RUnfyb4QPdQ+MjmCVNd8XE/4bRQEqoKb++CJvr9xYndZAIh63cmn/VIQQPX Eq5g== X-Gm-Message-State: AOJu0YxE5BKphfkOLhFMSNyC5xtXGJdVC9gSkgZ1sESNN+6hGRJ54a5u 85NPgw/7fTQD6qIuorFtXIvz759oheMSag77eHXO9t6V6qzR1/4YcFrQnQaQiE+1XUNg/L99jYM ooOZsAvQOaJTeA95qJpgEs+mwBtjXuYYKRVkneEJKfODlFEldAiUyHd3dQNoY7WRD9U2UL9wkRE 28+TqeZALMTMh2k/5oyXewiOzEypaNrVgqa7oiQfLk X-Google-Smtp-Source: AGHT+IEqSj+e4CWddv0Zv31thGIYPIQZTrseG42Gi+gq+ZgFTNKjV+1+58JZzZpdt5ns36g+XvN5VaW5 X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:a8c:b0:dc2:65e9:6a35 with SMTP id cd12-20020a0569020a8c00b00dc265e96a35mr2594822ybb.4.1706021687204; Tue, 23 Jan 2024 06:54:47 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:10 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6698; i=ardb@kernel.org; h=from:subject; bh=5dZBKPpsAfolZRpZ7v54Gy8vlDdggwgRtcVwD8tvCcA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pWveyvfuvb9e6Gs17/W8B8+6pS93/zbx23PM/L2qk nyVdo55RykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIisOMDGd9k/LXBtwI46jb 875aPrL6ZPD/266PJlxaKGmVnhXpp8XIcLktI/CinUhjy/tpwhysB8rz2KO2+gQLParu7/tUO3s JIwA= X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-63-ardb+git@google.com> Subject: [PATCH v7 11/50] arm64: idreg-override: Move to early mini C runtime 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-20240123_065448_229312_04AD4371 X-CRM114-Status: GOOD ( 17.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 From: Ard Biesheuvel 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 | 9 +++++ arch/arm64/kernel/pi/Makefile | 5 +-- arch/arm64/kernel/{ => pi}/idreg-override.c | 35 +++++++++----------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 84db82cf6ba8..649efbbf0225 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/ obj-$(CONFIG_COMPAT) += sys32.o signal32.o \ sys_compat.o @@ -57,7 +56,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 a8fa64fc30d7..ca5e5fbefcd3 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -510,10 +510,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 e931ce078a00..eacc3d167733 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -37,6 +37,15 @@ PROVIDE(__pi___memmove = __pi_memmove); PROVIDE(__pi___memset = __pi_memset); PROVIDE(__pi_vabits_actual = vabits_actual); +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 d084c1dcf416..7f6dfce893c3 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 93% rename from arch/arm64/kernel/idreg-override.c rename to arch/arm64/kernel/pi/idreg-override.c index e30fd9e32ef3..f9e05c10faab 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -14,6 +14,8 @@ #include #include +#include "pi.h" + #define FTR_DESC_NAME_LEN 20 #define FTR_DESC_FIELD_LEN 10 #define FTR_ALIAS_NAME_LEN 30 @@ -21,15 +23,6 @@ static u64 __boot_status __initdata; -// temporary __prel64 related definitions -// to be removed when this code is moved under pi/ - -#define __prel64_initconst __initconst - -#define PREL64(type, name) union { type *name; } - -#define prel64_pointer(__d) (__d) - typedef bool filter_t(u64 val); struct ftr_set_desc { @@ -313,16 +306,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; @@ -334,9 +322,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); @@ -346,9 +334,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) { struct arm64_ftr_override *override; const struct ftr_set_desc *reg; @@ -364,7 +352,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++) { reg = prel64_pointer(regs[i].reg); @@ -373,3 +361,10 @@ asmlinkage void __init init_feature_override(u64 boot_status) (unsigned long)(override + 1)); } } + +char * __init skip_spaces(const char *str) +{ + while (isspace(*str)) + ++str; + return (char *)str; +}