From: Geert Uytterhoeven <[email protected]>
On recent kernels, I get the following error when using an initrd:
| initrd overwritten (0x00b78000 < 0x07668000) - disabling it.
My Amiga 4000 has 12 MiB of RAM at physical address 0x07400000 (virtual
0x00000000).
The initrd is located at the end of RAM: 0x00b78000 - 0x00c00000 (virtual).
The overwrite test compares the (virtual) initrd location to the (physical)
first available memory location, which fails.
This patch converts initrd_start to a page frame number, so it can safely be
compared with min_low_pfn.
Before the introduction of discontiguous memory support on m68k
(12d810c1b8c2b913d48e629e2b5c01d105029839), min_low_pfn was just left
untouched by the m68k-specific code (zero, I guess), and everything worked
fine.
Signed-off-by: Geert Uytterhoeven <[email protected]>
---
On several platforms, initrd_below_start_ok is set to 1:
| arch/mips/kernel/setup.c: initrd_below_start_ok = 1;
| arch/parisc/mm/init.c: initrd_below_start_ok = 1;
| arch/powerpc/kernel/prom.c: initrd_below_start_ok = 1;
| arch/ppc/platforms/hdpu.c: initrd_below_start_ok = 1;
| arch/xtensa/kernel/setup.c: initrd_below_start_ok = 1;
Some of these may be workarounds for this bug. Please check.
init/main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--- a/init/main.c
+++ b/init/main.c
@@ -630,9 +630,10 @@ asmlinkage void __init start_kernel(void
#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start && !initrd_below_start_ok &&
- initrd_start < min_low_pfn << PAGE_SHIFT) {
+ page_to_pfn(virt_to_page(initrd_start)) < min_low_pfn) {
printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
- "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
+ "disabling it.\n",
+ page_to_pfn(virt_to_page(initrd_start)), min_low_pfn);
initrd_start = 0;
}
#endif
--
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Thu, 17 Jul 2008 21:16:36 +0200, Geert Uytterhoeven <[email protected]> wrote:
> if (initrd_start && !initrd_below_start_ok &&
> - initrd_start < min_low_pfn << PAGE_SHIFT) {
> + page_to_pfn(virt_to_page(initrd_start)) < min_low_pfn) {
> printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
> - "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
> + "disabling it.\n",
> + page_to_pfn(virt_to_page(initrd_start)), min_low_pfn);
> initrd_start = 0;
> }
This patch causes warnings on mips:
linux/init/main.c: In function 'start_kernel':
linux/init/main.c:633: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
linux/init/main.c:636: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
Because an argument of mips virt_to_phys() is an pointer and
initrd_start is unsigned long. It seems most (all?) arch's
virt_to_phys() casts its argument to unsigned long internally. Should
mips follow?
---
Atsushi Nemoto
Hi Nemoto-san,
On Fri, 25 Jul 2008, Atsushi Nemoto wrote:
> On Thu, 17 Jul 2008 21:16:36 +0200, Geert Uytterhoeven <[email protected]> wrote:
> > if (initrd_start && !initrd_below_start_ok &&
> > - initrd_start < min_low_pfn << PAGE_SHIFT) {
> > + page_to_pfn(virt_to_page(initrd_start)) < min_low_pfn) {
> > printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
> > - "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
> > + "disabling it.\n",
> > + page_to_pfn(virt_to_page(initrd_start)), min_low_pfn);
> > initrd_start = 0;
> > }
>
> This patch causes warnings on mips:
>
> linux/init/main.c: In function 'start_kernel':
> linux/init/main.c:633: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
> linux/init/main.c:636: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
>
> Because an argument of mips virt_to_phys() is an pointer and
> initrd_start is unsigned long. It seems most (all?) arch's
> virt_to_phys() casts its argument to unsigned long internally. Should
> mips follow?
Alternatively, as initrd_start is really a virtual kernel address,
perhaps it should be changed from unsigned long to void * instead?
It's cast to `void *' in several place. arch/xtensa/kernel/setup.c even
has `extern void *initrd_start' to fool around this?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Thu, 24 Jul 2008 20:49:27 +0200 (CEST), Geert Uytterhoeven <[email protected]> wrote:
> > Because an argument of mips virt_to_phys() is an pointer and
> > initrd_start is unsigned long. It seems most (all?) arch's
> > virt_to_phys() casts its argument to unsigned long internally. Should
> > mips follow?
>
> Alternatively, as initrd_start is really a virtual kernel address,
> perhaps it should be changed from unsigned long to void * instead?
>
> It's cast to `void *' in several place. arch/xtensa/kernel/setup.c even
> has `extern void *initrd_start' to fool around this?
I agree it would make code cleaner, but the conversion might be
somewhat hard.
If we converted initrd_start (and initrd_end) to void *, we should
also convert INITRD_START, free_initrd_mem(), some other arch specific
local/global variables and printk format strings. Also code like
"initrd_start & PAGE_MASK" should be changed too...
Is it worth to do?
---
Atsushi Nemoto
On Sat, 26 Jul 2008, Atsushi Nemoto wrote:
> On Thu, 24 Jul 2008 20:49:27 +0200 (CEST), Geert Uytterhoeven <[email protected]> wrote:
> > > Because an argument of mips virt_to_phys() is an pointer and
> > > initrd_start is unsigned long. It seems most (all?) arch's
> > > virt_to_phys() casts its argument to unsigned long internally. Should
> > > mips follow?
> >
> > Alternatively, as initrd_start is really a virtual kernel address,
> > perhaps it should be changed from unsigned long to void * instead?
> >
> > It's cast to `void *' in several place. arch/xtensa/kernel/setup.c even
> > has `extern void *initrd_start' to fool around this?
>
> I agree it would make code cleaner, but the conversion might be
> somewhat hard.
>
> If we converted initrd_start (and initrd_end) to void *, we should
> also convert INITRD_START, free_initrd_mem(), some other arch specific
> local/global variables and printk format strings. Also code like
> "initrd_start & PAGE_MASK" should be changed too...
>
> Is it worth to do?
Maybe not.
Several free_initrd_mem() implementations (including the mips one, which
has to call virt_to_phys()) just cast the parameters to `void *'.
Others call free_area() or free_init_pages() (other callers of these have to
cast `void *' to `unsigned long'!).
Further, we have:
memset((void *)initrd_start, 0, initrd_end - initrd_start);
I agree `unsigned long' is nicer for `for (; start < end; start +=
PAGE_SIZE)' loops and `initrd_start & PAGE_MASK' (don't we have a macro
for that?), though.
So there's definitely room for a small janitors project...
Probably the best short term solution is to make mips' virt_to_page()
cast to `unsigned long' internally, like the other platforms.
Alternatively, you can try the patch below (compile-tested on mips :-),
which does add a cast to the generic code.
Subject: [PATCH] initrd: cast `initrd_start' to `void *'
commit fb6624ebd912e3d6907ca6490248e73368223da9 (initrd: Fix virtual/physical
mix-up in overwrite test) introduced the compiler warning below on mips,
as its virt_to_page() doesn't cast the passed address to unsigned long
internally, unlike on most other architectures:
init/main.c: In function ‘start_kernel’:
init/main.c:633: warning: passing argument 1 of ‘virt_to_phys’ makes pointer from integer without a cast
init/main.c:636: warning: passing argument 1 of ‘virt_to_phys’ makes pointer from integer without a cast
For now, kill the warning by explicitly casting initrd_start to `void *', as
that's the type it should really be.
Noticed by Atsushi Nemoto <[email protected]>
Signed-off-by: Geert Uytterhoeven <[email protected]>
diff --git a/init/main.c b/init/main.c
index 756eca4..525b2ac 100644
--- a/init/main.c
+++ b/init/main.c
@@ -630,10 +630,11 @@ asmlinkage void __init start_kernel(void)
#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start && !initrd_below_start_ok &&
- page_to_pfn(virt_to_page(initrd_start)) < min_low_pfn) {
+ page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
"disabling it.\n",
- page_to_pfn(virt_to_page(initrd_start)), min_low_pfn);
+ page_to_pfn(virt_to_page((void *)initrd_start)),
+ min_low_pfn);
initrd_start = 0;
}
#endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Fri, 25 Jul 2008 21:22:20 +0200 (CEST), Geert Uytterhoeven <[email protected]> wrote:
> So there's definitely room for a small janitors project...
>
> Probably the best short term solution is to make mips' virt_to_page()
> cast to `unsigned long' internally, like the other platforms.
>
> Alternatively, you can try the patch below (compile-tested on mips :-),
> which does add a cast to the generic code.
Thanks, I prefer this one for short term solution, while I think
explicit argument type would be better in general.
---
Atsushi Nemoto