MIPS: fix mapstart when using initrd
PATCH 1/1 MIPS: fix mapstart when using initrd
When initrd is present in the PFN right after the _end, bootmem bitmap(mapstart) overwrites it. So check for initrd_end in mapstart calculation.
---
This is seen after the commit
"mips: fix start of free memory when using initrd"
in git://git.linux-mips.org/pub/scm/ralf/upstream-sfr.git branch
Tested the image on MIPS platform creating the above said scenario and initrd was corrupted.
arch/mips/kernel/setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/kernel/setup.c +5 -0
@@ -364,6 +364,11 @@ static void __init bootmem_init(void) }/* +* mapstart should be after initrd_end +*/ + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end))); + +/* * Initialize the boot-time allocator with low memory only. */ bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
Signature · 1 line
1.7.6
Quoted 11 lines · Ashok Kumar
Date: Mon, 23 Sep 2013 19:40:26 +0530
From: Ashok Kumar <[email protected]>
To: [email protected], [email protected]
cc: [email protected], Ashok Kumar <[email protected]>
Subject: [PATCH] MIPS: fix mapstart when using initrd
Content-Type: text/plainWhen initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.
Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
And it gloriously breaks the build if CONFIG_BLK_DEV_INITRD is disabled. Now most configurations will fail with something like:
[...]
LD vmlinuxarch/mips/built-in.o: In function `setup_arch':
(.init.text+0xff8): undefined reference to initrd_end' arch/mips/built-in.o: In function setup_arch':
(.init.text+0xffc): undefined reference to `initrd_end' make[2]: *** [vmlinux] Error 1
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/home/ralf/src/linux/obj/lasat-build'
Ralf
Quoted 35 lines · Ralf Baechle
Quoted 11 lines · Ashok Kumar
Date: Mon, 23 Sep 2013 19:40:26 +0530
From: Ashok Kumar <[email protected]>
To: [email protected], [email protected]
cc: [email protected], Ashok Kumar <[email protected]>
Subject: [PATCH] MIPS: fix mapstart when using initrd
Content-Type: text/plainWhen initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
And it gloriously breaks the build if
CONFIG_BLK_DEV_INITRDis disabled. Now most configurations will fail with something like:[...]
LD vmlinuxarch/mips/built-in.o: In function `setup_arch':
(.init.text+0xff8): undefined reference toinitrd_end' arch/mips/built-in.o: In functionsetup_arch':
(.init.text+0xffc): undefined reference to `initrd_end' make[2]: *** [vmlinux] Error 1
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/home/ralf/src/linux/obj/lasat-build'
Quoted 2 lines
Ralf
Hi Ralf,
I just sent a patch for that
Quoted 36 lines · Markos Chandras
Quoted 35 lines · Ralf Baechle
Quoted 11 lines · Ashok Kumar
Date: Mon, 23 Sep 2013 19:40:26 +0530
From: Ashok Kumar <[email protected]>
To: [email protected], [email protected]
cc: [email protected], Ashok Kumar <[email protected]>
Subject: [PATCH] MIPS: fix mapstart when using initrd
Content-Type: text/plainWhen initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
And it gloriously breaks the build if
CONFIG_BLK_DEV_INITRDis disabled. Now most configurations will fail with something like:[...]
LD vmlinuxarch/mips/built-in.o: In function `setup_arch':
(.init.text+0xff8): undefined reference toinitrd_end' arch/mips/built-in.o: In functionsetup_arch':
(.init.text+0xffc): undefined reference to `initrd_end' make[2]: *** [vmlinux] Error 1
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/home/ralf/src/linux/obj/lasat-build'
Quoted 7 lines
Quoted 2 lines
Ralf
Hi Ralf,
I just sent a patch for that
Yes, I noticed that. I folded that into Greg's original patch as well.
And now back to the scheduled development program :)
Btw, brownie points for an #ifdef-less fix ...
Ralf
Quoted 4 lines · Ashok Kumar
When initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.
Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
Unfortunately this commit breaks booting ramdisk images on bcm63xx, at least git bisect claims it to be responsible for:
Closing DMA Channels.
Starting program at 0x80284b60
[ 0.000000] Linux version 3.12.0-rc4+ (jonas@ixxyvirt) (gcc version
4.8.) #254 SMP Mon Oct 14 13:12:35 CEST 2013
[ 0.000000] Detected Broadcom 0x6328 CPU revision b0
[ 0.000000] CPU frequency is 320 MHz
[ 0.000000] 128MB of RAM installed
[ 0.000000] registering 32 GPIOs
[ 0.000000] board_bcm963xx: CFE version: 1.0.37-106.17
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU revision is: 0002a075 (Broadcom BMIPS4350)
[ 0.000000] board_bcm963xx: board name: 96328avng
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 08000000 @ 00000000 (usable)
**Exception 8: EPC=00000000, Cause=00000000 (Interrupt)
RA=00000000, VAddr=00000000
0 ($00) = 8016E5F4 AT ($01) = 00000000
v0 ($02) = 00000000 v1 ($03) = 0000000A
a0 ($04) = FFFFFFFF a1 ($05) = 0006FFFF
a2 ($06) = 00000000 a3 ($07) = 803D6730
t0 ($08) = 0000002A t1 ($09) = 00000000
t2 ($10) = 802D5203 t3 ($11) = 8029D2F8
t4 ($12) = 803D6737 t5 ($13) = 802D5203
t6 ($14) = 00000000 t7 ($15) = 8030BD68
s0 ($16) = 8016E5F4 s1 ($17) = 803D6737
s2 ($18) = 802D5203 s3 ($19) = 8029D2F8
s4 ($20) = 8030BD90 s5 ($21) = 8016E5F4
s6 ($22) = 00000001 s7 ($23) = 803D6730
t8 ($24) = 0000000A t9 ($25) = FFFFFFFF
k0 ($26) = 0006FFFF k1 ($27) = 8016EF08
gp ($28) = 803F0000 sp ($29) = 8001DAC0
fp ($30) = 0000001D ra ($31) = 00000000Probably relevant config parts are:
CONFIG_BLK_DEV_INITRD=y CONFIG_INITRAMFS_SOURCE="/home/jonas/openwrt/trunk/build_dir/target-mips_mips32_uClibc-0.9.33.2/root-brcm63xx /home/jonas/openwrt/trunk/target/linux/generic/image/initramfs-base-files.txt" CONFIG_INITRAMFS_ROOT_UID=1000CONFIG_INITRAMFS_ROOT_GID=1000
# CONFIG_RD_GZIP is not set
# CONFIG_RD_BZIP2 is not set
# CONFIG_RD_LZMA is not setCONFIG_RD_XZ=y
# CONFIG_RD_LZO is not set
# CONFIG_RD_LZ4 is not set
# CONFIG_INITRAMFS_COMPRESSION_NONE is not setCONFIG_INITRAMFS_COMPRESSION_XZ=y
Quoted 8 lines
arch/mips/kernel/setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)arch/mips/kernel/setup.c +0
-0
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 369
Quoted 6 lines
arch/mips/kernel/setup.c +3
-0@@ -364,6 +364,11 @@ static void __init bootmem_init(void) }/* +* mapstart should be after initrd_end +*/ + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end)));
I wonder if this still holds if the initrd is compressed like in my config, but that's just random guessing. I can't test it since I need a compressed initrd, else the elf gets too big for CFE.
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 374
Quoted 5 lines
arch/mips/kernel/setup.c +2
-0+ +/* * Initialize the boot-time allocator with low memory only. */ bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
Regards
Jonas
Quoted 78 lines · Jonas Gorski
Quoted 4 lines · Ashok Kumar
When initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
Unfortunately this commit breaks booting ramdisk images on bcm63xx, at least git bisect claims it to be responsible for:
Closing DMA Channels.
Starting program at0x80284b60[ 0.000000] Linux version 3.12.0-rc4+ (jonas@ixxyvirt) (gcc version 4.8.) #254 SMP Mon Oct 14 13:12:35 CEST 2013 [ 0.000000] Detected Broadcom 0x6328 CPU revision b0 [ 0.000000] CPU frequency is 320 MHz [ 0.000000] 128MB of RAM installed [ 0.000000] registering 32 GPIOs [ 0.000000] board_bcm963xx: CFE version: 1.0.37-106.17 [ 0.000000] bootconsole [early0] enabled [ 0.000000] CPU revision is: 0002a075 (Broadcom BMIPS4350) [ 0.000000] board_bcm963xx: board name: 96328avng [ 0.000000] Determined physical RAM map: [ 0.000000] memory: 08000000 @ 00000000 (usable) **Exception 8: EPC=00000000, Cause=00000000 (Interrupt) RA=00000000, VAddr=00000000 0 ($00) = 8016E5F4 AT ($01) = 00000000 v0 ($02) = 00000000 v1 ($03) = 0000000A a0 ($04) = FFFFFFFF a1 ($05) = 0006FFFF a2 ($06) = 00000000 a3 ($07) = 803D6730 t0 ($08) = 0000002A t1 ($09) = 00000000 t2 ($10) = 802D5203 t3 ($11) = 8029D2F8 t4 ($12) = 803D6737 t5 ($13) = 802D5203 t6 ($14) = 00000000 t7 ($15) = 8030BD68 s0 ($16) = 8016E5F4 s1 ($17) = 803D6737 s2 ($18) = 802D5203 s3 ($19) = 8029D2F8 s4 ($20) = 8030BD90 s5 ($21) = 8016E5F4 s6 ($22) = 00000001 s7 ($23) = 803D6730 t8 ($24) = 0000000A t9 ($25) = FFFFFFFF k0 ($26) = 0006FFFF k1 ($27) = 8016EF08 gp ($28) = 803F0000 sp ($29) = 8001DAC0 fp ($30) = 0000001D ra ($31) = 00000000Probably relevant config parts are:
CONFIG_BLK_DEV_INITRD=yCONFIG_INITRAMFS_SOURCE="/home/jonas/openwrt/trunk/build_dir/target-mips_mips32_uClibc-0.9.33.2/root-brcm63xx/home/jonas/openwrt/trunk/target/linux/generic/image/initramfs-base-files.txt"CONFIG_INITRAMFS_ROOT_UID=1000CONFIG_INITRAMFS_ROOT_GID=1000
#CONFIG_RD_GZIPis not set
#CONFIG_RD_BZIP2is not set
#CONFIG_RD_LZMAis not setCONFIG_RD_XZ=y
#CONFIG_RD_LZOis not set
#CONFIG_RD_LZ4is not set
#CONFIG_INITRAMFS_COMPRESSION_NONEis not setCONFIG_INITRAMFS_COMPRESSION_XZ=yQuoted 10 lines
arch/mips/kernel/setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)arch/mips/kernel/setup.c +0
-0@@ -364,6 +364,11 @@ static void __init bootmem_init(void) }
Quoted 8 lines
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 369
Quoted 4 lines
arch/mips/kernel/setup.c +3
-0/* +* mapstart should be after initrd_end +*/ + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end)));I wonder if this still holds if the initrd is compressed like in my config, but that's just random guessing. I can't test it since I need a compressed initrd, else the elf gets too big for CFE.
when initramfs(compressed/uncompressed) is used and initrd is not used, initrd_end should be zero. In 32-bit kernel __pa(0) becomes 0x80000000 and mapstart points to wrong address. Added check for non zero initrd_end before finding max.
I have tested the below patch on XLP 32-bit BE/LE, 64-bit BE/LE and it works fine. could you please test this on your bcm63xx board.
arch/mips/kernel/setup.c +2 -2
@@ -367,7 +367,8 @@ static void __init bootmem_init(void)/* * mapstart should be after initrd_end */ - mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end))); +if (initrd_end) + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end)));#endif - Ashok
Quoted 11 lines
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 374
Quoted 6 lines
arch/mips/kernel/setup.c +2
-0+ +/* * Initialize the boot-time allocator with low memory only. */ bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,Regards
Jonas
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jonas Gorski
Tested-byQuoted 101 lines · Ashok Kumar
Quoted 78 lines · Jonas Gorski
Quoted 4 lines · Ashok Kumar
When initrd is present in the PFN right after the
_end, bootmem bitmap(mapstart) overwrites it. So check forinitrd_endin mapstart calculation.Quoted 8 lines
Signed-off-by Ashok Kumar <[email protected]>---
This is seen after the commit
"mips: fix start of free memory when using initrd"
ingit://git.linux-mips.org/pub/scm/ralf/upstream-sfr.gitbranchTested the image on MIPS platform creating the above said scenario and initrd was corrupted.
Unfortunately this commit breaks booting ramdisk images on bcm63xx, at least git bisect claims it to be responsible for:
Closing DMA Channels.
Starting program at0x80284b60[ 0.000000] Linux version 3.12.0-rc4+ (jonas@ixxyvirt) (gcc version 4.8.) #254 SMP Mon Oct 14 13:12:35 CEST 2013 [ 0.000000] Detected Broadcom 0x6328 CPU revision b0 [ 0.000000] CPU frequency is 320 MHz [ 0.000000] 128MB of RAM installed [ 0.000000] registering 32 GPIOs [ 0.000000] board_bcm963xx: CFE version: 1.0.37-106.17 [ 0.000000] bootconsole [early0] enabled [ 0.000000] CPU revision is: 0002a075 (Broadcom BMIPS4350) [ 0.000000] board_bcm963xx: board name: 96328avng [ 0.000000] Determined physical RAM map: [ 0.000000] memory: 08000000 @ 00000000 (usable) **Exception 8: EPC=00000000, Cause=00000000 (Interrupt) RA=00000000, VAddr=00000000 0 ($00) = 8016E5F4 AT ($01) = 00000000 v0 ($02) = 00000000 v1 ($03) = 0000000A a0 ($04) = FFFFFFFF a1 ($05) = 0006FFFF a2 ($06) = 00000000 a3 ($07) = 803D6730 t0 ($08) = 0000002A t1 ($09) = 00000000 t2 ($10) = 802D5203 t3 ($11) = 8029D2F8 t4 ($12) = 803D6737 t5 ($13) = 802D5203 t6 ($14) = 00000000 t7 ($15) = 8030BD68 s0 ($16) = 8016E5F4 s1 ($17) = 803D6737 s2 ($18) = 802D5203 s3 ($19) = 8029D2F8 s4 ($20) = 8030BD90 s5 ($21) = 8016E5F4 s6 ($22) = 00000001 s7 ($23) = 803D6730 t8 ($24) = 0000000A t9 ($25) = FFFFFFFF k0 ($26) = 0006FFFF k1 ($27) = 8016EF08 gp ($28) = 803F0000 sp ($29) = 8001DAC0 fp ($30) = 0000001D ra ($31) = 00000000Probably relevant config parts are:
CONFIG_BLK_DEV_INITRD=yCONFIG_INITRAMFS_SOURCE="/home/jonas/openwrt/trunk/build_dir/target-mips_mips32_uClibc-0.9.33.2/root-brcm63xx/home/jonas/openwrt/trunk/target/linux/generic/image/initramfs-base-files.txt"CONFIG_INITRAMFS_ROOT_UID=1000CONFIG_INITRAMFS_ROOT_GID=1000
#CONFIG_RD_GZIPis not set
#CONFIG_RD_BZIP2is not set
#CONFIG_RD_LZMAis not setCONFIG_RD_XZ=y
#CONFIG_RD_LZOis not set
#CONFIG_RD_LZ4is not set
#CONFIG_INITRAMFS_COMPRESSION_NONEis not setCONFIG_INITRAMFS_COMPRESSION_XZ=yQuoted 10 lines
arch/mips/kernel/setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)arch/mips/kernel/setup.c +0
-0@@ -364,6 +364,11 @@ static void __init bootmem_init(void) }Quoted 8 lines
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 369
Quoted 4 lines
arch/mips/kernel/setup.c +3
-0/* +* mapstart should be after initrd_end +*/ + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end)));I wonder if this still holds if the initrd is compressed like in my config, but that's just random guessing. I can't test it since I need a compressed initrd, else the elf gets too big for CFE.
when initramfs(compressed/uncompressed) is used and initrd is not used,
initrd_endshould be zero. In 32-bit kernel__pa(0)becomes0x80000000and mapstart points to wrong address. Added check for non zeroinitrd_endbefore finding max.I have tested the below patch on XLP 32-bit BE/LE, 64-bit BE/LE and it works fine. could you please test this on your bcm63xx board.
arch/mips/kernel/setup.c +0
-0
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 372
Quoted 7 lines
arch/mips/kernel/setup.c +2
-1@@ -367,7 +367,8 @@ static void __init bootmem_init(void)/* * mapstart should be after initrd_end */ - mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end))); +if (initrd_end) + mapstart =max (mapstart, (unsigned long )PFN_UP (__pa (initrd_end)));#endif
I came to the same conclusion/fix yesterday evening, so I can confirm this fixes it. I was just a bit inebriated at that time, and I didn't want to drink and submit ;). So
Thanks,
Jonas
Quoted 16 lines
arch/mips/kernel/setup.c +0
-1- AshokQuoted 11 lines
arch/mips/kernel/setup.c static void __init bootmem_init(void) · line 374
Quoted 6 lines
arch/mips/kernel/setup.c +2
-0+ +/* * Initialize the boot-time allocator with low memory only. */ bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,Regards
Jonas