aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel
diff options
context:
space:
mode:
authorMike Rapoport <rppt@linux.vnet.ibm.com>2018-09-10 05:23:18 -0400
committerPaul Burton <paul.burton@mips.com>2018-09-14 15:37:28 -0400
commitbcec54bf3118a26422cd83675cb461ef4dea81ef (patch)
tree8cd7e85d79392d0c3379086e2ab6ace7fd839a54 /arch/mips/kernel
parent0eb1cfffd5433d8dce3e4163a5cd9accc6000856 (diff)
mips: switch to NO_BOOTMEM
MIPS already has memblock support and all the memory is already registered with it. This patch replaces bootmem memory reservations with memblock ones and removes the bootmem initialization. Since memblock allocates memory in top-down mode, we ensure that memblock limit is max_low_pfn to prevent allocations from the high memory. To have the exceptions base in the lower 512M of the physical memory, its allocation in arch/mips/kernel/traps.c::traps_init() is using bottom-up mode. Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Paul Burton <paul.burton@mips.com> Patchwork: https://patchwork.linux-mips.org/patch/20560/ Cc: Serge Semin <fancer.lancer@gmail.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: James Hogan <jhogan@kernel.org> Cc: Huacai Chen <chenhc@lemote.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: linux-mips@linux-mips.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org
Diffstat (limited to 'arch/mips/kernel')
-rw-r--r--arch/mips/kernel/setup.c99
-rw-r--r--arch/mips/kernel/traps.c3
2 files changed, 26 insertions, 76 deletions
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 32fc11d72ad3..2fde53ebb3af 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -333,7 +333,7 @@ static void __init finalize_initrd(void)
333 333
334 maybe_bswap_initrd(); 334 maybe_bswap_initrd();
335 335
336 reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT); 336 memblock_reserve(__pa(initrd_start), size);
337 initrd_below_start_ok = 1; 337 initrd_below_start_ok = 1;
338 338
339 pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n", 339 pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
@@ -370,20 +370,10 @@ static void __init bootmem_init(void)
370 370
371#else /* !CONFIG_SGI_IP27 */ 371#else /* !CONFIG_SGI_IP27 */
372 372
373static unsigned long __init bootmap_bytes(unsigned long pages)
374{
375 unsigned long bytes = DIV_ROUND_UP(pages, 8);
376
377 return ALIGN(bytes, sizeof(long));
378}
379
380static void __init bootmem_init(void) 373static void __init bootmem_init(void)
381{ 374{
382 unsigned long reserved_end; 375 unsigned long reserved_end;
383 unsigned long mapstart = ~0UL;
384 unsigned long bootmap_size;
385 phys_addr_t ramstart = PHYS_ADDR_MAX; 376 phys_addr_t ramstart = PHYS_ADDR_MAX;
386 bool bootmap_valid = false;
387 int i; 377 int i;
388 378
389 /* 379 /*
@@ -395,6 +385,8 @@ static void __init bootmem_init(void)
395 init_initrd(); 385 init_initrd();
396 reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end)); 386 reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
397 387
388 memblock_reserve(PHYS_OFFSET, reserved_end << PAGE_SHIFT);
389
398 /* 390 /*
399 * max_low_pfn is not a number of pages. The number of pages 391 * max_low_pfn is not a number of pages. The number of pages
400 * of the system is given by 'max_low_pfn - min_low_pfn'. 392 * of the system is given by 'max_low_pfn - min_low_pfn'.
@@ -442,9 +434,6 @@ static void __init bootmem_init(void)
442 if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end))) 434 if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
443 continue; 435 continue;
444#endif 436#endif
445 if (start >= mapstart)
446 continue;
447 mapstart = max(reserved_end, start);
448 } 437 }
449 438
450 if (min_low_pfn >= max_low_pfn) 439 if (min_low_pfn >= max_low_pfn)
@@ -456,9 +445,11 @@ static void __init bootmem_init(void)
456 /* 445 /*
457 * Reserve any memory between the start of RAM and PHYS_OFFSET 446 * Reserve any memory between the start of RAM and PHYS_OFFSET
458 */ 447 */
459 if (ramstart > PHYS_OFFSET) 448 if (ramstart > PHYS_OFFSET) {
460 add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET, 449 add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
461 BOOT_MEM_RESERVED); 450 BOOT_MEM_RESERVED);
451 memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
452 }
462 453
463 if (min_low_pfn > ARCH_PFN_OFFSET) { 454 if (min_low_pfn > ARCH_PFN_OFFSET) {
464 pr_info("Wasting %lu bytes for tracking %lu unused pages\n", 455 pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
@@ -483,52 +474,6 @@ static void __init bootmem_init(void)
483 max_low_pfn = PFN_DOWN(HIGHMEM_START); 474 max_low_pfn = PFN_DOWN(HIGHMEM_START);
484 } 475 }
485 476
486#ifdef CONFIG_BLK_DEV_INITRD
487 /*
488 * mapstart should be after initrd_end
489 */
490 if (initrd_end)
491 mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
492#endif
493
494 /*
495 * check that mapstart doesn't overlap with any of
496 * memory regions that have been reserved through eg. DTB
497 */
498 bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
499
500 bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
501 bootmap_size);
502 for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
503 unsigned long mapstart_addr;
504
505 switch (boot_mem_map.map[i].type) {
506 case BOOT_MEM_RESERVED:
507 mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
508 boot_mem_map.map[i].size);
509 if (PHYS_PFN(mapstart_addr) < mapstart)
510 break;
511
512 bootmap_valid = memory_region_available(mapstart_addr,
513 bootmap_size);
514 if (bootmap_valid)
515 mapstart = PHYS_PFN(mapstart_addr);
516 break;
517 default:
518 break;
519 }
520 }
521
522 if (!bootmap_valid)
523 panic("No memory area to place a bootmap bitmap");
524
525 /*
526 * Initialize the boot-time allocator with low memory only.
527 */
528 if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
529 min_low_pfn, max_low_pfn))
530 panic("Unexpected memory size required for bootmap");
531
532 for (i = 0; i < boot_mem_map.nr_map; i++) { 477 for (i = 0; i < boot_mem_map.nr_map; i++) {
533 unsigned long start, end; 478 unsigned long start, end;
534 479
@@ -577,9 +522,9 @@ static void __init bootmem_init(void)
577 default: 522 default:
578 /* Not usable memory */ 523 /* Not usable memory */
579 if (start > min_low_pfn && end < max_low_pfn) 524 if (start > min_low_pfn && end < max_low_pfn)
580 reserve_bootmem(boot_mem_map.map[i].addr, 525 memblock_reserve(boot_mem_map.map[i].addr,
581 boot_mem_map.map[i].size, 526 boot_mem_map.map[i].size);
582 BOOTMEM_DEFAULT); 527
583 continue; 528 continue;
584 } 529 }
585 530
@@ -602,15 +547,9 @@ static void __init bootmem_init(void)
602 size = end - start; 547 size = end - start;
603 548
604 /* Register lowmem ranges */ 549 /* Register lowmem ranges */
605 free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
606 memory_present(0, start, end); 550 memory_present(0, start, end);
607 } 551 }
608 552
609 /*
610 * Reserve the bootmap memory.
611 */
612 reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
613
614#ifdef CONFIG_RELOCATABLE 553#ifdef CONFIG_RELOCATABLE
615 /* 554 /*
616 * The kernel reserves all memory below its _end symbol as bootmem, 555 * The kernel reserves all memory below its _end symbol as bootmem,
@@ -907,21 +846,29 @@ static void __init arch_mem_init(char **cmdline_p)
907 early_init_fdt_scan_reserved_mem(); 846 early_init_fdt_scan_reserved_mem();
908 847
909 bootmem_init(); 848 bootmem_init();
849
850 /*
851 * Prevent memblock from allocating high memory.
852 * This cannot be done before max_low_pfn is detected, so up
853 * to this point is possible to only reserve physical memory
854 * with memblock_reserve; memblock_virt_alloc* can be used
855 * only after this point
856 */
857 memblock_set_current_limit(PFN_PHYS(max_low_pfn));
858
910#ifdef CONFIG_PROC_VMCORE 859#ifdef CONFIG_PROC_VMCORE
911 if (setup_elfcorehdr && setup_elfcorehdr_size) { 860 if (setup_elfcorehdr && setup_elfcorehdr_size) {
912 printk(KERN_INFO "kdump reserved memory at %lx-%lx\n", 861 printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
913 setup_elfcorehdr, setup_elfcorehdr_size); 862 setup_elfcorehdr, setup_elfcorehdr_size);
914 reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size, 863 memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
915 BOOTMEM_DEFAULT);
916 } 864 }
917#endif 865#endif
918 866
919 mips_parse_crashkernel(); 867 mips_parse_crashkernel();
920#ifdef CONFIG_KEXEC 868#ifdef CONFIG_KEXEC
921 if (crashk_res.start != crashk_res.end) 869 if (crashk_res.start != crashk_res.end)
922 reserve_bootmem(crashk_res.start, 870 memblock_reserve(crashk_res.start,
923 crashk_res.end - crashk_res.start + 1, 871 crashk_res.end - crashk_res.start + 1);
924 BOOTMEM_DEFAULT);
925#endif 872#endif
926 device_tree_init(); 873 device_tree_init();
927 sparse_init(); 874 sparse_init();
@@ -931,7 +878,7 @@ static void __init arch_mem_init(char **cmdline_p)
931 /* Tell bootmem about cma reserved memblock section */ 878 /* Tell bootmem about cma reserved memblock section */
932 for_each_memblock(reserved, reg) 879 for_each_memblock(reserved, reg)
933 if (reg->size != 0) 880 if (reg->size != 0)
934 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT); 881 memblock_reserve(reg->base, reg->size);
935 882
936 reserve_bootmem_region(__pa_symbol(&__nosave_begin), 883 reserve_bootmem_region(__pa_symbol(&__nosave_begin),
937 __pa_symbol(&__nosave_end)); /* Reserve for hibernation */ 884 __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 576aeef89423..5feef28deac8 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -29,6 +29,7 @@
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/kallsyms.h> 30#include <linux/kallsyms.h>
31#include <linux/bootmem.h> 31#include <linux/bootmem.h>
32#include <linux/memblock.h>
32#include <linux/interrupt.h> 33#include <linux/interrupt.h>
33#include <linux/ptrace.h> 34#include <linux/ptrace.h>
34#include <linux/kgdb.h> 35#include <linux/kgdb.h>
@@ -2260,8 +2261,10 @@ void __init trap_init(void)
2260 unsigned long size = 0x200 + VECTORSPACING*64; 2261 unsigned long size = 0x200 + VECTORSPACING*64;
2261 phys_addr_t ebase_pa; 2262 phys_addr_t ebase_pa;
2262 2263
2264 memblock_set_bottom_up(true);
2263 ebase = (unsigned long) 2265 ebase = (unsigned long)
2264 __alloc_bootmem(size, 1 << fls(size), 0); 2266 __alloc_bootmem(size, 1 << fls(size), 0);
2267 memblock_set_bottom_up(false);
2265 2268
2266 /* 2269 /*
2267 * Try to ensure ebase resides in KSeg0 if possible. 2270 * Try to ensure ebase resides in KSeg0 if possible.