mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-03 17:40:04 +00:00
powerpc: Force page alignment for initrd reserved memory
When using 64K pages with a separate cpio rootfs, U-Boot will align the rootfs on a 4K page boundary. When the memory is reserved, and subsequent early memblock_alloc is called, it will allocate memory between the 64K page alignment and reserved memory. When the reserved memory is subsequently freed, it is done so by pages, causing the early memblock_alloc requests to be re-used, which in my case, caused the device-tree to be clobbered. This patch forces the reserved memory for initrd to be kernel page aligned, and will move the device tree if it overlaps with the range extension of initrd. This patch will also consolidate the identical function free_initrd_mem() from mm/init_32.c, init_64.c to mm/mem.c, and adds the same range extension when freeing initrd. free_initrd_mem() is also moved to the __init section. Many thanks to Milton Miller for his input on this patch. [BenH: Fixed build without CONFIG_BLK_DEV_INITRD] Signed-off-by: Dave Carroll <dcarroll@astekcorp.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This commit is contained in:
parent
d660474e84
commit
307cfe7153
4 changed files with 43 additions and 32 deletions
|
@ -82,11 +82,29 @@ static int __init early_parse_mem(char *p)
|
|||
}
|
||||
early_param("mem", early_parse_mem);
|
||||
|
||||
/*
|
||||
* overlaps_initrd - check for overlap with page aligned extension of
|
||||
* initrd.
|
||||
*/
|
||||
static inline int overlaps_initrd(unsigned long start, unsigned long size)
|
||||
{
|
||||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
if (!initrd_start)
|
||||
return 0;
|
||||
|
||||
return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
|
||||
start <= _ALIGN_UP(initrd_end, PAGE_SIZE);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* move_device_tree - move tree to an unused area, if needed.
|
||||
*
|
||||
* The device tree may be allocated beyond our memory limit, or inside the
|
||||
* crash kernel region for kdump. If so, move it out of the way.
|
||||
* crash kernel region for kdump, or within the page aligned range of initrd.
|
||||
* If so, move it out of the way.
|
||||
*/
|
||||
static void __init move_device_tree(void)
|
||||
{
|
||||
|
@ -99,7 +117,8 @@ static void __init move_device_tree(void)
|
|||
size = be32_to_cpu(initial_boot_params->totalsize);
|
||||
|
||||
if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) ||
|
||||
overlaps_crashkernel(start, size)) {
|
||||
overlaps_crashkernel(start, size) ||
|
||||
overlaps_initrd(start, size)) {
|
||||
p = __va(memblock_alloc(size, PAGE_SIZE));
|
||||
memcpy(p, initial_boot_params, size);
|
||||
initial_boot_params = (struct boot_param_header *)p;
|
||||
|
@ -555,7 +574,9 @@ static void __init early_reserve_mem(void)
|
|||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
/* then reserve the initrd, if any */
|
||||
if (initrd_start && (initrd_end > initrd_start))
|
||||
memblock_reserve(__pa(initrd_start), initrd_end - initrd_start);
|
||||
memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
|
||||
_ALIGN_UP(initrd_end, PAGE_SIZE) -
|
||||
_ALIGN_DOWN(initrd_start, PAGE_SIZE));
|
||||
#endif /* CONFIG_BLK_DEV_INITRD */
|
||||
|
||||
#ifdef CONFIG_PPC32
|
||||
|
|
|
@ -223,21 +223,6 @@ void free_initmem(void)
|
|||
#undef FREESEC
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
void free_initrd_mem(unsigned long start, unsigned long end)
|
||||
{
|
||||
if (start < end)
|
||||
printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
|
||||
for (; start < end; start += PAGE_SIZE) {
|
||||
ClearPageReserved(virt_to_page(start));
|
||||
init_page_count(virt_to_page(start));
|
||||
free_page(start);
|
||||
totalram_pages++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_8xx /* No 8xx specific .c file to put that in ... */
|
||||
void setup_initial_memory_limit(phys_addr_t first_memblock_base,
|
||||
phys_addr_t first_memblock_size)
|
||||
|
|
|
@ -99,20 +99,6 @@ void free_initmem(void)
|
|||
((unsigned long)__init_end - (unsigned long)__init_begin) >> 10);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
void free_initrd_mem(unsigned long start, unsigned long end)
|
||||
{
|
||||
if (start < end)
|
||||
printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
|
||||
for (; start < end; start += PAGE_SIZE) {
|
||||
ClearPageReserved(virt_to_page(start));
|
||||
init_page_count(virt_to_page(start));
|
||||
free_page(start);
|
||||
totalram_pages++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void pgd_ctor(void *addr)
|
||||
{
|
||||
memset(addr, 0, PGD_TABLE_SIZE);
|
||||
|
|
|
@ -382,6 +382,25 @@ void __init mem_init(void)
|
|||
mem_init_done = 1;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
void __init free_initrd_mem(unsigned long start, unsigned long end)
|
||||
{
|
||||
if (start >= end)
|
||||
return;
|
||||
|
||||
start = _ALIGN_DOWN(start, PAGE_SIZE);
|
||||
end = _ALIGN_UP(end, PAGE_SIZE);
|
||||
pr_info("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
|
||||
|
||||
for (; start < end; start += PAGE_SIZE) {
|
||||
ClearPageReserved(virt_to_page(start));
|
||||
init_page_count(virt_to_page(start));
|
||||
free_page(start);
|
||||
totalram_pages++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is called when a page has been modified by the kernel.
|
||||
* It just marks the page as not i-cache clean. We do the i-cache
|
||||
|
|
Loading…
Reference in a new issue