From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88E02FC6160 for ; Sat, 3 Jan 2026 18:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A7ify8gGfRN7Wub05P3hV43ZnxigfEVeL6Pufnyr+2Q=; b=C1Kx6cEri14BOs LcJ48O4roK+VNLAIzvdrr9GV7JgSi8+4GHAPSj24rKLxUvm7spPDz6M6HM8nDEcSdxKaB7UuW27Mi DZg3VRGtcvB28rx9s3D1wKJvZ4FZZwAllXGIt+2XKKh4h0FFlSHoFzm/IrVMYPTM/jvA8vfIVpmyy PE1jIXVPK1D7yxzC5o80vdbVAcpsnpmi8KET1eMo0+ke96qbodkmM+cYcyiFX/6yWLK3jioeo1hmu mycbKs38RclM3s7m0ngKYjubthk/Iez3eul6XGIq6zKC+Yx0ABVBatGojNBt9XAG8iorVIUWY2Hfs Gc5OLxEMp+BQkqGxGs8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vc6m4-00000009hLS-1yJ1; Sat, 03 Jan 2026 18:54:52 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vc6m0-00000009hKw-0mMi; Sat, 03 Jan 2026 18:54:50 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 1784D40423; Sat, 3 Jan 2026 18:54:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09051C113D0; Sat, 3 Jan 2026 18:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767466485; bh=JJi0MIW7ufay+ZZEo6EH5bf/kqP+vRBsByx4CICNQCs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ntpZea6Sa23o++gxekMhG3I2QU/XUTWc5nMNjfwy8Zyi3NxPf/H771f3L1fK5G+JV BrIkjrHnTIa77Opbod1/wKDGPBT3rKbTairESVy5GIn6kLNbwjXgkey0AYjrLhGdtm 1WmiT9BvnPKoouYAqUVpZ8pMait9YtcjloPtOthbURuem94A6kCmWXPP6kGGR5TMsk u58EQYc7patXv3IP/W4ZCBdZ3acr/VkBhoQVGrCvo13QtDF90hlUSKKPF5FMbB73Cg bSz/V5A/Jkpw/H2SFDajyAjOcb+N26PpJKiNlYzPGaxtX/S68RKs74BHnvORKROqCy PVF9NX0W2W0Vg== Date: Sat, 3 Jan 2026 20:54:23 +0200 From: Mike Rapoport To: Klara Modin Cc: Andrew Morton , Alex Shi , Alexander Gordeev , Andreas Larsson , Borislav Petkov , Brian Cain , "Christophe Leroy (CS GROUP)" , Catalin Marinas , "David S. Miller" , Dave Hansen , David Hildenbrand , Dinh Nguyen , Geert Uytterhoeven , Guo Ren , Heiko Carstens , Helge Deller , Huacai Chen , Ingo Molnar , Johannes Berg , John Paul Adrian Glaubitz , Jonathan Corbet , "Liam R. Howlett" , Lorenzo Stoakes , Magnus Lindholm , Matt Turner , Max Filippov , Michael Ellerman , Michal Hocko , Michal Simek , Muchun Song , Oscar Salvador , Palmer Dabbelt , Pratyush Yadav , Richard Weinberger , Russell King , Stafford Horne , Suren Baghdasaryan , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Vineet Gupta , Vlastimil Babka , Will Deacon , x86@kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-um@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org Subject: Re: [PATCH v2 22/28] arch, mm: consolidate initialization of nodes, zones and memory map Message-ID: References: <20260102070005.65328-1-rppt@kernel.org> <20260102070005.65328-23-rppt@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260103_105448_278380_9184E409 X-CRM114-Status: GOOD ( 40.60 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Hi, On Sat, Jan 03, 2026 at 12:33:29AM +0100, Klara Modin wrote: > On 2026-01-02 08:59:58 +0200, Mike Rapoport wrote: > > From: "Mike Rapoport (Microsoft)" > > > > To initialize node, zone and memory map data structures every architecture > > calls free_area_init() during setup_arch() and passes it an array of zone > > limits. > > > > Beside code duplication it creates "interesting" ordering cases between > > allocation and initialization of hugetlb and the memory map. Some > > architectures allocate hugetlb pages very early in setup_arch() in certain > > cases, some only create hugetlb CMA areas in setup_arch() and sometimes > > hugetlb allocations happen mm_core_init(). > > > > With arch_zone_limits_init() helper available now on all architectures it > > is no longer necessary to call free_area_init() from architecture setup > > code. Rather core MM initialization can call arch_zone_limits_init() in a > > single place. > > > > This allows to unify ordering of hugetlb vs memory map allocation and > > initialization. > > > > Remove the call to free_area_init() from architecture specific code and > > place it in a new mm_core_init_early() function that is called immediately > > after setup_arch(). > > > > After this refactoring it is possible to consolidate hugetlb allocations > > and eliminate differences in ordering of hugetlb and memory map > > initialization among different architectures. > > > > As the first step of this consolidation move hugetlb_bootmem_alloc() to > > mm_core_early_init(). > > > > Signed-off-by: Mike Rapoport (Microsoft) > > This breaks boot on my Raspberry Pi 1. The reason seems to be the use of > page_folio() when initializing the dynamically allocated zero page in > arm, which doesn't work when free_area_init() hasn't been called yet. I believe the reason is rather the use of virt_to_phys() that now happens before the memory map is ready. > The following oopses are generated: > > 8<--- cut here --- > Unable to handle kernel paging request at virtual address 003dfb44 when read > [003dfb44] *pgd=00000000 > Internal error: Oops: 5 [#1] ARM > CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-rc3-03898-g7975b0084358 #451 NONE > Hardware name: BCM2835 > PC is at paging_init (include/linux/page-flags.h:284 (discriminator 2) arch/arm/mm/mmu.c:1790 (discriminator 2)) > LR is at paging_init (arch/arm/mm/mmu.c:1789 (discriminator 1)) ... > 8<--- cut here --- > > and the second one repeats for some time afterwards. > > I experimented a little by allocating the zero page statically as many > other arches do which fixes the issue as it does not need to be > initialized at this point anymore, though I have no idea if that's > appropriate. Do you mean putting the zero in the BSS like, e.g. arm64? I don't see a reason why this shouldn't work. I also have a patch with some minor changes that still keeps empty_zero_page allocated, but avoids virt_to_page() and folio_page() dance. Can you please test it in your setup? >From 8a213c13211106d592fbe96b68ee29879ed739f8 Mon Sep 17 00:00:00 2001 From: "Mike Rapoport (Microsoft)" Date: Sat, 3 Jan 2026 20:40:09 +0200 Subject: [PATCH] arm: make initialization of zero page independent of the memory map Unlike most architectures, arm keeps a struct page pointer to the empty_zero_page and to initialize it requires conversion of a virtual address to page which makes it necessary to have memory map initialized before creating the empty_zero_page. Make empty_zero_page a void * to decouple it's initialization from the initialization of the memory map. Signed-off-by: Mike Rapoport (Microsoft) --- arch/arm/include/asm/pgtable.h | 4 ++-- arch/arm/mm/mmu.c | 10 +++------- arch/arm/mm/nommu.c | 10 +++------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 86378eec7757..08bbd2aed6c9 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -15,8 +15,8 @@ * ZERO_PAGE is a global shared page that is always zero: used * for zero-mapped memory areas etc.. */ -extern struct page *empty_zero_page; -#define ZERO_PAGE(vaddr) (empty_zero_page) +extern void *empty_zero_page; +#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) #endif #include diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 8bac96e205ac..867258f1ae09 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -45,7 +45,7 @@ extern unsigned long __atags_pointer; * empty_zero_page is a special page that is used for * zero-initialized data and COW. */ -struct page *empty_zero_page; +void *empty_zero_page; EXPORT_SYMBOL(empty_zero_page); /* @@ -1754,8 +1754,6 @@ static void __init early_fixmap_shutdown(void) */ void __init paging_init(const struct machine_desc *mdesc) { - void *zero_page; - #ifdef CONFIG_XIP_KERNEL /* Store the kernel RW RAM region start/end in these variables */ kernel_sec_start = CONFIG_PHYS_OFFSET & SECTION_MASK; @@ -1782,12 +1780,10 @@ void __init paging_init(const struct machine_desc *mdesc) top_pmd = pmd_off_k(0xffff0000); /* allocate the zero page. */ - zero_page = early_alloc(PAGE_SIZE); + empty_zero_page = early_alloc(PAGE_SIZE); + __cpuc_flush_dcache_area(empty_zero_page, PAGE_SIZE); bootmem_init(); - - empty_zero_page = virt_to_page(zero_page); - __flush_dcache_folio(NULL, page_folio(empty_zero_page)); } void __init early_mm_init(const struct machine_desc *mdesc) diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index d638cc87807e..f80ff5a69fbb 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -31,7 +31,7 @@ unsigned long vectors_base; * empty_zero_page is a special page that is used for * zero-initialized data and COW. */ -struct page *empty_zero_page; +void *empty_zero_page; EXPORT_SYMBOL(empty_zero_page); #ifdef CONFIG_ARM_MPU @@ -156,18 +156,14 @@ void __init adjust_lowmem_bounds(void) */ void __init paging_init(const struct machine_desc *mdesc) { - void *zero_page; - early_trap_init((void *)vectors_base); mpu_setup(); /* allocate the zero page. */ - zero_page = (void *)memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE); + empty_zero_page = memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE); + __cpuc_flush_dcache_area(empty_zero_page, PAGE_SIZE); bootmem_init(); - - empty_zero_page = virt_to_page(zero_page); - flush_dcache_page(empty_zero_page); } /* -- 2.51.0 > Regards, > Klara Modin > -- Sincerely yours, Mike. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv