mm: highmem cleanups
Subsystems (16)
v3 cover mm: highmem cleanups
From: Arnd Bergmann <[email protected]>
This is an updated series from what I posted last year [1] and last week[2].
At LPC 2025 [3], we got rough consensus on the plan to keep the funcationality present for the time being but instead reduce the scope of highmem in the kernel as much as we can without hurting users.
The short summary is a three stage process:
1. Nudge users towards using a larger lowmem zone with the CONFIG_VMSPLIT_* options if at all possible.
2. Drop most __GFP_HIGHMEM allocations and corresponding kmap() calls from the kernel, leaving only the subset that is likely to contain the majority of the actual allocations. Specifically we will keep anonymous and regular file backed user mappings, zsmalloc, and huge pages.
3. In a few years, also drop the page cache allocations and leave perhaps only zsmalloc using a much simpler interface. I suggested five years as the time until we do this, but the timing depends a lot on how the first two stages work out in practice, and how long the remaining highmem users plan to keep updating their kernels.
This series implements stage 1, mostly using Kconfig changes to the default settings but leaving the traditional behavior as a CONFIG_EXPERT choice in Kconfig. With the new defaults, most installations that use highmem today with 1 GiB or 2 GiB of system RAM will see all of their RAM in the lowmem zone after upgrading their kernels. My estimate is that instead of 80% to 90% of maintained embedded 32-bit systems, this should cover over 98%.
As I don't actually have hardware in the category that still needs highmem, I tested this using a qemu-system for Armv7 and PPC6xx running a Debian userland with all combinations of VMSPLIT and HIGHMEM options. I ran some kernel builds on the Arm guest to ensure that the new options don't cause functional or performance regressions for regular workloads that don't exceed the virtual address space. I also ran some tests with Firefox and was positively surprised to see that this still works on the VMSPLIT_2G_OPT configuration without highmem, though it gets close to both the address space and lowmem size limits.
The change to use VMSPLIT_3G_OPT by default on Armv5 means that I could include a patch to no longer support highmem at all on VIVT caches, as suggested by Jason Gunthorpe. I also included the patch to drop HIGHPTE support now, as suggested by David Hildenbrand.
The patches from this series are available in [4] for testing.
Once there are no further concerns about the contents, I would suggest merging this through the asm-generic tree, as it touches mostly architecture specific code and that is not easily split from the core mm/* code. Merging everything through the mm tree would of course also work.
Arnd
[1] https://lore.kernel.org/all/[email protected]/ # v1
[2] https://lore.kernel.org/all/[email protected]/ # v2
[3] https://lwn.net/Articles/1051010/
[4] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=highmem-7.4
Changes since v2:
- Add preparation patch for Arm PXA [sashiko-bot]
- Add preparation patch for powerpc32/kvm [sashiko-bot]
- Fix Arm ARCH_MMAP_RND_BITS_MAX calculation [sashiko-bot]
- Simplification for pte_alloc_one() [Mike Rapoport]
- Drop stale references to highpte [David Hildenbrand]
- improve __print_bad_page_map_pgtable()
- Split out Arm changes for CONFIG_VMSPLIT_2G_OPT
Changes since v1:
- rebase to v7.4-rc
- add patch to drop highpte
Arnd Bergmann (10):
ARM: remove support for highmem on VIVT
ARM: drop CONFIG_HIGHPTE support
ARM: pxa: support arbitrary PAGE_OFFSET
powerpc: kvm: allow flexible PAGE_OFFSET
arch/*: increase lowmem size to avoid highmem use
ARM: add CONFIG_VMSPLIT_2G_OPT option
ARM: defconfig: turn off highmem in favor of CONFIG_VMSPLIT_2G_OPT
mm: remove ARCH_NEEDS_KMAP_HIGH_GET
mm: drop HIGHPTE support altogether
mm: print pte in __print_bad_page_map_pgtable()
arch/arm/Kconfig | 27 +++--- arch/arm/configs/aspeed_g5_defconfig | 3 +- arch/arm/configs/gemini_defconfig | 1 - arch/arm/configs/lpae.config | 1 + arch/arm/configs/multi_v5_defconfig | 1 - arch/arm/configs/multi_v7_defconfig | 1 + arch/arm/configs/mvebu_v5_defconfig | 1 - arch/arm/configs/omap2plus_defconfig | 1 + arch/arm/configs/u8500_defconfig | 1 - arch/arm/configs/vt8500_v6_v7_defconfig | 2 - arch/arm/include/asm/highmem.h | 56 +---------- arch/arm/include/asm/pgalloc.h | 13 +-- arch/arm/mach-omap2/Kconfig | 1 - arch/arm/mach-pxa/pxa3xx.c | 2 +- arch/arm/mm/cache-feroceon-l2.c | 31 +----- arch/arm/mm/cache-xsc3l2.c | 47 +-------- arch/arm/mm/dma-mapping.c | 12 +-- arch/arm/mm/flush.c | 19 +--- arch/microblaze/Kconfig | 9 +- arch/microblaze/configs/mmu_defconfig | 1 - arch/powerpc/Kconfig | 24 +++-- arch/powerpc/configs/44x/akebono_defconfig | 1 - arch/powerpc/configs/85xx/ksi8560_defconfig | 1 - arch/powerpc/configs/85xx/stx_gp3_defconfig | 1 - arch/powerpc/kvm/book3s_32_sr.S | 4 +- arch/powerpc/kvm/booke_interrupts.S | 4 +- arch/powerpc/kvm/e500_mmu_host.c | 3 +- arch/x86/Kconfig | 4 +- include/linux/hugetlb.h | 5 +- include/linux/mm.h | 1 - include/linux/pgtable.h | 13 --- mm/highmem.c | 100 ++------------------ mm/memory.c | 21 ++-- mm/pgtable-generic.c | 25 +++-- mm/userfaultfd.c | 6 +- 35 files changed, 104 insertions(+), 339 deletions(-)
Signature · 29 lines
2.53.0 Cc: Andreas Larsson <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Christophe Leroy (CS GROUP) <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Hildenbrand (Arm) <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Lorenzo Stoakes (ARM) <[email protected]> Cc: Lucas Stach <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Malin Jonsson <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Nishanth Menon <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
PATCH v3 1/10 ARM: remove support for highmem on VIVT
From: Arnd Bergmann <[email protected]>
As Jason Gunthorpe noticed, supporting VIVT caches adds some complications to highmem that can be avoided these days:
While all ARMv4 and ARMv5 CPUs use virtually indexed caches, they no longer really need highmem because we have practically discontinued support for large-memory configurations already. The only machines I could find anywhere for memory on ARMv5 are:
- The Intel IOP platform was used on relatively large memory configurations but we dropped kernel support in 2019 and 2022, respectively.
- The Marvell mv78xx0 platform was the initial user of Arm highmem, with the DB-78x00-BP supporting 2GB of memory. The only remaining board file is for Buffalo WLX (Terastation Duo), which has only 512MB and is going to be removed soon.
- The Kirkwood platform supports 2GB, and there are actually boards with that configuration that can still work. However, there are no known users of the OpenBlocks A7, and the Freebox V6 is already using CONFIG_VMSPLIT_2G to avoid enabling highmem.
Remove the Arm specific portions here, making CONFIG_HIGHMEM conditional on modern caches. Since the cache type is enforced by Kconfig, no boot time check is needed here.
--- arch/arm/Kconfig | 1 + arch/arm/configs/gemini_defconfig | 1 - arch/arm/configs/multi_v5_defconfig | 1 - arch/arm/configs/mvebu_v5_defconfig | 1 - arch/arm/include/asm/highmem.h | 56 ++--------------------------- arch/arm/mm/cache-feroceon-l2.c | 31 ++-------------- arch/arm/mm/cache-xsc3l2.c | 47 +++--------------------- arch/arm/mm/dma-mapping.c | 12 ++----- arch/arm/mm/flush.c | 19 +++------- 9 files changed, 16 insertions(+), 153 deletions(-)
arch/arm/Kconfig +1 -0
@@ -1208,6 +1208,7 @@ config ARCH_SPARSEMEM_ENABLE config HIGHMEM bool "High Memory Support" depends on MMU + depends on !CPU_CACHE_VIVT select KMAP_LOCAL select KMAP_LOCAL_NON_LINEAR_PTE_ARRAY help
arch/arm/configs/gemini_defconfig +0 -1
@@ -11,7 +11,6 @@ CONFIG_KEXEC=y CONFIG_ARCH_MULTI_V4=y # CONFIG_ARCH_MULTI_V7 is not set CONFIG_ARCH_GEMINI=y -CONFIG_HIGHMEM=y CONFIG_CMDLINE="console=ttyS0,115200n8" CONFIG_PM=y CONFIG_PARTITION_ADVANCED=y
arch/arm/configs/multi_v5_defconfig +0 -1
@@ -27,7 +27,6 @@ CONFIG_MACH_D2NET_DT=y CONFIG_MACH_MSS2_DT=y CONFIG_ARCH_SUNXI=y CONFIG_ARCH_VERSATILE=y -CONFIG_HIGHMEM=y CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y CONFIG_CPU_FREQ=y
arch/arm/configs/mvebu_v5_defconfig +0 -1
@@ -13,7 +13,6 @@ CONFIG_MACH_RD88F5182_DT=y CONFIG_MACH_LINKSTATION_MINI=y CONFIG_MACH_D2NET_DT=y CONFIG_MACH_MSS2_DT=y -CONFIG_HIGHMEM=y CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y CONFIG_CPU_FREQ=y
arch/arm/include/asm/highmem.h +2 -54
68 lines not on this page · raw message
arch/arm/mm/cache-feroceon-l2.c +2 -29
@@ -12,7 +12,6 @@#include <linux/init.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/highmem.h> #include <linux/io.h> #include <asm/cacheflush.h> #include <asm/cp15.h>
@@ -38,30 +37,6 @@* between which we don't want to be preempted. */ -static inline unsigned long l2_get_va (unsigned long paddr) -{ -#ifdef CONFIG_HIGHMEM -/* -* Because range ops can't be done on physical addresses, -* we simply install a virtual mapping for it only for the -* TLB lookup to occur, hence no need to flush the untouched -* memory mapping afterwards (note: a cache flush may happen -* in some circumstances depending on the path taken in kunmap_atomic). -*/ -void *vaddr =kmap_atomic_pfn (paddr >>PAGE_SHIFT ); -return (unsigned long )vaddr + (paddr & ~PAGE_MASK ); -#else -return __phys_to_virt (paddr); -#endif -} - -static inline void l2_put_va (unsigned long vaddr) -{ -#ifdef CONFIG_HIGHMEM -kunmap_atomic ((void *)vaddr); -#endif -} -static inline void l2_clean_pa (unsigned long addr) { __asm__("mcr p15, 1, %0, c15, c9, 3" : :"r" (addr));
@@ -78,14 +53,13 @@ static inline void l2_clean_pa_range(unsigned long start, unsigned long end)*/ BUG_ON ((start ^ end) >>PAGE_SHIFT ); - va_start =l2_get_va (start); + va_start =__phys_to_virt (start); va_end = va_start + (end - start);raw_local_irq_save (flags); __asm__("mcr p15, 1, %0, c15, c9, 4\n\t" "mcr p15, 1, %1, c15, c9, 5" : :"r" (va_start),"r" (va_end));raw_local_irq_restore (flags); -l2_put_va (va_start); }static inline void l2_clean_inv_pa (unsigned long addr)
@@ -109,14 +83,13 @@ static inline void l2_inv_pa_range(unsigned long start, unsigned long end)*/ BUG_ON ((start ^ end) >>PAGE_SHIFT ); - va_start =l2_get_va (start); + va_start =__phys_to_virt (start); va_end = va_start + (end - start);raw_local_irq_save (flags); __asm__("mcr p15, 1, %0, c15, c11, 4\n\t" "mcr p15, 1, %1, c15, c11, 5" : :"r" (va_start),"r" (va_end));raw_local_irq_restore (flags); -l2_put_va (va_start); }static inline void l2_inv_all (void )
arch/arm/mm/cache-xsc3l2.c +5 -42
106 lines not on this page · raw message
arch/arm/mm/dma-mapping.c +2 -10
@@ -647,18 +647,10 @@ static void dma_cache_maint_page(phys_addr_t phys, size_t size,if (len + offset >PAGE_SIZE ) len =PAGE_SIZE - offset; -if (cache_is_vipt_nonaliasing ()) { - vaddr =kmap_atomic_pfn (pfn); + vaddr =kmap_atomic (phys_to_page (phys)); +if (vaddr) {op (vaddr + offset, len, dir);kunmap_atomic (vaddr); - }else { -struct page *page =phys_to_page (phys); - - vaddr =kmap_high_get (page); -if (vaddr) { -op (vaddr + offset, len, dir); -kunmap_high (page); - } } }else { phys += offset;
arch/arm/mm/flush.c +4 -15
@@ -208,21 +208,10 @@ void __flush_dcache_folio(struct address_space *mapping, struct folio *folio) folio_size(folio)); }else {unsigned long i; -if (cache_is_vipt_nonaliasing ()) { -for (i =0 ; i <folio_nr_pages (folio); i++) { -void *addr =kmap_local_folio (folio, - i *PAGE_SIZE ); -__cpuc_flush_dcache_area (addr,PAGE_SIZE ); -kunmap_local (addr); - } - }else { -for (i =0 ; i <folio_nr_pages (folio); i++) { -void *addr =kmap_high_get (folio_page (folio, i)); -if (addr) { -__cpuc_flush_dcache_area (addr,PAGE_SIZE ); -kunmap_high (folio_page (folio, i)); - } - } +for (i =0 ; i <folio_nr_pages (folio); i++) { +void *addr =kmap_local_folio (folio, i *PAGE_SIZE ); +__cpuc_flush_dcache_area (addr,PAGE_SIZE ); +kunmap_local (addr); } }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 01/10] ARM: remove support for highmem on VIVT
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] ARM: dma-mapping: kmap_atomic_pfn() replaced in dma_cache_maint_page() - [Low] ARM: cache-xsc3l2…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] ARM: dma-mapping: kmap_atomic_pfn() replaced in dma_cache_maint_page()
- [Low] ARM: cache-xsc3l2: dead vaddr = -1 in xsc3_l2_clean/flush_range()
--
commit f8716df5db2cf8798681c350ff9ec3e69d48df95
Author: Arnd Bergmann <[email protected]>
ARM: remove support for highmem on VIVT
This commit disables CONFIG_HIGHMEM when CONFIG_CPU_CACHE_VIVT is enabled and removes highmem support paths specific to VIVT caches across ARM cache and memory management code.
Quoted 4 lines
arch/arm/mm/cache-xsc3l2.c +0
-0
[ ... ]
Quoted 20 lines
arch/arm/mm/cache-xsc3l2.c +1
-4@@ -135,13 +102,11 @@ static void xsc3_l2_clean_range(unsigned long start, unsigned long end) start &= ~(CACHE_LINE_SIZE -1 );while (start < end) { - vaddr =l2_map_va (start, vaddr); + vaddr =__phys_to_virt (start);xsc3_l2_clean_mva (vaddr); start +=CACHE_LINE_SIZE ; } -l2_unmap_va (vaddr); -dsb (); }@@ -178,14 +143,12 @@ static void xsc3_l2_flush_range(unsigned long start, unsigned long end) start &= ~(CACHE_LINE_SIZE -1 );while (start < end) { - vaddr =l2_map_va (start, vaddr);
arch/arm/mm/cache-xsc3l2.c static void xsc3_l2_flush_range(unsigned long start, unsigned long end) · line 153
Quoted 10 lines
arch/arm/mm/cache-xsc3l2.c +1
-2+ vaddr =__phys_to_virt (start);xsc3_l2_clean_mva (vaddr);xsc3_l2_inv_mva (vaddr); start +=CACHE_LINE_SIZE ; } -l2_unmap_va (vaddr); -dsb (); }
[Severity: Low]
This isn't a bug, but both xsc3_l2_clean_range() and xsc3_l2_flush_range() still initialize vaddr = -1 with the comment "to force the first mapping" right above these loops. With l2_map_va() and l2_unmap_va() gone, those initializations are dead and could be dropped just like in xsc3_l2_inv_range().
Quoted 15 lines
arch/arm/mm/dma-mapping.c +2
-3@@ -647,18 +647,10 @@ static void dma_cache_maint_page(phys_addr_t phys, size_t size,if (len + offset >PAGE_SIZE ) len =PAGE_SIZE - offset; -if (cache_is_vipt_nonaliasing ()) { - vaddr =kmap_atomic_pfn (pfn); + vaddr =kmap_atomic (phys_to_page (phys)); +if (vaddr) {op (vaddr + offset, len, dir);kunmap_atomic (vaddr); - }else {
arch/arm/mm/dma-mapping.c static void dma_cache_maint_page(phys_addr_t phys, size_t size, · line 656
Quoted 10 lines
arch/arm/mm/dma-mapping.c +0
-7-struct page *page =phys_to_page (phys); - - vaddr =kmap_high_get (page); -if (vaddr) { -op (vaddr + offset, len, dir); -kunmap_high (page); - } } }else { phys += offset;
[Severity: Low]
Should this keep the kmap_atomic_pfn(pfn) call and drop the if (vaddr) check?
52c9aa1adc30 ("ARM: dma-mapping: Reduce struct page exposure in arch_sync_dma*()") converted this path to kmap_atomic_pfn(pfn) so that only the kmap_high_get() branch still needed phys_to_page(phys). Using kmap_atomic(phys_to_page(phys)) reintroduces a struct page round-trip, and kmap_atomic_pfn() never returns NULL.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 01/10] ARM: remove support for highmem on VIVT
Quoted 11 lines · On Tue, Nov 17, 2026, at 13:49, [email protected] wrote:
Quoted 11 lines
arch/arm/mm/cache-xsc3l2.c +1
-1@@ -178,14 +143,12 @@ static void xsc3_l2_flush_range(unsigned long start, unsigned long end) start &= ~(CACHE_LINE_SIZE -1 );while (start < end) { - vaddr =l2_map_va (start, vaddr); + vaddr =__phys_to_virt (start);xsc3_l2_clean_mva (vaddr);xsc3_l2_inv_mva (vaddr); start +=CACHE_LINE_SIZE ; }
Quoted 11 lines
arch/arm/mm/cache-xsc3l2.c static void xsc3_l2_inv_range(unsigned long start, unsigned long end) · line 95
Quoted 4 lines
arch/arm/mm/cache-xsc3l2.c +0
-2-l2_unmap_va (vaddr); -dsb (); }[Severity: Low]
This isn't a bug, but bothxsc3_l2_clean_range()andxsc3_l2_flush_range()still initialize vaddr = -1 with the comment "to force the first mapping" right above these loops. Withl2_map_va()andl2_unmap_va()gone, those initializations are dead and could be dropped just like inxsc3_l2_inv_range().
ok, fixed.
Quoted 30 lines
Quoted 15 lines
arch/arm/mm/dma-mapping.c +2
-3@@ -647,18 +647,10 @@ static void dma_cache_maint_page(phys_addr_t phys, size_t size,if (len + offset >PAGE_SIZE ) len =PAGE_SIZE - offset; -if (cache_is_vipt_nonaliasing ()) { - vaddr =kmap_atomic_pfn (pfn); + vaddr =kmap_atomic (phys_to_page (phys)); +if (vaddr) {op (vaddr + offset, len, dir);kunmap_atomic (vaddr); - }else {arch/arm/mm/dma-mapping.c static void dma_cache_maint_page(phys_addr_t phys, size_t size, · line 656
Quoted 10 lines
arch/arm/mm/dma-mapping.c +0
-7-struct page *page =phys_to_page (phys); - - vaddr =kmap_high_get (page); -if (vaddr) { -op (vaddr + offset, len, dir); -kunmap_high (page); - } } }else { phys += offset;[Severity: Low]
Should this keep thekmap_atomic_pfn(pfn)call and drop the if (vaddr) check?
Quoted 5 lines
52c9aa1adc30("ARM: dma-mapping: Reduce struct page exposure in arch_sync_dma*()") converted this path tokmap_atomic_pfn(pfn)so that only thekmap_high_get()branch still neededphys_to_page(phys). Using kmap_atomic(phys_to_page(phys)) reintroduces a struct page round-trip, andkmap_atomic_pfn()never returns NULL.
done.
Arnd
Re: [PATCH v3 01/10] ARM: remove support for highmem on VIVT
In reply to Arnd BergmannQuoted 24 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
As Jason Gunthorpe noticed, supporting VIVT caches adds some complications to highmem that can be avoided these days:
While all ARMv4 and ARMv5 CPUs use virtually indexed caches, they no longer really need highmem because we have practically discontinued support for large-memory configurations already. The only machines I could find anywhere for memory on ARMv5 are:
- The Intel IOP platform was used on relatively large memory configurations but we dropped kernel support in 2019 and 2022, respectively.
- The Marvell mv78xx0 platform was the initial user of Arm highmem, with the DB-78x00-BP supporting 2GB of memory. The only remaining board file is for Buffalo WLX (Terastation Duo), which has only 512MB and is going to be removed soon.
- The Kirkwood platform supports 2GB, and there are actually boards with that configuration that can still work. However, there are no known users of the OpenBlocks A7, and the Freebox V6 is already using
CONFIG_VMSPLIT_2Gto avoid enabling highmem.
Quoted 8 lines
Remove the Arm specific portions here, making
CONFIG_HIGHMEMconditional on modern caches. Since the cache type is enforced byKconfig, no boot time check is needed here.Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>
Good riddance I'd say. I'd choose VMSPLIT_2G over highmem any day.
Yours,
Linus Walleij
PATCH v3 2/10 ARM: drop CONFIG_HIGHPTE support
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
CONFIG_HIGHPTE was added in linux-2.6.32, a few years before 64-bit support. At the time it made sense, as the CONFIG_ARM_LPAE option allowed systems with 16GB of memory that made lowmem a particularly scarce resource, and the HIGHPTE implementation gave feature parity with 32-bit x86 and frv machines.
Since Arm is the last architecture remaining that uses this, and almost no 32-bit machines support more than 4GB of RAM, the cost of continuing to maintain HIGHPTE seems unjustified, so remove it here to allow simplifying the generic page table handling.
--- arch/arm/Kconfig | 11 ----------- arch/arm/configs/vt8500_v6_v7_defconfig | 1 - arch/arm/include/asm/pgalloc.h | 13 +++---------- 3 files changed, 3 insertions(+), 22 deletions(-)
arch/arm/Kconfig +0 -11
@@ -1225,17 +1225,6 @@ config HIGHMEM If unsure, say n. -config HIGHPTE - bool "Allocate 2nd-level pagetables from highmem" if EXPERT - depends on HIGHMEM && !PREEMPT_RT - default y - help - The VM uses one page of physical memory for each page table. - For systems with a lot of processes, this can use a lot of - precious low memory, eventually leading to low memory being - consumed by page tables. Setting this option will allow - user-space 2nd level page tables to reside in high memory. - config ARM_PAN bool "Enable privileged no-access" depends on MMU
arch/arm/configs/vt8500_v6_v7_defconfig +0 -1
@@ -9,7 +9,6 @@ CONFIG_ARM_ERRATA_754322=y CONFIG_ARM_ERRATA_775420=y CONFIG_HAVE_ARM_ARCH_TIMER=y CONFIG_HIGHMEM=y -CONFIG_HIGHPTE=y CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y CONFIG_VFP=y
arch/arm/include/asm/pgalloc.h +3 -10
@@ -85,22 +85,15 @@ pte_alloc_one_kernel(struct mm_struct *mm)return pte; } -#ifdef CONFIG_HIGHPTE -#define PGTABLE_HIGHMEM __GFP_HIGHMEM -#else -#define PGTABLE_HIGHMEM 0 -#endif -static inline pgtable_t pte_alloc_one (struct mm_struct *mm) {struct page *pte; - pte =__pte_alloc_one (mm,GFP_PGTABLE_USER |PGTABLE_HIGHMEM ); -if (!pte) -return NULL ; -if (!PageHighMem (pte)) + pte =__pte_alloc_one (mm,GFP_PGTABLE_USER ); +if (pte)clean_pte_table (page_address (pte)); +return pte; }
Signature · 1 line
2.53.0
PATCH v3 3/10 ARM: pxa: support arbitrary PAGE_OFFSET
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
The pxa3xx_cpu_pm_suspend() implementation hardcodes the default PAGE_OFFSET value for CONFIG_VMSPLIT_3G. This has always been broken for other configurations but becomes much worse now that the default is changing.
Fix this to use the correct compile-time constant instead.
--- arch/arm/mach-pxa/pxa3xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-pxa/pxa3xx.c +1 -1
@@ -103,7 +103,7 @@ static void pxa3xx_cpu_standby(unsigned int pwrmode)*/ static void pxa3xx_cpu_pm_suspend (void ) { -volatile unsigned long *p = (volatile void *)0xc0000000 ; +volatile unsigned long *p = (volatile void *)PAGE_OFFSET ;unsigned long saved_data = *p;#ifndef CONFIG_IWMMXT u64 acc0;
Signature · 1 line
2.53.0
PATCH v3 4/10 powerpc: kvm: allow flexible PAGE_OFFSET
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
As described by the Sashiko bot, the KVM code on powerpc has multiple hardcoded PAGE_OFFSET values. In order to change the default, make these compute the correct register values from configuration symbols.
--- arch/powerpc/kvm/book3s_32_sr.S | 4 ++-- arch/powerpc/kvm/booke_interrupts.S | 4 ++-- arch/powerpc/kvm/e500_mmu_host.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_32_sr.S +2 -2
@@ -113,8 +113,8 @@ li r0, 4 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + lis r4, (PAGE_OFFSET >> 16) 3: mtsrin r3, r4 addi r3, r3, 0x111 /* increment VSID */ addis r4, r4, 0x1000 /* address of next segment */
arch/powerpc/kvm/booke_interrupts.S +2 -2
@@ -230,8 +230,8 @@ _GLOBAL(kvmppc_resume_host) #endif /* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always 0xc0000000. */ - lis r3, 0xc000 + * that Linux IVPR is always PAGE_OFFSET. */ + lis r3, PAGE_OFFSET >> 16 mtspr SPRN_IVPR, r3 /* Switch to kernel stack and jump to handler. */
arch/powerpc/kvm/e500_mmu_host.c +2 -1
@@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr)mtspr (SPRN_MAS6 ,0 ); mas4 =mfspr (SPRN_MAS4 );mtspr (SPRN_MAS4 , mas4 & ~MAS4_TLBSEL_MASK ); - asmvolatile ("tlbsx 0, %0" : :"b" (eaddr & ~CONFIG_PAGE_OFFSET )); + asmvolatile ("tlbsx 0, %0" : + :"b" (eaddr & (rounddown_pow_of_two (PAGE_OFFSET )-1 ))); mas0 =mfspr (SPRN_MAS0 );mtspr (SPRN_MAS4 , mas4);local_irq_restore (flags);
Signature · 1 line
2.53.0
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
Hi Arnd,
Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
Quoted 18 lines
From: Arnd Bergmann <[email protected]>
As described by the Sashiko bot, the KVM code on powerpc has multiple hardcoded
PAGE_OFFSETvalues. In order to change the default, make these compute the correct register values from configuration symbols.Signed-off-by Arnd Bergmann <[email protected]>--- arch/powerpc/kvm/book3s_32_sr.S | 4 ++-- arch/powerpc/kvm/booke_interrupts.S | 4 ++-- arch/powerpc/kvm/e500_mmu_host.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s_32_sr.S +0
-0
arch/powerpc/kvm/book3s_32_sr.S line 117
Quoted 7 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2@@ -113,8 +113,8 @@ li r0, 4 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + lis r4, (PAGE_OFFSET >> 16)
This is not enough I think. You need to load ctr with the number of segments you want to populate. Here above it is hardcoded to 4.
Quoted 8 lines
arch/powerpc/kvm/book3s_32_sr.S +0
-03: mtsrin r3, r4 addi r3, r3, 0x111 /* increment VSID */ addis r4, r4, 0x1000 /* address of next segment */arch/powerpc/kvm/booke_interrupts.S +0
-0
arch/powerpc/kvm/booke_interrupts.S _GLOBAL(kvmppc_resume_host) · line 234
Quoted 7 lines
arch/powerpc/kvm/booke_interrupts.S +2
-2@@ -230,8 +230,8 @@ _GLOBAL(kvmppc_resume_host) #endif /* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always 0xc0000000. */ - lis r3, 0xc000 + * that Linux IVPR is always PAGE_OFFSET. */ + lis r3, PAGE_OFFSET >> 16
Maybe use PAGE_OFFSET@h instead of PAGE_OFFSET >> 16.
arch/powerpc/kvm/booke_interrupts.S _GLOBAL(kvmppc_resume_host) · line 235
Quoted 1 line
arch/powerpc/kvm/booke_interrupts.S +0
-0mtspr SPRN_IVPR, r3
That's probably valid but wouldn't it be more correct to use interrupt_base@h as in head_44x.S and head_85xx.S :
lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
mtspr SPRN_IVPR,r4
arch/powerpc/kvm/e500_mmu_host.c static u32 get_host_mas0(unsigned long eaddr) · line 119
Quoted 13 lines
arch/powerpc/kvm/booke_interrupts.S +0
-0/* Switch to kernel stack and jump to handler. */arch/powerpc/kvm/e500_mmu_host.c +2
-1@@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr)mtspr (SPRN_MAS6 ,0 ); mas4 =mfspr (SPRN_MAS4 );mtspr (SPRN_MAS4 , mas4 & ~MAS4_TLBSEL_MASK ); - asmvolatile ("tlbsx 0, %0" : :"b" (eaddr & ~CONFIG_PAGE_OFFSET )); + asmvolatile ("tlbsx 0, %0" : + :"b" (eaddr & (rounddown_pow_of_two (PAGE_OFFSET )-1 )));
I think this is not valid.
With PAGE_OFFSET equal to 0xc0000000,
Before:
eaddr & 0x3fffffff
Now:
eaddr & (0x80000000 - 1) = eaddr & 0x7fffffff
arch/powerpc/kvm/e500_mmu_host.c static u32 get_host_mas0(unsigned long eaddr) · line 122
Quoted 3 lines
arch/powerpc/kvm/e500_mmu_host.c +0
-0mas0 =mfspr (SPRN_MAS0 );mtspr (SPRN_MAS4 , mas4);local_irq_restore (flags);
Christophe
Re: [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
Quoted 7 lines · Christophe Leroy (CS GROUP)
Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +0
-0@@ -113,8 +113,8 @@
Quoted 9 lines
arch/powerpc/kvm/book3s_32_sr.S line 117
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2li r0, 4 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + lis r4, (PAGE_OFFSET >> 16)This is not enough I think. You need to load ctr with the number of segments you want to populate. Here above it is hardcoded to 4.
Ok, trying this one now
arch/powerpc/kvm/book3s_32_sr.S +5 -7
@@ -107,14 +107,12 @@ KVM_LOAD_BAT(2, r9, r10, r11) KVM_LOAD_BAT(3, r9, r10, r11) - /* Restore Segment Registers */ - - /* 0xc - 0xf */ - - li r0, 4 + /* Restore Segment Registers, assumes PAGE_OFFSET is segment aligned */ + li r0, (0x100000000 - PAGE_OFFSET) >> 28 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + + lis r4, PAGE_OFFSET@h 3: mtsrin r3, r4 addi r3, r3, 0x111 /* increment VSID */ addis r4, r4, 0x1000 /* address of next segment */
Quoted 8 lines
arch/powerpc/kvm/book3s_32_sr.S line 120
Quoted 5 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2/* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always 0xc0000000. */ - lis r3, 0xc000 + * that Linux IVPR is always PAGE_OFFSET. */ + lis r3, PAGE_OFFSET >> 16Maybe use PAGE_OFFSET@h instead of
PAGE_OFFSET>> 16.
Quoted 7 lines
Quoted 1 line
mtspr
SPRN_IVPR, r3That's probably valid but wouldn't it be more correct to use interrupt_base@h as in
head_44x.Sandhead_85xx.S:lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
mtspr SPRN_IVPR,r4
Ok, copying that version now:
arch/powerpc/kvm/booke_interrupts.S +2 -3
@@ -229,9 +229,8 @@ _GLOBAL(kvmppc_resume_host) mtspr SPRN_PID1, r3 #endif - /* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always PAGE_OFFSET. */ - lis r3, PAGE_OFFSET >> 16 + /* Restore host IVPR before re-enabling interrupts. */ + lis r3, interrupt_base@h /* IVPR only uses the high 16-bits */ mtspr SPRN_IVPR, r3 /* Switch to kernel stack and jump to handler. */
Quoted 12 lines
arch/powerpc/kvm/book3s_32_sr.S static u32 get_host_mas0(unsigned long eaddr) · line 119
Quoted 7 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-1@@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr) mtspr(SPRN_MAS6, 0); mas4 = mfspr(SPRN_MAS4); mtspr(SPRN_MAS4, mas4 & ~MAS4_TLBSEL_MASK); - asm volatile("tlbsx 0, %0" : : "b" (eaddr & ~CONFIG_PAGE_OFFSET)); + asm volatile("tlbsx 0, %0" : + : "b" (eaddr & (rounddown_pow_of_two(PAGE_OFFSET)-1)));I think this is not valid.
With
PAGE_OFFSETequal to0xc0000000,
Quoted 7 lines
Before:
eaddr &
0x3fffffffNow:
eaddr & (
0x80000000- 1) = eaddr &0x7fffffff
I'm probably still misunderstanding the intention of this code then, my reading of the comment was that both 0x3fffffff and 0x7fffffff would be valid choices here as both are below PAGE_OFFSET and large enough to alias the correct set.
What are the actual requirements for the mask?
Thanks for looking at these bits in detail, I'm quite out of my comfort zone here, especially with the book-e stuff.
Arnd
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
Le 16/11/2026 à 23:54, Arnd Bergmann a écrit :
Quoted 23 lines · Christophe Leroy (CS GROUP)
Quoted 7 lines
Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +0
-0@@ -113,8 +113,8 @@Quoted 9 lines
arch/powerpc/kvm/book3s_32_sr.S
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2li r0, 4 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + lis r4, (PAGE_OFFSET >> 16)This is not enough I think. You need to load ctr with the number of segments you want to populate. Here above it is hardcoded to 4.
Ok, trying this one now
arch/powerpc/kvm/book3s_32_sr.S line 111
Quoted 10 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-5@@ -107,14 +107,12 @@ KVM_LOAD_BAT(2, r9, r10, r11) KVM_LOAD_BAT(3, r9, r10, r11) - /* Restore Segment Registers */ - - /* 0xc - 0xf */ - - li r0, 4 + /* Restore Segment Registers, assumes PAGE_OFFSET is segment aligned */ + li r0, (0x100000000 - PAGE_OFFSET) >> 28
Fine, thank should work allthough I would have used 0x10 - (PAGE_OFFSET >> 28)
arch/powerpc/kvm/book3s_32_sr.S line 113
Quoted 4 lines
arch/powerpc/kvm/book3s_32_sr.S +1
-2mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28)))
Maybe an opportunity to replace 0x20000000 by SR_KP
Quoted 57 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-0+ + lis r4, PAGE_OFFSET@h 3: mtsrin r3, r4 addi r3, r3, 0x111 /* increment VSID */ addis r4, r4, 0x1000 /* address of next segment */Quoted 9 lines
arch/powerpc/kvm/book3s_32_sr.S line 120
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2/* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always 0xc0000000. */ - lis r3, 0xc000 + * that Linux IVPR is always PAGE_OFFSET. */ + lis r3, PAGE_OFFSET >> 16Maybe use PAGE_OFFSET@h instead of
PAGE_OFFSET>> 16.Quoted 7 lines
Quoted 1 line
mtspr
SPRN_IVPR, r3That's probably valid but wouldn't it be more correct to use interrupt_base@h as in
head_44x.Sandhead_85xx.S:lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
mtspr SPRN_IVPR,r4Ok, copying that version now:
arch/powerpc/kvm/booke_interrupts.S +2
-3@@ -229,9 +229,8 @@ _GLOBAL(kvmppc_resume_host) mtspr SPRN_PID1, r3 #endif - /* Restore host IVPR before re-enabling interrupts. We cheat and know - * that Linux IVPR is always PAGE_OFFSET. */ - lis r3, PAGE_OFFSET >> 16 + /* Restore host IVPR before re-enabling interrupts. */ + lis r3, interrupt_base@h /* IVPR only uses the high 16-bits */ mtspr SPRN_IVPR, r3 /* Switch to kernel stack and jump to handler. */Quoted 19 lines
arch/powerpc/kvm/book3s_32_sr.S static u32 get_host_mas0(unsigned long eaddr) · line 119
Quoted 8 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-1@@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr) mtspr(SPRN_MAS6, 0); mas4 = mfspr(SPRN_MAS4); mtspr(SPRN_MAS4, mas4 & ~MAS4_TLBSEL_MASK); - asm volatile("tlbsx 0, %0" : : "b" (eaddr & ~CONFIG_PAGE_OFFSET)); + asm volatile("tlbsx 0, %0" : + : "b" (eaddr & (rounddown_pow_of_two(PAGE_OFFSET)-1)));I think this is not valid.
With
PAGE_OFFSETequal to0xc0000000,Before:
eaddr &
0x3fffffffNow:
Quoted 8 lines
Quoted 1 line
eaddr & (
0x80000000- 1) = eaddr &0x7fffffffI'm probably still misunderstanding the intention of this code then, my reading of the comment was that both
0x3fffffffand0x7fffffffwould be valid choices here as both are belowPAGE_OFFSETand large enough to alias the correct set.What are the actual requirements for the mask?
I'm also struggling to understand this so I might be wrong. My understanding at the moment is that here we are looking for the physical address matching that effective addr in order to find the 1:1 MMU mapping. The particularity of booke is that you cannot turn off the MMU, so to simulate MMU off you have to have a MMU translation to translate logical address 0 to physical address 0.
Therefore IIUC the correct calculation should be (eaddr - PAGE_OFFSET)
I guess we need some feedback from Scott Cristal Wood, but I have not seen this person recently on the lists.
Quoted 5 lines
Thanks for looking at these bits in detail, I'm quite out of my comfort zone here, especially with the book-e stuff.
Arnd
Christophe
Re: [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
Quoted 19 lines · Christophe Leroy (CS GROUP)
Le 16/11/2026 à 23:54, Arnd Bergmann a écrit :
Quoted 6 lines · Christophe Leroy (CS GROUP)
Quoted 1 line
Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
arch/powerpc/kvm/book3s_32_sr.S line 111
Quoted 10 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-5@@ -107,14 +107,12 @@ KVM_LOAD_BAT(2, r9, r10, r11) KVM_LOAD_BAT(3, r9, r10, r11) - /* Restore Segment Registers */ - - /* 0xc - 0xf */ - - li r0, 4 + /* Restore Segment Registers, assumes PAGE_OFFSET is segment aligned */ + li r0, (0x100000000 - PAGE_OFFSET) >> 28Fine, thank should work allthough I would have used
0x10- (PAGE_OFFSET
Quoted 8 lines
arch/powerpc/kvm/book3s_32_sr.S line 113
Quoted 6 lines
arch/powerpc/kvm/book3s_32_sr.S +1
-2> 28) mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28)))Maybe an opportunity to replace
0x20000000bySR_KP
Ok, changed both.
Quoted 27 lines
Quoted 18 lines
arch/powerpc/kvm/book3s_32_sr.S +0
-0>> @@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr)Quoted 17 lines
Review
Quoted 6 lines
mtspr(SPRN_MAS6, 0); mas4 = mfspr(SPRN_MAS4); mtspr(SPRN_MAS4, mas4 & ~MAS4_TLBSEL_MASK);(quoted diff) +2
-1- asm volatile("tlbsx 0, %0" : : "b" (eaddr & ~CONFIG_PAGE_OFFSET)); + asm volatile("tlbsx 0, %0" : + : "b" (eaddr & (rounddown_pow_of_two(PAGE_OFFSET)-1)));I think this is not valid.
With
PAGE_OFFSETequal to0xc0000000,Before:
eaddr &
0x3fffffffNow:
Quoted 8 lines
Quoted 1 line
eaddr & (
0x80000000- 1) = eaddr &0x7fffffffI'm probably still misunderstanding the intention of this code then, my reading of the comment was that both
0x3fffffffand0x7fffffffwould be valid choices here as both are belowPAGE_OFFSETand large enough to alias the correct set.What are the actual requirements for the mask?
Quoted 8 lines
I'm also struggling to understand this so I might be wrong. My understanding at the moment is that here we are looking for the physical address matching that effective addr in order to find the 1:1 MMU mapping. The particularity of booke is that you cannot turn off the MMU, so to simulate MMU off you have to have a MMU translation to translate logical address 0 to physical address 0.
Therefore IIUC the correct calculation should be (eaddr -
PAGE_OFFSET)
AIU that would be wrong for PAGE_OFFSET=0x70000000 if eaddr>0xf0000000 is a valid argument here, as that would still point into the linear lowmem map. I've added Crystal and Alex to Cc with their current work emails, maybe one of them knows.
Arnd
[email protected]
AI reviewRe: [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
In reply to Arnd BergmannThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] powerpc: kvm: incomplete SR restoration in LOAD_HOST_SEGMENTS --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] powerpc: kvm: incomplete SR restoration in LOAD_HOST_SEGMENTS --
commit 32f84cc08116a09feebba0ce8cd2fcce44ce22ae
Author: Arnd Bergmann <[email protected]>
powerpc: kvm: allow flexible PAGE_OFFSET
This commit replaces hardcoded 0xc0000000 assumptions in PowerPC KVM code with expressions derived from PAGE_OFFSET.
Quoted 5 lines
arch/powerpc/kvm/book3s_32_sr.S +0
-0
arch/powerpc/kvm/book3s_32_sr.S line 120
Quoted 10 lines
arch/powerpc/kvm/book3s_32_sr.S +2
-2@@ -113,8 +113,8 @@ li r0, 4 mtctr r0 - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc)) - lis r4, 0xc000 + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28))) + lis r4, (PAGE_OFFSET >> 16) 3: mtsrin r3, r4 addi r3, r3, 0x111 /* increment VSID */ addis r4, r4, 0x1000 /* address of next segment */
[Severity: High]
Does LOAD_HOST_SEGMENTS leave host kernel segment registers holding guest values on VM exit when PAGE_OFFSET is not 0xc0000000?
LOAD_GUEST_SEGMENTS overwrites all 16 segment registers on guest entry. On exit, this loop keeps the iteration count in r0 hardcoded to 4, so when PAGE_OFFSET is below 0xc0000000 it only restores 4 segments starting at PAGE_OFFSET and leaves the upper kernel segment registers up to SR15 with guest values, causing subsequent host accesses to upper kernel memory to translate through guest segment registers.
In addition, switch_mmu_context() called after this loop only restores user segments below ALIGN(TASK_SIZE, SZ_256M) via update_user_segment(), while Book3S-32 places MODULES_VADDR in the segment below PAGE_OFFSET. Should this loop start at NUM_USER_SEGMENTS and run for
16 - NUM_USER_SEGMENTS iterations, matching load_segment_registers in arch/powerpc/kernel/head_book3s_32.S?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v3 5/10 ARM: add CONFIG_VMSPLIT_2G_OPT option
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
Unlike x86 and powerpc, there is currently no option to use exactly 2GiB of lowmem on Arm. Since 2GiB is still a relatively common configuration on embedded systems, it makes sense to allow this to be used in non-highmem builds.
Add the Kconfig option and make this the default for non-LPAE builds with highmem enabled instead of CONFIG_VMSPLIT_2G. LPAE still requires the vmsplit to be on a gigabyte boundary, so this is only available for classic pagetables at the moment, same as CONFIG_VMSPLIT_3G_OPT. Keep ARCH_MMAP_RND_BITS_MAX at 15 for this.
Tested in qemu -M virt, both with and without HIGHMEM enabled.
---
v2: Change ARCH_MMAP_RND_BITS_MAX for PAGE_OFFSET=0x70000000 (Sashiko bot)
--- arch/arm/Kconfig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/Kconfig +7 -2
@@ -333,8 +333,8 @@ config ARCH_MMAP_RND_BITS_MIN default 8 config ARCH_MMAP_RND_BITS_MAX - default 14 if PAGE_OFFSET=0x40000000 - default 15 if PAGE_OFFSET=0x80000000 + default 14 if PAGE_OFFSET<=0x40000000 + default 15 if PAGE_OFFSET<=0x80000000 default 16 config ARCH_MULTIPLATFORM
@@ -1039,6 +1039,9 @@ choice bool "3G/1G user/kernel split (for full 1G low memory)" config VMSPLIT_2G bool "2G/2G user/kernel split" + config VMSPLIT_2G_OPT + depends on !ARM_LPAE + bool "2G/2G user/kernel split (for full 2G low memory)" config VMSPLIT_1G bool "1G/3G user/kernel split" endchoice
@@ -1047,6 +1050,7 @@ config PAGE_OFFSET hex default PHYS_OFFSET if !MMU default 0x40000000 if VMSPLIT_1G + default 0x70000000 if VMSPLIT_2G_OPT default 0x80000000 if VMSPLIT_2G default 0xB0000000 if VMSPLIT_3G_OPT default 0xC0000000
@@ -1055,6 +1059,7 @@ config KASAN_SHADOW_OFFSET hex depends on KASAN default 0x1f000000 if PAGE_OFFSET=0x40000000 + default 0x4f000000 if PAGE_OFFSET=0x70000000 default 0x5f000000 if PAGE_OFFSET=0x80000000 default 0x9f000000 if PAGE_OFFSET=0xC0000000 default 0x8f000000 if PAGE_OFFSET=0xB0000000
Signature · 1 line
2.53.0
PATCH v3 6/10 arch/*: increase lowmem size to avoid highmem use
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
Most of the common 32-bit architectures (x86, arm, powerpc) all use the default virtual memory layout that was already in place for i386 systems in the 1990s, using exactly 3GiB of user TASK_SIZE, with the upper 1GiB of addresses split between (at most 896MiB) lowmem and vmalloc.
Linux-2.3 introduced CONFIG_HIGHMEM for large x86 server machines that had 4GiB of RAM or more, with the VMSPLIT_3G/2G/1G options added in v2.6.16 for machines that had one or two gigabytes of memory but wanted to avoid the overhead from managing highmem. Over time, similar options appeared on other 32-bit architectures.
Twenty years later, it makes sense to reconsider the default settings, as the tradeoffs have changed a bit:
- Configurations with more than 2GiB have become extremely rare, as any users with large memory have moved on to 64-bit systems. There were only ever a few Laptop models in this category: Apple Powerbook G4 (2005), Macbook (2006), IBM Thinkpad X60 (2006), Arm Chromebooks based on Exynos 5800 (2014), Tegra K1 (2014) and RK3288 (2015), and manufacturer support for all of these has ended in 2020 or (much) earlier.
Embedded systems with more than 2GiB use additional SoCs of a similar vintage: Intel Atom Z5xx (2008), Freescale QorIQ (2008), Marvell Armada XP (2010), Freescale i.MX6Q (2011), LSI Axxia (2013), TI Keystone2 (2014), Renesas RZ/G1M (2015). Most boards based on these have stopped receiving kernel upgrades and later 32-bit chips only support smaller memory configurations, though in particular the i.MX6Q and Keystone2 families have expected support cycles past 2035. While 32-bit server installations used to support even larger memory, none of those seem to still be used in production on any architecture.
- While general-purpose distributes for 32-bit targets were common, it was rather risky to change the CONFIG_VMSPLIT setting because there is always a possibility of running into device driver bugs or applications that need a large virtual memory size. Presumably a lot of these issues have been resolved now, so most setups should be fine using a custom vmsplit instead of highmem now.
- As fewer users test highmem, the expectation is that it will increasingly break in the future, so getting users to change the vmsplit means that even if there is a bug to fix initially, it improves the situation in the long run.
- Highmem will ultimately need to be removed, at least for the page cache and most other code using it today. In a previous discussion, I had suggested doing this as early as 2029, but based on the discussions since ELC, the plan is now to leave highmem-enabled page cache as an option until at least 2029, at which point remaining users will have the choice between no longer updating kernels or using a combination of a custom vmsplit and zram/zswap. Changing the defaults now should both speed up the highmem deprecation and make it less painful for users.
- The most VM space intensive applications tend to be web browsers, specifcally Chrome/ChromeOS and Firefox. Both have now stopped providing binary updates.
Testing various combinations on Debian/armhf, I found that Firefox 140 can still show complex websites with VMSPLIT_2G_OPT with and without HIGHMEM, though it failed for me both with the small address space of VMSPLIT_1G and the small lowmem of VMSPLIT_3G_OPT when HIGHMEM is disabled.
This is likely to get worse with future versions, so embedded users may still be forced to migrate to specialized browsers like WPE Webkit when HIGHMEM pagecache is finally removed.
Based on the above observations and the discussion at the kernel summit, change the defaults to the most appropriate values: use 1GiB of lowmem on non-highmem configurations, and either 2GiB or 1.75GiB of lowmem on highmem builds, depending on what is available on the architecture. As ARM_LPAE and X86_PAE builds both require a gigabyte-aligned vmsplit, those get to use VMSPLIT_2G. The result is that the majority of previous highmem users now only need lowmem. For platform specific defconfig files that are known to only support up to 1GiB of RAM, drop the CONFIG_HIGHMEM line as well as a simplification.
On PowerPC and Microblaze, the options have somewhat different names but should have the same effect. MIPS and Xtensa cannot support a larger than 512MB of lowmem but are limited to small DDR2 memory in most implementations, with MT7621 being a notable exception. ARC and C-Sky could support a configurable vmsplit in theory, but it's not clear if anyone still cares.
SPARC is currently limited to 192MB of lowmem and should get patched to behave either like arm/x86 or powerpc/microblaze to support 2GiB of lowmem.
There are likely going to be regressions from the changed defaults, in particular when hitting previously hidden device driver bugs that fail to set the correct DMA mask, or from applications that need a large virtual address space.
Ideally the in-kernel problems should all be fixable, but as a fallback, the previous behavior is still selectable based on CONFIG_EXPERT=y.
--- arch/arm/Kconfig | 6 +++++- arch/arm/configs/u8500_defconfig | 1 - arch/arm/configs/vt8500_v6_v7_defconfig | 1 - arch/microblaze/Kconfig | 9 +++++--- arch/microblaze/configs/mmu_defconfig | 1 - arch/powerpc/Kconfig | 24 +++++++++++++-------- arch/powerpc/configs/44x/akebono_defconfig | 1 - arch/powerpc/configs/85xx/ksi8560_defconfig | 1 - arch/powerpc/configs/85xx/stx_gp3_defconfig | 1 - arch/x86/Kconfig | 4 +++- 10 files changed, 29 insertions(+), 20 deletions(-)
arch/arm/Kconfig +5 -1
@@ -1025,7 +1025,9 @@ config BL_SWITCHER_DUMMY_IF choice prompt "Memory split" depends on MMU - default VMSPLIT_3G + default VMSPLIT_2G if ARM_LPAE + default VMSPLIT_2G_OPT if HIGHMEM + default VMSPLIT_3G_OPT help Select the desired split between kernel and user memory.
@@ -1034,8 +1036,10 @@ choice config VMSPLIT_3G bool "3G/1G user/kernel split" + depends on !HIGHMEM || EXPERT config VMSPLIT_3G_OPT depends on !ARM_LPAE + depends on !HIGHMEM || EXPERT bool "3G/1G user/kernel split (for full 1G low memory)" config VMSPLIT_2G bool "2G/2G user/kernel split"
arch/arm/configs/u8500_defconfig +0 -1
@@ -6,7 +6,6 @@ CONFIG_KALLSYMS_ALL=y CONFIG_ARCH_U8500=y CONFIG_SMP=y CONFIG_NR_CPUS=2 -CONFIG_HIGHMEM=y CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y CONFIG_CMDLINE="root=/dev/ram0 console=ttyAMA2,115200n8"
arch/arm/configs/vt8500_v6_v7_defconfig +0 -1
@@ -8,7 +8,6 @@ CONFIG_ARM_ERRATA_720789=y CONFIG_ARM_ERRATA_754322=y CONFIG_ARM_ERRATA_775420=y CONFIG_HAVE_ARM_ARCH_TIMER=y -CONFIG_HIGHMEM=y CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y CONFIG_VFP=y
arch/microblaze/Kconfig +6 -3
@@ -164,7 +164,8 @@ config LOWMEM_SIZE_BOOL config LOWMEM_SIZE hex "Maximum low memory size (in bytes)" if LOWMEM_SIZE_BOOL - default "0x30000000" + default "0x80000000" if HIGHMEM + default "0x40000000" config MANUAL_RESET_VECTOR hex "Microblaze reset vector address setup"
@@ -190,7 +191,8 @@ config KERNEL_START_BOOL config KERNEL_START hex "Virtual address of kernel base" if KERNEL_START_BOOL - default "0xc0000000" + default "0x70000000" if HIGHMEM + default "0xb0000000" config TASK_SIZE_BOOL bool "Set custom user task size"
@@ -204,7 +206,8 @@ config TASK_SIZE_BOOL config TASK_SIZE hex "Size of user task space" if TASK_SIZE_BOOL - default "0x80000000" + default "0x70000000" if HIGHMEM + default "0xb0000000" config MB_MANAGER bool "Support for Microblaze Manager"
arch/microblaze/configs/mmu_defconfig +0 -1
@@ -15,7 +15,6 @@ CONFIG_XILINX_MICROBLAZE0_USE_FPU=2 CONFIG_HZ_100=y CONFIG_CMDLINE_BOOL=y CONFIG_CMDLINE_FORCE=y -CONFIG_HIGHMEM=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y CONFIG_PARTITION_ADVANCED=y
arch/powerpc/Kconfig +15 -9
@@ -489,6 +489,7 @@ menu "Kernel options" config HIGHMEM bool "High memory support" depends on PPC32 + depends on PPC_BOOK3S_32 || PPC_85xx || 44x select KMAP_LOCAL source "kernel/Kconfig.hz"
@@ -1190,7 +1191,10 @@ config LOWMEM_SIZE_BOOL config LOWMEM_SIZE hex "Maximum low memory size (in bytes)" if LOWMEM_SIZE_BOOL - default "0x30000000" + default "0x40000000" if 44x + default "0x70000000" if HIGHMEM && KASAN + default "0x80000000" if HIGHMEM + default "0x40000000" config LOWMEM_CAM_NUM_BOOL bool "Set number of CAMs to use to map low memory"
@@ -1207,10 +1211,10 @@ config LOWMEM_CAM_NUM_BOOL config LOWMEM_CAM_NUM depends on PPC_85xx int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL - default 3 if !STRICT_KERNEL_RWX - default 9 if DATA_SHIFT >= 24 - default 12 if DATA_SHIFT >= 22 - default 15 + default 8 if !STRICT_KERNEL_RWX + default 14 if DATA_SHIFT >= 24 + default 17 if DATA_SHIFT >= 22 + default 20 config DYNAMIC_MEMSTART bool "Enable page aligned dynamic load address for kernel"
@@ -1242,7 +1246,8 @@ config PAGE_OFFSET_BOOL config PAGE_OFFSET hex "Virtual address of memory base" if PAGE_OFFSET_BOOL - default "0xc0000000" + default "0x70000000" if HIGHMEM && !44x + default "0xb0000000" config KERNEL_START_BOOL bool "Set custom kernel base address"
@@ -1258,8 +1263,9 @@ config KERNEL_START_BOOL config KERNEL_START hex "Virtual address of kernel base" if KERNEL_START_BOOL default PAGE_OFFSET if PAGE_OFFSET_BOOL - default "0xc2000000" if CRASH_DUMP && !NONSTATIC_KERNEL - default "0xc0000000" + default "0x72000000" if HIGHMEM && !44x && CRASH_DUMP && !NONSTATIC_KERNEL + default "0xb2000000" if CRASH_DUMP && !NONSTATIC_KERNEL + default PAGE_OFFSET config PHYSICAL_START_BOOL bool "Set physical address where the kernel is loaded"
@@ -1295,7 +1301,7 @@ config TASK_SIZE_BOOL config TASK_SIZE hex "Size of maximum user task space" if TASK_SIZE_BOOL default "0x80000000" if PPC_8xx - default "0xc0000000" + default PAGE_OFFSET config MODULES_SIZE_BOOL bool "Set custom size for modules/execmem area"
arch/powerpc/configs/44x/akebono_defconfig +0 -1
@@ -14,7 +14,6 @@ CONFIG_MODULE_UNLOAD=y CONFIG_PPC_47x=y # CONFIG_EBONY is not set CONFIG_AKEBONO=y -CONFIG_HIGHMEM=y CONFIG_HZ_100=y CONFIG_IRQ_ALL_CPUS=y # CONFIG_COMPACTION is not set
arch/powerpc/configs/85xx/ksi8560_defconfig +0 -1
@@ -9,7 +9,6 @@ CONFIG_PARTITION_ADVANCED=y CONFIG_KSI8560=y CONFIG_CPM2=y CONFIG_GEN_RTC=y -CONFIG_HIGHMEM=y CONFIG_BINFMT_MISC=y CONFIG_MATH_EMULATION=y # CONFIG_SECCOMP is not set
arch/powerpc/configs/85xx/stx_gp3_defconfig +0 -1
@@ -7,7 +7,6 @@ CONFIG_MODULES=y CONFIG_MODVERSIONS=y # CONFIG_BLK_DEV_BSG is not set CONFIG_STX_GP3=y -CONFIG_HIGHMEM=y CONFIG_BINFMT_MISC=m CONFIG_MATH_EMULATION=y CONFIG_PCI=y
arch/x86/Kconfig +3 -1
@@ -1410,7 +1410,9 @@ config HIGHMEM4G choice prompt "Memory split" if EXPERT - default VMSPLIT_3G + default VMSPLIT_2G_OPT if HIGHMEM && !X86_PAE + default VMSPLIT_2G if X86_PAE + default VMSPLIT_3G_OPT depends on X86_32 help Select the desired split between kernel and user memory.
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 06/10] arch/*: increase lowmem size to avoid highmem use
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] KVM: PPC: Book3S: LOAD_HOST_SEGMENTS only restores 4 kernel SRs on exit - [Medium] powerpc/85xx…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] KVM: PPC: Book3S: LOAD_HOST_SEGMENTS only restores 4 kernel SRs on exit
- [Medium] powerpc/85xx: LOWMEM_CAM_NUM defaults exceed 16 TLB1 entries on e500v1/v2
--
commit f9466fba88fe066bf9e204a300df08d4c66f1149
Author: Arnd Bergmann <[email protected]>
arch/*: increase lowmem size to avoid highmem use
This commit increases the default lowmem size across 32-bit architectures (arm, microblaze, powerpc, and x86) to 1GiB for non-highmem builds and up to 2GiB for highmem builds, and drops CONFIG_HIGHMEM from several board defconfigs that have at most 1GiB of RAM.
Quoted 4 lines
arch/powerpc/Kconfig +0
-0
[ ... ]
arch/powerpc/Kconfig config LOWMEM_CAM_NUM_BOOL · line 1217
Quoted 12 lines
arch/powerpc/Kconfig +4
-4@@ -1207,10 +1211,10 @@ config LOWMEM_CAM_NUM_BOOL config LOWMEM_CAM_NUM depends on PPC_85xx int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL - default 3 if !STRICT_KERNEL_RWX - default 9 if DATA_SHIFT >= 24 - default 12 if DATA_SHIFT >= 22 - default 15 + default 8 if !STRICT_KERNEL_RWX + default 14 if DATA_SHIFT >= 24 + default 17 if DATA_SHIFT >= 22 + default 20
[Severity: Medium]
Can the new default values of 17 and 20 for LOWMEM_CAM_NUM exceed the 16 hardware TLB1 entries on e500v1 and e500v2 cores (CONFIG_PPC_85xx=y with CONFIG_PPC_E500MC=n)?
During boot in adjust_total_lowmem() and secondary CPU bringup in __secondary_start, switch_to_as1() uses the last hardware TLB1 slot (entry 15 on 16-entry e500v1/v2) for its temporary AS=1 mapping while map_mem_in_cams_addr() populates up to CONFIG_LOWMEM_CAM_NUM slots starting from 0 without clamping against SPRN_TLB1CFG:
arch/powerpc/mm/nohash/e500.c:map_mem_in_cams_addr() {
...
for (i = 0; boundary && i < max_cam_idx; i++) {
...
}
for (ram -= amount_mapped; ram && i < max_cam_idx; i++) {
...
}
if (init) {
loadcam_multi(0, i, max_cam_idx);
tlbcam_index = i;
}
...
}Because PAGE_OFFSET is now 0xb0000000 or 0x70000000 (an odd multiple of 256MiB), calc_cam_sz() caps each CAM at 256MiB even on e500v2. When CONFIG_STRICT_KERNEL_RWX=y and CONFIG_DATA_SHIFT is set below 24, mapping 1GiB or 2GiB of RAM reaches index 15 and overwrites the active AS=1 entry in TLB1[15] (and wraps the 4-bit MAS0[ESEL] field at index 16 onto TLB1[0]), crashing during boot. Also, increasing all defaults by 5 unconditionally reserves CAMs for 2GiB of lowmem even when CONFIG_HIGHMEM=n caps LOWMEM_SIZE at 1GiB.
arch/powerpc/Kconfig config PAGE_OFFSET_BOOL · line 1250
Quoted 9 lines
arch/powerpc/Kconfig +2
-1config DYNAMIC_MEMSTART bool "Enable page aligned dynamic load address for kernel"@@ -1242,7 +1246,8 @@ config PAGE_OFFSET_BOOL config PAGE_OFFSET hex "Virtual address of memory base" if PAGE_OFFSET_BOOL - default "0xc0000000" + default "0x70000000" if HIGHMEM && !44x + default "0xb0000000"
[Severity: High]
With PAGE_OFFSET lowered to 0xb0000000 or 0x70000000 on 32-bit Book3S, does LOAD_HOST_SEGMENTS on KVM guest exit leave the upper host kernel segment registers holding guest values?
Commit "powerpc: kvm: allow flexible PAGE_OFFSET" updated the starting segment and address in LOAD_HOST_SEGMENTS, but kept the loop count hardcoded to 4:
arch/powerpc/kvm/book3s_32_sr.S:LOAD_HOST_SEGMENTS {
...
li r0, 4
mtctr r0
LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28)))
lis r4, (PAGE_OFFSET >> 16)
3: mtsrin r3, r4
addi r3, r3, 0x111 /* increment VSID */
addis r4, r4, 0x1000 /* address of next segment */
bdnz 3b
...
}LOAD_GUEST_SEGMENTS overwrites all 16 segment registers on guest entry. When PAGE_OFFSET is 0xb0000000, the 4-iteration loop only restores SRs 11..14, leaving SR15 (0xf0000000..0xffffffff, used for vmalloc, ioremap and fixmap) with the guest's SR15 value; when PAGE_OFFSET is 0x70000000, SRs 11..15 (0xb0000000..0xffffffff) remain unrestored. In addition, when CONFIG_EXECMEM=y places MODULES_BASE in the 256MiB segment below PAGE_OFFSET, NUM_USER_SEGMENTS is (PAGE_OFFSET >> 28) - 1, so starting the restore loop at PAGE_OFFSET >> 28 instead of NUM_USER_SEGMENTS (for 16 - NUM_USER_SEGMENTS iterations, as load_segment_registers does at boot) also leaves the module segment register unrestored.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v3 06/10] arch/*: increase lowmem size to avoid highmem use
Quoted 46 lines · On Tue, Nov 17, 2026, at 13:49, [email protected] wrote:
Quoted 4 lines
arch/powerpc/Kconfig +0
-0[ ... ]
arch/powerpc/Kconfig config LOWMEM_CAM_NUM_BOOL · line 1217
Quoted 12 lines
arch/powerpc/Kconfig +4
-4@@ -1207,10 +1211,10 @@ config LOWMEM_CAM_NUM_BOOL config LOWMEM_CAM_NUM depends on PPC_85xx int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL - default 3 if !STRICT_KERNEL_RWX - default 9 if DATA_SHIFT >= 24 - default 12 if DATA_SHIFT >= 22 - default 15 + default 8 if !STRICT_KERNEL_RWX + default 14 if DATA_SHIFT >= 24 + default 17 if DATA_SHIFT >= 22 + default 20[Severity: Medium]
Can the new default values of 17 and 20 forLOWMEM_CAM_NUMexceed the 16 hardware TLB1 entries on e500v1 and e500v2 cores (CONFIG_PPC_85xx=y withCONFIG_PPC_E500MC=n)?During boot in
adjust_total_lowmem()and secondary CPU bringup in__secondary_start,switch_to_as1()uses the last hardware TLB1 slot (entry 15 on 16-entry e500v1/v2) for its temporary AS=1 mapping whilemap_mem_in_cams_addr()populates up toCONFIG_LOWMEM_CAM_NUMslots starting from 0 without clamping againstSPRN_TLB1CFG:arch/powerpc/mm/nohash/e500.c:map_mem_in_cams_addr() { ... for (i = 0; boundary && i < max_cam_idx; i++) { ... } for (ram -= amount_mapped; ram && i < max_cam_idx; i++) { ... } if (init) { loadcam_multi(0, i, max_cam_idx); tlbcam_index = i; } ... }
Quoted 6 lines
Because
PAGE_OFFSETis now0xb0000000or0x70000000(an odd multiple of 256MiB),calc_cam_sz()caps each CAM at 256MiB even on e500v2. WhenCONFIG_STRICT_KERNEL_RWX=yandCONFIG_DATA_SHIFTis set below 24, mapping 1GiB or 2GiB of RAM reaches index 15 and overwrites the active AS=1 entry in TLB1[15] (and wraps the 4-bit MAS0[ESEL] field at index 16 onto TLB1[0]), crashing during boot.
Ah, this would explain why Richard was able to boot using my patch with 1.75GiB but not 2GiB, at least if he was using DATA_SHIFT=22. Hopefully this should still work as expected if we force DATA_SHIFT=24 for larger lowmem sizes like.
arch/powerpc/Kconfig +3 -1
@@ -897,7 +897,8 @@ config DATA_SHIFT default 24 if STRICT_KERNEL_RWX && PPC64 range 17 28 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_BOOK3S_32 range 14 23 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_8xx - range 20 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx + range 20 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx && LOWMEM_SIZE<=0x30000000 + range 22 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx && LOWMEM_SIZE<=0x40000000 + range 24 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx default 22 if STRICT_KERNEL_RWX && PPC_BOOK3S_32 default 18 if (DEBUG_PAGEALLOC || KFENCE) && PPC_BOOK3S_32
default 23 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_8xx && \
Quoted 3 lines
Also, increasing all defaults by 5 unconditionally reserves CAMs for 2GiB of lowmem even when
CONFIG_HIGHMEM=ncapsLOWMEM_SIZEat 1GiB.
This feels like Kconfig is not the ideal tool for calculating these ;-) I've tried to fit this into a concise form that doesn't overshoot too much, and list the calculation in the help text for reference:
config LOWMEM_CAM_NUM
depends on PPC_85xx
int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL default 8 if !STRICT_KERNEL_RWX && LOWMEM_SIZE > 0x40000000 default 4 if !STRICT_KERNEL_RWX && LOWMEM_SIZE <= 0x40000000 default 14 if LOWMEM_SIZE > 0x40000000 # requires DATA_SHIFT=24 default 10 if DATA_SHIFT >= 24
default 13 if DATA_SHIFT >= 22
default 15 # 768MiB lowmem, DATA_SHIFT=20
help
Without STRICT_KERNEL_RWX, 1 CAM is used per 256MiB of lowmem, with STRICT_KERNEL_RWX, extra entries are usually needed for smaller sections depending on DATA_SHIFT. On 2GiB lowmem systems with 16 CAMs, only DATA_SHIFT=24 (16MiB alignment) can work.
The default values are optimized for LOWMEM_SIZE of 1GiB or 2GiB and could be adjusted for smaller systems:
2GiB lowmem, 256MiB aligned: 8*256
1GiB lowmem, 256MiB aligned: 4*256
2GiB lowmem, 16MiB aligned: 4*16, 3*64, 7*256 1GiB lowmem, 16MiB aligned: 4*16, 3*64, 3*256
1GiB lowmem, 4MiB aligned: 4*4, 3*16, 3*64, 3*256
768MiB lowmem, 1MiB aligned: 4*1, 3*4, 3*16, 3*64, 2*256
Quoted 12 lines
arch/powerpc/Kconfig config PAGE_OFFSET_BOOL · line 1250
Quoted 7 lines
arch/powerpc/Kconfig +2
-1@@ -1242,7 +1246,8 @@ config PAGE_OFFSET_BOOL config PAGE_OFFSET hex "Virtual address of memory base" if PAGE_OFFSET_BOOL - default "0xc0000000" + default "0x70000000" if HIGHMEM && !44x + default "0xb0000000"[Severity: High]
WithPAGE_OFFSETlowered to0xb0000000or0x70000000on 32-bit Book3S, doesLOAD_HOST_SEGMENTSon KVM guest exit leave the upper host kernel segment registers holding guest values?
That should be addressed by my update in reply to Christophe pointing out the same mistake.
Arnd
AW: [PATCH v3 06/10] arch/*: increase lowmem size to avoid highmem use
Am Wed, Nov 18, 2026, 10:36 schrieb Arnd Bergmann <[email protected]>:
Quoted 11 lines
Quoted 6 lines
Because
PAGE_OFFSETis now0xb0000000or0x70000000(an odd multiple of 256MiB),calc_cam_sz()caps each CAM at 256MiB even on e500v2. WhenCONFIG_STRICT_KERNEL_RWX=yandCONFIG_DATA_SHIFTis set below 24, mapping 1GiB or 2GiB of RAM reaches index 15 and overwrites the active AS=1 entry in TLB1[15] (and wraps the 4-bit MAS0[ESEL] field at index 16 onto TLB1[0]), crashing during boot.Ah, this would explain why Richard was able to boot using my patch with 1.75GiB but not 2GiB, at least if he was using DATA_SHIFT=22. Hopefully this should still work as expected if we force DATA_SHIFT=24 for larger lowmem sizes like.
Hmm, David and I have CONFIG_DATA_SHIFT=24 in our setup.
I'm currently fighting with a different problem in the board. As soon as I have more input, I'll let you know!
Thanks,
//richard
PATCH v3 7/10 ARM: defconfig: turn off highmem in favor of CONFIG_VMSPLIT_2G_OPT
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
The multi_v7_defconfig and omap2plus_defconfig attempt to support a broad range of hardware. This is at odds with the setting for highmem being slowly phased out on the one hand but still enabled by means of CONFIG_ARCH_OMAP2PLUS_TYPICAL, leading to a default CONFIG_VMSPLIT_2G_OPT split.
None of the upstream OMAP2+ DTS files actually list more than 2GiB of RAM, so it seems fine to just turn off highmem by default and use CONFIG_VMSPLIT_2G_OPT from the defconfig to still support the same hardware but not require highmem.
This also changes multi_v7_defconfig, which currently supports all sorts of ARMv7 systems except those that require LPAE.
The best comprimise I can think of again is to use VMSPLIT_2G_OPT in place of highmem. Compared to highmem configurations, this should be an improvement on most machines with 2GiB of installed memory for the lower overhead and complexity, but it does degrade machines that rely on highmem to access all memory, as well as reduce the available user address space (1.75GiB instead of the traditional 3GiB).
For aspeed_g5_defconfig, the decision is trivial, as there are no 4GiB configurations we need to support, but g6 is known to use up to 2GiB.
If you run into problems on production machines with the new default, with the absence of highmem, or the smaller user area, please complain.
--- arch/arm/configs/aspeed_g5_defconfig | 3 +-- arch/arm/configs/lpae.config | 1 + arch/arm/configs/multi_v7_defconfig | 1 + arch/arm/configs/omap2plus_defconfig | 1 + arch/arm/mach-omap2/Kconfig | 1 - 5 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/configs/aspeed_g5_defconfig +1 -2
@@ -25,9 +25,8 @@ CONFIG_MACH_ASPEED_G6=y # CONFIG_CACHE_L2X0 is not set CONFIG_SMP=y # CONFIG_ARM_CPU_TOPOLOGY is not set -CONFIG_VMSPLIT_2G=y +CONFIG_VMSPLIT_2G_OPT=y CONFIG_NR_CPUS=2 -CONFIG_HIGHMEM=y CONFIG_UACCESS_WITH_MEMCPY=y CONFIG_VFP=y CONFIG_NEON=y
arch/arm/configs/lpae.config +1 -0
@@ -1,3 +1,4 @@ # Help: Enable Large Physical Address Extension mode CONFIG_ARM_LPAE=y CONFIG_VMSPLIT_2G=y +CONFIG_HIGHMEM=y
arch/arm/configs/multi_v7_defconfig +1 -0
@@ -103,6 +103,7 @@ CONFIG_ARCH_VEXPRESS_TC2_PM=y CONFIG_ARCH_WM8850=y CONFIG_ARCH_ZYNQ=y CONFIG_SMP=y +CONFIG_VMSPLIT_2G_OPT=y CONFIG_NR_CPUS=16 CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y
arch/arm/configs/omap2plus_defconfig +1 -0
@@ -36,6 +36,7 @@ CONFIG_POWER_AVS_OMAP_CLASS3=y CONFIG_ARM_THUMBEE=y CONFIG_ARM_ERRATA_411920=y CONFIG_SMP=y +CONFIG_VMSPLIT_2G_OPT=y CONFIG_NR_CPUS=2 CONFIG_ARM_APPENDED_DTB=y CONFIG_ARM_ATAG_DTB_COMPAT=y
arch/arm/mach-omap2/Kconfig +0 -1
@@ -135,7 +135,6 @@ config ARCH_OMAP2PLUS_TYPICAL bool "Typical OMAP configuration" default y select AEABI - select HIGHMEM select I2C select I2C_OMAP select MENELAUS if ARCH_OMAP2
Signature · 1 line
2.53.0
PATCH v3 8/10 mm: remove ARCH_NEEDS_KMAP_HIGH_GET
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
Arm has stopped setting ARCH_NEEDS_KMAP_HIGH_GET, so this is handled using the same wrappers across all architectures now, which leaves room for simplification.
Replace lock_kmap()/unlock_kmap() with open-coded spinlocks and drop the now empty arch_kmap_local_high_get() and kmap_high_unmap_local() helpers.
--- mm/highmem.c | 100 ++++++--------------------------------------------- 1 file changed, 10 insertions(+), 90 deletions(-)
mm/highmem.c +10 -90
@@ -143,25 +143,6 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kmap_lock);pte_t *pkmap_page_table; -/* -* Most architectures have no use for kmap_high_get(), so let's abstract -* the disabling of IRQ out of the locking in that case to save on a -* potential useless overhead. -*/ -#ifdef ARCH_NEEDS_KMAP_HIGH_GET -#define lock_kmap () spin_lock_irq(&kmap_lock) -#define unlock_kmap () spin_unlock_irq(&kmap_lock) -#define lock_kmap_any (flags) spin_lock_irqsave(&kmap_lock, flags) -#define unlock_kmap_any (flags) spin_unlock_irqrestore(&kmap_lock, flags) -#else -#define lock_kmap () spin_lock(&kmap_lock) -#define unlock_kmap () spin_unlock(&kmap_lock) -#define lock_kmap_any (flags) \ - do { spin_lock(&kmap_lock); (void)(flags); } while (0) -#define unlock_kmap_any (flags) \ - do { spin_unlock(&kmap_lock); (void)(flags); } while (0) -#endif -struct page *__kmap_to_page (void *vaddr) {unsigned long base = (unsigned long ) vaddr &PAGE_MASK ;
@@ -238,9 +219,9 @@ static void flush_all_zero_pkmaps(void)void __kmap_flush_unused (void ) { -lock_kmap (); +spin_lock (&kmap_lock);flush_all_zero_pkmaps (); -unlock_kmap (); +spin_unlock (&kmap_lock); }static inline unsigned long map_new_virtual (struct page *page)
@@ -274,10 +255,10 @@ static inline unsigned long map_new_virtual(struct page *page)__set_current_state (TASK_UNINTERRUPTIBLE );add_wait_queue (pkmap_map_wait, &wait); -unlock_kmap (); +spin_unlock (&kmap_lock);schedule ();remove_wait_queue (pkmap_map_wait, &wait); -lock_kmap (); +spin_lock (&kmap_lock);/* Somebody else might have mapped it while we slept */ if (page_address (page))
@@ -313,60 +294,32 @@ void *kmap_high(struct page *page)* For highmem pages, we can't trust "virtual" until * after we have the lock. */ -lock_kmap (); +spin_lock (&kmap_lock); vaddr = (unsigned long )page_address (page);if (!vaddr) vaddr =map_new_virtual (page); pkmap_count[PKMAP_NR (vaddr)]++;BUG_ON (pkmap_count[PKMAP_NR (vaddr)] <2 ); -unlock_kmap (); +spin_unlock (&kmap_lock);return (void *) vaddr; }EXPORT_SYMBOL (kmap_high); -#ifdef ARCH_NEEDS_KMAP_HIGH_GET -/** -* kmap_high_get - pin a highmem page into memory -* @page: &struct page to pin -* -* Returns the page's current virtual memory address, or NULL if no mapping -* exists. If and only if a non null address is returned then a -* matching call to kunmap_high() is necessary. -* -* This can be called from any context. -*/ -void *kmap_high_get (const struct page *page) -{ -unsigned long vaddr, flags; - -lock_kmap_any (flags); - vaddr = (unsigned long )page_address (page); -if (vaddr) { -BUG_ON (pkmap_count[PKMAP_NR (vaddr)] <1 ); - pkmap_count[PKMAP_NR (vaddr)]++; - } -unlock_kmap_any (flags); -return (void *) vaddr; -} -#endif -/** * kunmap_high - unmap a highmem page into memory * @page: &struct page to unmap * -* If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called -* only from user context. +* This may be called only from user context. */ void kunmap_high (const struct page *page) {unsigned long vaddr;unsigned long nr; -unsigned long flags;int need_wakeup;unsigned int color =get_pkmap_color (page);wait_queue_head_t *pkmap_map_wait; -lock_kmap_any (flags); +spin_lock (&kmap_lock); vaddr = (unsigned long )page_address (page);BUG_ON (!vaddr); nr =PKMAP_NR (vaddr);
@@ -393,7 +346,7 @@ void kunmap_high(const struct page *page) pkmap_map_wait =get_pkmap_wait_queue_head (color); need_wakeup =waitqueue_active (pkmap_map_wait); } -unlock_kmap_any (flags); +spin_unlock (&kmap_lock);/* do wake-up, if needed, race-free outside of the spin lock */ if (need_wakeup)
@@ -508,30 +461,11 @@ static inline void kmap_local_idx_pop(void)#define arch_kmap_local_unmap_idx (idx, vaddr) kmap_local_calc_idx(idx)#endif -#ifndef arch_kmap_local_high_get -static inline void *arch_kmap_local_high_get (const struct page *page) -{ -return NULL ; -} -#endif -#ifndef arch_kmap_local_set_pte#define arch_kmap_local_set_pte (mm, vaddr, ptep, ptev) \ set_pte_at(mm, vaddr, ptep, ptev)#endif -/* Unmap a local mapping which was obtained by kmap_high_get() */ -static inline bool kmap_high_unmap_local (unsigned long vaddr) -{ -#ifdef ARCH_NEEDS_KMAP_HIGH_GET -if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) { -kunmap_high (pte_page (ptep_get (&pkmap_page_table[PKMAP_NR (vaddr)]))); -return true; - } -#endif -return false; -} -static pte_t *__kmap_pte;static pte_t *kmap_get_pte (unsigned long vaddr,int idx)
@@ -575,8 +509,6 @@ EXPORT_SYMBOL_GPL(__kmap_local_pfn_prot);void *__kmap_local_page_prot (const struct page *page,pgprot_t prot) { -void *kmap; -/* * To broaden the usage of the actual kmap_local() machinery always map * pages when debugging is enabled and the architecture has no problems
@@ -585,11 +517,6 @@ void *__kmap_local_page_prot(const struct page *page, pgprot_t prot)if (!IS_ENABLED (CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP ) && !PageHighMem (page))return page_address (page); -/* Try kmap_high_get() if architecture has it enabled */ - kmap =arch_kmap_local_high_get (page); -if (kmap) -return kmap; -return __kmap_local_pfn_prot (page_to_pfn (page), prot); }EXPORT_SYMBOL (__kmap_local_page_prot);
@@ -607,14 +534,7 @@ void kunmap_local_indexed(const void *vaddr)WARN_ON_ONCE (1 );return ; } -/* -* Handle mappings which were obtained by kmap_high_get() -* first as the virtual address of such mappings is below -* PAGE_OFFSET. Warn for all other addresses which are in -* the user space part of the virtual address space. -*/ -if (!kmap_high_unmap_local (addr)) -WARN_ON_ONCE (addr <PAGE_OFFSET ); +WARN_ON_ONCE (addr <PAGE_OFFSET );return ; }
Signature · 1 line
2.53.0
Re: [PATCH v3 08/10] mm: remove ARCH_NEEDS_KMAP_HIGH_GET
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Arm has stopped setting
ARCH_NEEDS_KMAP_HIGH_GET, so this is handled using the same wrappers across all architectures now, which leaves room for simplification.
Quoted 8 lines
Replace lock_kmap()/unlock_kmap() with open-coded spinlocks and drop the now empty
arch_kmap_local_high_get()andkmap_high_unmap_local()helpers.Signed-off-by Arnd Bergmann <[email protected]>---
Signature · 3 lines
Cheers, David
PATCH v3 9/10 mm: drop HIGHPTE support altogether
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
With both x86 and arm having dropped CONFIG_HIGHPTE support, no architecture is left using it, so remove the remnants in common code.
It is likely that further cleanups are possible in the page table code but those are not obvious from the config options.
--- include/linux/hugetlb.h | 5 +---- include/linux/mm.h | 1 - include/linux/pgtable.h | 13 ------------- mm/pgtable-generic.c | 25 ++++++++++++------------- mm/userfaultfd.c | 6 +----- 5 files changed, 14 insertions(+), 36 deletions(-)
include/linux/hugetlb.h +1 -4
@@ -178,7 +178,6 @@ void hugetlb_bootmem_set_nodes(void);/* arch callbacks */ -#ifndef CONFIG_HIGHPTE /* * pte_offset_huge() and pte_alloc_huge() are helpers for those architectures * which may go down to the lowest PTE level in their huge_pte_offset() and
@@ -193,7 +192,6 @@ static inline pte_t *pte_alloc_huge(struct mm_struct *mm, pmd_t *pmd, {return pte_alloc (mm, pmd) ?NULL :pte_offset_huge (pmd, address); } -#endif pte_t *huge_pte_alloc (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr,unsigned long sz);
@@ -1047,9 +1045,8 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate *h,*/ if (size >=PUD_SIZE )return pud_lockptr (mm, (pud_t *) pte); -else if (size >=PMD_SIZE ||IS_ENABLED (CONFIG_HIGHPTE )) +else if (size >=PMD_SIZE )return pmd_lockptr (mm, (pmd_t *) pte); -/* pte_alloc_huge() only applies with !CONFIG_HIGHPTE */ return ptep_lockptr (mm, pte); }
include/linux/mm.h +0 -1
@@ -4025,7 +4025,6 @@ static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)static inline spinlock_t *ptep_lockptr (struct mm_struct *mm,pte_t *pte) { -BUILD_BUG_ON (IS_ENABLED (CONFIG_HIGHPTE ));BUILD_BUG_ON (MAX_PTRS_PER_PTE *sizeof (pte_t) >PAGE_SIZE );return ptlock_ptr (virt_to_ptdesc (pte)); }
include/linux/pgtable.h +0 -13
@@ -100,23 +100,10 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)#define pte_offset_kernel pte_offset_kernel#endif -#ifdef CONFIG_HIGHPTE -#define __pte_map (pmd, address) \ - ((pte_t *)kmap_local_page(pmd_page(*(pmd))) + pte_index((address))) -#define pte_unmap (pte) do { \ - kunmap_local((pte)); \ - rcu_read_unlock(); \ -} while (0) -#else -static inline pte_t *__pte_map (pmd_t *pmd,unsigned long address) -{ -return pte_offset_kernel (pmd, address); -}static inline void pte_unmap (pte_t *pte) {rcu_read_unlock (); } -#endif void pte_free_defer (struct mm_struct *mm,pgtable_t pgtable);
mm/pgtable-generic.c +12 -13
@@ -314,7 +314,7 @@ pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp)pmd_clear_bad (pmd); goto nomap; } -return __pte_map (&pmdval, addr); +return pte_offset_kernel (&pmdval, addr); nomap:rcu_read_unlock ();return NULL ;
@@ -353,11 +353,11 @@ pte_t *pte_offset_map_rw_nolock(struct mm_struct *mm, pmd_t *pmd,* for read (or for write). In a few cases, it may be used with pmd pointing to * a pmd_t already copied to or constructed on the stack. * -* When successful, it returns the pte pointer for addr, with its page table -* kmapped if necessary (when CONFIG_HIGHPTE), and locked against concurrent -* modification by software, with a pointer to that spinlock in ptlp (in some -* configs mm->page_table_lock, in SPLIT_PTLOCK configs a spinlock in table's -* struct page). pte_unmap_unlock(pte, ptl) to unlock and unmap afterwards. +* When successful, it returns the pte pointer for addr, locked against +* concurrent modification by software, with a pointer to that spinlock in ptlp +* (in some configs mm->page_table_lock, in SPLIT_PTLOCK configs a spinlock in +* table's struct page). pte_unmap_unlock(pte, ptl) to unlock and unmap +* afterwards. * * But it is unsuccessful, returning NULL with *ptlp unchanged, if there is no * page table at *pmd: if, for example, the page table has just been removed,
@@ -366,13 +366,12 @@ pte_t *pte_offset_map_rw_nolock(struct mm_struct *mm, pmd_t *pmd,* page table can be safely removed or replaced by THP while holding its lock.) * * pte_offset_map(pmd, addr), and its internal helper __pte_offset_map() above, -* just returns the pte pointer for addr, its page table kmapped if necessary; -* or NULL if there is no page table at *pmd. It does not attempt to lock the -* page table, so cannot normally be used when the page table is to be updated, -* or when entries read must be stable. But it does take rcu_read_lock(): so -* that even when page table is racily removed, it remains a valid though empty -* and disconnected table. Until pte_unmap(pte) unmaps and rcu_read_unlock()s -* afterwards. +* just returns the pte pointer for addr, or NULL if there is no page table at +* *pmd. It does not attempt to lock the page table, so cannot normally be +* used when the page table is to be updated, or when entries read must be +* stable. But it does take rcu_read_lock(): so that even when page table is +* racily removed, it remains a valid though empty and disconnected table. +* Until pte_unmap(pte) unmaps and rcu_read_unlock()s afterwards. * * pte_offset_map_ro_nolock(mm, pmd, addr, ptlp), above, is like pte_offset_map(); * but when successful, it also outputs a pointer to the spinlock in ptlp - as
mm/userfaultfd.c +1 -5
@@ -1696,11 +1696,7 @@ static long move_pages_ptes(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmdfolio_unlock (src_folio);folio_put (src_folio); } -/* -* Unmap in reverse order (LIFO) to maintain proper kmap_local -* index ordering when CONFIG_HIGHPTE is enabled. We mapped dst_pte -* first, then src_pte, so we must unmap src_pte first, then dst_pte. -*/ +if (src_pte)pte_unmap (src_pte);if (dst_pte)
Signature · 1 line
2.53.0
PATCH v3 10/10 mm: print pte in __print_bad_page_map_pgtable()
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
HIGHPTE support is gone now, so it's easy enough to print the PTE here along with the upper level entries.
--- mm/memory.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
mm/memory.c +14 -7
@@ -528,9 +528,11 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long addchar p4d_str[PTVAL_STR_MAX ];char pud_str[PTVAL_STR_MAX ];char pmd_str[PTVAL_STR_MAX ]; +char pte_str[PTVAL_STR_MAX ];p4d_t p4d, *p4dp;pud_t pud, *pudp;pmd_t pmd, *pmdp; +pte_t pte, *ptep;pgd_t *pgdp;/*
@@ -567,13 +569,18 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long add pmd =pmdp_get (pmdp);ptval_to_str (pmd_str,pmd_val (pmd)); -/* -* Dumping the PTE would be nice, but it's tricky with CONFIG_HIGHPTE, -* because the table should already be mapped by the caller and -* doing another map would be bad. print_bad_page_map() should -* already take care of printing the PTE. -*/ -pr_alert ("pgd:%s p4d:%s pud:%s pmd:%s\n" , pgd_str, p4d_str, pud_str, pmd_str); +if (!pmd_present (pmd) ||pmd_leaf (pmd)) { +pr_alert ("pgd:%s p4d:%s pud:%s pmd: %s\n" , + pgd_str, p4d_str, pud_str, pmd_str); +return ; + } + + ptep =pte_offset_kernel (pmdp, addr); + pte =ptep_get (ptep); +ptval_to_str (pte_str,pte_val (pte)); + +pr_alert ("pgd:%s p4d:%s pud:%s pmd:%s pte:%s\n" , + pgd_str, p4d_str, pud_str, pmd_str, pte_str); }/*
Signature · 1 line
2.53.0
Re: [PATCH v3 10/10] mm: print pte in __print_bad_page_map_pgtable()
Quoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
HIGHPTE support is gone now, so it's easy enough to print the PTE here along with the upper level entries.
Signed-off-by Arnd Bergmann <[email protected]>
Quoted 3 lines
--- mm/memory.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Signature · 2 lines
Sincerely yours, Mike.
[email protected]
AI reviewRe: [PATCH v3 10/10] mm: print pte in __print_bad_page_map_pgtable()
In reply to Arnd BergmannThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm: TOCTOU race and missing RCU protection in __print_bad_page_map_pgtable() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mm: TOCTOU race and missing RCU protection in __print_bad_page_map_pgtable()
--
commit ba4bdee29bb52c7a53d86e0e93403b7b06ce3b2f
Author: Arnd Bergmann <[email protected]>
mm: print pte in __print_bad_page_map_pgtable()
This commit extends __print_bad_page_map_pgtable() to also read and print the PTE entry alongside the upper page table levels.
Quoted 30 lines
mm/memory.c +5
-7@@ -528,9 +528,11 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long addchar p4d_str[PTVAL_STR_MAX ];char pud_str[PTVAL_STR_MAX ];char pmd_str[PTVAL_STR_MAX ]; +char pte_str[PTVAL_STR_MAX ];p4d_t p4d, *p4dp;pud_t pud, *pudp;pmd_t pmd, *pmdp; +pte_t pte, *ptep;pgd_t *pgdp;/* @@ -567,13 +569,18 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long add pmd =pmdp_get (pmdp);ptval_to_str (pmd_str,pmd_val (pmd)); -/* -* Dumping the PTE would be nice, but it's tricky with CONFIG_HIGHPTE, -* because the table should already be mapped by the caller and -* doing another map would be bad. print_bad_page_map() should -* already take care of printing the PTE. -*/ -pr_alert ("pgd:%s p4d:%s pud:%s pmd:%s\n" , pgd_str, p4d_str, pud_str, pmd_str); +if (!pmd_present (pmd) ||pmd_leaf (pmd)) { +pr_alert ("pgd:%s p4d:%s pud:%s pmd: %s\n" , + pgd_str, p4d_str, pud_str, pmd_str);
mm/memory.c static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long add · line 584
Quoted 10 lines
mm/memory.c +9
-0+return ; + } + + ptep =pte_offset_kernel (pmdp, addr); + pte =ptep_get (ptep); +ptval_to_str (pte_str,pte_val (pte)); + +pr_alert ("pgd:%s p4d:%s pud:%s pmd:%s pte:%s\n" , + pgd_str, p4d_str, pud_str, pmd_str, pte_str); }
[Severity: Medium]
Can pte_offset_kernel(pmdp, addr) and ptep_get(ptep) race with concurrent PTE table reclaim or collapse and read a freed or invalid PTE table?
pte_offset_kernel(pmdp, addr) dereferences *pmdp again after the local pmd copy was validated, and accesses the PTE page table without rcu_read_lock(). Although print_bad_page_map() assumes callers keep the leaf page table mapped, callers such as do_swap_page() unmap the PTE (dropping both the PTL and rcu_read_lock() in pte_unmap_same()) before calling print_bad_pte():
mm/memory.c:do_swap_page() {
...
if (!pte_unmap_same(vmf))
goto out;
...
} else {
print_bad_pte(vma, vmf->address, vmf->orig_pte, NULL);
}Other paths such as get_gate_page() and hmm_vma_handle_pte() also call vm_normal_page() under pte_offset_map() without holding the leaf PTL:
CPU0 CPU1do_swap_page()
pte_unmap_same(vmf)
print_bad_pte()
...
pmd = pmdp_get(pmdp)
if (!pmd_present(pmd) || ...)
retract_page_tables() / zap_pte_range()
pmdp_collapse_flush() / pmd_clear() pte_free_defer()
/* RCU grace period elapses */
ptep = pte_offset_kernel(pmdp, addr)
pte = ptep_get(ptep) <-- bogus address or use-after-free
If CPU1 clears *pmdp or replaces it with a huge leaf PMD and frees the PTE page table via RCU between pmdp_get(pmdp) and ptep_get(ptep), CPU0 will re-read the modified *pmdp and dereference a bogus kernel address or freed PTE table. Using pte_offset_map() and pte_unmap() here avoids re-reading *pmdp and keeps the PTE page table RCU-protected while reading the entry.
Also, this isn't a bug, but the early-return pr_alert() above adds an extra space in "pmd: %s" compared to "pmd:%s" in the other messages.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH v3 10/10] mm: print pte in __print_bad_page_map_pgtable()
Quoted 11 lines · On Tue, Nov 17, 2026, at 13:50, [email protected] wrote:
print_bad_pte()
...
pmd = pmdp_get(pmdp)
if (!pmd_present(pmd) || ...)
retract_page_tables() / zap_pte_range()
pmdp_collapse_flush() / pmd_clear()
pte_free_defer()
/* RCU grace period elapses */
ptep = pte_offset_kernel(pmdp, addr)
pte = ptep_get(ptep) <-- bogus address or use-after-freeQuoted 5 lines
If CPU1 clears *pmdp or replaces it with a huge leaf PMD and frees the PTE page table via RCU between
pmdp_get(pmdp)andptep_get(ptep), CPU0 will re-read the modified *pmdp and dereference a bogus kernel address or freed PTE table. Usingpte_offset_map()andpte_unmap()here avoids re-reading *pmdp and keeps the PTE page table RCU-protected while reading the entry.
This looks like it should be prevented calling conventions for print_bad_page_map():
* This function must be called during a proper page table walk, as it will
* re-walk the page table to dump information: the caller MUST prevent page
* table teardown (by holding mmap, vma or rmap lock) and MUST hold the leaf
* page table lock.
Is that a case of do_swap_page() calling print_bad_pte() incorrectly that I can ignore here, or should I actually change this? Is the same race present in the upper page table lookups?
Quoted 2 lines
Also, this isn't a bug, but the early-return
pr_alert()above adds an extra space in "pmd: %s" compared to "pmd:%s" in the other messages.
Fixed.
Arnd
David Hildenbrand (Arm)
maintainerRe: [PATCH v3 10/10] mm: print pte in __print_bad_page_map_pgtable()
Quoted 22 lines · Arnd Bergmann
Quoted 11 lines · On Tue, Nov 17, 2026, at 13:50, [email protected] wrote:
print_bad_pte() ... pmd = pmdp_get(pmdp) if (!pmd_present(pmd) || ...) retract_page_tables() / zap_pte_range() pmdp_collapse_flush() / pmd_clear() pte_free_defer() /* RCU grace period elapses */ ptep = pte_offset_kernel(pmdp, addr) pte = ptep_get(ptep) <-- bogus address or use-after-freeQuoted 5 lines
If CPU1 clears *pmdp or replaces it with a huge leaf PMD and frees the PTE page table via RCU between
pmdp_get(pmdp)andptep_get(ptep), CPU0 will re-read the modified *pmdp and dereference a bogus kernel address or freed PTE table. Usingpte_offset_map()andpte_unmap()here avoids re-reading *pmdp and keeps the PTE page table RCU-protected while reading the entry.This looks like it should be prevented calling conventions for
print_bad_page_map():
Quoted 8 lines
* This function must be called during a proper page table walk, as it will
* re-walk the page table to dump information: the caller MUST prevent page
* table teardown (by holding mmap, vma or rmap lock) and MUST hold the leaf
* page table lock.Is that a case of
do_swap_page()callingprint_bad_pte()incorrectly that I can ignore here, or should I actually change this? Is the same race present in the upper page table lookups?
TBH, I wouldn't worry about. If we run into this the system is already pretty messed up ...
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerQuoted 117 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
This is an updated series from what I posted last year [1] and last week[2].
At LPC 2025 [3], we got rough consensus on the plan to keep the funcationality present for the time being but instead reduce the scope of highmem in the kernel as much as we can without hurting users.
The short summary is a three stage process:
1. Nudge users towards using a larger lowmem zone with the CONFIG_VMSPLIT_* options if at all possible.
2. Drop most
__GFP_HIGHMEMallocations and correspondingkmap()calls from the kernel, leaving only the subset that is likely to contain the majority of the actual allocations. Specifically we will keep anonymous and regular file backed user mappings, zsmalloc, and huge pages.3. In a few years, also drop the page cache allocations and leave perhaps only zsmalloc using a much simpler interface. I suggested five years as the time until we do this, but the timing depends a lot on how the first two stages work out in practice, and how long the remaining highmem users plan to keep updating their kernels.
This series implements stage 1, mostly using
Kconfigchanges to the default settings but leaving the traditional behavior as aCONFIG_EXPERTchoice inKconfig. With the new defaults, most installations that use highmem today with 1 GiB or 2 GiB of system RAM will see all of their RAM in the lowmem zone after upgrading their kernels. My estimate is that instead of 80% to 90% of maintained embedded 32-bit systems, this should cover over 98%.As I don't actually have hardware in the category that still needs highmem, I tested this using a qemu-system for Armv7 and PPC6xx running a Debian userland with all combinations of VMSPLIT and HIGHMEM options. I ran some kernel builds on the Arm guest to ensure that the new options don't cause functional or performance regressions for regular workloads that don't exceed the virtual address space. I also ran some tests with Firefox and was positively surprised to see that this still works on the
VMSPLIT_2G_OPTconfiguration without highmem, though it gets close to both the address space and lowmem size limits.The change to use
VMSPLIT_3G_OPTby default on Armv5 means that I could include a patch to no longer support highmem at all on VIVT caches, as suggested by Jason Gunthorpe. I also included the patch to drop HIGHPTE support now, as suggested by David Hildenbrand.The patches from this series are available in [4] for testing.
Once there are no further concerns about the contents, I would suggest merging this through the asm-generic tree, as it touches mostly architecture specific code and that is not easily split from the core
mm/*code. Merging everything through the mm tree would of course also work.Arnd
[1] https://lore.kernel.org/all/[email protected]/ # v1
[2] https://lore.kernel.org/all/[email protected]/ # v2
[3] https://lwn.net/Articles/1051010/
[4] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=highmem-7.4Changes since v2:
- Add preparation patch for Arm PXA [sashiko-bot]
- Add preparation patch for powerpc32/kvm [sashiko-bot]
- Fix ArmARCH_MMAP_RND_BITS_MAXcalculation [sashiko-bot]
- Simplification forpte_alloc_one()[Mike Rapoport]
- Drop stale references to highpte [David Hildenbrand]
- improve__print_bad_page_map_pgtable()
- Split out Arm changes forCONFIG_VMSPLIT_2G_OPTChanges since v1:
- rebase to v7.4-rc
- add patch to drop highpteArnd Bergmann (10):
ARM: remove support for highmem on VIVT
ARM: dropCONFIG_HIGHPTEsupport
ARM: pxa: support arbitraryPAGE_OFFSET
powerpc: kvm: allow flexiblePAGE_OFFSET
arch/*: increase lowmem size to avoid highmem use
ARM: addCONFIG_VMSPLIT_2G_OPToption
ARM: defconfig: turn off highmem in favor ofCONFIG_VMSPLIT_2G_OPT
mm: removeARCH_NEEDS_KMAP_HIGH_GET
mm: drop HIGHPTE support altogether
mm: print pte in__print_bad_page_map_pgtable()arch/arm/Kconfig | 27 +++--- arch/arm/configs/aspeed_g5_defconfig | 3 +- arch/arm/configs/gemini_defconfig | 1 - arch/arm/configs/lpae.config | 1 + arch/arm/configs/multi_v5_defconfig | 1 - arch/arm/configs/multi_v7_defconfig | 1 + arch/arm/configs/mvebu_v5_defconfig | 1 - arch/arm/configs/omap2plus_defconfig | 1 + arch/arm/configs/u8500_defconfig | 1 - arch/arm/configs/vt8500_v6_v7_defconfig | 2 - arch/arm/include/asm/highmem.h | 56 +---------- arch/arm/include/asm/pgalloc.h | 13 +-- arch/arm/mach-omap2/Kconfig | 1 - arch/arm/mach-pxa/pxa3xx.c | 2 +- arch/arm/mm/cache-feroceon-l2.c | 31 +----- arch/arm/mm/cache-xsc3l2.c | 47 +-------- arch/arm/mm/dma-mapping.c | 12 +-- arch/arm/mm/flush.c | 19 +--- arch/microblaze/Kconfig | 9 +- arch/microblaze/configs/mmu_defconfig | 1 - arch/powerpc/Kconfig | 24 +++-- arch/powerpc/configs/44x/akebono_defconfig | 1 - arch/powerpc/configs/85xx/ksi8560_defconfig | 1 - arch/powerpc/configs/85xx/stx_gp3_defconfig | 1 - arch/powerpc/kvm/book3s_32_sr.S | 4 +- arch/powerpc/kvm/booke_interrupts.S | 4 +- arch/powerpc/kvm/e500_mmu_host.c | 3 +-
Quoted 8 lines
arch/x86/Kconfig | 4 +- include/linux/hugetlb.h | 5 +- include/linux/mm.h | 1 - include/linux/pgtable.h | 13 --- mm/highmem.c | 100 ++------------------ mm/memory.c | 21 ++-- mm/pgtable-generic.c | 25 +++-- mm/userfaultfd.c | 6 +-
I can pick up the MM patches after the ARM stuff upstream, or the MM patches can go upstream in the same go as the ARM stuff.
I don't expect conflicts in that area.
Just let me know what you+people prefer.
Signature · 3 lines
Cheers, David