hw/mips: align initrd to 64KB to avoid kernel error
PATCH 1/1 hw/mips: align initrd to 64KB to avoid kernel error
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new INITRD_PAGE_MASK rather than TARGET_PAGE_MASK.
--- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- include/hw/mips/mips.h | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-)
hw/mips/mips_fulong2e.c +1 -1
@@ -126,7 +126,7 @@ static int64_t load_kernel (CPUMIPSState *env)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",
hw/mips/mips_malta.c +1 -1
@@ -699,7 +699,7 @@ static int64_t load_kernel (void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",
hw/mips/mips_mipssim.c +1 -1
@@ -83,7 +83,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > loaderparams.ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",
hw/mips/mips_r4k.c +1 -1
@@ -102,7 +102,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",
include/hw/mips/mips.h +3 -0
@@ -2,6 +2,9 @@#define HW_MIPS_H /* Definitions for mips board emulation. */ +/* Kernels can be configured with 64KB pages */ +#define INITRD_PAGE_MASK (~((1 << 16) - 1)) +#include "exec/memory.h" /* gt64xxx.c */
Signature · 1 line
1.7.5.4
Quoted 6 lines · Leon Alrae
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new
INITRD_PAGE_MASKrather thanTARGET_PAGE_MASK.
This is kind of similar to the ARM bug fixed in 98ed805c3. I wonder if we ought to have a per-CPU #define for "largest possible page alignment for this architecture" as well as "smallest possible" (the latter being TARGET_PAGE_MASK).
This patch is a reasonable enough way to fix things though, so I'm not objecting to it.
Aside: given the repetitive nature of the context hunks observable in this patch, it looks like it ought to be possible to abstract out some of the initrd/kernel load code from all those boards...
thanks
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Leon Alrae
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new
INITRD_PAGE_MASKrather thanTARGET_PAGE_MASK.
Quoted 4 lines
This is kind of similar to the ARM bug fixed in
98ed805c3. I wonder if we ought to have a per-CPU #define for "largest possible page alignment for this architecture" as well as "smallest possible" (the latter beingTARGET_PAGE_MASK).
Yes, very similar. Although "largest possible" is probably quite Linux specific so I'm not sure where it should really go (some arches support pages up to 4MB and beyond, but obviously they're never used as basic pages by Linux).
LINUX_MAXPAGE_MASK?
Quoted 7 lines
This patch is a reasonable enough way to fix things though, so I'm not objecting to it.
Aside: given the repetitive nature of the context hunks observable in this patch, it looks like it ought to be possible to abstract out some of the initrd/kernel load code from all those boards...
That thought did occur to me too :)
Cheers
James
ping
http://patchwork.ozlabs.org/patch/255005/
Quoted 83 lines · Leon Alrae
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new
INITRD_PAGE_MASKrather thanTARGET_PAGE_MASK.Signed-off-by James Hogan <[email protected]>Signed-off-by Leon Alrae <[email protected]>--- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- include/hw/mips/mips.h | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-)hw/mips/mips_fulong2e.c +1
-1@@ -126,7 +126,7 @@ static int64_t load_kernel (CPUMIPSState *env)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_malta.c +1
-1@@ -699,7 +699,7 @@ static int64_t load_kernel (void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_mipssim.c +1
-1@@ -83,7 +83,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > loaderparams.ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_r4k.c +1
-1@@ -102,7 +102,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",include/hw/mips/mips.h +3
-0@@ -2,6 +2,9 @@#define HW_MIPS_H /* Definitions for mips board emulation. */ +/* Kernels can be configured with 64KB pages */ +#define INITRD_PAGE_MASK (~((1 << 16) - 1)) +#include "exec/memory.h" /* gt64xxx.c */
ping
Quoted 89 lines · Leon Alrae
ping
http://patchwork.ozlabs.org/patch/255005/
Quoted 83 lines · Leon Alrae
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new
INITRD_PAGE_MASKrather thanTARGET_PAGE_MASK.Signed-off-by James Hogan <[email protected]>Signed-off-by Leon Alrae <[email protected]>--- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- include/hw/mips/mips.h | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-)hw/mips/mips_fulong2e.c +1
-1@@ -126,7 +126,7 @@ static int64_t load_kernel (CPUMIPSState *env)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_malta.c +1
-1@@ -699,7 +699,7 @@ static int64_t load_kernel (void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_mipssim.c +1
-1@@ -83,7 +83,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > loaderparams.ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_r4k.c +1
-1@@ -102,7 +102,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",include/hw/mips/mips.h +3
-0@@ -2,6 +2,9 @@#define HW_MIPS_H /* Definitions for mips board emulation. */ +/* Kernels can be configured with 64KB pages */ +#define INITRD_PAGE_MASK (~((1 << 16) - 1)) +#include "exec/memory.h" /* gt64xxx.c */
Aurelien Jarno
AppliedQuoted 74 lines · Leon Alrae
From: James Hogan <[email protected]>
The Linux kernel can be configured to use 64KB pages, but it also requires initrd to be page aligned. Therefore, to be safe, align the initrd to 64KB using a new
INITRD_PAGE_MASKrather thanTARGET_PAGE_MASK.Signed-off-by James Hogan <[email protected]>Signed-off-by Leon Alrae <[email protected]>--- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- include/hw/mips/mips.h | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-)hw/mips/mips_fulong2e.c +1
-1@@ -126,7 +126,7 @@ static int64_t load_kernel (CPUMIPSState *env)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_malta.c +1
-1@@ -699,7 +699,7 @@ static int64_t load_kernel (void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_mipssim.c +1
-1@@ -83,7 +83,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > loaderparams.ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",hw/mips/mips_r4k.c +1
-1@@ -102,7 +102,7 @@ static int64_t load_kernel(void)if (loaderparams.initrd_filename) { initrd_size =get_image_size (loaderparams.initrd_filename);if (initrd_size >0 ) { - initrd_offset = (kernel_high + ~TARGET_PAGE_MASK ) &TARGET_PAGE_MASK ; + initrd_offset = (kernel_high + ~INITRD_PAGE_MASK ) &INITRD_PAGE_MASK ;if (initrd_offset + initrd_size > ram_size) { fprintf(stderr, "qemu: memory too small for initial ram disk '%s'\n",include/hw/mips/mips.h +0
-0
include/hw/mips/mips.h line 10
Quoted 9 lines
include/hw/mips/mips.h +3
-0@@ -2,6 +2,9 @@#define HW_MIPS_H /* Definitions for mips board emulation. */ +/* Kernels can be configured with 64KB pages */ +#define INITRD_PAGE_MASK (~((1 << 16) - 1)) +#include "exec/memory.h" /* gt64xxx.c */
Thanks, applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net