Skip to content

Commit

Permalink
Introduce flags for reserve_bootmem()
Browse files Browse the repository at this point in the history
This patchset adds a flags variable to reserve_bootmem() and uses the
BOOTMEM_EXCLUSIVE flag in crashkernel reservation code to detect collisions
between crashkernel area and already used memory.

This patch:

Change the reserve_bootmem() function to accept a new flag BOOTMEM_EXCLUSIVE.
If that flag is set, the function returns with -EBUSY if the memory already
has been reserved in the past.  This is to avoid conflicts.

Because that code runs before SMP initialisation, there's no race condition
inside reserve_bootmem_core().

[[email protected]: coding-style fixes]
[[email protected]: fix powerpc build]
Signed-off-by: Bernhard Walle <[email protected]>
Cc: <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Vivek Goyal <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Bernhard Walle authored and Linus Torvalds committed Feb 7, 2008
1 parent 25fad94 commit 72a7fe3
Show file tree
Hide file tree
Showing 43 changed files with 183 additions and 105 deletions.
3 changes: 2 additions & 1 deletion arch/alpha/kernel/core_irongate.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ albacore_init_arch(void)
size / 1024);
}
#endif
reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop - pci_mem);
reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
pci_mem, BOOTMEM_DEFAULT);
printk("irongate_init_arch: temporarily reserving "
"region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
}
Expand Down
5 changes: 3 additions & 2 deletions arch/alpha/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ setup_memory(void *kernel_end)
}

/* Reserve the bootmap memory. */
reserve_bootmem(PFN_PHYS(bootmap_start), bootmap_size);
reserve_bootmem(PFN_PHYS(bootmap_start), bootmap_size,
BOOTMEM_DEFAULT);
printk("reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));

#ifdef CONFIG_BLK_DEV_INITRD
Expand All @@ -446,7 +447,7 @@ setup_memory(void *kernel_end)
phys_to_virt(PFN_PHYS(max_low_pfn)));
} else {
reserve_bootmem(virt_to_phys((void *)initrd_start),
INITRD_SIZE);
INITRD_SIZE, BOOTMEM_DEFAULT);
}
}
#endif /* CONFIG_BLK_DEV_INITRD */
Expand Down
5 changes: 3 additions & 2 deletions arch/alpha/mm/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ setup_memory_node(int nid, void *kernel_end)
}

/* Reserve the bootmap memory. */
reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(bootmap_start), bootmap_size);
reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(bootmap_start),
bootmap_size, BOOTMEM_DEFAULT);
printk(" reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));

node_set_online(nid);
Expand Down Expand Up @@ -281,7 +282,7 @@ setup_memory(void *kernel_end)
nid = kvaddr_to_nid(initrd_start);
reserve_bootmem_node(NODE_DATA(nid),
virt_to_phys((void *)initrd_start),
INITRD_SIZE);
INITRD_SIZE, BOOTMEM_DEFAULT);
}
}
#endif /* CONFIG_BLK_DEV_INITRD */
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi)
* Reserve the bootmem bitmap for this node.
*/
reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,
boot_pages << PAGE_SHIFT);
boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);

#ifdef CONFIG_BLK_DEV_INITRD
/*
* If the initrd is in this node, reserve its memory.
*/
if (node == initrd_node) {
reserve_bootmem_node(pgdat, phys_initrd_start,
phys_initrd_size);
phys_initrd_size, BOOTMEM_DEFAULT);
initrd_start = __phys_to_virt(phys_initrd_start);
initrd_end = initrd_start + phys_initrd_size;
}
Expand Down
17 changes: 11 additions & 6 deletions arch/arm/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,19 @@ void __init reserve_node_zero(pg_data_t *pgdat)
* Note that this can only be in node 0.
*/
#ifdef CONFIG_XIP_KERNEL
reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start);
reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start,
BOOTMEM_DEFAULT);
#else
reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext);
reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext,
BOOTMEM_DEFAULT);
#endif

/*
* Reserve the page tables. These are already in use,
* and can only be in node 0.
*/
reserve_bootmem_node(pgdat, __pa(swapper_pg_dir),
PTRS_PER_PGD * sizeof(pgd_t));
PTRS_PER_PGD * sizeof(pgd_t), BOOTMEM_DEFAULT);

/*
* Hmm... This should go elsewhere, but we really really need to
Expand All @@ -638,8 +640,10 @@ void __init reserve_node_zero(pg_data_t *pgdat)
/* H1940 and RX3715 need to reserve this for suspend */

if (machine_is_h1940() || machine_is_rx3715()) {
reserve_bootmem_node(pgdat, 0x30003000, 0x1000);
reserve_bootmem_node(pgdat, 0x30081000, 0x1000);
reserve_bootmem_node(pgdat, 0x30003000, 0x1000,
BOOTMEM_DEFAULT);
reserve_bootmem_node(pgdat, 0x30081000, 0x1000,
BOOTMEM_DEFAULT);
}

#ifdef CONFIG_SA1111
Expand All @@ -650,7 +654,8 @@ void __init reserve_node_zero(pg_data_t *pgdat)
res_size = __pa(swapper_pg_dir) - PHYS_OFFSET;
#endif
if (res_size)
reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size);
reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size,
BOOTMEM_DEFAULT);
}

/*
Expand Down
9 changes: 6 additions & 3 deletions arch/arm/mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ void __init reserve_node_zero(pg_data_t *pgdat)
* Note that this can only be in node 0.
*/
#ifdef CONFIG_XIP_KERNEL
reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start);
reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start,
BOOTMEM_DEFAULT);
#else
reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext);
reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext,
BOOTMEM_DEFAULT);
#endif

/*
* Register the exception vector page.
* some architectures which the DRAM is the exception vector to trap,
* alloc_page breaks with error, although it is not NULL, but "0."
*/
reserve_bootmem_node(pgdat, CONFIG_VECTORS_BASE, PAGE_SIZE);
reserve_bootmem_node(pgdat, CONFIG_VECTORS_BASE, PAGE_SIZE,
BOOTMEM_DEFAULT);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/plat-omap/fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void __init omapfb_reserve_sdram(void)
return;
}
if (rg.paddr)
reserve_bootmem(rg.paddr, rg.size);
reserve_bootmem(rg.paddr, rg.size, BOOTMEM_DEFAULT);
reserved += rg.size;
omapfb_config.mem_desc.region[i] = rg;
configured_regions++;
Expand Down
6 changes: 4 additions & 2 deletions arch/avr32/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ static void __init setup_bootmem(void)
/* Reserve space for the bootmem bitmap... */
reserve_bootmem_node(NODE_DATA(node),
PFN_PHYS(bootmap_pfn),
bootmap_size);
bootmap_size,
BOOTMEM_DEFAULT);

/* ...and any other reserved regions. */
for (res = reserved; res; res = res->sibling) {
Expand All @@ -505,7 +506,8 @@ static void __init setup_bootmem(void)
&& res->end < PFN_PHYS(max_pfn))
reserve_bootmem_node(
NODE_DATA(node), res->start,
res->end - res->start + 1);
res->end - res->start + 1,
BOOTMEM_DEFAULT);
}

node_set_online(node);
Expand Down
2 changes: 1 addition & 1 deletion arch/blackfin/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void __init setup_arch(char **cmdline_p)
*/
free_bootmem(memory_start, memory_end - memory_start);

reserve_bootmem(memory_start, bootmap_size);
reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
/*
* get kmalloc into gear
*/
Expand Down
2 changes: 1 addition & 1 deletion arch/cris/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ setup_arch(char **cmdline_p)
* Arguments are start, size
*/

reserve_bootmem(PFN_PHYS(start_pfn), bootmap_size);
reserve_bootmem(PFN_PHYS(start_pfn), bootmap_size, BOOTMEM_DEFAULT);

/* paging_init() sets up the MMU and marks all pages as reserved */

Expand Down
16 changes: 10 additions & 6 deletions arch/frv/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,15 @@ static void __init setup_linux_memory(void)
#endif

/* take back the memory occupied by the kernel image and the bootmem alloc map */
reserve_bootmem(kstart, kend - kstart + bootmap_size);
reserve_bootmem(kstart, kend - kstart + bootmap_size,
BOOTMEM_DEFAULT);

/* reserve the memory occupied by the initial ramdisk */
#ifdef CONFIG_BLK_DEV_INITRD
if (LOADER_TYPE && INITRD_START) {
if (INITRD_START + INITRD_SIZE <= (low_top_pfn << PAGE_SHIFT)) {
reserve_bootmem(INITRD_START, INITRD_SIZE);
reserve_bootmem(INITRD_START, INITRD_SIZE,
BOOTMEM_DEFAULT);
initrd_start = INITRD_START + PAGE_OFFSET;
initrd_end = initrd_start + INITRD_SIZE;
}
Expand Down Expand Up @@ -986,24 +988,26 @@ static void __init setup_uclinux_memory(void)

/* now take back the bits the core kernel is occupying */
#ifndef CONFIG_PROTECT_KERNEL
reserve_bootmem(kend, bootmap_size);
reserve_bootmem(kend, bootmap_size, BOOTMEM_DEFAULT);
reserve_bootmem((unsigned long) &__kernel_image_start,
kend - (unsigned long) &__kernel_image_start);
kend - (unsigned long) &__kernel_image_start,
BOOTMEM_DEFAULT);

#else
dampr = __get_DAMPR(0);
dampr &= xAMPRx_SS;
dampr = (dampr >> 4) + 17;
dampr = 1 << dampr;

reserve_bootmem(__get_DAMPR(0) & xAMPRx_PPFN, dampr);
reserve_bootmem(__get_DAMPR(0) & xAMPRx_PPFN, dampr, BOOTMEM_DEFAULT);
#endif

/* reserve some memory to do uncached DMA through if requested */
#ifdef CONFIG_RESERVE_DMA_COHERENT
if (dma_coherent_mem_start)
reserve_bootmem(dma_coherent_mem_start,
dma_coherent_mem_end - dma_coherent_mem_start);
dma_coherent_mem_end - dma_coherent_mem_start,
BOOTMEM_DEFAULT);
#endif

} /* end setup_uclinux_memory() */
Expand Down
2 changes: 1 addition & 1 deletion arch/h8300/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void __init setup_arch(char **cmdline_p)
* the bootmem bitmap so we then reserve it after freeing it :-)
*/
free_bootmem(memory_start, memory_end - memory_start);
reserve_bootmem(memory_start, bootmap_size);
reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
/*
* get kmalloc into gear
*/
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/mm/contig.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ find_memory (void)

/* Free all available memory, then mark bootmem-map as being in use. */
efi_memmap_walk(filter_rsvd_memory, free_bootmem);
reserve_bootmem(bootmap_start, bootmap_size);
reserve_bootmem(bootmap_start, bootmap_size, BOOTMEM_DEFAULT);

find_initrd();

Expand Down
4 changes: 2 additions & 2 deletions arch/ia64/mm/discontig.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ static void __init reserve_pernode_space(void)
pages = bdp->node_low_pfn - (bdp->node_boot_start>>PAGE_SHIFT);
size = bootmem_bootmap_pages(pages) << PAGE_SHIFT;
base = __pa(bdp->node_bootmem_map);
reserve_bootmem_node(pdp, base, size);
reserve_bootmem_node(pdp, base, size, BOOTMEM_DEFAULT);

/* Now the per-node space */
size = mem_data[node].pernode_size;
base = __pa(mem_data[node].pernode_addr);
reserve_bootmem_node(pdp, base, size);
reserve_bootmem_node(pdp, base, size, BOOTMEM_DEFAULT);
}
}

Expand Down
11 changes: 7 additions & 4 deletions arch/m32r/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,28 @@ static unsigned long __init setup_memory(void)
*/
reserve_bootmem(CONFIG_MEMORY_START + PAGE_SIZE,
(PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE - 1)
- CONFIG_MEMORY_START);
- CONFIG_MEMORY_START,
BOOTMEM_DEFAULT);

/*
* reserve physical page 0 - it's a special BIOS page on many boxes,
* enabling clean reboots, SMP operation, laptop functions.
*/
reserve_bootmem(CONFIG_MEMORY_START, PAGE_SIZE);
reserve_bootmem(CONFIG_MEMORY_START, PAGE_SIZE, BOOTMEM_DEFAULT);

/*
* reserve memory hole
*/
#ifdef CONFIG_MEMHOLE
reserve_bootmem(CONFIG_MEMHOLE_START, CONFIG_MEMHOLE_SIZE);
reserve_bootmem(CONFIG_MEMHOLE_START, CONFIG_MEMHOLE_SIZE,
BOOTMEM_DEFAULT);
#endif

#ifdef CONFIG_BLK_DEV_INITRD
if (LOADER_TYPE && INITRD_START) {
if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
reserve_bootmem(INITRD_START, INITRD_SIZE);
reserve_bootmem(INITRD_START, INITRD_SIZE,
BOOTMEM_DEFAULT);
initrd_start = INITRD_START + PAGE_OFFSET;
initrd_end = initrd_start + INITRD_SIZE;
printk("initrd:start[%08lx],size[%08lx]\n",
Expand Down
5 changes: 3 additions & 2 deletions arch/m32r/mm/discontig.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ unsigned long __init setup_memory(void)
PFN_PHYS(mp->pages));

reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn),
PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size);
PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size,
BOOTMEM_DEFAULT);

if (max_low_pfn < max_pfn)
max_low_pfn = max_pfn;
Expand All @@ -104,7 +105,7 @@ unsigned long __init setup_memory(void)
if (LOADER_TYPE && INITRD_START) {
if (INITRD_START + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) {
reserve_bootmem_node(NODE_DATA(0), INITRD_START,
INITRD_SIZE);
INITRD_SIZE, BOOTMEM_DEFAULT);
initrd_start = INITRD_START + PAGE_OFFSET;
initrd_end = initrd_start + INITRD_SIZE;
printk("initrd:start[%08lx],size[%08lx]\n",
Expand Down
2 changes: 1 addition & 1 deletion arch/m68k/atari/stram.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void __init atari_stram_reserve_pages(void *start_mem)
/* always reserve first page of ST-RAM, the first 2 kB are
* supervisor-only! */
if (!kernel_in_stram)
reserve_bootmem (0, PAGE_SIZE);
reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);

}

Expand Down
3 changes: 2 additions & 1 deletion arch/m68k/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ void __init setup_arch(char **cmdline_p)
#ifdef CONFIG_BLK_DEV_INITRD
if (m68k_ramdisk.size) {
reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
m68k_ramdisk.addr, m68k_ramdisk.size);
m68k_ramdisk.addr, m68k_ramdisk.size,
BOOTMEM_DEFAULT);
initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
initrd_end = initrd_start + m68k_ramdisk.size;
printk("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
Expand Down
2 changes: 1 addition & 1 deletion arch/m68knommu/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void __init setup_arch(char **cmdline_p)
* the bootmem bitmap so we then reserve it after freeing it :-)
*/
free_bootmem(memory_start, memory_end - memory_start);
reserve_bootmem(memory_start, bootmap_size);
reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);

/*
* Get kmalloc into gear.
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static void __init finalize_initrd(void)
goto disable;
}

reserve_bootmem(__pa(initrd_start), size);
reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
initrd_below_start_ok = 1;

printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
Expand Down Expand Up @@ -413,7 +413,7 @@ static void __init bootmem_init(void)
/*
* Reserve the bootmap memory.
*/
reserve_bootmem(PFN_PHYS(mapstart), bootmap_size);
reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);

/*
* Reserve initrd memory if needed.
Expand Down
3 changes: 2 additions & 1 deletion arch/mips/sgi-ip27/ip27-memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ static void __init node_mem_init(cnodeid_t node)
free_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT,
(slot_lastpfn - slot_firstpfn) << PAGE_SHIFT);
reserve_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT,
((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size);
((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size,
BOOTMEM_DEFAULT);
}

/*
Expand Down
Loading

0 comments on commit 72a7fe3

Please sign in to comment.