Skip to contentSkip to conversation

hw/mips: align initrd to 64KB to avoid kernel error

PATCH Applied Leon Alrae 4 participants 6 messages Jun 27, 2013 – Jul 28, 2013

lore
Share & tools
lore

Leon Alrae

author
#0 lore raw

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
index 1aac93a..c03a4f2 100644
@@ -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
index 5033d51..526a122 100644
@@ -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
index d1681ec..3f54e64 100644
@@ -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
index 4646ab6..fb7eb14 100644
@@ -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
index 291e85f..2a7a9c9 100644
@@ -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
#1 lore raw
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_MASK rather than TARGET_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

#2 lore raw
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_MASK rather than TARGET_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 being TARGET_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

author
#3 lore raw
In reply to 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_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
index 1aac93a..c03a4f2 100644
@@ -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
index 5033d51..526a122 100644
@@ -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
index d1681ec..3f54e64 100644
@@ -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
index 4646ab6..fb7eb14 100644
@@ -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
index 291e85f..2a7a9c9 100644
@@ -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 */
author
#4 lore raw

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_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
index 1aac93a..c03a4f2 100644
@@ -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
index 5033d51..526a122 100644
@@ -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
index d1681ec..3f54e64 100644
@@ -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
index 4646ab6..fb7eb14 100644
@@ -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
index 291e85f..2a7a9c9 100644
@@ -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 */
#5 lore raw
In reply to Leon Alrae
Quoted 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_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
index 1aac93a..c03a4f2 100644
@@ -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
index 5033d51..526a122 100644
@@ -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
index d1681ec..3f54e64 100644
@@ -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
index 4646ab6..fb7eb14 100644
@@ -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
index 291e85f..2a7a9c9 100644

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