Patch "mips: Fix max_mapnr being uninitialized on early stages" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    mips: Fix max_mapnr being uninitialized on early stages

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     mips-fix-max_mapnr-being-uninitialized-on-early-stag.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 301cb6150a66b37ec3293d30460880681a8e8c93
Author: Serge Semin <fancer.lancer@xxxxxxxxx>
Date:   Sat Dec 2 14:14:20 2023 +0300

    mips: Fix max_mapnr being uninitialized on early stages
    
    [ Upstream commit e1a9ae45736989c972a8d1c151bc390678ae6205 ]
    
    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@xxxxxxxxxxxxxxx
    Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
    Signed-off-by: Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 07e84a774938..32e7b869a291 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -421,7 +421,12 @@ void __init paging_init(void)
 		       (highend_pfn - max_low_pfn) << (PAGE_SHIFT - 10));
 		max_zone_pfns[ZONE_HIGHMEM] = max_low_pfn;
 	}
+
+	max_mapnr = highend_pfn ? highend_pfn : max_low_pfn;
+#else
+	max_mapnr = max_low_pfn;
 #endif
+	high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
 
 	free_area_init(max_zone_pfns);
 }
@@ -457,16 +462,6 @@ void __init mem_init(void)
 	 */
 	BUILD_BUG_ON(IS_ENABLED(CONFIG_32BIT) && (_PFN_SHIFT > PAGE_SHIFT));
 
-#ifdef CONFIG_HIGHMEM
-#ifdef CONFIG_DISCONTIGMEM
-#error "CONFIG_HIGHMEM and CONFIG_DISCONTIGMEM dont work together yet"
-#endif
-	max_mapnr = highend_pfn ? highend_pfn : max_low_pfn;
-#else
-	max_mapnr = max_low_pfn;
-#endif
-	high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
-
 	maar_init();
 	memblock_free_all();
 	setup_zero_pages();	/* Setup zeroed pages.  */




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux