FLATMEM: allow memory to start at pfn != 0
PATCH 1/2 Setup min_low_pfn/max_low_pfn correctly
In reply to Franck Bui-HuuFrom: Franck Bui-Huu <[email protected]>
This patch makes a better usage of these two globals. 'min_low_pfn' is now correctly setup for all configs, which allow us to rely on it in boot memory code init.
--- arch/mips/kernel/setup.c | 29 ++++++++++++++++++++--------- arch/mips/mm/init.c | 23 +++++++++++------------ include/asm-mips/dma.h | 1 + 3 files changed, 32 insertions(+), 21 deletions(-)
arch/mips/kernel/setup.c +20 -9
@@ -271,8 +271,7 @@ static void __init bootmem_init(void)static void __init bootmem_init (void ) {unsigned long reserved_end; -unsigned long highest =0 ; -unsigned long mapstart =-1UL ; +unsigned long mapstart = ~0UL ;unsigned long bootmap_size;int i;
@@ -284,6 +283,13 @@ static void __init bootmem_init(void) reserved_end =max (init_initrd (),PFN_UP (__pa_symbol (&_end)));/* +* max_low_pfn is not a number of pages. The number of pages +* of the system is given by 'max_low_pfn - min_low_pfn'. +*/ + min_low_pfn = ~0UL ; + max_low_pfn =0 ; + +/* * Find the highest page frame number we have available. */ for (i =0 ; i < boot_mem_map.nr_map; i++) {
@@ -296,8 +302,10 @@ static void __init bootmem_init(void) end =PFN_DOWN (boot_mem_map.map[i].addr + boot_mem_map.map[i].size); -if (end > highest) - highest = end; +if (end > max_low_pfn) + max_low_pfn = end; +if (start < min_low_pfn) + min_low_pfn = start;if (end <= reserved_end)continue ;if (start >= mapstart)
@@ -305,22 +313,25 @@ static void __init bootmem_init(void) mapstart =max (reserved_end, start); } +if (min_low_pfn >= max_low_pfn) +panic ("Incorrect memory mapping !!!" ); +/* * Determine low and high memory ranges */ -if (highest >PFN_DOWN (HIGHMEM_START )) { +if (max_low_pfn >PFN_DOWN (HIGHMEM_START )) {#ifdef CONFIG_HIGHMEM highstart_pfn =PFN_DOWN (HIGHMEM_START ); - highend_pfn = highest; + highend_pfn = max_low_pfn;#endif - highest =PFN_DOWN (HIGHMEM_START ); + max_low_pfn =PFN_DOWN (HIGHMEM_START ); }/* * Initialize the boot-time allocator with low memory only. */ - bootmap_size =init_bootmem (mapstart, highest); - + bootmap_size =init_bootmem_node (NODE_DATA (0 ), mapstart, + min_low_pfn, max_low_pfn);/* * Register fully available low RAM pages with the bootmem allocator. */
arch/mips/mm/init.c +11 -12
@@ -341,7 +341,6 @@ static int __init page_is_ram(unsigned long pagenr)void __init paging_init (void ) {unsigned long zones_size[MAX_NR_ZONES ] = {0 , }; -unsigned long max_dma, low;#ifndef CONFIG_FLATMEM unsigned long zholes_size[MAX_NR_ZONES ] = {0 , };unsigned long i, j, pfn;
@@ -354,19 +353,19 @@ void __init paging_init(void)#endif kmap_coherent_init (); - max_dma =virt_to_phys ((char *)MAX_DMA_ADDRESS ) >>PAGE_SHIFT ; - low = max_low_pfn; -#ifdef CONFIG_ISA -if (low < max_dma) - zones_size[ZONE_DMA ] = low; -else { - zones_size[ZONE_DMA ] = max_dma; - zones_size[ZONE_NORMAL ] = low - max_dma; - } -#else - zones_size[ZONE_DMA ] = low; +if (max_low_pfn >=MAX_DMA_PFN ) +if (min_low_pfn >=MAX_DMA_PFN ) { + zones_size[ZONE_DMA ] =0 ; + zones_size[ZONE_NORMAL ] = max_low_pfn - min_low_pfn; + }else { + zones_size[ZONE_DMA ] =MAX_DMA_PFN - min_low_pfn; + zones_size[ZONE_NORMAL ] = max_low_pfn -MAX_DMA_PFN ; + } + else#endif + zones_size[ZONE_DMA ] = max_low_pfn - min_low_pfn; +#ifdef CONFIG_HIGHMEM zones_size[ZONE_HIGHMEM ] = highend_pfn - highstart_pfn;
include/asm-mips/dma.h +1 -0
@@ -91,6 +91,7 @@#else #define MAX_DMA_ADDRESS (PAGE_OFFSET + 0x01000000)#endif +#define MAX_DMA_PFN PFN_DOWN(virt_to_phys((void *)MAX_DMA_ADDRESS))/* 8237 DMA controllers */ #define IO_DMA1_BASE 0x00/* 8 bit slave DMA, channels 0..3 */
Signature · 1 line
1.4.4.3.ge6d4
PATCH 2/2 FLATMEM: introduce PHYS_OFFSET.
In reply to Franck Bui-HuuFrom: Franck Bui-Huu <[email protected]>
The old code was assuming that min_low_pfn was always 0. This means that platforms having a big hole at their memory start paid the price of wasting some memory for the allocation of unused entries in mem_map[].
This patch prevents this waste.
It introduces PHYS_OFFSET define which is the start of the physical memory and uses it wherever needed. Specially when converting physical/virtual addresses into virtual/physical ones.
Currently all platforms defines PHYS_OFFSET to 0.
--- arch/mips/kernel/setup.c | 3 +++ include/asm-mips/io.h | 4 ++-- include/asm-mips/page.h | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-)
arch/mips/kernel/setup.c +3 -0
@@ -315,6 +315,9 @@ static void __init bootmem_init(void)if (min_low_pfn >= max_low_pfn)panic ("Incorrect memory mapping !!!" ); +if (min_low_pfn !=ARCH_PFN_OFFSET ) +panic ("PHYS_OFFSET(%lx) and your mem start(%lx) don't match" , +PHYS_OFFSET ,PFN_PHYS (min_low_pfn));/* * Determine low and high memory ranges
include/asm-mips/io.h +2 -2
@@ -115,7 +115,7 @@ static inline void set_io_port_base(unsigned long base)*/ static inline unsigned long virt_to_phys (volatile const void *address) { -return (unsigned long )address -PAGE_OFFSET ; +return (unsigned long )address -PAGE_OFFSET +PHYS_OFFSET ; }/*
@@ -132,7 +132,7 @@ static inline unsigned long virt_to_phys(volatile const void *address)*/ static inline void *phys_to_virt (unsigned long address) { -return (void *)(address +PAGE_OFFSET ); +return (void *)(address +PAGE_OFFSET -PHYS_OFFSET ); }/*
include/asm-mips/page.h +21 -4
@@ -34,6 +34,20 @@#ifndef __ASSEMBLY__ +/* +* This gives the physical RAM offset. +*/ +#ifndef PHYS_OFFSET +#define PHYS_OFFSET 0UL +#endif + +/* +* It's normally defined only for FLATMEM config but it's +* used in our early mem init code for all memory models. +* So always define it. +*/ +#define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET) +#include <linux/pfn.h> #include <asm/io.h>
@@ -132,20 +146,23 @@ typedef struct { unsigned long pgprot; } pgprot_t;/* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN (addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK) +/* +* __pa()/__va() should be used only during mem init. +*/ #if defined(CONFIG_64BIT ) && !defined(CONFIG_BUILD_ELF64 )#define __pa_page_offset (x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)#else #define __pa_page_offset (x) PAGE_OFFSET#endif -#define __pa (x) ((unsigned long)(x) - __pa_page_offset(x)) -#define __pa_symbol (x) __pa(RELOC_HIDE((unsigned long)(x),0)) -#define __va (x) ((void *)((unsigned long)(x) + PAGE_OFFSET)) +#define __pa (x) ((unsigned long)(x) - __pa_page_offset(x) + PHYS_OFFSET) +#define __va (x) ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET)) +#define __pa_symbol (x) __pa(RELOC_HIDE((unsigned long)(x),0))#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)#ifdef CONFIG_FLATMEM -#define pfn_valid (pfn) ((pfn) < max_mapnr) +#define pfn_valid (pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)#elif defined(CONFIG_SPARSEMEM )
Signature · 1 line
1.4.4.3.ge6d4
cover FLATMEM: allow memory to start at pfn != 0
Ralf,
I'm resending this patchset with almost no change. The only one made is in patch #1 in paging_init() when CONFIG_ISA is set.
I know that you encountered some issues when using malta config. It seems that this platform uses HIGHMEM but no ISA config. So this new patchset shouldn't fix anything for you, but I need more info to debug it.
Could you give a try to patch #1 _only_ and give me the console output ? That would be really nice.
Thanks
Franck
Re: [PATCH 1/2] Setup min_low_pfn/max_low_pfn correctly
In reply to a message not in the archiveQuoted 6 lines · Ralf Baechle
Quoted 3 lines · Franck Bui-Huu
This patch makes a better usage of these two globals. '
min_low_pfn' is now correctly setup for all configs, which allow us to rely on it in boot memory code init.
[snip]
Quoted 8 lines
Call Trace: [<80109484>] dump_stack+0x8/0x34 [<80159fbc>] bad_page+0x68/0xa8 [<8015a804>] free_hot_cold_page+0x3a4/0x3b4 [<80414150>] free_all_bootmem_core+0x150/0x258 [<8040aefc>] mem_init+0x40/0x1c0 [<80400940>] start_kernel+0x2b4/0x3c8
[snip]
Quoted 8 lines
From a working kernel:
Determined physical RAM map:
memory: 00001000 @ 00000000 (reserved)
memory:000ef000@ 00001000 (ROM data)
memory:0035a000@000f0000(reserved)
memory:03bb6000@0044a000(usable)
Quoted 4 lines
So it's basically 64MB starting at physical 0.
Oh and Malta does not use
CONFIG_HIGHMEM.
Yeah I just noticed that, Malta supports highmem but actually doesn't use it.
Regarding to your mapping, usable ram starts at 0x44a000. So min_low_pfn is now set to the corresponding pfn and the bootmem alloc assumes it's the begining of your memory. This is done by bootmem_init():
bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
min_low_pfn, max_low_pfn);However, old code always assumed that the begining of the memory was
0. That was done by:
bootmap_size = init_bootmem(mapstart, highest);
After a while paging_init() is called which in turn calls:
free_area_init(zones_size);
which expands to:
free_area_init_node(0, NODE_DATA(0), zones_size, __pa(PAGE_OFFSET) >> PAGE_SHIFT, NULL);
In your case "__pa(PAGE_OFFSET) >> PAGE_SHIFT" results in 0 since you haven't applied patch #2 and setup PHYS_OFFSET. So now, we're assuming that the start of physical mem is 0 and I think it's wrong since we previously assumed a different value.
Could you try to apply patch #2 on top of patch #1 and give it a try ? I expect your kernel to panic in a different way. This time you should be shooted by the following sanity check added by patch #2:
if (min_low_pfn != ARCH_PFN_OFFSET)
panic("PHYS_OFFSET(%lx) and your mem start(%lx) don't match",
PHYS_OFFSET, PFN_PHYS(min_low_pfn));If so, could you give another try with PHYS_OFFSET defined as follow:
#define PHYS_OFFSET 0x44a000
BTW mem_map[] size should be 32Kb smaller.
thanks,
Franck