switch several architectures NO_BOOTMEM
Subsystems (5)
cover switch several architectures NO_BOOTMEM
Hi,
These patches perform conversion to NO_BOOTMEM of hexagon, nios2, uml and unicore32. The architecture maintainers have acked the patches, but, since I've got no confirmation the patches are going through the arch tree I'd appreciate if the set would be applied to the -mm tree.
Mike Rapoport (7):
hexagon: switch to NO_BOOTMEM
of: ignore sub-page memory regions
nios2: use generic early_init_dt_add_memory_arch
nios2: switch to NO_BOOTMEM
um: setup_physmem: stop using global variables
um: switch to NO_BOOTMEM
unicore32: switch to NO_BOOTMEM
arch/hexagon/Kconfig | 3 +++ arch/hexagon/mm/init.c | 20 +++++++----------- arch/nios2/Kconfig | 3 +++ arch/nios2/kernel/prom.c | 17 --------------- arch/nios2/kernel/setup.c | 39 ++++++---------------------------- arch/um/Kconfig.common | 2 ++ arch/um/kernel/physmem.c | 22 +++++++++---------- arch/unicore32/Kconfig | 1 + arch/unicore32/mm/init.c | 54 +---------------------------------------------- drivers/of/fdt.c | 11 +++++----- 10 files changed, 41 insertions(+), 131 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/7 hexagon: switch to NO_BOOTMEM
This patch adds registration of the system memory with memblock, eliminates bootmem initialization and converts early memory reservations from bootmem to memblock.
--- arch/hexagon/Kconfig | 3 +++ arch/hexagon/mm/init.c | 20 ++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-)
arch/hexagon/Kconfig +3 -0
@@ -28,6 +28,9 @@ config HEXAGON select GENERIC_CLOCKEVENTS_BROADCAST select MODULES_USE_ELF_RELA select GENERIC_CPU_DEVICES + select HAVE_MEMBLOCK + select ARCH_DISCARD_MEMBLOCK + select NO_BOOTMEM ---help--- Qualcomm Hexagon is a processor architecture designed for high performance and low power across a wide variety of applications.
arch/hexagon/mm/init.c +8 -12
@@ -21,6 +21,7 @@#include <linux/init.h> #include <linux/mm.h> #include <linux/bootmem.h> +#include <linux/memblock.h> #include <asm/atomic.h> #include <linux/highmem.h> #include <asm/tlb.h>
@@ -176,7 +177,6 @@ size_t hexagon_coherent_pool_size = (size_t) (DMA_RESERVE << 22);void __init setup_arch_memory (void ) { -int bootmap_size;/* XXX Todo: this probably should be cleaned up */ u32 *segtable = (u32 *) &swapper_pg_dir[0 ];u32 *segtable_end;
@@ -195,18 +195,22 @@ void __init setup_arch_memory(void) bootmem_lastpg =PFN_DOWN ((bootmem_lastpg <<PAGE_SHIFT ) & ~((BIG_KERNEL_PAGE_SIZE ) -1 )); +memblock_add (PHYS_OFFSET , + (bootmem_lastpg -ARCH_PFN_OFFSET ) <<PAGE_SHIFT ); + +/* Reserve kernel text/data/bss */ +memblock_reserve (PHYS_OFFSET , + (bootmem_startpg -ARCH_PFN_OFFSET ) <<PAGE_SHIFT );/* * Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached) * memory allocation */ - max_low_pfn = bootmem_lastpg -PFN_DOWN (DMA_RESERVED_BYTES ); min_low_pfn =ARCH_PFN_OFFSET ; - bootmap_size =init_bootmem_node (NODE_DATA (0 ), bootmem_startpg, min_low_pfn, max_low_pfn); +memblock_reserve (PFN_PHYS (max_low_pfn),DMA_RESERVED_BYTES );printk (KERN_INFO "bootmem_startpg: 0x%08lx\n" , bootmem_startpg);printk (KERN_INFO "bootmem_lastpg: 0x%08lx\n" , bootmem_lastpg); -printk (KERN_INFO "bootmap_size: %d\n" , bootmap_size);printk (KERN_INFO "min_low_pfn: 0x%08lx\n" , min_low_pfn);printk (KERN_INFO "max_low_pfn: 0x%08lx\n" , max_low_pfn);
@@ -257,14 +261,6 @@ void __init setup_arch_memory(void)#endif /* -* Free all the memory that wasn't taken up by the bootmap, the DMA -* reserve, or kernel itself. -*/ -free_bootmem (PFN_PHYS (bootmem_startpg) + bootmap_size, -PFN_PHYS (bootmem_lastpg - bootmem_startpg) - bootmap_size - -DMA_RESERVED_BYTES ); - -/* * The bootmem allocator seemingly just lives to feed memory * to the paging system */
Signature · 1 line
2.7.4
PATCH 2/7 of: ignore sub-page memory regions
In reply to Mike RapoportMemory region size is rounded down to page boundary and with sub-page region it becomes 0 and there is no point to add an empty region. Moreover, when the base is less than PAGE_SIZE we get a bogus size as (base + size - 1) evaluates to -1.
The commit 8cccffc52694 ("of: check for size < 0 after rounding in early_init_dt_add_memory_arch") introduced a test for wrap around for the case when base is not page aligned, the same test can be used to ignore sub-page region sizes.
--- drivers/of/fdt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/of/fdt.c +6 -5
@@ -1134,12 +1134,13 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) {const u64 phys_offset =MIN_MEMBLOCK_ADDR ; +if (size <PAGE_SIZE - (base & ~PAGE_MASK )) { +pr_warn ("Ignoring memory block 0x%llx - 0x%llx\n" , + base, base + size); +return ; + } +if (!PAGE_ALIGNED (base)) { -if (size <PAGE_SIZE - (base & ~PAGE_MASK )) { -pr_warn ("Ignoring memory block 0x%llx - 0x%llx\n" , - base, base + size); -return ; - } size -=PAGE_SIZE - (base & ~PAGE_MASK ); base =PAGE_ALIGN (base); }
Signature · 1 line
2.7.4
PATCH 3/7 nios2: use generic early_init_dt_add_memory_arch
In reply to Mike RapoportAll we have to do is to enable memblock, the generic FDT code will take care of the rest.
--- arch/nios2/Kconfig | 1 + arch/nios2/kernel/prom.c | 10 ---------- arch/nios2/kernel/setup.c | 2 ++ 3 files changed, 3 insertions(+), 10 deletions(-)
arch/nios2/Kconfig +1 -0
@@ -19,6 +19,7 @@ config NIOS2 select SPARSE_IRQ select USB_ARCH_HAS_HCD if USB_SUPPORT select CPU_NO_EFFICIENT_FFS + select HAVE_MEMBLOCK config GENERIC_CSUM def_bool y
arch/nios2/kernel/prom.c +0 -10
@@ -32,16 +32,6 @@#include <asm/sections.h> -void __init early_init_dt_add_memory_arch (u64 base,u64 size) -{ -u64 kernel_start = (u64 )virt_to_phys (_text); - -if (!memory_size && - (kernel_start >= base) && (kernel_start < (base + size))) - memory_size = size; - -} -int __init early_init_dt_reserve_memory_arch (phys_addr_t base,phys_addr_t size,bool nomap) {
arch/nios2/kernel/setup.c +2 -0
@@ -17,6 +17,7 @@#include <linux/sched/task.h> #include <linux/console.h> #include <linux/bootmem.h> +#include <linux/memblock.h> #include <linux/initrd.h> #include <linux/of_fdt.h> #include <linux/screen_info.h>
@@ -147,6 +148,7 @@ void __init setup_arch(char **cmdline_p)console_verbose (); + memory_size =memblock_phys_mem_size (); memory_start =PAGE_ALIGN ((unsigned long )__pa (_end)); memory_end = (unsigned long )CONFIG_NIOS2_MEM_BASE + memory_size;
Signature · 1 line
2.7.4
PATCH 4/7 nios2: switch to NO_BOOTMEM
In reply to Mike RapoportRemove bootmem bitmap initialization and replace reserve_bootmem() with memblock_reserve().
--- arch/nios2/Kconfig | 2 ++ arch/nios2/kernel/prom.c | 7 ------- arch/nios2/kernel/setup.c | 37 +++++-------------------------------- 3 files changed, 7 insertions(+), 39 deletions(-)
arch/nios2/Kconfig +2 -0
@@ -20,6 +20,8 @@ config NIOS2 select USB_ARCH_HAS_HCD if USB_SUPPORT select CPU_NO_EFFICIENT_FFS select HAVE_MEMBLOCK + select ARCH_DISCARD_MEMBLOCK + select NO_BOOTMEM config GENERIC_CSUM def_bool y
arch/nios2/kernel/prom.c +0 -7
@@ -32,13 +32,6 @@#include <asm/sections.h> -int __init early_init_dt_reserve_memory_arch (phys_addr_t base,phys_addr_t size, -bool nomap) -{ -reserve_bootmem (base, size,BOOTMEM_DEFAULT ); -return 0 ; -} -void __init early_init_devtree (void *params) {__be32 *dtb = (u32 *)__dtb_start;
arch/nios2/kernel/setup.c +5 -32
@@ -144,10 +144,11 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,void __init setup_arch (char **cmdline_p) { -int bootmap_size; +int dram_start;console_verbose (); + dram_start =memblock_start_of_DRAM (); memory_size =memblock_phys_mem_size (); memory_start =PAGE_ALIGN ((unsigned long )__pa (_end)); memory_end = (unsigned long )CONFIG_NIOS2_MEM_BASE + memory_size;
@@ -165,39 +166,11 @@ void __init setup_arch(char **cmdline_p) max_low_pfn =PFN_DOWN (memory_end); max_mapnr = max_low_pfn; -/* -* give all the memory to the bootmap allocator, tell it to put the -* boot mem_map at the start of memory -*/ -pr_debug ("init_bootmem_node(?,%#lx, %#x, %#lx)\n" , - min_low_pfn,PFN_DOWN (PHYS_OFFSET ), max_low_pfn); - bootmap_size =init_bootmem_node (NODE_DATA (0 ), - min_low_pfn,PFN_DOWN (PHYS_OFFSET ), - max_low_pfn); - -/* -* free the usable memory, we have to make sure we do not free -* the bootmem bitmap so we then reserve it after freeing it :-) -*/ -pr_debug ("free_bootmem(%#lx, %#lx)\n" , - memory_start, memory_end - memory_start); -free_bootmem (memory_start, memory_end - memory_start); - -/* -* Reserve the bootmem bitmap itself as well. We do this in two -* steps (first step was init_bootmem()) because this catches -* the (very unlikely) case of us accidentally initializing the -* bootmem allocator with an invalid RAM area. -* -* Arguments are start, size -*/ -pr_debug ("reserve_bootmem(%#lx, %#x)\n" , memory_start, bootmap_size); -reserve_bootmem (memory_start, bootmap_size,BOOTMEM_DEFAULT ); - +memblock_reserve (dram_start, memory_start - dram_start);#ifdef CONFIG_BLK_DEV_INITRD if (initrd_start) { -reserve_bootmem (virt_to_phys ((void *)initrd_start), - initrd_end - initrd_start,BOOTMEM_DEFAULT ); +memblock_reserve (virt_to_phys ((void *)initrd_start), + initrd_end - initrd_start); }#endif /* CONFIG_BLK_DEV_INITRD */
Signature · 1 line
2.7.4
PATCH 5/7 um: setup_physmem: stop using global variables
In reply to Mike RapoportThe setup_physmem() function receives uml_physmem and uml_reserved as parameters and still used these global variables. Replace such usage with local variables.
--- arch/um/kernel/physmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/um/kernel/physmem.c +3 -3
@@ -86,7 +86,7 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,long map_size;int err; - offset = uml_reserved - uml_physmem; + offset = reserve_end - start; map_size = len - offset;if (map_size <=0 ) { os_warn("Too few physical memory! Needed=%lu, given=%lu\n",
@@ -96,12 +96,12 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, physmem_fd =create_mem_file (len + highmem); - err =os_map_memory ((void *) uml_reserved, physmem_fd, offset, + err =os_map_memory ((void *) reserve_end, physmem_fd, offset, map_size,1 ,1 ,1 );if (err <0 ) {os_warn ("setup_physmem - mapping %ld bytes of memory at 0x%p " "failed - errno = %d\n" , map_size, - (void *) uml_reserved, err); + (void *) reserve_end, err);exit (1 ); }
Signature · 1 line
2.7.4
PATCH 6/7 um: switch to NO_BOOTMEM
In reply to Mike RapoportReplace bootmem initialization with memblock_add and memblock_reserve calls and explicit initialization of {min,max}_low_pfn.
--- arch/um/Kconfig.common | 2 ++ arch/um/kernel/physmem.c | 20 +++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-)
arch/um/Kconfig.common +2 -0
@@ -8,6 +8,8 @@ config UML select HAVE_UID16 select HAVE_FUTEX_CMPXCHG if FUTEX select HAVE_DEBUG_KMEMLEAK + select HAVE_MEMBLOCK + select NO_BOOTMEM select GENERIC_IRQ_SHOW select GENERIC_CPU_DEVICES select GENERIC_CLOCKEVENTS
arch/um/kernel/physmem.c +9 -11
@@ -5,6 +5,7 @@#include <linux/module.h> #include <linux/bootmem.h> +#include <linux/memblock.h> #include <linux/mm.h> #include <linux/pfn.h> #include <asm/page.h>
@@ -80,23 +81,18 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, unsigned long len, unsigned long long highmem) {unsigned long reserve = reserve_end - start; -unsigned long pfn =PFN_UP (__pa (reserve_end)); -unsigned long delta = (len - reserve) >>PAGE_SHIFT ; -unsigned long offset, bootmap_size; -long map_size; +long map_size = len - reserve;int err; - offset = reserve_end - start; - map_size = len - offset;if (map_size <=0 ) {os_warn ("Too few physical memory! Needed=%lu, given=%lu\n" , - offset, len); + reserve, len);exit (1 ); } physmem_fd =create_mem_file (len + highmem); - err =os_map_memory ((void *) reserve_end, physmem_fd, offset, + err =os_map_memory ((void *) reserve_end, physmem_fd, reserve, map_size,1 ,1 ,1 );if (err <0 ) { os_warn("setup_physmem - mapping %ld bytes of memory at 0x%p "
@@ -113,9 +109,11 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,os_write_file (physmem_fd, __syscall_stub_start,PAGE_SIZE );os_fsync_file (physmem_fd); - bootmap_size =init_bootmem (pfn, pfn + delta); -free_bootmem (__pa (reserve_end) + bootmap_size, - len - bootmap_size - reserve); +memblock_add (__pa (start), len + highmem); +memblock_reserve (__pa (start), reserve); + + min_low_pfn =PFN_UP (__pa (reserve_end)); + max_low_pfn = min_low_pfn + (map_size >>PAGE_SHIFT ); }int phys_mapping (unsigned long phys,unsigned long long *offset_out)
Signature · 1 line
2.7.4
PATCH 7/7 unicore32: switch to NO_BOOTMEM
In reply to Mike RapoportThe unicore32 already supports memblock and uses it for some early memory reservations, e.g initrd and the page tables.
At some point unicore32 allocates the bootmem bitmap from the memblock and then hands over the memory reservations from memblock to bootmem.
This patch removes the bootmem initialization and leaves memblock as the only boot time memory manager for unicore32.
--- arch/unicore32/Kconfig | 1 + arch/unicore32/mm/init.c | 54 +----------------------------------------------- 2 files changed, 2 insertions(+), 53 deletions(-)
arch/unicore32/Kconfig +1 -0
@@ -5,6 +5,7 @@ config UNICORE32 select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select HAVE_MEMBLOCK + select NO_BOOTMEM select HAVE_GENERIC_DMA_COHERENT select HAVE_KERNEL_GZIP select HAVE_KERNEL_BZIP2
arch/unicore32/mm/init.c +1 -53
66 lines not on this page · raw message
Signature · 1 line
2.7.4
Any updates on this?
Quoted 32 lines · Mike Rapoport
Hi,
These patches perform conversion to
NO_BOOTMEMof hexagon, nios2, uml and unicore32. The architecture maintainers have acked the patches, but, since I've got no confirmation the patches are going through the arch tree I'd appreciate if the set would be applied to the -mm tree.Mike Rapoport (7):
hexagon: switch toNO_BOOTMEM
of: ignore sub-page memory regions
nios2: use genericearly_init_dt_add_memory_arch
nios2: switch toNO_BOOTMEM
um:setup_physmem: stop using global variables
um: switch toNO_BOOTMEM
unicore32: switch toNO_BOOTMEMarch/hexagon/Kconfig | 3 +++ arch/hexagon/mm/init.c | 20 +++++++----------- arch/nios2/Kconfig | 3 +++ arch/nios2/kernel/prom.c | 17 --------------- arch/nios2/kernel/setup.c | 39 ++++++---------------------------- arch/um/Kconfig.common | 2 ++ arch/um/kernel/physmem.c | 22 +++++++++---------- arch/unicore32/Kconfig | 1 + arch/unicore32/mm/init.c | 54 +---------------------------------------------- drivers/of/fdt.c | 11 +++++----- 10 files changed, 41 insertions(+), 131 deletions(-)Signature · 1 line
2.7.4
Signature · 2 lines
Sincerely yours, Mike.