Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e63075a3 authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt
Browse files

memblock: Introduce default allocation limit and use it to replace explicit ones



This introduce memblock.current_limit which is used to limit allocations
from memblock_alloc() or memblock_alloc_base(..., MEMBLOCK_ALLOC_ACCESSIBLE).

The old MEMBLOCK_ALLOC_ANYWHERE changes value from 0 to ~(u64)0 and can still
be used with memblock_alloc_base() to allocate really anywhere.

It is -no-longer- cropped to MEMBLOCK_REAL_LIMIT which disappears.

Note to archs: I'm leaving the default limit to MEMBLOCK_ALLOC_ANYWHERE. I
strongly recommend that you ensure that you set an appropriate limit
during boot in order to guarantee that an memblock_alloc() at any time
results in something that is accessible with a simple __va().

The reason is that a subsequent patch will introduce the ability for
the array to resize itself by reallocating itself. The MEMBLOCK core will
honor the current limit when performing those allocations.

Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 27f574c2
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -9,9 +9,6 @@
#ifndef _ASM_MICROBLAZE_MEMBLOCK_H
#define _ASM_MICROBLAZE_MEMBLOCK_H

/* MEMBLOCK limit is OFF */
#define MEMBLOCK_REAL_LIMIT	0xFFFFFFFF

#endif /* _ASM_MICROBLAZE_MEMBLOCK_H */

+0 −7
Original line number Diff line number Diff line
@@ -5,11 +5,4 @@

#define MEMBLOCK_DBG(fmt...) udbg_printf(fmt)

#ifdef CONFIG_PPC32
extern phys_addr_t lowmem_end_addr;
#define MEMBLOCK_REAL_LIMIT	lowmem_end_addr
#else
#define MEMBLOCK_REAL_LIMIT	0
#endif

#endif /* _ASM_POWERPC_MEMBLOCK_H */
+19 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ static void __init move_device_tree(void)

	if ((memory_limit && (start + size) > memory_limit) ||
			overlaps_crashkernel(start, size)) {
		p = __va(memblock_alloc_base(size, PAGE_SIZE, memblock.rmo_size));
		p = __va(memblock_alloc(size, PAGE_SIZE));
		memcpy(p, initial_boot_params, size);
		initial_boot_params = (struct boot_param_header *)p;
		DBG("Moved device tree to 0x%p\n", p);
@@ -655,6 +655,21 @@ static void __init phyp_dump_reserve_mem(void)
static inline void __init phyp_dump_reserve_mem(void) {}
#endif /* CONFIG_PHYP_DUMP  && CONFIG_PPC_RTAS */

static void set_boot_memory_limit(void)
{
#ifdef CONFIG_PPC32
	/* 601 can only access 16MB at the moment */
	if (PVR_VER(mfspr(SPRN_PVR)) == 1)
		memblock_set_current_limit(0x01000000);
	/* 8xx can only access 8MB at the moment */
	else if (PVR_VER(mfspr(SPRN_PVR)) == 0x50)
		memblock_set_current_limit(0x00800000);
	else
		memblock_set_current_limit(0x10000000);
#else
	memblock_set_current_limit(memblock.rmo_size);
#endif
}

void __init early_init_devtree(void *params)
{
@@ -683,6 +698,7 @@ void __init early_init_devtree(void *params)

	/* Scan memory nodes and rebuild MEMBLOCKs */
	memblock_init();

	of_scan_flat_dt(early_init_dt_scan_root, NULL);
	of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);

@@ -718,6 +734,8 @@ void __init early_init_devtree(void *params)

	DBG("Phys. mem: %llx\n", memblock_phys_mem_size());

	set_boot_memory_limit();

	/* We may need to relocate the flat tree, do it now.
	 * FIXME .. and the initrd too? */
	move_device_tree();
+1 −1
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ static void __init irqstack_early_init(void)
	unsigned int i;

	/* interrupt stacks must be in lowmem, we get that for free on ppc32
	 * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
	 * as the memblock is limited to lowmem by default */
	for_each_possible_cpu(i) {
		softirq_ctx[i] = (struct thread_info *)
			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
+3 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/highmem.h>
#include <linux/memblock.h>

#include <asm/pgalloc.h>
#include <asm/prom.h>
@@ -47,6 +48,7 @@
#include <asm/bootx.h>
#include <asm/machdep.h>
#include <asm/setup.h>

#include "mmu_decl.h"

extern int __map_without_ltlbs;
@@ -139,8 +141,7 @@ unsigned long __init mmu_mapin_ram(unsigned long top)
	 * coverage with normal-sized pages (or other reasons) do not
	 * attempt to allocate outside the allowed range.
	 */

	__initial_memory_limit_addr = memstart_addr + mapped;
	memblock_set_current_limit(memstart_addr + mapped);

	return mapped;
}
Loading