Skip to contentSkip to conversation

ARM: set !LPAE MAX_PHYSMEM_BITS to 32 and remove supersection mappings

PATCH In review Karl Mehltretter 2 participants 3 messages Jul 25 – Aug 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ARM: set !LPAE MAX_PHYSMEM_BITS to 32 and remove supersection mappings

An ARM randconfig with CONFIG_GET_FREE_REGION=y and CONFIG_WERROR=y fails to build:

include/linux/minmax.h:86:37: error: conversion from 'long long unsigned int' to 'resource_size_t' {aka 'unsigned int'} changes value from '68719476735' to '4294967295' [-Werror=overflow]

Commit 14b80582c43e ("resource: Introduce alloc_free_mem_region()") made kernel/resource.c clamp against
(1ULL << MAX_PHYSMEM_BITS) - 1. resource_size_t is 32-bit without LPAE, but ARM's default MAX_PHYSMEM_BITS is 36.

That default was added by commit db57f88e4ccb ("ARM: 8411/1: Add default SPARSEMEM settings") because several platforms needed at least 36 physical address bits. !LPAE could map addresses above 32 bits only through supersections.

CONFIG_IO_36, added by commit 23bdf86aa06e ("[ARM] 3377/2: add support for intel xsc3 core"), enabled these for XSC3 I/O. IXP23xx placed static I/O mappings above 4GiB until its removal in 2012, and IOP13xx ioremap()ed its PCIe windows there until its removal in 2019. The only remaining XSC3 platform, PXA3xx, has nothing above 4GiB.

Supersection address bits overlap the descriptor domain field, so IO_36 also renumbered the domains to make DOMAIN_IO zero. Remove IO_36, the alternate domain numbering, and ioremap()'s supersection path. Reject !LPAE ioremap ranges extending past 4GiB before phys_addr_t truncation, drop the now-unneeded high static-mapping exclusion, and reduce ioremap alignment from 16MiB to the 2MiB covered by a PMD's pair of sections.

The other supersection user, create_36bit_mapping(), was added by commit 0b7cd62ecdc1 ("[ARM] 3017/1: Add support for 36-bit addresses to create_mapping()") for IXP2350 and carried IXP23xx's high static mappings. Before this change, its only remaining call path was efi_create_mapping() -> create_mapping_late(), for an EFI runtime region above 4GiB.

No real-world user of this !LPAE path is known. AArch32 UEFI requires RAM described by its memory map to be identity-mapped during boot services, which a 32-bit virtual address space cannot provide above 4GiB. Systems needing wider physical addressing are expected to use LPAE.

Remove create_36bit_mapping() and the supersection definitions. If firmware nevertheless advertises such a region on !LPAE, efi_create_mapping() rejects it before __pfn_to_phys() truncates its address to a low alias. EFI runtime services remain disabled, but the kernel continues to boot. LPAE kernels are unaffected.

With no remaining !LPAE mappings above 4GiB, set MAX_PHYSMEM_BITS to 32 for !LPAE and retain 36 for LPAE, where phys_addr_t is 64-bit.

---
v3: per Arnd's request, remove the remaining supersection code as
well: create_36bit_mapping() and the PMD_SECT_SUPER/SUPERSECTION_* definitions. efi_create_mapping() now rejects EFI runtime regions extending beyond 4GiB on !LPAE with -ERANGE before __pfn_to_phys() truncates their addresses, so efi_virtmap_init() keeps runtime services disabled. Corrected history: the 36-bit default came from db57f88e4ccb, and create_36bit_mapping() served IXP23xx's static mappings. Retitled (was: "ARM: set !LPAE MAX_PHYSMEM_BITS to 32 and remove IO_36").

Build-tested: multi_v7 + EFI (!LPAE and LPAE), pxa3xx_defconfig (XSC3; build only - QEMU has no XSC3 emulation), versatile_defconfig, and the originally failing GET_FREE_REGION + WERROR configuration. Boot-tested on QEMU virt/Cortex-A15 with 32-bit EDK2, covering the rejection boundaries: stock firmware keeps runtime services on !LPAE; a runtime region ending exactly at 4GiB is accepted and mapped; regions crossing 4GiB, starting exactly at 4GiB, and entirely above it are each rejected on !LPAE with runtime services cleanly disabled and the boot continuing; an LPAE kernel maps the

Quoted 1 line

4GiB region; efivars works in every enabled case. versatilepb

(ARMv5, UP, !SMP ioremap path) boots to a shell. Applies to v6.1 with a one-line include-context fixup in efi.c.

v2: https://lore.kernel.org/all/[email protected]/
fold in the IO_36 removal and its ioremap path, as requested by Arnd; correct the history (IOP13xx was removed in 2019, not 2012).

v1: https://lore.kernel.org/all/[email protected]/

 arch/arm/include/asm/domain.h               | 17 -----
 arch/arm/include/asm/memory.h               |  4 +-
 arch/arm/include/asm/pgtable-2level-hwdef.h |  1 -
 arch/arm/include/asm/pgtable-2level.h       |  7 --
 arch/arm/include/asm/sparsemem.h            |  4 ++
 arch/arm/kernel/efi.c                       | 13 ++++
 arch/arm/mm/Kconfig                         |  7 --
 arch/arm/mm/ioremap.c                       | 53 ++------------
 arch/arm/mm/mmu.c                           | 76 +--------------------
 9 files changed, 27 insertions(+), 155 deletions(-)
arch/arm/include/asm/domain.h +0 -17
index d48859fdf32c..f91c2a72b9dc 100644
@@ -18,27 +18,10 @@
  *  DOMAIN_IO     - domain 2 includes all IO only
  *  DOMAIN_USER   - domain 1 includes all user memory only
  *  DOMAIN_KERNEL - domain 0 includes all kernel memory only
- *
- * The domain numbering depends on whether we support 36 physical
- * address for I/O or not.  Addresses above the 32 bit boundary can
- * only be mapped using supersections and supersections can only
- * be set for domain 0.  We could just default to DOMAIN_IO as zero,
- * but there may be systems with supersection support and no 36-bit
- * addressing.  In such cases, we want to map system memory with
- * supersections to reduce TLB misses and footprint.
- *
- * 36-bit addressing and supersections are only available on
- * CPUs based on ARMv6+ or the Intel XSC3 core.
  */
-#ifndef CONFIG_IO_36
 #define DOMAIN_KERNEL	0
 #define DOMAIN_USER	1
 #define DOMAIN_IO	2
-#else
-#define DOMAIN_KERNEL	2
-#define DOMAIN_USER	1
-#define DOMAIN_IO	0
-#endif
 #define DOMAIN_VECTORS	3
 
 /*
arch/arm/include/asm/memory.h +2 -2
index 7c2fa7dcec6d..e25749bfbf90 100644
@@ -89,9 +89,9 @@
 
 #if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
 /*
- * Allow 16MB-aligned ioremap pages
+ * Allow 2MB-aligned ioremap pages
  */
-#define IOREMAP_MAX_ORDER	24
+#define IOREMAP_MAX_ORDER	21
 #endif
 
 #define VECTORS_BASE		UL(0xffff0000)
arch/arm/include/asm/pgtable-2level-hwdef.h +0 -1
index 556937e1790e..3fa254ac8a26 100644
@@ -35,7 +35,6 @@
 #define PMD_SECT_APX		(_AT(pmdval_t, 1) << 15)	/* v6 */
 #define PMD_SECT_S		(_AT(pmdval_t, 1) << 16)	/* v6 */
 #define PMD_SECT_nG		(_AT(pmdval_t, 1) << 17)	/* v6 */
-#define PMD_SECT_SUPER		(_AT(pmdval_t, 1) << 18)	/* v6 */
 #define PMD_SECT_AF		(_AT(pmdval_t, 0))
 
 #define PMD_SECT_UNCACHED	(_AT(pmdval_t, 0))
arch/arm/include/asm/pgtable-2level.h +0 -7
index 6b5392e20f41..7e1c08fdd029 100644
@@ -96,13 +96,6 @@
 #define SECTION_SIZE		(1UL << SECTION_SHIFT)
 #define SECTION_MASK		(~(SECTION_SIZE-1))
 
-/*
- * ARMv6 supersection address mask and size definitions.
- */
-#define SUPERSECTION_SHIFT	24
-#define SUPERSECTION_SIZE	(1UL << SUPERSECTION_SHIFT)
-#define SUPERSECTION_MASK	(~(SUPERSECTION_SIZE-1))
-
 #define USER_PTRS_PER_PGD	(TASK_SIZE / PGDIR_SIZE)
 
 /*
arch/arm/include/asm/sparsemem.h +4 -0
index 421e3415338a..6b512be3a34a 100644
@@ -19,7 +19,11 @@
  * These can be overridden in your mach/memory.h.
  */
 #if !defined(MAX_PHYSMEM_BITS) || !defined(SECTION_SIZE_BITS)
+#ifdef CONFIG_ARM_LPAE
 #define MAX_PHYSMEM_BITS	36
+#else
+#define MAX_PHYSMEM_BITS	32
+#endif
 #define SECTION_SIZE_BITS	28
 #endif
 
arch/arm/kernel/efi.c +13 -0
index 6f9ec7d28a71..c14275257a8a 100644
@@ -6,6 +6,7 @@
 #include <linux/efi.h>
 #include <linux/memblock.h>
 #include <linux/screen_info.h>
+#include <linux/sizes.h>
 
 #include <asm/efi.h>
 #include <asm/mach/map.h>
@@ -54,6 +55,18 @@ int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
 		.length		= md->num_pages * EFI_PAGE_SIZE,
 	};
 
+	/*
+	 * Non-LPAE page tables cannot map EFI runtime regions extending
+	 * beyond the 32-bit physical address space.
+	 */
+	if (!IS_ENABLED(CONFIG_ARM_LPAE) &&
+	    (md->phys_addr >= SZ_4G ||
+	     md->num_pages > (SZ_4G - md->phys_addr) / EFI_PAGE_SIZE)) {
+		pr_warn("EFI runtime region at 0x%llx exceeds 32-bit physical address space\n",
+			md->phys_addr);
+		return -ERANGE;
+	}
+
 	/*
 	 * Order is important here: memory regions may have all of the
 	 * bits below set (and usually do), so we check them in order of
arch/arm/mm/Kconfig +0 -7
index 871bd58d2ccc..07f1165ca794 100644
@@ -328,7 +328,6 @@ config CPU_XSC3
 	select CPU_PABRT_LEGACY
 	select CPU_THUMB_CAPABLE
 	select CPU_TLB_V4WBI if MMU
-	select IO_36
 
 # Marvell PJ1 (Mohawk)
 config CPU_MOHAWK
@@ -652,12 +651,6 @@ config CPU_V7M_NUM_IRQ
 
 	  If unsure, keep default value.
 
-#
-# CPU supports 36-bit I/O
-#
-config IO_36
-	bool
-
 comment "Processor Features"
 
 config ARM_LPAE
arch/arm/mm/ioremap.c +7 -46

89 lines not on this page · raw message

arch/arm/mm/mmu.c +1 -75

94 lines not on this page · raw message

Signature · 1 line
2.53.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 53 lines · Karl Mehltretter

An ARM randconfig with CONFIG_GET_FREE_REGION=y and CONFIG_WERROR=y fails to build:

include/linux/minmax.h:86:37: error: conversion from 'long long unsigned int' to 'resource_size_t' {aka 'unsigned int'} changes value from '68719476735' to '4294967295' [-Werror=overflow]

Commit 14b80582c43e ("resource: Introduce alloc_free_mem_region()") made kernel/resource.c clamp against
(1ULL << MAX_PHYSMEM_BITS) - 1. resource_size_t is 32-bit without LPAE, but ARM's default MAX_PHYSMEM_BITS is 36.

That default was added by commit db57f88e4ccb ("ARM: 8411/1: Add default SPARSEMEM settings") because several platforms needed at least 36 physical address bits. !LPAE could map addresses above 32 bits only through supersections.

CONFIG_IO_36, added by commit 23bdf86aa06e ("[ARM] 3377/2: add support for intel xsc3 core"), enabled these for XSC3 I/O. IXP23xx placed static I/O mappings above 4GiB until its removal in 2012, and IOP13xx ioremap()ed its PCIe windows there until its removal in 2019. The only remaining XSC3 platform, PXA3xx, has nothing above 4GiB.

Supersection address bits overlap the descriptor domain field, so IO_36 also renumbered the domains to make DOMAIN_IO zero. Remove IO_36, the alternate domain numbering, and ioremap()'s supersection path. Reject !LPAE ioremap ranges extending past 4GiB before phys_addr_t truncation, drop the now-unneeded high static-mapping exclusion, and reduce ioremap alignment from 16MiB to the 2MiB covered by a PMD's pair of sections.

The other supersection user, create_36bit_mapping(), was added by commit 0b7cd62ecdc1 ("[ARM] 3017/1: Add support for 36-bit addresses to create_mapping()") for IXP2350 and carried IXP23xx's high static mappings. Before this change, its only remaining call path was efi_create_mapping() -> create_mapping_late(), for an EFI runtime region above 4GiB.

No real-world user of this !LPAE path is known. AArch32 UEFI requires RAM described by its memory map to be identity-mapped during boot services, which a 32-bit virtual address space cannot provide above 4GiB. Systems needing wider physical addressing are expected to use LPAE.

Remove create_36bit_mapping() and the supersection definitions. If firmware nevertheless advertises such a region on !LPAE, efi_create_mapping() rejects it before __pfn_to_phys() truncates its address to a low alias. EFI runtime services remain disabled, but the kernel continues to boot. LPAE kernels are unaffected.

With no remaining !LPAE mappings above 4GiB, set MAX_PHYSMEM_BITS to 32 for !LPAE and retain 36 for LPAE, where phys_addr_t is 64-bit.

Quoted 7 lines

Link:
https://lore.kernel.org/all/[email protected]/
Link:
https://lore.kernel.org/all/CAK8P3a2MCdUbN0QSb+M3g5_6HjPsaQwtKxFjADMZWomdry4-Ww@mail.gmail.com/

Fixes 14b80582c43e ("resource: Introduce alloc_free_mem_region()")
Assisted-by Claude:claude-fable-5

Let's give others a few more workdays to comment, if nobody has any concerns please add this to Russell's patch tracker at https://www.arm.linux.org.uk/developer/patches/info.php

Arnd