2008-01-15 13:37:08

by Jesper Nilsson

[permalink] [raw]
Subject: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

- Move alignment to page size of init data outside ifdef for BLK_DEV_INITRD.
The reservation up to page size of memory after init data was previously
not done if BLK_DEV_INITRD was undefined.
This caused a kernel oops when init memory pages were freed after startup,
data placed in the same page as the last init memory would also be freed
and reused, with disastrous results.

- Use macros for initcalls and .text sections.

- Replace hardcoded page size constant with PAGE_SIZE define.

- Change include/asm-cris/page.h to use the _AC macro to instead
of testing __ASSEMBLY__.

Signed-off-by: Jesper Nilsson <[email protected]>
---

NOTE: This patch supercedes
arch-cris-arch-v10-vmlinuxldss-fix-boot-problem.patch
by Yuusei KUWANA <[email protected]> in the -mm tree.

That patch only restricts which sections are counted as init memory,
and does not solve the underlying problem (that memory that is not part
of init data can be freed)

arch/cris/arch-v10/vmlinux.lds.S | 33 +++++++++++++++------------------
include/asm-cris/page.h | 7 ++-----
2 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/arch/cris/arch-v10/vmlinux.lds.S b/arch/cris/arch-v10/vmlinux.lds.S
index 9859d49..97a7876 100644
--- a/arch/cris/arch-v10/vmlinux.lds.S
+++ b/arch/cris/arch-v10/vmlinux.lds.S
@@ -9,7 +9,8 @@
*/

#include <asm-generic/vmlinux.lds.h>
-
+#include <asm/page.h>
+
jiffies = jiffies_64;
SECTIONS
{
@@ -23,7 +24,7 @@ SECTIONS
_stext = .;
__stext = .;
.text : {
- *(.text)
+ TEXT_TEXT
SCHED_TEXT
LOCK_TEXT
*(.fixup)
@@ -49,10 +50,10 @@ SECTIONS
__edata = . ; /* End of data section */
_edata = . ;

- . = ALIGN(8192); /* init_task and stack, must be aligned */
+ . = ALIGN(PAGE_SIZE); /* init_task and stack, must be aligned */
.data.init_task : { *(.data.init_task) }

- . = ALIGN(8192); /* Init code and data */
+ . = ALIGN(PAGE_SIZE); /* Init code and data */
__init_begin = .;
.init.text : {
_sinittext = .;
@@ -66,13 +67,7 @@ SECTIONS
__setup_end = .;
.initcall.init : {
__initcall_start = .;
- *(.initcall1.init);
- *(.initcall2.init);
- *(.initcall3.init);
- *(.initcall4.init);
- *(.initcall5.init);
- *(.initcall6.init);
- *(.initcall7.init);
+ INITCALLS
__initcall_end = .;
}

@@ -88,16 +83,18 @@ SECTIONS
__initramfs_start = .;
*(.init.ramfs)
__initramfs_end = .;
- /* We fill to the next page, so we can discard all init
- pages without needing to consider what payload might be
- appended to the kernel image. */
- FILL (0);
- . = ALIGN (8192);
}
#endif
-
__vmlinux_end = .; /* last address of the physical file */
- __init_end = .;
+
+ /*
+ * We fill to the next page, so we can discard all init
+ * pages without needing to consider what payload might be
+ * appended to the kernel image.
+ */
+ . = ALIGN(PAGE_SIZE);
+
+ __init_end = .;

__data_end = . ; /* Move to _edata ? */
__bss_start = .; /* BSS */
diff --git a/include/asm-cris/page.h b/include/asm-cris/page.h
index 0648e31..b84353e 100644
--- a/include/asm-cris/page.h
+++ b/include/asm-cris/page.h
@@ -4,14 +4,11 @@
#ifdef __KERNEL__

#include <asm/arch/page.h>
+#include <linux/const.h>

/* PAGE_SHIFT determines the page size */
#define PAGE_SHIFT 13
-#ifndef __ASSEMBLY__
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#else
-#define PAGE_SIZE (1 << PAGE_SHIFT)
-#endif
+#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))

#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
--
1.5.3.6.970.gd25430


/^JN - Jesper Nilsson
--
Jesper Nilsson -- [email protected]


2008-01-15 13:54:23

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

On Tue, Jan 15, 2008 at 02:36:24PM +0100, Jesper Nilsson wrote:
> - Move alignment to page size of init data outside ifdef for BLK_DEV_INITRD.
> The reservation up to page size of memory after init data was previously
> not done if BLK_DEV_INITRD was undefined.
> This caused a kernel oops when init memory pages were freed after startup,
> data placed in the same page as the last init memory would also be freed
> and reused, with disastrous results.
>
> - Use macros for initcalls and .text sections.
>
> - Replace hardcoded page size constant with PAGE_SIZE define.
>
> - Change include/asm-cris/page.h to use the _AC macro to instead
> of testing __ASSEMBLY__.

Looks good.

What about applying the same fixes/changes to v32?

It would btw. be nice to move the vmlinux.lds.S files to
arch/cris/kernel/.
Se how x86 handle build for two different bit sizes.

If this is done then cris is less awkward compared
to the other archs.

Sam

2008-01-15 14:23:31

by Jesper Nilsson

[permalink] [raw]
Subject: Re: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

On Tue, Jan 15, 2008 at 02:54:19PM +0100, Sam Ravnborg wrote:
> On Tue, Jan 15, 2008 at 02:36:24PM +0100, Jesper Nilsson wrote:
> > - Move alignment to page size of init data outside ifdef for BLK_DEV_INITRD.
> > The reservation up to page size of memory after init data was previously
> > not done if BLK_DEV_INITRD was undefined.
> > This caused a kernel oops when init memory pages were freed after startup,
> > data placed in the same page as the last init memory would also be freed
> > and reused, with disastrous results.
> >
> > - Use macros for initcalls and .text sections.
> >
> > - Replace hardcoded page size constant with PAGE_SIZE define.
> >
> > - Change include/asm-cris/page.h to use the _AC macro to instead
> > of testing __ASSEMBLY__.
>
> Looks good.

Thanks.

> What about applying the same fixes/changes to v32?

In the works.

> It would btw. be nice to move the vmlinux.lds.S files to
> arch/cris/kernel/.
> Se how x86 handle build for two different bit sizes.
>
> If this is done then cris is less awkward compared
> to the other archs.

That's a really good idea. I'll add that to my todo-list.

> Sam

/^JN - Jesper Nilsson
--
Jesper Nilsson -- [email protected]

2008-01-15 14:38:10

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

> > What about applying the same fixes/changes to v32?
>
> In the works.
>
> > It would btw. be nice to move the vmlinux.lds.S files to
> > arch/cris/kernel/.
> > Se how x86 handle build for two different bit sizes.
> >
> > If this is done then cris is less awkward compared
> > to the other archs.
>
> That's a really good idea. I'll add that to my todo-list.

Thanks Jesper.
It is good to see cris getting some love and care in the public!

Sam

2008-01-15 20:36:48

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

On Tue, 15 Jan 2008 14:36:24 +0100 Jesper Nilsson <[email protected]> wrote:

> - Move alignment to page size of init data outside ifdef for BLK_DEV_INITRD.
> The reservation up to page size of memory after init data was previously
> not done if BLK_DEV_INITRD was undefined.
> This caused a kernel oops when init memory pages were freed after startup,
> data placed in the same page as the last init memory would also be freed
> and reused, with disastrous results.

So this is a 2.6.24 thing?

> - Use macros for initcalls and .text sections.
>
> - Replace hardcoded page size constant with PAGE_SIZE define.
>
> - Change include/asm-cris/page.h to use the _AC macro to instead
> of testing __ASSEMBLY__.

Even though those are not.

2008-01-15 21:03:25

by Adrian Bunk

[permalink] [raw]
Subject: Re: [PATCH] CRIS v10: vmlinux.lds.S Fix kernel oops on boot and use common defines

On Tue, Jan 15, 2008 at 12:35:15PM -0800, Andrew Morton wrote:
> On Tue, 15 Jan 2008 14:36:24 +0100 Jesper Nilsson <[email protected]> wrote:
>
> > - Move alignment to page size of init data outside ifdef for BLK_DEV_INITRD.
> > The reservation up to page size of memory after init data was previously
> > not done if BLK_DEV_INITRD was undefined.
> > This caused a kernel oops when init memory pages were freed after startup,
> > data placed in the same page as the last init memory would also be freed
> > and reused, with disastrous results.
>
> So this is a 2.6.24 thing?

The cris architecture does not compile in Linus' tree since 2 or 3 years,
so there shouldn't be any hurry for any cris specific patches.

> > - Use macros for initcalls and .text sections.
> >
> > - Replace hardcoded page size constant with PAGE_SIZE define.
> >
> > - Change include/asm-cris/page.h to use the _AC macro to instead
> > of testing __ASSEMBLY__.
>
> Even though those are not.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed