All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Carroll <dcarroll@astekcorp.com>
To: "'Milton Miller'" <miltonm@bga.com>
Cc: Paul Mackerras <paulus@samba.org>,
	LPPC <linuxppc-dev@lists.ozlabs.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH v4] powerpc: Force page alignment for initrd reserved memory
Date: Sun, 22 May 2011 20:31:11 -0600	[thread overview]
Message-ID: <522F24EF533FC546962ECFA2054FF777373072AB75@MAILSERVER2.cos.astekcorp.com> (raw)
In-Reply-To: <initrd-reserve-reply2@mdm.bga.com>

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 <dcarroll@astekcorp.com>
---

* 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(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 48aeb55..387e5c9 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -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_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
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index d65b591..1aad444 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -226,13 +226,16 @@ void free_initmem(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       if (start < end)
+       if (start && (start < end)) {
+               start = _ALIGN_DOWN(start, PAGE_SIZE);
+               end = _ALIGN_UP(end, PAGE_SIZE);
                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++;
+               for (; start < end; start += PAGE_SIZE) {
+                       ClearPageReserved(virt_to_page(start));
+                       init_page_count(virt_to_page(start));
+                       free_page(start);
+                       totalram_pages++;
+               }
        }
 }
 #endif
diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 6374b21..fa9586b 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -102,13 +102,16 @@ void free_initmem(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       if (start < end)
+       if (start && (start < end)) {
+               start = _ALIGN_DOWN(start, PAGE_SIZE);
+               end = _ALIGN_UP(end, PAGE_SIZE);
                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++;
+               for (; start < end; start += PAGE_SIZE) {
+                       ClearPageReserved(virt_to_page(start));
+                       init_page_count(virt_to_page(start));
+                       free_page(start);
+                       totalram_pages++;
+               }
        }
 }
 #endif
--
1.7.4


WARNING: multiple messages have this Message-ID (diff)
From: Dave Carroll <dcarroll@astekcorp.com>
To: 'Milton Miller' <miltonm@bga.com>
Cc: LPPC <linuxppc-dev@lists.ozlabs.org>,
	Paul Mackerras <paulus@samba.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v4] powerpc: Force page alignment for initrd reserved memory
Date: Sun, 22 May 2011 20:31:11 -0600	[thread overview]
Message-ID: <522F24EF533FC546962ECFA2054FF777373072AB75@MAILSERVER2.cos.astekcorp.com> (raw)
In-Reply-To: <initrd-reserve-reply2@mdm.bga.com>

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 <dcarroll@astekcorp.com>
---

* 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(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 48aeb55..387e5c9 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -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=
art);
+               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
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index d65b591..1aad444 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -226,13 +226,16 @@ void free_initmem(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       if (start < end)
+       if (start && (start < end)) {
+               start =3D _ALIGN_DOWN(start, PAGE_SIZE);
+               end =3D _ALIGN_UP(end, PAGE_SIZE);
                printk ("Freeing initrd memory: %ldk freed\n", (end - start=
) >> 10);
-       for (; start < end; start +=3D PAGE_SIZE) {
-               ClearPageReserved(virt_to_page(start));
-               init_page_count(virt_to_page(start));
-               free_page(start);
-               totalram_pages++;
+               for (; start < end; start +=3D PAGE_SIZE) {
+                       ClearPageReserved(virt_to_page(start));
+                       init_page_count(virt_to_page(start));
+                       free_page(start);
+                       totalram_pages++;
+               }
        }
 }
 #endif
diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 6374b21..fa9586b 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -102,13 +102,16 @@ void free_initmem(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       if (start < end)
+       if (start && (start < end)) {
+               start =3D _ALIGN_DOWN(start, PAGE_SIZE);
+               end =3D _ALIGN_UP(end, PAGE_SIZE);
                printk ("Freeing initrd memory: %ldk freed\n", (end - start=
) >> 10);
-       for (; start < end; start +=3D PAGE_SIZE) {
-               ClearPageReserved(virt_to_page(start));
-               init_page_count(virt_to_page(start));
-               free_page(start);
-               totalram_pages++;
+               for (; start < end; start +=3D PAGE_SIZE) {
+                       ClearPageReserved(virt_to_page(start));
+                       init_page_count(virt_to_page(start));
+                       free_page(start);
+                       totalram_pages++;
+               }
        }
 }
 #endif
--
1.7.4

  parent reply	other threads:[~2011-05-23  2:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-20 21:26 [PATCH]powerpc: Force page alignment for early reserved memory Dave Carroll
2011-05-20 21:26 ` Dave Carroll
2011-05-20 22:27 ` Benjamin Herrenschmidt
2011-05-20 22:27   ` Benjamin Herrenschmidt
2011-05-20 23:23   ` [PATCH v2]powerpc: Force page alignment for initrd Dave Carroll
2011-05-20 23:23     ` Dave Carroll
2011-05-21 10:36     ` [v2] powerpc: " Milton Miller
2011-05-21 10:36       ` Milton Miller
2011-05-21 17:05       ` [PATCH v3] powerpc: Force page alignment for initrd reserved memory Dave Carroll
2011-05-21 17:05         ` Dave Carroll
2011-05-22 21:17         ` [PATCH v3] powerpc: Force page alignment for initrd reserved memory, " 'Milton Miller'
2011-05-22 21:17           ` 'Milton Miller'
2011-05-23  1:29           ` Dave Carroll
2011-05-23  1:29             ` Dave Carroll
2011-05-23  2:31           ` Dave Carroll [this message]
2011-05-23  2:31             ` [PATCH v4] " Dave Carroll
2011-05-23 16:50             ` [ " Dave Carroll
2011-05-23 16:50               ` Dave Carroll
2011-05-23 17:39               ` Milton Miller
2011-05-23 17:39                 ` Milton Miller
2011-05-23 22:54                 ` [PATCH v5] " Dave Carroll
2011-05-23 22:54                   ` Dave Carroll
2011-05-25  9:28                   ` [v5] " Milton Miller
2011-05-25  9:28                     ` Milton Miller
2011-05-26  2:00                     ` [PATCH v6] " Dave Carroll
2011-05-26  2:00                       ` Dave Carroll
2011-05-26  2:32                     ` [PATCH v7] " Dave Carroll
2011-05-26  2:32                       ` Dave Carroll
2011-05-26 11:18                       ` Milton Miller
2011-05-26 11:18                         ` Milton Miller
2011-05-26 16:53                         ` [PATCH v8] " Dave Carroll
2011-05-26 16:53                           ` Dave Carroll
2011-06-11  1:38                     ` [PATCH 1/2] powerpc: Move free_initmem to common code Dave Carroll
2011-06-11  1:38                       ` Dave Carroll
2011-06-11  1:38                       ` [PATCH 2/2] powerpc: Add printk companion for ppc_md.progress Dave Carroll
2011-06-11  1:38                         ` Dave Carroll

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=522F24EF533FC546962ECFA2054FF777373072AB75@MAILSERVER2.cos.astekcorp.com \
    --to=dcarroll@astekcorp.com \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=miltonm@bga.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.