From: Mike Rapoport <rppt@kernel.org>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: Mark Brown <broonie@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Andreas Larsson <andreas@gaisler.com>,
Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Borislav Petkov <bp@alien8.de>, Brian Cain <bcain@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"David S. Miller" <davem@davemloft.net>,
Dinh Nguyen <dinguyen@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Guo Ren <guoren@kernel.org>, Heiko Carstens <hca@linux.ibm.com>,
Helge Deller <deller@gmx.de>, Huacai Chen <chenhuacai@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Jiaxun Yang <jiaxun.yang@flygoat.com>,
Johannes Berg <johannes@sipsolutions.net>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Matt Turner <mattst88@gmail.com>,
Max Filippov <jcmvbkbc@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Michal Simek <monstr@monstr.eu>,
Palmer Dabbelt <palmer@dabbelt.com>,
Peter Zijlstra <peterz@infradead.org>,
Richard Weinberger <richard@nod.at>,
Stafford Horne <shorne@gmail.com>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Thomas Gleixner <tglx@linutronix.de>,
Vasily Gorbik <gor@linux.ibm.com>,
Vineet Gupta <vgupta@kernel.org>, Will Deacon <will@kernel.org>,
linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-snps-arc@lists.infradead.org,
linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org,
linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev,
linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
sparclinux@vger.kernel.org, linux-um@lists.infradead.org,
linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org
Subject: Re: [PATCH 10/13] arch, mm: set high_memory in free_area_init()
Date: Wed, 12 Mar 2025 08:34:56 +0200 [thread overview]
Message-ID: <Z9ErEBuMMvd6i2n9@kernel.org> (raw)
In-Reply-To: <Z9CyRHewqfZlmgIo@shell.armlinux.org.uk>
On Tue, Mar 11, 2025 at 09:59:32PM +0000, Russell King (Oracle) wrote:
> On Tue, Mar 11, 2025 at 05:51:06PM +0000, Mark Brown wrote:
> > On Thu, Mar 06, 2025 at 08:51:20PM +0200, Mike Rapoport wrote:
> > > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> > >
> > > high_memory defines upper bound on the directly mapped memory.
> > > This bound is defined by the beginning of ZONE_HIGHMEM when a system has
> > > high memory and by the end of memory otherwise.
> > >
> > > All this is known to generic memory management initialization code that
> > > can set high_memory while initializing core mm structures.
> > >
> > > Remove per-architecture calculation of high_memory and add a generic
> > > version to free_area_init().
> >
> > This patch appears to be causing breakage on a number of 32 bit arm
> > platforms, including qemu's virt-2.11,gic-version=3. Affected platforms
> > die on boot with no output, a bisect with qemu points at this commit and
> > those for physical platforms appear to be converging on the same place.
>
> I'm not convinced that the old and the new code is doing the same
> thing.
>
> The new code:
>
> + phys_addr_t highmem = memblock_end_of_DRAM();
> +
> +#ifdef CONFIG_HIGHMEM
> + unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM];
> +
> + if (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn))
> + highmem = PFN_PHYS(pfn);
> +#endif
> +
> + high_memory = phys_to_virt(highmem - 1) + 1;
>
> First, when CONFIG_HIGHMEM is disabled, this code assumes that the last
> byte of DRAM declared to memblock is the highmem limit. This _could_
> overflow phys_to_virt() and lead to an invalid value for high_memory.
>
> Second, arch_zone_lowest_possible_pfn[ZONE_HIGHMEM] is the _start_ of
> highmem. This is not what arch code sets high_memory to - because
> the start of highmem may not contiguously follow on from lowmem.
>
> In arch/arm/mm/mmu.c, lowmem_limit is computed to be the highest + 1
> physical address that lowmem can possibly be, taking into account the
> amount of vmalloc memory that is required. This is used to set
> high_memory.
>
> We also limit the amount of usable RAM via memblock_set_current_limit()
> which memblock_end_of_DRAM() doesn't respect.
>
> I don't think the proposed generic version is suitable for 32-bit arm.
Unless I'm missing something, both memblock.current_limit and start of
ZONE_HIGHMEM are set to arm_lowmem_limit which will be different from
memblock_end_of_DRAM() only for machines with more than nearly 4GiB of RAM
and those will supposedly use HIGHMEM anyway.
But this does not matter anyway because failures Mark reported happen
because 32-bit arm uses high_memory before mem_init() and that what causes
the hangs.
Here's the fix I have, I'll send v2 shortly.
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index e492d58a0386..f02f872ea8a9 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1250,6 +1250,8 @@ void __init adjust_lowmem_bounds(void)
arm_lowmem_limit = lowmem_limit;
+ high_memory = __va(arm_lowmem_limit - 1) + 1;
+
if (!memblock_limit)
memblock_limit = arm_lowmem_limit;
diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c
index 65903ed5e80d..1a8f6914ee59 100644
--- a/arch/arm/mm/nommu.c
+++ b/arch/arm/mm/nommu.c
@@ -146,6 +146,7 @@ void __init adjust_lowmem_bounds(void)
phys_addr_t end;
adjust_lowmem_bounds_mpu();
end = memblock_end_of_DRAM();
+ high_memory = __va(end - 1) + 1;
memblock_set_current_limit(end);
}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 545e11f1a3ba..0aef4bef93c4 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1765,14 +1765,20 @@ static bool arch_has_descending_max_zone_pfns(void)
static void set_high_memory(void)
{
+ unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM];
phys_addr_t highmem = memblock_end_of_DRAM();
-#ifdef CONFIG_HIGHMEM
- unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM];
+ /*
+ * Some architectures (e.g. ARM) set high_memory very early and
+ * use it in arch setup code.
+ * If an architecture already set high_memory don't overwrite it
+ */
+ if (high_memory)
+ return;
- if (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn))
+ if (IS_ENABLED(CONFIG_HIGHMEM) &&
+ (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn)))
highmem = PFN_PHYS(pfn);
-#endif
high_memory = phys_to_virt(highmem - 1) + 1;
}
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2025-03-12 6:35 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 18:51 [PATCH 00/13] arch, mm: reduce code duplication in mem_init() Mike Rapoport
2025-03-06 18:51 ` [PATCH 01/13] arm: mem_init: use memblock_phys_free() to free DMA memory on SA1111 Mike Rapoport
2025-03-06 18:51 ` [PATCH 02/13] csky: move setup_initrd() to setup.c Mike Rapoport
2025-03-10 0:43 ` Guo Ren
2025-03-06 18:51 ` [PATCH 03/13] hexagon: move initialization of init_mm.context init to paging_init() Mike Rapoport
2025-03-06 18:51 ` [PATCH 04/13] MIPS: consolidate mem_init() for NUMA machines Mike Rapoport
2025-03-06 18:51 ` [PATCH 05/13] MIPS: make setup_zero_pages() use memblock Mike Rapoport
2025-03-11 5:57 ` Mike Rapoport
2025-03-06 18:51 ` [PATCH 06/13] nios2: move pr_debug() about memory start and end to setup_arch() Mike Rapoport
2025-03-06 18:51 ` [PATCH 07/13] s390: make setup_zero_pages() use memblock Mike Rapoport
2025-03-07 15:28 ` Heiko Carstens
2025-03-11 5:55 ` Mike Rapoport
2025-03-12 15:56 ` Ard Biesheuvel
2025-03-12 16:09 ` Mike Rapoport
2025-03-06 18:51 ` [PATCH 08/13] xtensa: split out printing of virtual memory layout to a function Mike Rapoport
2025-03-06 18:51 ` [PATCH 09/13] arch, mm: set max_mapnr when allocating memory map for FLATMEM Mike Rapoport
2025-03-06 18:51 ` [PATCH 10/13] arch, mm: set high_memory in free_area_init() Mike Rapoport
2025-03-11 17:51 ` Mark Brown
2025-03-11 21:06 ` Mike Rapoport
2025-03-11 21:33 ` Mark Brown
2025-03-11 21:41 ` Geert Uytterhoeven
2025-03-12 15:26 ` Mark Brown
2025-03-11 21:44 ` Russell King (Oracle)
2025-03-11 22:05 ` Russell King (Oracle)
2025-03-11 21:59 ` Russell King (Oracle)
2025-03-12 6:34 ` Mike Rapoport [this message]
2025-03-15 14:55 ` Soekris crypto 1411, where to find ? DiTBho Down in The Bunny hole
2025-03-06 18:51 ` [PATCH 11/13] arch, mm: streamline HIGHMEM freeing Mike Rapoport
2025-03-06 18:51 ` [PATCH 12/13] arch, mm: introduce arch_mm_preinit Mike Rapoport
2025-03-06 18:51 ` [PATCH 13/13] arch, mm: make releasing of memory to page allocator more explicit Mike Rapoport
2025-03-06 19:38 ` [PATCH 00/13] arch, mm: reduce code duplication in mem_init() Dave Hansen
2025-03-06 21:20 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9ErEBuMMvd6i2n9@kernel.org \
--to=rppt@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andreas@gaisler.com \
--cc=arnd@arndb.de \
--cc=bcain@kernel.org \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=deller@gmx.de \
--cc=dinguyen@kernel.org \
--cc=geert@linux-m68k.org \
--cc=gerald.schaefer@linux.ibm.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=gor@linux.ibm.com \
--cc=guoren@kernel.org \
--cc=hca@linux.ibm.com \
--cc=jcmvbkbc@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=johannes@sipsolutions.net \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-um@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mattst88@gmail.com \
--cc=mingo@redhat.com \
--cc=monstr@monstr.eu \
--cc=mpe@ellerman.id.au \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=richard@nod.at \
--cc=shorne@gmail.com \
--cc=sparclinux@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tsbogend@alpha.franken.de \
--cc=vgupta@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).