From: Dave Carroll <hidden> Date: 2011-05-20 21:32:18
When using 64K pages with a separate cpio rootfs, U-Boot will align the roo=
tfs on a 4K
page boundary. When the memory is reserved, and subsequent early memblock_a=
lloc
is called, it will allocate memory between the 64K page alignment and reser=
ved
memory. When the reserved memory is subsequently freed, it is done so by pa=
ges,
causing the early memblock_alloc requests to be re-used, which in my case, =
caused
the device-tree to be clobbered.
This patch forces all early reserved memory to be kernel page aligned, to m=
atch
the mechanism used to free reserved memory.
Signed-off-by: Dave Carroll <redacted>
---
arch/powerpc/kernel/prom.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
From: Benjamin Herrenschmidt <benh@kernel.crashing.org> Date: 2011-05-20 22:27:57
On Fri, 2011-05-20 at 15:26 -0600, Dave Carroll wrote:
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 all early reserved memory to be kernel page aligned, to match
the mechanism used to free reserved memory.
Hrm...
Reserved memory isn't normally freed. The rootfs is a special case here,
shouldn't we special case it and thus align that specific reserve at the
call site ?
Not a huge deal either way now that I fixed memblock_reserve() to cope
with overlaps but could be a problem if we want to backport your patch.
Cheers,
Ben.
@@ -534,6 +534,19 @@ void __init early_init_dt_setup_initrd_arch(unsigned long start,}#endif+staticvoid__initreserve_mem(u64base,u64size)+{+u64top=base+size;+if(size==0)+return;++base=_ALIGN_DOWN(base,PAGE_SIZE);+top=_ALIGN_UP(top,PAGE_SIZE);+size=top-base;+memblock_reserve(base,size);++}+staticvoid__initearly_reserve_mem(void){u64base,size;
@@ -547,12 +560,12 @@ static void __init early_reserve_mem(void)/* before we do anything, lets reserve the dt blob */self_base=__pa((unsignedlong)initial_boot_params);self_size=initial_boot_params->totalsize;-memblock_reserve(self_base,self_size);+reserve_mem(self_base,self_size);#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);+reserve_mem(__pa(initrd_start),initrd_end-initrd_start);#endif /* CONFIG_BLK_DEV_INITRD */#ifdef CONFIG_PPC32
From: Dave Carroll <hidden> Date: 2011-05-20 23:24:01
When using 64K pages with a separate cpio rootfs, U-Boot will align the roo=
tfs
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 alig=
nment
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 initrd to be kernel page aligned, to match the mechanism =
used
to free reserved memory.
Signed-off-by: Dave Carroll <redacted>
---
arch/powerpc/kernel/prom.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
@@ -555,7 +555,8 @@ 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_st=
From: Milton Miller <hidden> Date: 2011-05-21 10:36:30
On Fri, 20 May 2011 about 13:23:36 -0000, Dave Carroll wrote:
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 initrd to be kernel page aligned, to match the
mechanism used to free reserved memory.
Actually it is only forcing the memory reserved for the initrd (its
not moving the contents nor filling the extra space).
quoted hunk
@@ -555,7 +555,8 @@ 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),+ PAGE_ALIGN(initrd_end) - _ALIGN_DOWN(initrd_start, PAGE_SIZE));
Please align up the end, then change free_initrd_mem (32 and 64 bit)
to do the same range extension.
Thanks,
milton
From: Dave Carroll <hidden> Date: 2011-05-21 17:05:44
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 adds the same range extension when freeing initrd.
Signed-off-by: Dave Carroll <redacted>
---
arch/powerpc/kernel/prom.c | 4 +++-
arch/powerpc/mm/init_32.c | 3 +++
arch/powerpc/mm/init_64.c | 3 +++
3 files changed, 9 insertions(+), 1 deletions(-)
@@ -555,7 +555,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_st=
On Sat, 21 May 2011 about 11:05:27 -0600, Dave Carroll wrote:
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 adds the same range extension when freeing initrd.
@@ -555,7 +555,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))
Here you test the unaligned values
void free_initrd_mem(unsigned long start, unsigned long end)
{
+ start = _ALIGN_DOWN(start, PAGE_SIZE);
+ end = _ALIGN_UP(end, PAGE_SIZE);
+
if (start < end)
printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
But here you test the aligned values. And they are aligned with
opposite bias. Which means that if start == end (or is less than,
but within the same page), a page that wasn't reserved (same
32 and 64 bit) gets freed.
I thought "what happens if we are within a page of end, could we
free the last page of bss?", but then I checked vmlinux.lds and we
align end to page size. I thought other allocations should be safe,
but then remembered:
The flattened device tree (of which we continue to use the string
table after boot) could be a problem.
milton
From: Dave Carroll <hidden> Date: 2011-05-23 01:30:05
On Sun, 22 May 2011 about 15:17, Milton Miller wrote:
quoted
On Sat, 21 May 2011 about 11:05:27 -0600, Dave Carroll wrote:>
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 adds the same range extension when freeing initrd.
@@ -555,7 +555,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))
Here you test the unaligned values
quoted
void free_initrd_mem(unsigned long start, unsigned long end)
{
+ start =3D _ALIGN_DOWN(start, PAGE_SIZE);
+ end =3D _ALIGN_UP(end, PAGE_SIZE);
+
if (start < end)
printk ("Freeing initrd memory: %ldk freed\n", (end - st=
art) >> 10);
But here you test the aligned values. And they are aligned with
opposite bias. Which means that if start =3D=3D end (or is less than,
but within the same page), a page that wasn't reserved (same
32 and 64 bit) gets freed.
Agreed ... I'll have the but shortly ...
I thought "what happens if we are within a page of end, could we
free the last page of bss?", but then I checked vmlinux.lds and we
align end to page size. I thought other allocations should be safe,
but then remembered:
The flattened device tree (of which we continue to use the string
table after boot) could be a problem.
I had previouly looked at free_initrd_mem, and thought the same conditions
should be used to handle the memory release, but as for the explicit alignm=
ent
of the release areas, that seemed to be handled by the fact that all of the
releases are specifically page aligned. The remainder of the free_initrd_me=
m
routine:
for (; start < end; start +=3D PAGE_SIZE) {
ClearPageReserved(virt_to_page(start));
init_page_count(virt_to_page(start));
free_page(start);
totalram_pages++;
}
implicitly aligns down start to a page boundary, and also would implicitly =
align
up the end address. While I would be a proponent of something like;
if (start && (start < end)) do { remainder of free_initrd_mem }
I'm not sure of the goal in explicitly attempting to align the addresses in=
the
routine as you proposed.
As for the FDT, if the FDT is packed contiguous with initrd, and the alignm=
ent is on
4K page boundaries, it would have been released before this patch. In my ca=
se (U-Boot),
they are not near each other.
Thanks,
-Dave
From: Dave Carroll <hidden> Date: 2011-05-23 02:31:27
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 adds the same range extension when freeing initrd.
Signed-off-by: Dave Carroll <redacted>
---
* I think this handles Milton's concerns with the exception of
a packed FDT next to initrd with mismatched page sizes. That
would require coordination with the bootloader.
arch/powerpc/kernel/prom.c | 4 +++-
arch/powerpc/mm/init_32.c | 15 +++++++++------
arch/powerpc/mm/init_64.c | 15 +++++++++------
3 files changed, 21 insertions(+), 13 deletions(-)
@@ -555,7 +555,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_st=
From: Dave Carroll <hidden> Date: 2011-05-23 16:50:22
I'm withdrawing this patch for the moment, due to two areas that need furth=
er research;
1) An adjacent FDT blob, as mentioned by Milton Miller, and
2) Potential interaction with the crash kernel, as used in
init/initramfs.c
If anyone sees other interactions, please feel free to let me know ...
Thanks,
-Dave Carroll
From: Milton Miller <hidden> Date: 2011-05-23 17:39:13
On Mon, 23 May 2011 about 10:50:07 -0600, Dave Carroll wrote:
I'm withdrawing this patch for the moment, due to two areas that need
further research;
1) An adjacent FDT blob, as mentioned by Milton Miller, and
Ok ... by the way, see move_device_tree() in arch/powerpc/kernel/prom.c
2) Potential interaction with the crash kernel, as used in
init/initramfs.c
which already goes around the start and end of crashk_res, which
is adjusted to PAGE_ALIGN in reserve_crashkernel() in machine_kexec.c
If anyone sees other interactions, please feel free to let me know ...
Thanks,
-Dave Carroll
One interaction that I have ignored is preserve_initrd overlapping
crash kernel. Loading the crash kernel destroys the preserved initrd.
But that is beyond the scope of your current patch (and probably a
seperate patch, with cross-architecture scope).
milton
From: Dave Carroll <hidden> Date: 2011-05-23 22:54:43
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 adds the same range extension when freeing initrd. It
will also move the device tree if it overlaps with the reserved memory
for initrd.
Many thanks to Milton Miller for his input on this patch.
Signed-off-by: Dave Carroll <redacted>
---
* This patch is based on Linus' current tree
arch/powerpc/kernel/prom.c | 11 ++++++++---
arch/powerpc/mm/init_32.c | 5 ++++-
arch/powerpc/mm/init_64.c | 5 ++++-
3 files changed, 16 insertions(+), 5 deletions(-)
From: Milton Miller <hidden> Date: 2011-05-25 09:28:36
On Mon, 23 May 2011 about 12:54:25 -0000, Dave Carroll wrote:
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 adds the same range extension when freeing initrd. It
will also move the device tree if it overlaps with the reserved memory
for initrd.
Many thanks to Milton Miller for his input on this patch.
Signed-off-by: Dave Carroll <redacted>
---
* This patch is based on Linus' current tree
Ben if I had reviewed this closely, so I tried to apply it. First
it failed because it arrived with
Content-Transfer-Encoding: quoted-printable
patchwork was nice enough to fix that, but it still didn't apply
because tabs were changed to spaces.
While both of those things can be fixed, It would reduce the burden
to test and apply if you can fix your mailer.
When reviewing that with Ben, I thought the && should have been ||. But
upon further review and comparison with overlaps_crashkernel, I see &&
is correct; it checks both the end is after the start and start is after end.
But that does point out the expression is too complex to read. Please
create a helper overlaps_initrd similar to overlaps_crashkernel. In that
function you should also return false if initrd_start is 0.
With the additional code added, Ben and I both noticed the indent
level can be reduced by reversing the condition and issuing an
early return. eg:
if (start >= end)
return;
This will also bring the printk line back under 80 columns.
Ben noticed the duplication and asked that the function be moved to
mem.c, which is common for 32 and 64 bit.
I would ask that, in addition, you prepare a second patch that
consolidates the free_initmem functions just above them by
noting that all sections except init were removed in v2.6.15 by
6c45ab992e4299c869fb26427944a8f8ea177024 (powerpc: Remove section
free() and linker script bits), and therefore the bulk of the executed
code is identical.
However, I see its a bit more involved because of that last line in
the 32 bit code which clears ppc_md.progress. A bit of research shows
we mostly don't call ppc_md.progress after init calls, but powermac
has a late initcall to clear it because they call it from a smp hook,
and the progress function is marked __init. Further research shows
most are marked init, including somewhat duplicated functions across
64 bit powerpc; the exception seems to be rtas_progress which is
called directly (not through ppc_md) from rtas-proc.c.
So upon further review, clear the ppc_md.progress to NULL at the
beginning of the consolidated function (before we start to release
the pages with the code). You can then remove the late_initcall in
the powermac code.
Extra credit to create and consolidate a printk_progress companion
to the udbg_progress call (but located somewhere common like
arch/powerpc/kernel/setup-common.c).
Thanks,
milton
From: Dave Carroll <hidden> Date: 2011-05-26 02:18:48
From: Dave Carroll <redacted>
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.
Many thanks to Milton Miller for his input on this patch.
Signed-off-by: Dave Carroll <redacted>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
arch/powerpc/kernel/prom.c | 21 ++++++++++++++++++---
arch/powerpc/mm/init_32.c | 15 ---------------
arch/powerpc/mm/init_64.c | 13 -------------
arch/powerpc/mm/mem.c | 19 +++++++++++++++++++
4 files changed, 37 insertions(+), 31 deletions(-)
@@ -555,7 +568,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-voidfree_initrd_mem(unsignedlongstart,unsignedlongend)-{-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 ... */voidsetup_initial_memory_limit(phys_addr_tfirst_memblock_base,phys_addr_tfirst_memblock_size)
From: Dave Carroll <hidden> Date: 2011-05-26 02:49:33
From: Dave Carroll <redacted>
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.
Many thanks to Milton Miller for his input on this patch.
Signed-off-by: Dave Carroll <redacted>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
* The previous patch [v6] was the wrong copy, sorry ...
arch/powerpc/kernel/prom.c | 21 ++++++++++++++++++---
arch/powerpc/mm/init_32.c | 15 ---------------
arch/powerpc/mm/init_64.c | 13 -------------
arch/powerpc/mm/mem.c | 19 +++++++++++++++++++
4 files changed, 37 insertions(+), 31 deletions(-)
@@ -555,7 +568,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-voidfree_initrd_mem(unsignedlongstart,unsignedlongend)-{-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 ... */voidsetup_initial_memory_limit(phys_addr_tfirst_memblock_base,phys_addr_tfirst_memblock_size)
From: Milton Miller <hidden> Date: 2011-05-26 11:18:56
On Wed, 25 May 2011 about 20:32:42 -0600, Dave Carroll wrote:
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.
Many thanks to Milton Miller for his input on this patch.
Thanks for the mailer update, it applied cleanly.
quoted hunk
Signed-off-by: Dave Carroll <redacted>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
* The previous patch [v6] was the wrong copy, sorry ...
arch/powerpc/kernel/prom.c | 21 ++++++++++++++++++---
arch/powerpc/mm/init_32.c | 15 ---------------
arch/powerpc/mm/init_64.c | 13 -------------
arch/powerpc/mm/mem.c | 19 +++++++++++++++++++
4 files changed, 37 insertions(+), 31 deletions(-)
@@ -81,12 +81,24 @@ static int __init early_parse_mem(char *p)return0;}early_param("mem",early_parse_mem);+/**+*overlaps_initrd-checkforoverlapwithpagealignedextensionof+*initrd.+*/
1) Please place a blank line after the above early_param before
the comment block.
2) /** says it is kernel doc format, so you need to follow the rules.
The description should fit on one line (I might say: ... with the initrd,
page aligned.) and you have to document the parameters. (Or just make
it a simple comment block by removing the second *)
+static inline int overlaps_initrd(unsigned long start, unsigned long size)
+{
+ if (!initrd_start)
+ return 0;
+ return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
+ start <= _ALIGN_UP(initrd_end, PAGE_SIZE);
+}
/**
need a blank line after the function before this comment block too.
* 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.
@@ -223,21 +223,6 @@ void free_initmem(void)#undef FREESEC}-#ifdef CONFIG_BLK_DEV_INITRD-voidfree_initrd_mem(unsignedlongstart,unsignedlongend)-{-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 ... */voidsetup_initial_memory_limit(phys_addr_tfirst_memblock_base,phys_addr_tfirst_memblock_size)
@@ -160,6 +160,25 @@ walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,}EXPORT_SYMBOL_GPL(walk_system_ram_range);+#ifdef CONFIG_BLK_DEV_INITRD+voidfree_initrd_mem(unsignedlongstart,unsignedlongend)+{+if(start>=end)+return;++start=_ALIGN_DOWN(start,PAGE_SIZE);+end=_ALIGN_UP(end,PAGE_SIZE);+printk(KERN_INFO"Freeing initrd memory: %ldk freed\n",+(end-start)>>10);
If you use pr_info then the above again fits on one line.
(this is what triggered my formatting and whitespace review).
Although I would then add a blank line before the loop for readability.
Nit: Looking at the whole file I would put this after mem_init
because that puts it next to the other code that sets page counts,
clears PageReerved, and hands pages to page_alloc.
/*
* Initialize the bootmem system and give it all the memory we
* have available. If we are using highmem, we only put the
--
1.7.4
From: Dave Carroll <hidden> Date: 2011-05-26 17:11:24
From: Dave Carroll <redacted>
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.
Signed-off-by: Dave Carroll <redacted>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
arch/powerpc/kernel/prom.c | 23 ++++++++++++++++++++---
arch/powerpc/mm/init_32.c | 15 ---------------
arch/powerpc/mm/init_64.c | 14 --------------
arch/powerpc/mm/mem.c | 19 +++++++++++++++++++
4 files changed, 39 insertions(+), 32 deletions(-)
@@ -555,7 +570,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-voidfree_initrd_mem(unsignedlongstart,unsignedlongend)-{-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 ... */voidsetup_initial_memory_limit(phys_addr_tfirst_memblock_base,phys_addr_tfirst_memblock_size)
From: Dave Carroll <hidden> Date: 2011-06-11 01:57:35
From: Dave Carroll <redacted>
The free_initmem function is basically duplicated in mm/init_32,
and init_64, and is moved to the common 32/64-bit mm/mem.c.
All other sections except init were removed in v2.6.15 by
6c45ab992e4299c869fb26427944a8f8ea177024 (powerpc: Remove section
free() and linker script bits), and therefore the bulk of the executed
code is identical.
This patch also removes updating ppc_md.progress to NULL in the powermac
late_initcall.
Suggested-by: Milton Miller <redacted>
Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Dave Carroll <redacted>
---
arch/powerpc/mm/init_32.c | 32 -------------------------------
arch/powerpc/mm/init_64.c | 16 ---------------
arch/powerpc/mm/mem.c | 19 ++++++++++++++++++
arch/powerpc/platforms/powermac/setup.c | 3 --
4 files changed, 19 insertions(+), 51 deletions(-)
@@ -191,38 +191,6 @@ void __init *early_get_page(void)return__va(memblock_alloc(PAGE_SIZE,PAGE_SIZE));}-/* Free up now-unused memory */-staticvoidfree_sec(unsignedlongstart,unsignedlongend,constchar*name)-{-unsignedlongcnt=0;--while(start<end){-ClearPageReserved(virt_to_page(start));-init_page_count(virt_to_page(start));-free_page(start);-cnt++;-start+=PAGE_SIZE;-}-if(cnt){-printk(" %ldk %s",cnt<<(PAGE_SHIFT-10),name);-totalram_pages+=cnt;-}-}--voidfree_initmem(void)-{-#define FREESEC(TYPE) \-free_sec((unsignedlong)(&__##TYPE##_begin),\-(unsignedlong)(&__##TYPE##_end),\-#TYPE);--printk("Freeing unused kernel memory:");-FREESEC(init);-printk("\n");-ppc_md.progress=NULL;-#undef FREESEC-}-#ifdef CONFIG_8xx /* No 8xx specific .c file to put that in ... */voidsetup_initial_memory_limit(phys_addr_tfirst_memblock_base,phys_addr_tfirst_memblock_size)
@@ -355,9 +355,6 @@ static int initializing = 1;staticintpmac_late_init(void){initializing=0;-/* this is udbg (which is __init) and we can later use it during-*cpuhotplug(insmp_core99_kick_cpu)*/-ppc_md.progress=NULL;return0;}machine_late_initcall(powermac,pmac_late_init);
From: Dave Carroll <hidden> Date: 2011-06-11 01:57:57
From: Dave Carroll <redacted>
This patch adds a printk companion to replace the udbg progress function
when initmem is freed.
Suggested-by: Milton Miller <redacted>
Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Dave Carroll <redacted>
---
arch/powerpc/include/asm/setup.h | 2 ++
arch/powerpc/kernel/setup-common.c | 5 +++++
arch/powerpc/mm/mem.c | 2 +-
3 files changed, 8 insertions(+), 1 deletions(-)