linux-stable/arch/mips/mm
Serge Semin 4a5a77c92b mips: Fix max_mapnr being uninitialized on early stages
commit e1a9ae4573 upstream.

max_mapnr variable is utilized in the pfn_valid() method in order to
determine the upper PFN space boundary. Having it uninitialized
effectively makes any PFN passed to that method invalid. That in its turn
causes the kernel mm-subsystem occasion malfunctions even after the
max_mapnr variable is actually properly updated. For instance,
pfn_valid() is called in the init_unavailable_range() method in the
framework of the calls-chain on MIPS:
setup_arch()
+-> paging_init()
    +-> free_area_init()
        +-> memmap_init()
            +-> memmap_init_zone_range()
                +-> init_unavailable_range()

Since pfn_valid() always returns "false" value before max_mapnr is
initialized in the mem_init() method, any flatmem page-holes will be left
in the poisoned/uninitialized state including the IO-memory pages. Thus
any further attempts to map/remap the IO-memory by using MMU may fail.
In particular it happened in my case on attempt to map the SRAM region.
The kernel bootup procedure just crashed on the unhandled unaligned access
bug raised in the __update_cache() method:

> Unhandled kernel unaligned access[#1]:
> CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.7.0-rc1-XXX-dirty #2056
> ...
> Call Trace:
> [<8011ef9c>] __update_cache+0x88/0x1bc
> [<80385944>] ioremap_page_range+0x110/0x2a4
> [<80126948>] ioremap_prot+0x17c/0x1f4
> [<80711b80>] __devm_ioremap+0x8c/0x120
> [<80711e0c>] __devm_ioremap_resource+0xf4/0x218
> [<808bf244>] sram_probe+0x4f4/0x930
> [<80889d20>] platform_probe+0x68/0xec
> ...

Let's fix the problem by initializing the max_mapnr variable as soon as
the required data is available. In particular it can be done right in the
paging_init() method before free_area_init() is called since all the PFN
zone boundaries have already been calculated by that time.

Cc: stable@vger.kernel.org
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-31 16:18:52 -08:00
..
c-octeon.c MIPS: c-octeon: Provide alternative SMP cache flush function 2023-04-05 09:45:09 +02:00
c-r3k.c MIPS: mm: Remove local_cache_flush_page 2023-04-05 10:08:53 +02:00
c-r4k.c mips: implement the new page table range API 2023-08-24 16:20:22 -07:00
cache.c mips: use nth_page() in place of direct struct page manipulation 2023-11-28 17:20:05 +00:00
cerr-sb1.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
cex-gen.S
cex-oct.S
cex-sb1.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
context.c MIPS: mm: Use the bitmap API to allocate bitmaps 2022-07-11 10:28:12 +02:00
dma-noncoherent.c MIPS: mm: XBurst CPU requires sync after DMA 2021-06-01 11:44:46 +02:00
extable.c
fault.c mips/mm: Convert to using lock_mm_and_find_vma() 2023-06-24 14:12:58 -07:00
highmem.c mips/mm/highmem: Switch to generic kmap atomic 2020-11-06 23:14:56 +01:00
hugetlbpage.c hugetlb: pass vma into huge_pte_alloc() and huge_pmd_share() 2021-05-05 11:27:20 -07:00
init.c mips: Fix max_mapnr being uninitialized on early stages 2024-01-31 16:18:52 -08:00
ioremap.c MIPS: use ioremap_page_range 2020-04-19 16:13:18 +02:00
ioremap64.c MIPS: move ioremap_prot und iounmap out of line 2020-04-19 16:12:31 +02:00
maccess.c MIPS: uaccess: Added __get/__put_kernel_nofault 2021-04-06 14:36:56 +02:00
Makefile MIPS: Remove TX39XX support 2022-03-01 10:07:22 +01:00
mmap.c mips: use generic mmap top-down layout and brk randomization 2019-09-24 15:54:12 -07:00
page-funcs.S mips: replace #include <asm/export.h> with #include <linux/export.h> 2023-08-15 10:22:23 +02:00
page.c MIPS: remove asm/war.h 2022-02-22 09:35:49 +01:00
pgtable-32.c mips: implement the new page table range API 2023-08-24 16:20:22 -07:00
pgtable-64.c mips: implement the new page table range API 2023-08-24 16:20:22 -07:00
pgtable.c mips: convert various functions to use ptdescs 2023-08-21 13:37:56 -07:00
physaddr.c MIPS: Fixed __debug_virt_addr_valid() 2022-07-15 14:22:51 +02:00
sc-debugfs.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sc-ip22.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
sc-mips.c mips: fix Section mismatch in reference 2020-12-14 16:39:42 +01:00
sc-r5k.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
sc-rm7k.c
tlb-funcs.S mips: replace #include <asm/export.h> with #include <linux/export.h> 2023-08-15 10:22:23 +02:00
tlb-r3k.c MIPS: Remove TX39XX support 2022-03-01 10:07:22 +01:00
tlb-r4k.c mips: add pte_unmap() to balance pte_offset_map() 2023-06-19 16:19:07 -07:00
tlbex-fault.S
tlbex.c mips: implement the new page table range API 2023-08-24 16:20:22 -07:00
uasm-micromips.c mips: bpf: implement jitting of BPF_ALU | BPF_ARSH | BPF_X 2018-12-07 13:30:48 -08:00
uasm-mips.c mips, uasm: Enable muhu opcode for MIPS R6 2021-10-06 12:28:02 -07:00
uasm.c mips, uasm: Enable muhu opcode for MIPS R6 2021-10-06 12:28:02 -07:00