Skip to contentSkip to conversation

hw/i386/pc: run the multiboot loader before the PVH loader

PATCH In review Stefano Garzarella 4 participants 4 messages Feb 14, 2019 – Mar 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i386/pc: run the multiboot loader before the PVH loader

Some multiboot images could be in the ELF format. In the current implementation QEMU fails because we try to load these images as a PVH image.

In order to fix this issue, we should try multiboot first (we already check the multiboot magic header before to load it). If it is not a multiboot image, we can try the PVH loader.

Fixes ab969087da6 ("pvh: Boot uncompressed kernel using direct boot ABI", 2019-01-15)
---
 hw/i386/pc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
hw/i386/pc.c +11 -6
index 3889eccdc3..207c267093 100644
@@ -1209,6 +1209,17 @@ static void load_linux(PCMachineState *pcms,
     if (ldl_p(header+0x202) == 0x53726448) {
         protocol = lduw_p(header+0x206);
     } else {
+        /*
+         * This could be a multiboot kernel. If it is, let's stop treating it
+         * like a Linux kernel.
+         * Note: some multiboot images could be in the ELF format (the same of
+         * PVH), so we try multiboot first since we check the multiboot magic
+         * header before to load it.
+         */
+        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
+            return;
+        }
         /*
          * Check if the file is an uncompressed kernel file (ELF) and load it,
          * saving the PVH entry point used by the x86/HVM direct boot ABI.
@@ -1262,12 +1273,6 @@ static void load_linux(PCMachineState *pcms,
 
             return;
         }
-        /* This looks like a multiboot kernel. If it is, let's stop
-           treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header)) {
-            return;
-        }
         protocol = 0;
     }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stefano Garzarella

Some multiboot images could be in the ELF format. In the current implementation QEMU fails because we try to load these images as a PVH image.

In order to fix this issue, we should try multiboot first (we already check the multiboot magic header before to load it). If it is not a multiboot image, we can try the PVH loader.

Fixes ab969087da6 ("pvh: Boot uncompressed kernel using direct boot ABI", 2019-01-15)

Paolo can you pls merge since you did the pvh things?

Quoted 41 lines
---
 hw/i386/pc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
hw/i386/pc.c +11 -6
index 3889eccdc3..207c267093 100644
@@ -1209,6 +1209,17 @@ static void load_linux(PCMachineState *pcms,
     if (ldl_p(header+0x202) == 0x53726448) {
         protocol = lduw_p(header+0x206);
     } else {
+        /*
+         * This could be a multiboot kernel. If it is, let's stop treating it
+         * like a Linux kernel.
+         * Note: some multiboot images could be in the ELF format (the same of
+         * PVH), so we try multiboot first since we check the multiboot magic
+         * header before to load it.
+         */
+        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
+            return;
+        }
         /*
          * Check if the file is an uncompressed kernel file (ELF) and load it,
          * saving the PVH entry point used by the x86/HVM direct boot ABI.
@@ -1262,12 +1273,6 @@ static void load_linux(PCMachineState *pcms,
 
             return;
         }
-        /* This looks like a multiboot kernel. If it is, let's stop
-           treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header)) {
-            return;
-        }
         protocol = 0;
     }
 
Signature · 1 line
2.20.1
#2 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Stefano Garzarella

Some multiboot images could be in the ELF format. In the current implementation QEMU fails because we try to load these images as a PVH image.

In order to fix this issue, we should try multiboot first (we already check the multiboot magic header before to load it). If it is not a multiboot image, we can try the PVH loader.

Quoted 7 lines
Quoted 3 lines
Fixes ab969087da6 ("pvh: Boot uncompressed kernel using direct boot ABI", 2019-01-15)

Paolo can you pls merge since you did the pvh things?

Yes, queued.

Paolo

Quoted 41 lines
Quoted 41 lines
---
 hw/i386/pc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
hw/i386/pc.c +11 -6
index 3889eccdc3..207c267093 100644
@@ -1209,6 +1209,17 @@ static void load_linux(PCMachineState *pcms,
     if (ldl_p(header+0x202) == 0x53726448) {
         protocol = lduw_p(header+0x206);
     } else {
+        /*
+         * This could be a multiboot kernel. If it is, let's stop treating it
+         * like a Linux kernel.
+         * Note: some multiboot images could be in the ELF format (the same of
+         * PVH), so we try multiboot first since we check the multiboot magic
+         * header before to load it.
+         */
+        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
+            return;
+        }
         /*
          * Check if the file is an uncompressed kernel file (ELF) and load it,
          * saving the PVH entry point used by the x86/HVM direct boot ABI.
@@ -1262,12 +1273,6 @@ static void load_linux(PCMachineState *pcms,
 
             return;
         }
-        /* This looks like a multiboot kernel. If it is, let's stop
-           treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header)) {
-            return;
-        }
         protocol = 0;
     }
 
Signature · 1 line
2.20.1
Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Stefano Garzarella
Quoted 11 lines · Stefano Garzarella

Some multiboot images could be in the ELF format. In the current implementation QEMU fails because we try to load these images as a PVH image.

In order to fix this issue, we should try multiboot first (we already check the multiboot magic header before to load it). If it is not a multiboot image, we can try the PVH loader.

Fixes ab969087da6 ("pvh: Boot uncompressed kernel using direct boot ABI", 2019-01-15)
Quoted 28 lines
---
 hw/i386/pc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
hw/i386/pc.c +11 -0
index 3889eccdc3..207c267093 100644
@@ -1209,6 +1209,17 @@ static void load_linux(PCMachineState *pcms,
     if (ldl_p(header+0x202) == 0x53726448) {
         protocol = lduw_p(header+0x206);
     } else {
+        /*
+         * This could be a multiboot kernel. If it is, let's stop treating it
+         * like a Linux kernel.
+         * Note: some multiboot images could be in the ELF format (the same of
+         * PVH), so we try multiboot first since we check the multiboot magic
+         * header before to load it.
+         */
+        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
+            return;
+        }
         /*
          * Check if the file is an uncompressed kernel file (ELF) and load it,
          * saving the PVH entry point used by the x86/HVM direct boot ABI.
@@ -1262,12 +1273,6 @@ static void load_linux(PCMachineState *pcms,
 

hw/i386/pc.c static void load_linux(PCMachineState *pcms, · line 1277

Quoted 10 lines
hw/i386/pc.c +0 -6
             return;
         }
-        /* This looks like a multiboot kernel. If it is, let's stop
-           treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header)) {
-            return;
-        }
         protocol = 0;
     }

--
Alex Bennée