From nobody Fri Dec 19 00:18:27 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DB2E1E7C28; Tue, 25 Mar 2025 11:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742903382; cv=none; b=XWzFQWcSC+4ZXTrm44Nw8zkncQ6RSkxsmHt6iGzsMkZm3XO2aRvh0Ir2tt165D6seTPH4TREY1U8gZtyIhJGG6bRKW/dLAxZpPFuP2ERvKxaE+HHYlo0KuK5d2OKNgsOUNqu7TUSkCbPgKyzEyt5ZTMjMttW0IxN/gr23hHDUcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742903382; c=relaxed/simple; bh=qfpWtkjNYrQGK3RsZjqYJLcEX3OyIabqO13P6PMbc7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MGPnq3xPTkcNchBySiduLbMeC/XjbTeGe63OKXU1VmqDC0Lmu0/uWadwegbiSphd4QaaUgis4z85jlQtAr+cz+gcMo2xXWTgd69FQBdfzTVmJKSLDguXYuTxUrweFDi8+wP3RktA0U4HSo6x6x7g9OLBNMrrHxoPoLDpvXrSnIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oOf08xfD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oOf08xfD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC8A3C4CEED; Tue, 25 Mar 2025 11:49:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742903382; bh=qfpWtkjNYrQGK3RsZjqYJLcEX3OyIabqO13P6PMbc7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oOf08xfDf7JzudFmXaZx8QWeA/W+a8SOYgOsPFECAhIF+Kz9dt9TuQGFBcqSCdotd IoKuOSro0BZO0ID5go5sb8p8Nqjq5q6RSs4zpHIZJGG749PgL/qovWE0z5vhmBN+3W xhnUdNxCS7lSedIoO74EMJr9uNwWYu2iWpY9Ig3jRJ+YsMpgr/sEyhQSzo1VfS6ifV 54eD0LCdZYzKjgwkc3SwEvUifbEI8XH30cPaEupxQWQcdbFC5ESOCtORKNBk7rxm/T ogXNTDcmu2zBx51ubw91Gf0jjFjiwRXAN/KkeCajqMAzJfm/kVY3bQWO0HXMljOGoS ylQE4zurVIhIA== From: Mike Rapoport To: Andrew Morton Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , Ingo Molnar , Mike Rapoport , Nathan Chancellor , "H. Peter Anvin" , Peter Zijlstra , Thomas Bogendoerfer , Thomas Gleixner , Jiaxun Yang , kernel test robot , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: [PATCH 1/2] mm/mm_init: init holes in the end of the memory map for FLATMEM Date: Tue, 25 Mar 2025 13:49:27 +0200 Message-ID: <20250325114928.1791109-2-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250325114928.1791109-1-rppt@kernel.org> References: <20250325114928.1791109-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Kernel test robot reports the following crash on 32-bit system with FLATMEM and DEBUG_VM_PGFLAGS enabled: [ 0.478822][ T0] kernel BUG at include/linux/page-flags.h:536! [ 0.479312][ T0] Oops: invalid opcode: 0000 [#1] PREEMPT SMP [ 0.479768][ T0] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.14.= 0-rc6-00357-g8268af309d07 #1 [ 0.480470][ T0] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996= ), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 [ 0.481260][ T0] EIP: reserve_bootmem_region (include/linux/page-flags.h:53= 6) [ 0.481683][ T0] Code: 5d c3 01 f1 89 c8 ba e1 38 f4 c3 e8 1e 37 8e fc 0f 0= b b8 90 e2 62 c4 e8 e2 05 5e fc 01 f1 89 c8 ba be 85 f7 c3 e8 04 37 8e fc <= 0f> 0b b8 80 e2 62 c4 e8 c8 05 5e fc 55 89 e5 53 57 56 83 ec 10 89 [ 0.483177][ T0] EAX: 00000000 EBX: c425df50 ECX: 00000000 EDX: 00000= 000 [ 0.483712][ T0] ESI: 017ffc00 EDI: ffffffff EBP: c425df34 ESP: c425d= f2c [ 0.484248][ T0] DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 EFLAGS:= 00210046 [ 0.484846][ T0] CR0: 80050033 CR2: 00000000 CR3: 04b48000 CR4: 00000= 090 [ 0.485376][ T0] DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000= 000 [ 0.485907][ T0] DR6: fffe0ff0 DR7: 00000400 [ 0.486253][ T0] Call Trace: [ 0.486494][ T0] ? __die_body (arch/x86/kernel/dumpstack.c:478) [ 0.486822][ T0] ? die (arch/x86/kernel/dumpstack.c:?) [ 0.487099][ T0] ? do_trap (arch/x86/kernel/traps.c:? arch/x86/kernel/traps= .c:197) [ 0.487409][ T0] ? do_error_trap (arch/x86/kernel/traps.c:217) [ 0.487752][ T0] ? reserve_bootmem_region (include/linux/page-flags.h:536) [ 0.488153][ T0] ? exc_overflow (arch/x86/kernel/traps.c:301) [ 0.488490][ T0] ? handle_invalid_op (arch/x86/kernel/traps.c:254) [ 0.488869][ T0] ? reserve_bootmem_region (include/linux/page-flags.h:536) [ 0.489271][ T0] ? exc_invalid_op (arch/x86/kernel/traps.c:316) [ 0.489619][ T0] ? handle_exception (arch/x86/entry/entry_32.S:1055) [ 0.489996][ T0] ? exc_overflow (arch/x86/kernel/traps.c:301) [ 0.490332][ T0] ? reserve_bootmem_region (include/linux/page-flags.h:536) [ 0.490733][ T0] ? exc_overflow (arch/x86/kernel/traps.c:301) [ 0.491068][ T0] ? reserve_bootmem_region (include/linux/page-flags.h:536) [ 0.491470][ T0] memmap_init_reserved_pages (mm/memblock.c:2203) [ 0.491887][ T0] free_low_memory_core_early (mm/memblock.c:?) [ 0.492302][ T0] memblock_free_all (mm/memblock.c:2272 include/linux/atomic= /atomic-arch-fallback.h:546 include/linux/atomic/atomic-long.h:123 include/= linux/atomic/atomic-instrumented.h:3261 include/linux/mm.h:67 mm/memblock.c= :2273) [ 0.492659][ T0] mem_init (arch/x86/mm/init_32.c:735) [ 0.492952][ T0] mm_core_init (mm/mm_init.c:2730) [ 0.493271][ T0] start_kernel (init/main.c:958) [ 0.493604][ T0] i386_start_kernel (arch/x86/kernel/head32.c:79) [ 0.493969][ T0] startup_32_smp (arch/x86/kernel/head_32.S:292) The crash happens because after commit 8268af309d07 ("arch, mm: set max_mapnr when allocating memory map for FLATMEM") max_mapnr is rounded up to MAX_ORDER_NR_PAGES and the pages in the end of the memory map are passing pfn_valid() check in reserve_bootmem_region(). Make sure that that pages in the end of the memory map are initialized, just like the pages in the end of the last section for SPARSEMEM. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202503241424.d16223ec-lkp@intel.com Fixes: 8268af309d07 ("arch, mm: set max_mapnr when allocating memory map fo= r FLATMEM") Signed-off-by: Mike Rapoport (Microsoft) --- mm/mm_init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index a38a1909b407..84f14fa12d0d 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -984,19 +984,19 @@ static void __init memmap_init(void) } } =20 -#ifdef CONFIG_SPARSEMEM /* * Initialize the memory map for hole in the range [memory_end, - * section_end]. + * section_end] for SPARSEMEM and in the range [memory_end, memmap_end] + * for FLATMEM. * Append the pages in this hole to the highest zone in the last * node. - * The call to init_unavailable_range() is outside the ifdef to - * silence the compiler warining about zone_id set but not used; - * for FLATMEM it is a nop anyway */ +#ifdef CONFIG_SPARSEMEM end_pfn =3D round_up(end_pfn, PAGES_PER_SECTION); - if (hole_pfn < end_pfn) +#else + end_pfn =3D round_up(end_pfn, MAX_ORDER_NR_PAGES); #endif + if (hole_pfn < end_pfn) init_unavailable_range(hole_pfn, end_pfn, zone_id, nid); } =20 --=20 2.47.2 From nobody Fri Dec 19 00:18:27 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B16E71E7C28; Tue, 25 Mar 2025 11:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742903387; cv=none; b=apShQzqU3IdH3e+91TcZikBeqZskBhMnUfXEWw97Y/OFTTGzz9jFnfl4FT8eK4INolIwu9SGrb1y+OtJPvWcc15UBxwkhMO2H2Y8RULyqqXpVU3drlduPbmLgHS/FjYvxJnVadOfWYTfABKtHxBUCxoIvtmMde0CkdBzK6SNbsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742903387; c=relaxed/simple; bh=KjXVzwyQVPVG7ZDGogZ7pwFZUzgPV51utp1p2Si+3js=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L6/XsKYqaHXV05yqH8Q1vOr2EYNHolUaU27fY5e68aXK4zmk0rv2XCW2//VAqIK93HmccAOg1A7NJaieGMgdbQjktC9cl/88ZN+YDSrfJWHK9Nfzd/RCznr/DIzh+lyS4XmTALfUy9SirdDljZPkTEeWm1kLsVUSpXXRXg7LBgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LlmENNuW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LlmENNuW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B20B9C4CEE9; Tue, 25 Mar 2025 11:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742903387; bh=KjXVzwyQVPVG7ZDGogZ7pwFZUzgPV51utp1p2Si+3js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlmENNuWOSzOvGs96AushtPG9bBtDl6hM3+nqxlYmmYaE/ThuySmRGQjosM0AUOXR UdMsC0fDvyny1gFz0OogOT/19sg+tiajV7LTCrUIvnePjNqJPGgtDqwfq9VyFsFNYb UBWTyUVwiPNT7wsP63t3xozIA8yWGnfH+hzWYZVAACcabDM603Eo1kIoFMhYzvNFcg gHOAZv3QgU+0gv6cI60MYChaEeRDpKvwij//iW7o4L2MaWDz73Detuybq2YijYvUar 7NnKRw3BbGK45V7Kf/NURvWILQbRSsFkFGx3Y9Yo5bXzQhfAfNlbICxS57EgPPbQeV En3tNRx9fZGog== From: Mike Rapoport To: Andrew Morton Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , Ingo Molnar , Mike Rapoport , Nathan Chancellor , "H. Peter Anvin" , Peter Zijlstra , Thomas Bogendoerfer , Thomas Gleixner , Jiaxun Yang , kernel test robot , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: [PATCH 2/2] memblock: don't release high memory to page allocator when HIGHMEM is off Date: Tue, 25 Mar 2025 13:49:28 +0200 Message-ID: <20250325114928.1791109-3-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250325114928.1791109-1-rppt@kernel.org> References: <20250325114928.1791109-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Nathan Chancellor reports the following crash on a MIPS system with CONFIG_HIGHMEM=3Dn: Linux version 6.14.0-rc6-00359-g6faea3422e3b (nathan@ax162) (mips-linux-g= cc (GCC) 14.2.0, GNU ld (GNU Binutils) 2.42) #1 SMP Fri Mar 21 08:12:02 MST= 2025 earlycon: uart8250 at I/O port 0x3f8 (options '38400n8') printk: legacy bootconsole [uart8250] enabled Config serial console: console=3DttyS0,38400n8r CPU0 revision is: 00019300 (MIPS 24Kc) FPU revision is: 00739300 MIPS: machine is mti,malta Software DMA cache coherency enabled Initial ramdisk at: 0x8fad0000 (5360128 bytes) OF: reserved mem: Reserved memory: No reserved-memory node in the DT Primary instruction cache 2kB, VIPT, 2-way, linesize 16 bytes. Primary data cache 2kB, 2-way, VIPT, no aliases, linesize 16 bytes Zone ranges: DMA [mem 0x0000000000000000-0x0000000000ffffff] Normal [mem 0x0000000001000000-0x000000001fffffff] Movable zone start for each node Early memory node ranges node 0: [mem 0x0000000000000000-0x000000000fffffff] node 0: [mem 0x0000000090000000-0x000000009fffffff] Initmem setup node 0 [mem 0x0000000000000000-0x000000009fffffff] On node 0, zone Normal: 16384 pages in unavailable ranges random: crng init done percpu: Embedded 3 pages/cpu s18832 r8192 d22128 u49152 Kernel command line: rd_start=3D0xffffffff8fad0000 rd_size=3D5360128 con= sole=3DttyS0,38400n8r printk: log buffer data + meta data: 32768 + 102400 =3D 135168 bytes Dentry cache hash table entries: 65536 (order: 4, 262144 bytes, linear) Inode-cache hash table entries: 32768 (order: 3, 131072 bytes, linear) Writing ErrCtl register=3D00000000 Readback ErrCtl register=3D00000000 Built 1 zonelists, mobility grouping on. Total pages: 16384 mem auto-init: stack:all(zero), heap alloc:off, heap free:off Unhandled kernel unaligned access[#1]: CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.14.0-rc6-00359-g6faea342= 2e3b #1 Hardware name: mti,malta $ 0 : 00000000 00000001 81cb0880 00129027 $ 4 : 00000001 0000000a 00000002 00129026 $ 8 : ffffdfff 80101e00 00000002 00000000 $12 : 81c9c224 81c63e68 00000002 00000000 $16 : 805b1e00 00025800 81cb0880 00000002 $20 : 00000000 81c63e64 0000000a 81f10000 $24 : 81c63e64 81c63e60 $28 : 81c60000 81c63de0 00000001 81cc9d20 Hi : 00000000 Lo : 00000000 epc : 814a227c __free_pages_ok+0x144/0x3c0 ra : 81cc9d20 memblock_free_all+0x1d4/0x27c Status: 10000002 KERNEL EXL Cause : 00800410 (ExcCode 04) BadVA : 00129026 PrId : 00019300 (MIPS 24Kc) Modules linked in: Process swapper (pid: 0, threadinfo=3D(ptrval), task=3D(ptrval), tls=3D00= 000000) Stack : 81f10000 805a9e00 81c80000 00000000 00000002 814aa240 000003ff 00= 000400 00000000 81f10000 81c9c224 00003b1f 81c80000 81c63e60 81ca0000 81= c63e64 81f10000 0000000a 0000001f 81cc9d20 81f10000 81cc96d8 00000000 81= c80000 81c9c224 81c63e60 81c63e64 00000000 81f10000 00024000 00028000 00= 025c00 90000000 a0000000 00000002 00000017 00000000 00000000 81f10000 81= f10000 ... Call Trace: [<814a227c>] __free_pages_ok+0x144/0x3c0 [<81cc9d20>] memblock_free_all+0x1d4/0x27c [<81cc6764>] mm_core_init+0x100/0x138 [<81cb4ba4>] start_kernel+0x4a0/0x6e4 Code: 1080ffd5 02003825 2467ffff <8ce30000> 7c630500 1060ffd4 0000000= 0 8ce30000 7c630180 The crash happens because commit 6faea3422e3b ("arch, mm: streamline HIGHMEM freeing") too eagerly frees high memory to the page allocator even when HIGHMEM is disabled. Make sure that when CONFIG_HIGHMEM=3Dn the high memory is not released to t= he page allocator. Link: https://lore.kernel.org/all/20250323190647.GA1009914@ax162 Reported-by: Nathan Chancellor Fixes: 6faea3422e3b ("arch, mm: streamline HIGHMEM freeing") Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Nathan Chancellor --- mm/memblock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memblock.c b/mm/memblock.c index 64ae678cd1d1..d7ff8dfe5f88 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2166,6 +2166,9 @@ static unsigned long __init __free_memory_core(phys_a= ddr_t start, unsigned long start_pfn =3D PFN_UP(start); unsigned long end_pfn =3D PFN_DOWN(end); =20 + if (!IS_ENABLED(CONFIG_HIGHMEM) && end_pfn > max_low_pfn) + end_pfn =3D max_low_pfn; + if (start_pfn >=3D end_pfn) return 0; =20 --=20 2.47.2