Skip to contentSkip to conversation

ARM: set !LPAE MAX_PHYSMEM_BITS to 32 and remove IO_36

PATCH Superseded Karl Mehltretter 2 participants 4 messages Jul 24 – Jul 25 Arm (32-bit)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: set !LPAE MAX_PHYSMEM_BITS to 32 and remove IO_36

An arm randconfig with CONFIG_GET_FREE_REGION=y (selected by RESOURCE_KUNIT_TEST, DEVICE_PRIVATE, CXL_REGION or DRM_XE) and the default CONFIG_WERROR=y fails to build:

kernel/resource.c: In function 'gfr_start':
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]

since commit 14b80582c43e ("resource: Introduce alloc_free_mem_region()") clamps against (1ULL << MAX_PHYSMEM_BITS) - 1 in resource_size_t arithmetic, which is 32-bit without LPAE while arm's default MAX_PHYSMEM_BITS is 36.

The 36-bit default exists for CONFIG_IO_36, added in commit 23bdf86aa06e ("[ARM] 3377/2: add support for intel xsc3 core") to let IXP23xx ioremap() I/O above 4GiB using supersections. IXP23xx was removed in 2012, IOP13xx, the last user of addresses above 4GiB, in 2019 with v5.4, and PXA3xx as the only remaining XSC3 platform has nothing above 4GiB.

Supersection descriptors have no domain field, as those bits hold extended physical address bits. 36-bit I/O therefore required renumbering the protection domains to make DOMAIN_IO zero, and ioremap()'s supersection path is only compiled in that case.

Remove IO_36, the alternate domain numbering, and the ioremap() supersection path. Reject non-LPAE physical ranges beyond the 32-bit phys_addr_t limit before truncation, preventing faults from ranges crossing 4GiB. Since high non-LPAE ranges are rejected before truncation, remove the corresponding static-mapping exclusion as well. Reduce ioremap alignment from 16MiB to the 2MiB covered by a PMD's pair of sections.

With that, LPAE is the only way to address more than 32 bits of physical memory, so use the 36-bit MAX_PHYSMEM_BITS default only there, matching phys_addr_t.

---
v2: fold in the IO_36 removal and its ioremap path, as requested by Arnd; correct the history (IOP13xx was removed in 2019, not 2012).

Build-tested: the failing randconfig, PXA3xx/XSC3 UP, LPAE (keeps 36 bits); boot-tested on QEMU versatilepb (!LPAE) and virt/Cortex-A15 (LPAE); applies cleanly to v6.1.

Deliberately left in place: create_36bit_mapping() and the PMD_SECT_SUPER/SUPERSECTION_* definitions, now unreachable for device mappings. A follow-up patch can remove them.

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/sparsemem.h |  4 +++
 arch/arm/mm/Kconfig              |  7 -----
 arch/arm/mm/ioremap.c            | 53 +++++---------------------------
 5 files changed, 13 insertions(+), 72 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/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/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

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

An arm randconfig with CONFIG_GET_FREE_REGION=y (selected by RESOURCE_KUNIT_TEST, DEVICE_PRIVATE, CXL_REGION or DRM_XE) and the default CONFIG_WERROR=y fails to build:

kernel/resource.c: In function 'gfr_start':
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]

since commit 14b80582c43e ("resource: Introduce alloc_free_mem_region()") clamps against (1ULL << MAX_PHYSMEM_BITS) - 1 in resource_size_t arithmetic, which is 32-bit without LPAE while arm's default MAX_PHYSMEM_BITS is 36.

The 36-bit default exists for CONFIG_IO_36, added in commit 23bdf86aa06e ("[ARM] 3377/2: add support for intel xsc3 core") to let IXP23xx ioremap() I/O above 4GiB using supersections. IXP23xx was removed in 2012, IOP13xx, the last user of addresses above 4GiB, in 2019 with v5.4, and PXA3xx as the only remaining XSC3 platform has nothing above 4GiB.

Supersection descriptors have no domain field, as thos bits hold extended physical address bits. 36-bit I/O therefore required renumbering the protection domains to make DOMAIN_IO zero, and ioremap()'s supersection path is only compiled in that case.

Remove IO_36, the alternate domain numbering, and the ioremap() supersection path. Reject non-LPAE physical ranges beyond the 32-bit phys_addr_t limit before truncation, preventing faults from ranges crossing 4GiB. Since high non-LPAE ranges are rejected before truncation, remove the corresponding static-mapping exclusion as well. Reduce ioremap alignment from 16MiB to the 2MiB covered by a PMD's pair of sections.

With that, LPAE is the only way to address more than 32 bits of physical memory, so use the 36-bit MAX_PHYSMEM_BITS default only there, matching phys_addr_t.

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

This all looks very good to me, thanks for the updated version!

Quoted 3 lines

Deliberately left in place: create_36bit_mapping() and the PMD_SECT_SUPER/SUPERSECTION_* definitions, now unreachable for device mappings. A follow-up patch can remove them.

I'm not sure why you remove remap_area_supersections() but keep create_36bit_mapping(). I would just remove that as well.

#2 lore raw
Quoted 3 lines · Arnd Bergmann

I'm not sure why you remove remap_area_supersections() but keep create_36bit_mapping(). I would just remove that as well.

Sorry, my earlier explanation was confusing. create_36bit_mapping() is not totally unreachable after this patch. The ARM EFI path can reach it through:

    efi_create_mapping()
      -> create_mapping_late()
      -> create_36bit_mapping()

I verified this with a modified EDK2 build under QEMU that advertised an aligned, write-back EFI runtime memory descriptor above 4 GiB. The kernel successfully created the mapping and enabled EFI runtime services.

Admittedly, this is a synthetic configuration. Stock ARM32 EDK2 restricts allocations to below 4 GiB, and I believe the AArch32 UEFI specification requires RAM in the UEFI memory map to be identity-mapped during boot services. The test setup is therefore probably not a conforming real-world firmware configuration.

Maybe you want to keep create_36bit_mapping() because of that?

Alternatively, if this should be considered unsupported, I can remove it in v3 as you suggested.

If create_36bit_mapping() remains, I will update the commit message to clarify that the patch removes 36-bit I/O mappings, while retaining the generic supersection mapping path for domain-0 memory mappings.

Thanks,
Karl

#3 lore raw
Quoted 18 lines · Karl Mehltretter
Quoted 3 lines · Arnd Bergmann

I'm not sure why you remove remap_area_supersections() but keep create_36bit_mapping(). I would just remove that as well.

Sorry, my earlier explanation was confusing. create_36bit_mapping() is not totally unreachable after this patch. The ARM EFI path can reach it through:

    efi_create_mapping()
      -> create_mapping_late()
      -> create_36bit_mapping()

I verified this with a modified EDK2 build under QEMU that advertised an aligned, write-back EFI runtime memory descriptor above 4 GiB. The kernel successfully created the mapping and enabled EFI runtime services.

Quoted 5 lines

Admittedly, this is a synthetic configuration. Stock ARM32 EDK2 restricts allocations to below 4 GiB, and I believe the AArch32 UEFI specification requires RAM in the UEFI memory map to be identity-mapped during boot services. The test setup is therefore probably not a conforming real-world firmware configuration.

Ok, I see. I can't think of any scenario where this would do us any good to have an EFI runtime mapping for high memory when it can't be accessed by the kernel later. Anyone running Linux on an arm32 system with more than 4GB of physical addressing is already using an LPAE kernel and won't be missing it.

Please just remove this as well.

Arnd