All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Kees Cook <keescook@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>
Subject: [PATCH v7 01/33] arm64: mm: Avoid SWAPPER_BLOCK_xxx constants in FDT fixmap logic
Date: Fri, 11 Nov 2022 18:11:29 +0100	[thread overview]
Message-ID: <20221111171201.2088501-2-ardb@kernel.org> (raw)
In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org>

The FDT is permitted to be up to 2 MiB in size, and is mapped in the
fixmap region using the same granularity as we use for the initial ID
map, and up until recently, as we use for the preliminary mapping of the
kernel in swapper_pg_dir.

However, even though the constants are the same, the motivation is
different: on 4k pagesize configurations, the fixmap region only has 2
MiB's worth of level 3 PTE slots to begin with, and so mapping the FDT
down to pages in the fixmap would be wasteful, and this is why we use
block mappings in this case. This is also documented in the boot
protocol, i.e., adjacent regions must not be used by the platform in a
away that could result in the need for memory attributes that conflict
with the cacheable attributes used for the FDT block mapping.

For larger page sizes, using block mappings is unnecessary, and given
the potential issues caused by rounding, undesirable, so we use page
mappings in that case.

So to convey that this granularity is unrelated to the swapper block
size, and to allow us to rename or remove the associated constants in a
subsequent patch, use our own constants to define the granularity.

No functional change intended, although the FDT fixmap virtual address
will no longer be 2 MiB aligned on non-4k pages configurations.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/fixmap.h |  5 ++--
 arch/arm64/mm/mmu.c             | 27 ++++++++++----------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h
index 71ed5fdf718bd0fd..d09654af5b1277c6 100644
--- a/arch/arm64/include/asm/fixmap.h
+++ b/arch/arm64/include/asm/fixmap.h
@@ -40,11 +40,12 @@ enum fixed_addresses {
 	 * maximum supported size, and put it at the top of the fixmap region.
 	 * The additional space ensures that any FDT that does not exceed
 	 * MAX_FDT_SIZE can be mapped regardless of whether it crosses any
-	 * 2 MB alignment boundaries.
+	 * 2 MB alignment boundaries on 4k pages configurations.
 	 *
 	 * Keep this at the top so it remains 2 MB aligned.
 	 */
-#define FIX_FDT_SIZE		(MAX_FDT_SIZE + SZ_2M)
+#define FIX_FDT_BSIZE		(MAX_FDT_SIZE >= PMD_SIZE ? PMD_SIZE : PAGE_SIZE)
+#define FIX_FDT_SIZE		(MAX_FDT_SIZE + FIX_FDT_BSIZE)
 	FIX_FDT_END,
 	FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1,
 
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 9a7c38965154081e..757c2fe54d2e99f0 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1373,22 +1373,23 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 	 * allocate additional translation table pages, so that it is safe
 	 * to call create_mapping_noalloc() this early.
 	 *
-	 * On 64k pages, the FDT will be mapped using PTEs, so we need to
-	 * be in the same PMD as the rest of the fixmap.
-	 * On 4k pages, we'll use section mappings for the FDT so we only
-	 * have to be in the same PUD.
+	 * On 4k pages, the entire level 3 fixmap only covers 2 MiB, so we'll
+	 * need to use section mappings for the FDT, and these must be covered
+	 * by the same statically allocated PUD (bm_pud). Otherwise, the FDT
+	 * will be mapped using PTEs, so the entire mappings needs to fit into
+	 * a single PMD (bm_pmd).
 	 */
-	BUILD_BUG_ON(dt_virt_base % SZ_2M);
+	BUILD_BUG_ON(dt_virt_base % FIX_FDT_BSIZE);
 
-	BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT !=
-		     __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT);
+	BUILD_BUG_ON((__fix_to_virt(FIX_FDT_END) ^ __fix_to_virt(FIX_BTMAP_BEGIN))
+		     & ~((FIX_FDT_BSIZE << (PAGE_SHIFT - 3)) - 1));
 
-	offset = dt_phys % SWAPPER_BLOCK_SIZE;
+	offset = dt_phys % FIX_FDT_BSIZE;
 	dt_virt = (void *)dt_virt_base + offset;
 
 	/* map the first chunk so we can read the size from the header */
-	create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE),
-			dt_virt_base, SWAPPER_BLOCK_SIZE, prot);
+	create_mapping_noalloc(round_down(dt_phys, FIX_FDT_BSIZE),
+			       dt_virt_base, FIX_FDT_BSIZE, prot);
 
 	if (fdt_magic(dt_virt) != FDT_MAGIC)
 		return NULL;
@@ -1397,9 +1398,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 	if (*size > MAX_FDT_SIZE)
 		return NULL;
 
-	if (offset + *size > SWAPPER_BLOCK_SIZE)
-		create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
-			       round_up(offset + *size, SWAPPER_BLOCK_SIZE), prot);
+	if (offset + *size > FIX_FDT_BSIZE)
+		create_mapping_noalloc(round_down(dt_phys, FIX_FDT_BSIZE), dt_virt_base,
+				       round_up(offset + *size, FIX_FDT_BSIZE), prot);
 
 	return dt_virt;
 }
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-11-11 17:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 17:11 [PATCH v7 00/33] arm64: robustify boot sequence and add support for WXN Ard Biesheuvel
2022-11-11 17:11 ` Ard Biesheuvel [this message]
2022-11-11 17:11 ` [PATCH v7 02/33] arm64: mm: Avoid swapper block size when choosing vmemmap granularity Ard Biesheuvel
2022-11-24  5:11   ` Anshuman Khandual
2022-11-11 17:11 ` [PATCH v7 03/33] arm64: kaslr: don't pretend KASLR is enabled if offset < MIN_KIMG_ALIGN Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 04/33] arm64: kaslr: drop special case for ThunderX in kaslr_requires_kpti() Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 05/33] arm64: kernel: Disable latent_entropy GCC plugin in early C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 06/33] arm64: kernel: Add relocation check to code built under pi/ Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 07/33] arm64: kernel: Don't rely on objcopy to make code under pi/ __init Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 08/33] arm64: head: move relocation handling to C code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 09/33] arm64: Turn kaslr_feature_override into a generic SW feature override Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 10/33] arm64: idreg-override: Omit non-NULL checks for override pointer Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 11/33] arm64: idreg-override: Use relative references to override variables Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 12/33] arm64: idreg-override: Use relative references to filter routines Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 13/33] arm64: idreg-override: Avoid parameq() and parameqn() Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 14/33] arm64: idreg-override: avoid strlen() to check for empty strings Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 15/33] arm64: idreg-override: Avoid sprintf() for simple string concatenation Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 16/33] arm64: idreg_override: Avoid kstrtou64() to parse a single hex digit Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 17/33] arm64: idreg-override: Move to early mini C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 18/33] arm64: kernel: Remove early fdt remap code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 19/33] arm64: head: Clear BSS and the kernel page tables in one go Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 20/33] arm64: Move feature overrides into the BSS section Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 21/33] arm64: head: Run feature override detection before mapping the kernel Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 22/33] arm64: head: move dynamic shadow call stack patching into early C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 23/33] arm64: kaslr: Use feature override instead of parsing the cmdline again Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 24/33] arm64: idreg-override: Create a pseudo feature for rodata=off Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 25/33] arm64: head: allocate more pages for the kernel mapping Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 26/33] arm64: head: move memstart_offset_seed handling to C code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 27/33] arm64: head: Move early kernel mapping routines into " Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 28/33] arm64: mm: avoid fixmap for early swapper_pg_dir updates Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 29/33] arm64: mm: omit redundant remap of kernel image Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 30/33] arm64: Revert "mm: provide idmap pointer to cpu_replace_ttbr1()" Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 31/33] arm64: mmu: Retire SWAPPER_BLOCK_xxx and related constants Ard Biesheuvel
2022-11-11 17:12 ` [PATCH v7 32/33] mm: add arch hook to validate mmap() prot flags Ard Biesheuvel
2022-11-11 17:12 ` [PATCH v7 33/33] arm64: mm: add support for WXN memory translation attribute Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221111171201.2088501-2-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=anshuman.khandual@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.