From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AFA4606A31A for ; Tue, 1 Dec 2026 01:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kjRt94IQ; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lsuHpEDt DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=9gZUsZMi7XC4A995GRsc1XNFDdgSXUU4PIkIX+r3ABA=; b=kjRt94IQkmDV16 KOkbLNPu9INOaGm+Nc/jAE+oEFjyivvL20K8zQ4LlAyBKqeXsc9SJ86boIxRG+hsp70dziieOwgOn v7OLorUodfSLIbcgv7yj9c8o2NIgCXU2t2cbe5Elxj31tqx6vgieQbtfWHPdkTPCP2lNzP2kY9bwp Gr/+ixhNroN/AyieDnRBgve/BwUZbTbcuLMZnri4SIZucPdq1NwAEbLb8xWk64p1DQEiWFYLoFpgS wvkh1QITan2KGCl8jEIDeiP/8oQHKFDmtrrQli6R6kLmq5rh0lwcPWPRyVHQJnrLmGJ9HIYdRb/hb oNqFase6O/b/wc/zCvgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD4F-00000006EH4-3WXx; Tue, 01 Dec 2026 01:54:03 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD3Y-00000006Dh9-14GY for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 01:53:30 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso100153195e9.3 for ; Mon, 30 Nov 2026 17:53:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796089998; x=1796694798; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9gZUsZMi7XC4A995GRsc1XNFDdgSXUU4PIkIX+r3ABA=; b=lsuHpEDtyog4332vQHVZidQ641u1UXludaZDr25JRbHeU8GgRbGFMnADGJL5TDHklc /3cquLeJSrc+B6bYDkORArBK4toluINP4yPmtc4cWS0bL1Cml6iCHVCquvOAiy1uM5eA gRqS0PpWCED9IJRYg8LFF9fH2UMXuvXDBS4phUF2vQqlb849ik4B9H7p9grKZGtqlJea PGuv+6bsfx7JLJv3smn0EzhehoSLanNrC+DA2jod0/CTGYUm5VcR0DnY3egAna4TCK/W cE4h7VRiK8BiH04+ajIGSacgGr32xtqUJx/yss9VCntuipKUoKzSUgJkgbTMJL44Mjj7 KmLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796089998; x=1796694798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9gZUsZMi7XC4A995GRsc1XNFDdgSXUU4PIkIX+r3ABA=; b=g/eBLGWZYQDU7UPkCdzyOyDjS6Vog53G8K+H/clSrUEG7CJ4aaufItXXKaQVpv4Azr 5yPEFtgwDhLCXTSfBuSrh2qQT9ybygWStueclC0VhpZJIEeSCpxzDokpJeqL9qT1Z/WB qnWf6Squf/00cXPGcMdLZ/1TfpZOSJwbPKrwtTCA/EtwJINJzrPKODi7dIrHAIAPYCXI uRvHoUlhCR9hHW19vjlSgbabmWkG/oYgVnThUw58DPN9+U6GIHKGD+k9Ug2ZM7VSY1Iq nP0iYH7Gi54lgWN6nPHG0vbG6QkTaTZJodHZCgH3gJYwg079krOscsvAelOoB7gMN00c xlsw== X-Gm-Message-State: APuU4Z/4OqMCn+Z8xnlZWpNlt1i9K3A7u1zFTC5trmR9ZsL6bFnhP7II 57x7zSpQVaxVZuZIQBILgyi8acONFyOg7FgaXZv1GrRufEpRbYfV/iHOeFKWPPTlGVk4PKoP X-Gm-Gg: AZFdTZfuPYBK0c6MYhv/TaMyFF9Pv79KjIM60xMCn2NvQTaTxlPHso1vuvUIpP9P4Zr TUksQW4HBjNmYNPetbfLLNkGx2jzU6GPc2dM6no31iWqnOCuk0Uu2a8Wmvc3JBdO/zblXU+F/9V tCxC8NZPb7MBlRr/4NvV0gotXeQcoNOd8No8wm4xZk5ouoyjmTckITQjfPuvKyPhVuIlj7b4vkM KmKtaDcJ1ZzuJr8HmmSGiUGHG8d2gvp1oqA3tWkcuTY8I+mSbBeZRH4vU0N3kX9RpGBUotwNXq8 qRdTRY7H7p5aXgtWjIxLhr+EziigSYzRgDzXIad/U3LgWYLwNUhGh/HdOujm4dIIp0mN6MBeX1l vqeVDqxZZMFvQA355FLmzOpvMEB4b6rhdE3mhhoEQLH9F3gNYfbaT/MBuYQ9Cfzy9Z2s5JEswPz 6O4RCFQ9I/40EAxiV1oMlR/GxzWPxoV0YgpC9WGXCy2VrKlCXUf1/GqDcVJSIyFgzXwkr8mcmxJ lISoY3xnq8BT+oJX79WBB7nfSBd8aYSe0blLbS12bYl7FG29V0s/EdaDcC7lux5e3GqFSum3XEW so4a72Vd23mVhlyJHhN2BJki0s7Bu5wKgGlfBQ== X-Received: by 2002:a05:600c:4f07:b0:4bb:5dbf:af06 with SMTP id 5b1f17b1804b1-4bb88804d58mr806651915e9.9.1796089998301; Mon, 30 Nov 2026 17:53:18 -0800 (PST) Received: from NULL.Home.net ([2001:8a0:7280:4000:12d:c3b9:cecc:8966]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884911e3sm1199037055e9.6.2026.11.30.17.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 17:53:17 -0800 (PST) From: Eric Curtin To: linux-arm-kernel@lists.infradead.org Cc: Ryan Roberts , Catalin Marinas , Will Deacon , Mark Rutland Subject: [RFC PATCH v2 19/43] arm64: pi: Select the page size at runtime during early boot Date: Tue, 1 Dec 2026 01:51:51 +0000 Message-ID: <20261201015240.1017259-20-ericcurtin17@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com> References: <20261201015240.1017259-1-ericcurtin17@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_175320_538622_2A472A84 X-CRM114-Status: GOOD ( 30.53 ) X-Spam-Score: -1.8 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Ryan Roberts Make all the early code between the entry point and start_kernel() independent of the compile-time page size, so that the page size can be chosen at boot. For now the compile-time size is still the only one that is allowed, so behaviour does not change, but the range of allowed sizes is widened by later patches. probe_init_idmap_page_shift() picks the initial page size used for init_idmap_pg_dir: the largest size supported by the hardware that is also within [PAGE_SHIFT_MIN, PAGE_SHIFT_MAX]. Once the MMU is on, the command line is read from the device tree and the requested size is filtered by the same range. If none was requested, the configured default and then the initial size are used. If the final size or LPA2 differs from the initial setup, remap_idmap() repaints init_idmap_pg_dir and the FDT mapping for the new page size. To get there, compile-time decisions become runtime ones. map_range() and create_init_idmap() take the page size from tcr_el1.TG0 (or an explicit page_shift), and the output address encoding for 52-bit PA is chosen accordingly. The TG0, TG1 and DS fields are stashed in tcr_boot_fields so that __cpu_setup can program tcr_el1 on the primary and secondary CPUs. __enable_mmu, __cpu_secondary_check52bitva, offset_ttbr1 and cpu_has_lva()/cpu_has_lpa2() now check the installed page size rather than the configuration, and the LPA2 detection in the override code covers both the 4K and 16K granules. These checks are not in hot paths, so the runtime approach is used even for compile-time page size builds. The static page table storage is still sized for the compile-time page size. Signed-off-by: Ryan Roberts Signed-off-by: Eric Curtin (cherry picked from commit 4b79790f74f2492dd8c876af3e9dd935c02195bf) --- arch/arm64/include/asm/assembler.h | 50 ++++++- arch/arm64/include/asm/cpufeature.h | 33 +++-- arch/arm64/include/asm/pgtable-prot.h | 2 +- arch/arm64/kernel/head.S | 40 ++++-- arch/arm64/kernel/pi/idreg-override.c | 37 ++++-- arch/arm64/kernel/pi/map_kernel.c | 105 +++++++++++---- arch/arm64/kernel/pi/map_range.c | 183 ++++++++++++++++++++++---- arch/arm64/kernel/pi/pi.h | 61 ++++++++- arch/arm64/mm/proc.S | 24 ++-- 9 files changed, 434 insertions(+), 101 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 020670814bda..fc9659c64848 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -564,6 +564,14 @@ alternative_else_nop_endif mrs \rd, sp_el0 .endm +/* + * Retrieve and return tcr_el1.tg0 in \tg0. + */ + .macro get_tg0, tg0 + mrs \tg0, tcr_el1 + and \tg0, \tg0, #TCR_TG0_MASK + .endm + /* * If the kernel is built for 52-bit virtual addressing but the hardware only * supports 48 bits, we cannot program the pgdir address into TTBR1 directly, @@ -580,12 +588,16 @@ alternative_else_nop_endif * ttbr: Value of ttbr to set, modified. */ .macro offset_ttbr1, ttbr, tmp -#if defined(CONFIG_ARM64_VA_BITS_52) && !defined(CONFIG_ARM64_LPA2) +#if defined(CONFIG_ARM64_VA_BITS_52) + get_tg0 \tmp + cmp \tmp, #TCR_TG0_64K + b.ne .Ldone\@ mrs \tmp, tcr_el1 and \tmp, \tmp, #TCR_EL1_T1SZ_MASK cmp \tmp, #TCR_T1SZ(VA_BITS_MIN) orr \tmp, \ttbr, #TTBR1_BADDR_4852_OFFSET csel \ttbr, \tmp, \ttbr, eq +.Ldone\@: #endif .endm @@ -837,4 +849,40 @@ alternative_cb ARM64_ALWAYS_SYSTEM, spectre_bhb_patch_clearbhb alternative_cb_end #endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */ .endm + +/* + * Given \tg0, populates \val with one of the 3 passed in values, corresponding + * to the page size advertised by \tg0. + */ + .macro value_for_page_size, val, tg0, val4k, val16k, val64k +.Lsz_64k\@: + cmp \tg0, #TCR_TG0_64K + b.ne .Lsz_16k\@ + mov \val, #\val64k + b .Ldone\@ +.Lsz_16k\@: + cmp \tg0, #TCR_TG0_16K + b.ne .Lsz_4k\@ + mov \val, #\val16k + b .Ldone\@ +.Lsz_4k\@: + mov \val, #\val4k +.Ldone\@: + .endm + + .macro tgran_shift, val, tg0 + value_for_page_size \val, \tg0, ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_AA64MMFR0_EL1_TGRAN16_SHIFT, ID_AA64MMFR0_EL1_TGRAN64_SHIFT + .endm + + .macro tgran_min, val, tg0 + value_for_page_size \val, \tg0, ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN, ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MIN, ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MIN + .endm + + .macro tgran_max, val, tg0 + value_for_page_size \val, \tg0, ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MAX, ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MAX, ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MAX + .endm + + .macro tgran_lpa2, val, tg0 + value_for_page_size \val, \tg0, ID_AA64MMFR0_EL1_TGRAN4_52_BIT, ID_AA64MMFR0_EL1_TGRAN16_52_BIT, -1 + .endm #endif /* __ASM_ASSEMBLER_H */ diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 405291491866..35239ea01e77 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -26,6 +26,7 @@ #include #include #include +#include /* * CPU feature register tracking @@ -1101,10 +1102,13 @@ static inline bool cpu_has_pac(void) &id_aa64isar2_override); } -static inline bool cpu_has_lva(void) +static inline bool cpu_has_lva(u64 page_size) { u64 mmfr2; + if (page_size != SZ_64K) + return false; + mmfr2 = read_sysreg_s(SYS_ID_AA64MMFR2_EL1); mmfr2 &= ~id_aa64mmfr2_override.mask; mmfr2 |= id_aa64mmfr2_override.val; @@ -1112,22 +1116,31 @@ static inline bool cpu_has_lva(void) ID_AA64MMFR2_EL1_VARange_SHIFT); } -static inline bool cpu_has_lpa2(void) +static inline bool cpu_has_lpa2(u64 page_size) { -#ifdef CONFIG_ARM64_LPA2 u64 mmfr0; int feat; + int shift; + int minval; + + switch (page_size) { + case SZ_4K: + shift = ID_AA64MMFR0_EL1_TGRAN4_SHIFT; + minval = ID_AA64MMFR0_EL1_TGRAN4_52_BIT; + break; + case SZ_16K: + shift = ID_AA64MMFR0_EL1_TGRAN16_SHIFT; + minval = ID_AA64MMFR0_EL1_TGRAN16_52_BIT; + break; + default: + return false; + } mmfr0 = read_sysreg(id_aa64mmfr0_el1); mmfr0 &= ~id_aa64mmfr0_override.mask; mmfr0 |= id_aa64mmfr0_override.val; - feat = cpuid_feature_extract_signed_field(mmfr0, - ID_AA64MMFR0_EL1_TGRAN_SHIFT); - - return feat >= ID_AA64MMFR0_EL1_TGRAN_LPA2; -#else - return false; -#endif + feat = cpuid_feature_extract_signed_field(mmfr0, shift); + return feat >= minval; } #endif /* __ASSEMBLER__ */ diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 590ef4328f12..da792605ac57 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -78,7 +78,7 @@ extern unsigned long prot_ns_shared; #define PTE_MAYBE_NG (arm64_use_ng_mappings ? PTE_NG : 0) #define PMD_MAYBE_NG (arm64_use_ng_mappings ? PMD_SECT_NG : 0) -#ifndef CONFIG_ARM64_LPA2 +#ifndef CONFIG_ARM64_VA_BITS_52 #define lpa2_is_enabled() false #define PTE_MAYBE_SHARED PTE_SHARED #define PMD_MAYBE_SHARED PMD_SECT_S diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 2bdae5d0c5ef..3641e638b31e 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -89,6 +89,8 @@ SYM_CODE_START(primary_entry) adrp x1, early_init_stack mov sp, x1 mov x29, xzr + bl __pi_probe_init_idmap_page_shift + mov x3, x0 adrp x0, __pi_init_idmap_pg_dir adrp x1, __pi_init_idmap_pg_end mov x2, xzr @@ -457,11 +459,16 @@ SYM_FUNC_END(set_cpu_boot_mode_flag) */ .section ".idmap.text","a" SYM_FUNC_START(__enable_mmu) + get_tg0 x3 + tgran_shift x4, x3 + tgran_min x5, x3 + tgran_max x6, x3 mrs x3, ID_AA64MMFR0_EL1 - ubfx x3, x3, #ID_AA64MMFR0_EL1_TGRAN_SHIFT, 4 - cmp x3, #ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN + lsr x3, x3, x4 + ubfx x3, x3, #0, 4 + cmp x3, x5 b.lt __no_granule_support - cmp x3, #ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX + cmp x3, x6 b.gt __no_granule_support phys_to_ttbr x2, x2 msr ttbr0_el1, x2 // load TTBR0 @@ -474,17 +481,32 @@ SYM_FUNC_END(__enable_mmu) #ifdef CONFIG_ARM64_VA_BITS_52 SYM_FUNC_START(__cpu_secondary_check52bitva) -#ifndef CONFIG_ARM64_LPA2 + /* + * tcr_el1 is not yet loaded (there is a chicken-and-egg problem) so we + * can't figure out LPA2 vs LVA from that. But this is only called for + * secondary cpus so tcr_boot_fields has already been populated by the + * primary cpu. So grab that and rely on the DS bit to tell us if we are + * LPA2 or LVA. + */ + adr_l x1, __pi_tcr_boot_fields + ldr x0, [x1] + and x1, x0, #TCR_DS + cbnz x1, .Llpa2 +.Llva: mrs_s x0, SYS_ID_AA64MMFR2_EL1 and x0, x0, ID_AA64MMFR2_EL1_VARange_MASK cbnz x0, 2f -#else + b .Lfail +.Llpa2: + and x0, x0, #TCR_TG0_MASK + tgran_shift x1, x0 + tgran_lpa2 x2, x0 mrs x0, id_aa64mmfr0_el1 - sbfx x0, x0, #ID_AA64MMFR0_EL1_TGRAN_SHIFT, 4 - cmp x0, #ID_AA64MMFR0_EL1_TGRAN_LPA2 + lsr x0, x0, x1 + sbfx x0, x0, #0, 4 + cmp x0, x2 b.ge 2f -#endif - +.Lfail: update_early_cpu_boot_status \ CPU_STUCK_IN_KERNEL | CPU_STUCK_REASON_52_BIT_VA, x0, x1 1: wfe diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index f2641106e164..c58f34b24ea7 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -72,19 +72,38 @@ static const struct ftr_set_desc mmfr1 __prel64_initconst = { static bool __init mmfr2_varange_filter(u64 val) { - int __maybe_unused feat; + u64 mmfr0; + int feat; + int shift; + int minval; + bool lpa2_removed = false; if (val) return false; -#ifdef CONFIG_ARM64_LPA2 - feat = cpuid_feature_extract_signed_field(read_sysreg(id_aa64mmfr0_el1), - ID_AA64MMFR0_EL1_TGRAN_SHIFT); - if (feat >= ID_AA64MMFR0_EL1_TGRAN_LPA2) { - id_aa64mmfr0_override.val |= - (ID_AA64MMFR0_EL1_TGRAN_LPA2 - 1) << ID_AA64MMFR0_EL1_TGRAN_SHIFT; - id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_TGRAN_SHIFT; + mmfr0 = read_sysreg(id_aa64mmfr0_el1); + + /* Remove LPA2 support for 4K granule. */ + shift = ID_AA64MMFR0_EL1_TGRAN4_SHIFT; + minval = ID_AA64MMFR0_EL1_TGRAN4_52_BIT; + feat = cpuid_feature_extract_signed_field(mmfr0, shift); + if (feat >= minval) { + id_aa64mmfr0_override.val |= (minval - 1) << shift; + id_aa64mmfr0_override.mask |= 0xfU << shift; + lpa2_removed = true; + } + /* Remove LPA2 support for 16K granule. */ + shift = ID_AA64MMFR0_EL1_TGRAN16_SHIFT; + minval = ID_AA64MMFR0_EL1_TGRAN16_52_BIT; + feat = cpuid_feature_extract_signed_field(mmfr0, shift); + if (feat >= minval) { + id_aa64mmfr0_override.val |= (minval - 1) << shift; + id_aa64mmfr0_override.mask |= 0xfU << shift; + lpa2_removed = true; + } + + if (lpa2_removed) { /* * Override PARange to 48 bits - the override will just be * ignored if the actual PARange is smaller, but this is @@ -94,7 +113,7 @@ static bool __init mmfr2_varange_filter(u64 val) ID_AA64MMFR0_EL1_PARANGE_48 << ID_AA64MMFR0_EL1_PARANGE_SHIFT; id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_PARANGE_SHIFT; } -#endif + return true; } diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_kernel.c index 47d5b29cf99c..357ccb562746 100644 --- a/arch/arm64/kernel/pi/map_kernel.c +++ b/arch/arm64/kernel/pi/map_kernel.c @@ -139,16 +139,26 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_offset, int root_level) idmap_cpu_replace_ttbr1((phys_addr_t)swapper_pg_dir); } -static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(phys_addr_t ttbr) +static void noinline __section(".idmap.text") set_ttbr0(phys_addr_t ttbr, + bool use_lpa2, + int page_shift) { u64 sctlr = read_sysreg(sctlr_el1); - u64 tcr = read_sysreg(tcr_el1) | TCR_EL1_DS; - u64 mmfr0 = read_sysreg(id_aa64mmfr0_el1); - u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, - ID_AA64MMFR0_EL1_PARANGE_SHIFT); + u64 tcr = read_sysreg(tcr_el1); + u64 boot_fields = early_page_shift_to_tcr_tgx(page_shift); - tcr &= ~TCR_EL1_IPS_MASK; - tcr |= parange << TCR_EL1_IPS_SHIFT; + if (use_lpa2) { + u64 mmfr0 = read_sysreg(id_aa64mmfr0_el1); + u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_EL1_PARANGE_SHIFT); + + boot_fields |= TCR_EL1_DS; + tcr &= ~TCR_EL1_IPS_MASK; + tcr |= parange << TCR_EL1_IPS_SHIFT; + } + + tcr &= ~(TCR_EL1_TG0_MASK | TCR_EL1_TG1_MASK | TCR_EL1_DS); + tcr |= boot_fields; asm(" msr sctlr_el1, %0 ;" " isb ;" @@ -161,57 +171,66 @@ static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(phys_addr_t ttb " msr sctlr_el1, %3 ;" " isb ;" :: "r"(sctlr & ~SCTLR_ELx_M), "r"(ttbr), "r"(tcr), "r"(sctlr)); + + /* Stash this for __cpu_setup to configure secondary cpus' tcr_el1. */ + set_tcr_boot_fields(boot_fields); } -static void __init remap_idmap_for_lpa2(void) +static void __init remap_idmap(bool use_lpa2, int page_shift) { /* clear the bits that change meaning once LPA2 is turned on */ - ptval_t mask = PTE_SHARED; + ptval_t mask = use_lpa2 ? PTE_SHARED : 0; /* - * We have to clear bits [9:8] in all block or page descriptors in the - * initial ID map, as otherwise they will be (mis)interpreted as + * For LPA2, We have to clear bits [9:8] in all block or page descriptors + * in the initial ID map, as otherwise they will be (mis)interpreted as * physical address bits once we flick the LPA2 switch (TCR.DS). Since * we cannot manipulate live descriptors in that way without creating * potential TLB conflicts, let's create another temporary ID map in a * LPA2 compatible fashion, and update the initial ID map while running * from that. */ - create_init_idmap(init_pg_dir, init_pg_end, mask); + create_init_idmap(init_pg_dir, init_pg_end, mask, page_shift); dsb(ishst); - set_ttbr0_for_lpa2((phys_addr_t)init_pg_dir); + set_ttbr0((phys_addr_t)init_pg_dir, use_lpa2, page_shift); /* - * Recreate the initial ID map with the same granularity as before. - * Don't bother with the FDT, we no longer need it after this. + * Recreate the initial ID map with new page size and, if LPA2 is in + * use, bits [9:8] cleared. */ memset(init_idmap_pg_dir, 0, (char *)init_idmap_pg_end - (char *)init_idmap_pg_dir); - create_init_idmap(init_idmap_pg_dir, init_idmap_pg_end, mask); + create_init_idmap(init_idmap_pg_dir, init_idmap_pg_end, mask, page_shift); dsb(ishst); /* switch back to the updated initial ID map */ - set_ttbr0_for_lpa2((phys_addr_t)init_idmap_pg_dir); + set_ttbr0((phys_addr_t)init_idmap_pg_dir, use_lpa2, page_shift); /* wipe the temporary ID map from memory */ memset(init_pg_dir, 0, (char *)init_pg_end - (char *)init_pg_dir); } -static void *__init map_fdt(phys_addr_t fdt) +static void *__init map_fdt(phys_addr_t fdt, int page_shift) { static u8 ptes[INIT_IDMAP_FDT_SIZE_MAX] __initdata __aligned(PAGE_SIZE); + static bool first_time __initdata = true; u64 limit = (u64)&ptes[INIT_IDMAP_FDT_SIZE_MAX]; phys_addr_t efdt = fdt + MAX_FDT_SIZE; phys_addr_t ptep = (phys_addr_t)ptes; /* We're idmapped when called */ + if (!first_time) { + memset(ptes, 0, sizeof(ptes)); + first_time = false; + } + /* * Map up to MAX_FDT_SIZE bytes, but avoid overlap with * the kernel image. */ map_range(&ptep, limit, fdt, (u64)_text > fdt ? min((u64)_text, efdt) : efdt, - fdt, PAGE_KERNEL, IDMAP_ROOT_LEVEL(PAGE_SHIFT), + fdt, PAGE_KERNEL, IDMAP_ROOT_LEVEL(page_shift), (pte_t *)init_idmap_pg_dir, false, 0); dsb(ishst); isb(); @@ -245,12 +264,15 @@ static bool __init ng_mappings_allowed(void) asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt) { static char const chosen_str[] __initconst = "/chosen"; + u64 early_page_shift = early_tcr_tg0_to_page_shift(); u64 va_base, pa_base = (u64)&_text; u64 kaslr_offset = pa_base % MIN_KIMG_ALIGN; - int root_level = 4 - CONFIG_PGTABLE_LEVELS; int va_bits = VA_BITS; + bool use_lpa2 = false; + int root_level; + int page_shift; int chosen; - void *fdt_mapped = map_fdt(fdt); + void *fdt_mapped = map_fdt(fdt, early_page_shift); /* Clear BSS and the initial page tables */ memset(__bss_start, 0, (char *)init_pg_end - (char *)__bss_start); @@ -259,16 +281,43 @@ asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt) chosen = fdt_path_offset(fdt_mapped, chosen_str); init_feature_override(boot_status, fdt_mapped, chosen); - if (IS_ENABLED(CONFIG_ARM64_64K_PAGES) && !cpu_has_lva()) { - va_bits = VA_BITS_MIN; - } else if (IS_ENABLED(CONFIG_ARM64_LPA2) && !cpu_has_lpa2()) { - va_bits = VA_BITS_MIN; - root_level++; + /* + * Get page_shift from cmdline, falling back to the configured default + * and then to early_page_shift. + */ + page_shift = arm64_pageshift_cmdline(); + if (!page_shift && IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE) && + early_page_shift_supported(CONFIG_ARM64_BOOT_TIME_PAGE_SHIFT_DEFAULT)) + page_shift = CONFIG_ARM64_BOOT_TIME_PAGE_SHIFT_DEFAULT; + if (!page_shift) + page_shift = early_page_shift; + + if (va_bits > 48) { + u64 page_size = early_page_size(page_shift); + + if (page_size == SZ_64K) { + if (!cpu_has_lva(page_size)) + va_bits = VA_BITS_MIN; + } else { + use_lpa2 = cpu_has_lpa2(page_size); + if (!use_lpa2) + va_bits = VA_BITS_MIN; + } } if (va_bits > VA_BITS_MIN) sysreg_clear_set(tcr_el1, TCR_EL1_T1SZ_MASK, TCR_T1SZ(va_bits)); + /* + * This will update tg0/tg1 in tcr for the final page size. After this, + * PAGE_SIZE and friends can be used safely. kaslr_early_init(), below, + * is the first such user. + */ + if (use_lpa2 || page_shift != early_page_shift) { + remap_idmap(use_lpa2, page_shift); + map_fdt(fdt, page_shift); + } + /* * The virtual KASLR displacement modulo 2MiB is decided by the * physical placement of the image, as otherwise, we might not be able @@ -285,9 +334,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt) kaslr_offset |= kaslr_seed & ~(MIN_KIMG_ALIGN - 1); } - if (IS_ENABLED(CONFIG_ARM64_LPA2) && va_bits > VA_BITS_MIN) - remap_idmap_for_lpa2(); - va_base = KIMAGE_VADDR + kaslr_offset; + root_level = 4 - PGTABLE_LEVELS(page_shift, va_bits); map_kernel(kaslr_offset, va_base - pa_base, root_level); } diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c index 4ca0aaf12e17..0dc99cdd38d2 100644 --- a/arch/arm64/kernel/pi/map_range.c +++ b/arch/arm64/kernel/pi/map_range.c @@ -11,6 +11,34 @@ #include "pi.h" +static inline u64 __init pte_get_oa(pte_t pte, int page_shift, bool oa52bit) +{ + pteval_t pv = pte_val(pte); + +#ifdef CONFIG_ARM64_PA_BITS_52 + if (oa52bit) { + if (early_page_size(page_shift) == SZ_64K) + return (pv & GENMASK(47, 16)) | + ((pv & GENMASK(15, 12)) << 36); + return (pv & GENMASK(49, 12)) | ((pv & GENMASK(9, 8)) << 42); + } +#endif + return pv & GENMASK(47, 12); +} + +static inline u64 __init pte_prep_oa(u64 oa, int page_shift, bool oa52bit) +{ +#ifdef CONFIG_ARM64_PA_BITS_52 + if (oa52bit) { + if (early_page_size(page_shift) == SZ_64K) + return (oa & GENMASK(47, 16)) | + ((oa >> 36) & GENMASK(15, 12)); + return (oa & GENMASK(49, 12)) | ((oa >> 42) & GENMASK(9, 8)); + } +#endif + return oa; +} + static void __init mmuoff_data_clean(void) { bool cache_ena = !!(read_sysreg(sctlr_el1) & SCTLR_ELx_C); @@ -35,8 +63,19 @@ static void __init __noreturn report_cpu_stuck(long val) cpu_park_loop(); } +u64 __section(".mmuoff.data.read") tcr_boot_fields; + +void __init set_tcr_boot_fields(u64 val) +{ + WRITE_ONCE(tcr_boot_fields, val); + + /* Ensure the visibility of the new value */ + dsb(ishst); + mmuoff_data_clean(); +} + /** - * map_range - Map a contiguous range of physical pages into virtual memory + * __map_range - Map a contiguous range of physical pages into virtual memory * * @pte: Address of physical pointer to array of pages to * allocate page tables from @@ -50,22 +89,28 @@ static void __init __noreturn report_cpu_stuck(long val) * @may_use_cont: Whether the use of the contiguous attribute is allowed * @va_offset: Offset between a physical page and its current mapping * in the VA space + * @page_shift: Page size (as a shift) to create page table for + * @oa52bit: Whether to store output addresses in 52-bit format */ -void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, - phys_addr_t pa, - pgprot_t prot, int level, pte_t *tbl, bool may_use_cont, - u64 va_offset) +static void __init __map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, + phys_addr_t pa, pgprot_t prot, int level, + pte_t *tbl, bool may_use_cont, u64 va_offset, + int page_shift, bool oa52bit) { - u64 cmask = (level == 3) ? CONT_PTE_SIZE - 1 : U64_MAX; + const u64 page_size = early_page_size(page_shift); + const u64 page_mask = early_page_mask(page_shift); + const u64 cont_pte_size = early_cont_pte_size(page_shift); + const u64 ptrs_per_pte = early_ptrs_per_pte(page_shift); + u64 cmask = (level == 3) ? cont_pte_size - 1 : U64_MAX; ptval_t protval = pgprot_val(prot) & ~PTE_TYPE_MASK; - int lshift = (3 - level) * PTDESC_TABLE_SHIFT; - u64 lmask = (PAGE_SIZE << lshift) - 1; + int lshift = (3 - level) * (page_shift - PTDESC_ORDER); + u64 lmask = (page_size << lshift) - 1; - start &= PAGE_MASK; - pa &= PAGE_MASK; + start &= page_mask; + pa &= page_mask; /* Advance tbl to the entry that covers start */ - tbl += (start >> (lshift + PAGE_SHIFT)) % PTRS_PER_PTE; + tbl += (start >> (lshift + page_shift)) % ptrs_per_pte; /* * Set the right block/page bits for this level unless we are @@ -75,7 +120,7 @@ void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, protval |= (level == 2) ? PMD_TYPE_SECT : PTE_TYPE_PAGE; while (start < end) { - u64 next = min((start | lmask) + 1, PAGE_ALIGN(end)); + u64 next = min((start | lmask) + 1, ALIGN(end, page_size)); if (level < 2 || (level == 2 && (start | next | pa) & lmask)) { /* @@ -83,19 +128,19 @@ void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, * table mapping if necessary and recurse. */ if (pte_none(*tbl)) { - u64 size = PTRS_PER_PTE * sizeof(pte_t); + u64 size = ptrs_per_pte * sizeof(pte_t); if (*pte + size > limit) report_cpu_stuck( CPU_STUCK_REASON_NO_PGTABLE_MEM); - *tbl = __pte(__phys_to_pte_val(*pte) | + *tbl = __pte(pte_prep_oa(*pte, page_shift, oa52bit) | PMD_TYPE_TABLE | PMD_TABLE_UXN); *pte += size; } - map_range(pte, limit, start, next, pa, prot, level + 1, - (pte_t *)(__pte_to_phys(*tbl) + va_offset), - may_use_cont, va_offset); + __map_range(pte, limit, start, next, pa, prot, level + 1, + (pte_t *)(pte_get_oa(*tbl, page_shift, oa52bit) + va_offset), + may_use_cont, va_offset, page_shift, oa52bit); } else { /* * Start a contiguous range if start and pa are @@ -112,7 +157,8 @@ void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, protval &= ~PTE_CONT; /* Put down a block or page mapping */ - *tbl = __pte(__phys_to_pte_val(pa) | protval); + *tbl = __pte(pte_prep_oa(pa, page_shift, oa52bit) | + protval); } pa += next - start; start = next; @@ -120,10 +166,93 @@ void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, } } +/** + * map_range - Map a contiguous range of physical pages into virtual memory + * + * As per __map_range(), except it uses the page_shift and oa52bit of the + * currently tcr-installed granule size instead of passing explicitly. + */ +void __init map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, + phys_addr_t pa, pgprot_t prot, int level, pte_t *tbl, + bool may_use_cont, u64 va_offset) +{ + int page_shift = early_tcr_tg0_to_page_shift(); + bool oa52bit = false; + +#ifdef CONFIG_ARM64_PA_BITS_52 + /* + * We can safely assume 52bit for 64K pages because if it turns out to + * be 48bit, its still safe to treat [51:48] as address bits because + * they are 0. + */ + if (early_page_size(page_shift) == SZ_64K) + oa52bit = true; + /* + * For 4K and 16K, on the other hand, those bits are used for something + * else when LPA2 is not explicitly enabled. Deliberately not using + * read_tcr() since it is marked pure, and at this point, the tcr is not + * yet stable. + */ + else if (read_sysreg(tcr_el1) & TCR_DS) + oa52bit = true; +#endif + + __map_range(pte, limit, start, end, pa, prot, level, tbl, may_use_cont, + va_offset, page_shift, oa52bit); +} + +/* Whether @page_shift is allowed by the compilation config and the HW. */ +bool __init early_page_shift_supported(int page_shift) +{ + u64 mmfr0 = read_sysreg_s(SYS_ID_AA64MMFR0_EL1); + u32 tgran64 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN64, mmfr0); + u32 tgran16 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN16, mmfr0); + u32 tgran4 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN4, mmfr0); + + if (page_shift < PAGE_SHIFT_MIN || page_shift > PAGE_SHIFT_MAX) + return false; + + if (page_shift == ARM64_PAGE_SHIFT_64K) + return tgran64 >= ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MIN && + tgran64 <= ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MAX; + + if (page_shift == ARM64_PAGE_SHIFT_16K) + return tgran16 >= ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MIN && + tgran16 <= ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MAX; + + return page_shift == ARM64_PAGE_SHIFT_4K && + tgran4 >= ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN && + tgran4 <= ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MAX; +} + +asmlinkage u64 __init probe_init_idmap_page_shift(void) +{ + u64 page_shift; + + /* + * Select the largest page size supported by the HW, which is also + * allowed by the compilation config. + */ + if (early_page_shift_supported(ARM64_PAGE_SHIFT_64K)) + page_shift = ARM64_PAGE_SHIFT_64K; + else if (early_page_shift_supported(ARM64_PAGE_SHIFT_16K)) + page_shift = ARM64_PAGE_SHIFT_16K; + else if (early_page_shift_supported(ARM64_PAGE_SHIFT_4K)) + page_shift = ARM64_PAGE_SHIFT_4K; + else + report_cpu_stuck(CPU_STUCK_REASON_NO_GRAN); + + /* Stash this for __cpu_setup to configure primary cpu's tcr_el1. */ + set_tcr_boot_fields(early_page_shift_to_tcr_tgx(page_shift)); + + return page_shift; +} + asmlinkage phys_addr_t __init create_init_idmap(pgd_t *pg_dir, pgd_t *pg_end, - ptval_t clrmask) + ptval_t clrmask, int page_shift) { - phys_addr_t ptep = (phys_addr_t)pg_dir + PAGE_SIZE; /* MMU is off */ + const u64 page_size = early_page_size(page_shift); + phys_addr_t ptep = (phys_addr_t)pg_dir + page_size; /* MMU is off */ pgprot_t text_prot = PAGE_KERNEL_ROX; pgprot_t data_prot = PAGE_KERNEL; @@ -131,12 +260,14 @@ asmlinkage phys_addr_t __init create_init_idmap(pgd_t *pg_dir, pgd_t *pg_end, pgprot_val(data_prot) &= ~clrmask; /* MMU is off; pointer casts to phys_addr_t are safe */ - map_range(&ptep, (u64)pg_end, (u64)_stext, (u64)__initdata_begin, - (phys_addr_t)_stext, text_prot, - IDMAP_ROOT_LEVEL(PAGE_SHIFT), (pte_t *)pg_dir, false, 0); - map_range(&ptep, (u64)pg_end, (u64)__initdata_begin, (u64)_end, - (phys_addr_t)__initdata_begin, data_prot, - IDMAP_ROOT_LEVEL(PAGE_SHIFT), (pte_t *)pg_dir, false, 0); + __map_range(&ptep, (u64)pg_end, (u64)_stext, (u64)__initdata_begin, + (phys_addr_t)_stext, text_prot, + IDMAP_ROOT_LEVEL(page_shift), (pte_t *)pg_dir, false, 0, + page_shift, false); + __map_range(&ptep, (u64)pg_end, (u64)__initdata_begin, (u64)_end, + (phys_addr_t)__initdata_begin, data_prot, + IDMAP_ROOT_LEVEL(page_shift), (pte_t *)pg_dir, false, 0, + page_shift, false); return ptep; } diff --git a/arch/arm64/kernel/pi/pi.h b/arch/arm64/kernel/pi/pi.h index ce07cdc3445d..a92ba38a989d 100644 --- a/arch/arm64/kernel/pi/pi.h +++ b/arch/arm64/kernel/pi/pi.h @@ -24,6 +24,62 @@ extern bool dynamic_scs_is_enabled; extern pgd_t init_idmap_pg_dir[], init_idmap_pg_end[]; extern pgd_t init_pg_dir[], init_pg_end[]; +static inline u64 early_page_size(int page_shift) +{ + return 1UL << page_shift; +} + +static inline u64 early_page_mask(int page_shift) +{ + return ~(early_page_size(page_shift) - 1); +} + +static inline u64 early_cont_pte_size(int page_shift) +{ + switch (page_shift) { + case 16: /* 64K */ + case 14: /* 16K */ + return SZ_2M; + default: /* 12 4K */ + return SZ_64K; + } +} + +static inline u64 early_ptrs_per_pte(int page_shift) +{ + return 1UL << (page_shift - 3); +} + +static inline int early_tcr_tg0_to_page_shift(void) +{ + /* + * Deliberately not using read_tcr() since it is marked pure, and at + * this point, the tcr is not yet stable. + */ + u64 tg0 = read_sysreg(tcr_el1) & TCR_TG0_MASK; + + switch (tg0) { + case TCR_TG0_64K: + return 16; + case TCR_TG0_16K: + return 14; + default: /* TCR_TG0_4K */ + return 12; + } +} + +static inline u64 early_page_shift_to_tcr_tgx(int page_shift) +{ + switch (early_page_size(page_shift)) { + case SZ_64K: + return TCR_TG0_64K | TCR_TG1_64K; + case SZ_16K: + return TCR_TG0_16K | TCR_TG1_16K; + default: + return TCR_TG0_4K | TCR_TG1_4K; + } +} + void init_feature_override(u64 boot_status, const void *fdt, int chosen); u64 kaslr_early_init(void *fdt, int chosen); void relocate_kernel(u64 offset); @@ -35,5 +91,8 @@ void map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end, asmlinkage void early_map_kernel(u64 boot_status, phys_addr_t fdt); +void set_tcr_boot_fields(u64 val); +bool early_page_shift_supported(int page_shift); +asmlinkage u64 probe_init_idmap_page_shift(void); asmlinkage phys_addr_t create_init_idmap(pgd_t *pgd, pgd_t *pg_end, - ptval_t clrmask); + ptval_t clrmask, int page_shift); diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 62e790a2a779..afc9dc20084e 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -22,17 +22,6 @@ #include #include -#ifdef CONFIG_ARM64_64K_PAGES -#define TCR_TG_FLAGS ((TCR_EL1_TG0_64K << TCR_EL1_TG0_SHIFT) |\ - (TCR_EL1_TG1_64K << TCR_EL1_TG1_SHIFT)) -#elif defined(CONFIG_ARM64_16K_PAGES) -#define TCR_TG_FLAGS ((TCR_EL1_TG0_16K << TCR_EL1_TG0_SHIFT) |\ - (TCR_EL1_TG1_16K << TCR_EL1_TG1_SHIFT)) -#else /* CONFIG_ARM64_4K_PAGES */ -#define TCR_TG_FLAGS ((TCR_EL1_TG0_4K << TCR_EL1_TG0_SHIFT) |\ - (TCR_EL1_TG1_4K << TCR_EL1_TG1_SHIFT)) -#endif - #ifdef CONFIG_RANDOMIZE_BASE #define TCR_KASLR_FLAGS TCR_EL1_NFD1 #else @@ -535,19 +524,24 @@ SYM_FUNC_START(__cpu_setup) tcr2 .req x15 mov_q mair, MAIR_EL1_SET mov_q tcr, TCR_T0SZ(IDMAP_VA_BITS) | TCR_T1SZ(VA_BITS_MIN) | TCR_CACHE_FLAGS | \ - TCR_SHARED | TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_EL1_AS | \ + TCR_SHARED | TCR_KASLR_FLAGS | TCR_EL1_AS | \ TCR_EL1_TBI0 | TCR_EL1_A1 | TCR_KASAN_SW_FLAGS | TCR_MTE_FLAGS mov tcr2, xzr + /* + * Insert the boot-time determined fields (TG0, TG1 and DS), which are + * cached in the tcr_boot_fields variable. + */ + adr_l x2, __pi_tcr_boot_fields + ldr x3, [x2] + orr tcr, tcr, x3 + tcr_clear_errata_bits tcr, x9, x5 #ifdef CONFIG_ARM64_VA_BITS_52 mov x9, #64 - VA_BITS alternative_if ARM64_HAS_VA52 tcr_set_t1sz tcr, x9 -#ifdef CONFIG_ARM64_LPA2 - orr tcr, tcr, #TCR_EL1_DS -#endif alternative_else_nop_endif #endif