Skip to contentSkip to conversation

pvh: add new PVH option rom

PATCH In review Stefano Garzarella 4 participants 16 messages Jan 18, 2019 – Jan 22, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

v5 cover pvh: add new PVH option rom

This patch series is based on "[PATCH v3 0/4] QEMU changes to do PVH boot" and provides a PVH option rom that can be used with SeaBIOS to boot uncompressed kernel using the x86/HVM direct boot ABI.

Patches 1 and 2 are to prepare the PVH option rom, moving common functions in the new headers. Patch 3 adds the new PVH option rom. Patch 4 uses it when we are booting an uncompressed kernel using the x86/HVM direct boot ABI. Patch 5 adds the support of loading the initrd in the PVH option rom.

Based-on: <[email protected]>

Changes in v5:
- Patch 5: added R-b's
- Patch 3: updated .gitignore (by Liam)

Changes in v4:
- addressed comments by Paolo:
- Patch 2: linuxboot_dma.c: moved includes after the asm block to avoid compiler error
- Patch 3: Makefile: fixed pvh.img rule

Changes in v3:
- added R-b's
- added Patch 5 to support initrd
- addressed comments by Eric and Liam:
- Patch 3: comments by Liam
- Patch 4: moved Based-on tag in the cover letter (by Eric)
- Patch 3: added pc-bios/pvh.bin binary in the commit

Changes in v2:
- addressed comments by Stefan and Eric:
- Patch 2: moved inludes on top of linuxboot_dma.c and add <stdint.h> in optrom.h
- Patch 4: added check of pvh.bin in xen_load_linux()
- modified commit message of patch 2 to explain better the patch

Stefano Garzarella (5):
linuxboot_dma: remove duplicate definitions of FW_CFG
linuxboot_dma: move common functions in a new header
optionrom: add new PVH option rom hw/i386/pc: use PVH option rom optionrom/pvh: load initrd from fw_cfg

 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |   5 +
 pc-bios/optionrom/Makefile        |   5 +-
 pc-bios/optionrom/linuxboot_dma.c | 114 +++--------------
 pc-bios/optionrom/optrom.h        | 110 ++++++++++++++++
 pc-bios/optionrom/optrom_fw_cfg.h |  92 ++++++++++++++
 pc-bios/optionrom/pvh.S           | 200 ++++++++++++++++++++++++++++++
 pc-bios/optionrom/pvh_main.c      | 133 ++++++++++++++++++++
 pc-bios/pvh.bin                   | Bin 0 -> 1536 bytes
 10 files changed, 568 insertions(+), 97 deletions(-)
 create mode 100644 pc-bios/optionrom/optrom.h
 create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h
 create mode 100644 pc-bios/optionrom/pvh.S
 create mode 100644 pc-bios/optionrom/pvh_main.c
 create mode 100644 pc-bios/pvh.bin
Signature · 1 line
2.20.1
#1 lore raw

PATCH v5 1/5 linuxboot_dma: remove duplicate definitions of FW_CFG

FW_CFG_DMA_CTL_* bits and struct fw_cfg_dma_access are defined in the qemu_fw_cfg.h header file already included in linuxboot_dma.c, so we can remove the definition of BIOS_CFG_DMA_CTL_* and struct FWCfgDmaAccess.

---
 pc-bios/optionrom/linuxboot_dma.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
pc-bios/optionrom/linuxboot_dma.c +4 -16
index d856d41b55..f728dc839f 100644
@@ -58,12 +58,6 @@ asm(
 "   jmp load_kernel\n"
 );
 
-/* QEMU_CFG_DMA_CONTROL bits */
-#define BIOS_CFG_DMA_CTL_ERROR   0x01
-#define BIOS_CFG_DMA_CTL_READ    0x02
-#define BIOS_CFG_DMA_CTL_SKIP    0x04
-#define BIOS_CFG_DMA_CTL_SELECT  0x08
-
 #define BIOS_CFG_DMA_ADDR_HIGH 0x514
 #define BIOS_CFG_DMA_ADDR_LOW  0x518
 
@@ -75,12 +69,6 @@ asm(
 
 #define barrier() asm("" : : : "memory")
 
-typedef struct FWCfgDmaAccess {
-    uint32_t control;
-    uint32_t length;
-    uint64_t address;
-} __attribute__((packed)) FWCfgDmaAccess;
-
 static inline void outl(uint32_t value, uint16_t port)
 {
     asm("outl %0, %w1" : : "a"(value), "Nd"(port));
@@ -153,9 +141,9 @@ static inline uint32_t be32_to_cpu(uint32_t x)
 static __attribute__((__noinline__))
 void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
 {
-    FWCfgDmaAccess access;
-    uint32_t control = (entry << 16) | BIOS_CFG_DMA_CTL_SELECT
-                        | BIOS_CFG_DMA_CTL_READ;
+    struct fw_cfg_dma_access access;
+    uint32_t control = (entry << 16) | FW_CFG_DMA_CTL_SELECT
+                        | FW_CFG_DMA_CTL_READ;
 
     access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
     access.length = cpu_to_be32(len);
@@ -165,7 +153,7 @@ void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
 
     outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
 
-    while (be32_to_cpu(access.control) & ~BIOS_CFG_DMA_CTL_ERROR) {
+    while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) {
         barrier();
     }
 }
Signature · 1 line
2.20.1
#2 lore raw

PATCH v5 2/5 linuxboot_dma: move common functions in a new header

In reply to Stefano Garzarella

In order to allow other option roms to use these common useful functions and definitions, this patch put them in two new C header files called optrom.h and optrom_fw_cfg.h. We also add useful out*() in*() functions for different size, and new fw_cfg functions to use when DMA feature is not available.

---
 pc-bios/optionrom/linuxboot_dma.c | 102 ++++++---------------------
 pc-bios/optionrom/optrom.h        | 110 ++++++++++++++++++++++++++++++
 pc-bios/optionrom/optrom_fw_cfg.h |  92 +++++++++++++++++++++++++
 3 files changed, 221 insertions(+), 83 deletions(-)
 create mode 100644 pc-bios/optionrom/optrom.h
 create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h
pc-bios/optionrom/linuxboot_dma.c +19 -83
index f728dc839f..cbcf6679d9 100644
@@ -58,21 +58,13 @@ asm(
 "   jmp load_kernel\n"
 );
 
-#define BIOS_CFG_DMA_ADDR_HIGH 0x514
-#define BIOS_CFG_DMA_ADDR_LOW  0x518
-
-#define uint64_t unsigned long long
-#define uint32_t unsigned int
-#define uint16_t unsigned short
-
-#include "../../include/standard-headers/linux/qemu_fw_cfg.h"
-
-#define barrier() asm("" : : : "memory")
-
-static inline void outl(uint32_t value, uint16_t port)
-{
-    asm("outl %0, %w1" : : "a"(value), "Nd"(port));
-}
+/*
+ * The includes of C headers must be after the asm block to avoid compiler
+ * errors.
+ */
+#include <stdint.h>
+#include "optrom.h"
+#include "optrom_fw_cfg.h"
 
 static inline void set_es(void *addr)
 {
@@ -80,12 +72,6 @@ static inline void set_es(void *addr)
     asm("movl %0, %%es" : : "r"(seg));
 }
 
-#ifdef __clang__
-#define ADDR32
-#else
-#define ADDR32 "addr32 "
-#endif
-
 static inline uint16_t readw_es(uint16_t offset)
 {
     uint16_t val;
@@ -108,56 +94,6 @@ static inline void writel_es(uint16_t offset, uint32_t val)
     asm(ADDR32 "movl %0, %%es:(%1)" : : "r"(val), "r"((uint32_t)offset));
 }
 
-static inline uint32_t bswap32(uint32_t x)
-{
-    asm("bswapl %0" : "=r" (x) : "0" (x));
-    return x;
-}
-
-static inline uint64_t bswap64(uint64_t x)
-{
-    asm("bswapl %%eax; bswapl %%edx; xchg %%eax, %%edx" : "=A" (x) : "0" (x));
-    return x;
-}
-
-static inline uint64_t cpu_to_be64(uint64_t x)
-{
-    return bswap64(x);
-}
-
-static inline uint32_t cpu_to_be32(uint32_t x)
-{
-    return bswap32(x);
-}
-
-static inline uint32_t be32_to_cpu(uint32_t x)
-{
-    return bswap32(x);
-}
-
-/* clang is happy to inline this function, and bloats the
- * ROM.
- */
-static __attribute__((__noinline__))
-void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
-{
-    struct fw_cfg_dma_access access;
-    uint32_t control = (entry << 16) | FW_CFG_DMA_CTL_SELECT
-                        | FW_CFG_DMA_CTL_READ;
-
-    access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
-    access.length = cpu_to_be32(len);
-    access.control = cpu_to_be32(control);
-
-    barrier();
-
-    outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
-
-    while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) {
-        barrier();
-    }
-}
-
 /* Return top of memory using BIOS function E801. */
 static uint32_t get_e801_addr(void)
 {
@@ -211,9 +147,9 @@ void load_kernel(void)
     uint32_t initrd_end_page, max_allowed_page;
     uint32_t segment_addr, stack_addr;
 
-    bios_cfg_read_entry(&setup_addr, FW_CFG_SETUP_ADDR, 4);
-    bios_cfg_read_entry(&setup_size, FW_CFG_SETUP_SIZE, 4);
-    bios_cfg_read_entry(setup_addr, FW_CFG_SETUP_DATA, setup_size);
+    bios_cfg_read_entry_dma(&setup_addr, FW_CFG_SETUP_ADDR, 4);
+    bios_cfg_read_entry_dma(&setup_size, FW_CFG_SETUP_SIZE, 4);
+    bios_cfg_read_entry_dma(setup_addr, FW_CFG_SETUP_DATA, setup_size);
 
     set_es(setup_addr);
 
@@ -223,8 +159,8 @@ void load_kernel(void)
         writel_es(0x22c, 0x37ffffff);
     }
 
-    bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
-    bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4);
+    bios_cfg_read_entry_dma(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
+    bios_cfg_read_entry_dma(&initrd_size, FW_CFG_INITRD_SIZE, 4);
 
     initrd_end_page = ((uint32_t)(initrd_addr + initrd_size) & -4096);
     max_allowed_page = (readl_es(0x22c) & -4096);
@@ -239,15 +175,15 @@ void load_kernel(void)
 
     }
 
-    bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
+    bios_cfg_read_entry_dma(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
 
-    bios_cfg_read_entry(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
-    bios_cfg_read_entry(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
-    bios_cfg_read_entry(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
+    bios_cfg_read_entry_dma(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
+    bios_cfg_read_entry_dma(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
+    bios_cfg_read_entry_dma(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
 
-    bios_cfg_read_entry(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4);
-    bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4);
-    bios_cfg_read_entry(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size);
+    bios_cfg_read_entry_dma(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4);
+    bios_cfg_read_entry_dma(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4);
+    bios_cfg_read_entry_dma(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size);
 
     /* Boot linux */
     segment_addr = ((uint32_t)setup_addr >> 4);
pc-bios/optionrom/optrom.h new file +110 -0

110 lines not on this page · raw message

pc-bios/optionrom/optrom_fw_cfg.h new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

Re: [Qemu-devel] [PATCH v5 2/5] linuxboot_dma: move common functions in a new header

Quoted 14 lines · Stefano Garzarella
(quoted diff) +13 -0
+static inline uint8_t inb(uint16_t port)
+{
+    uint8_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    return value;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+    uint16_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));

Review

Quoted 10 lines
(quoted diff) +10 -0
+    return value;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+    uint32_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    return value;
+}

Almost:

pc-bios/optionrom/optrom.h +3 -3
index c5c8caa..1e5e265 100644
@@ -54,7 +54,7 @@ static inline uint8_t inb(uint16_t port)
 {
     uint8_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inb %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 
@@ -62,7 +62,7 @@ static inline uint16_t inw(uint16_t port)
 {
     uint16_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inw %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 
@@ -70,7 +70,7 @@ static inline uint32_t inl(uint16_t port)
 {
     uint32_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inl %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 

No need to repost.

Paolo

#4 lore raw

Re: [Qemu-devel] [PATCH v5 2/5] linuxboot_dma: move common functions in a new header

Quoted 60 lines · Paolo Bonzini
Quoted 14 lines · Stefano Garzarella
(quoted diff) +13 -0
+static inline uint8_t inb(uint16_t port)
+{
+    uint8_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    return value;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+    uint16_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));

Review

Quoted 10 lines
(quoted diff) +10 -0
+    return value;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+    uint32_t value;
+
+    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    return value;
+}

Almost:

pc-bios/optionrom/optrom.h +3 -3
index c5c8caa..1e5e265 100644
@@ -54,7 +54,7 @@ static inline uint8_t inb(uint16_t port)
 {
     uint8_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inb %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 
@@ -62,7 +62,7 @@ static inline uint16_t inw(uint16_t port)
 {
     uint16_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inw %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 
@@ -70,7 +70,7 @@ static inline uint32_t inl(uint16_t port)
 {
     uint32_t value;
 
-    asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port));
+    asm volatile("inl %w1, %0" : "=a"(value) : "Nd"(port));
     return value;
 }
 
Quoted 1 line

No need to repost.

Oooh, many thanks to catch!

Quoted 2 lines

Paolo

Signature · 2 lines
Stefano Garzarella
Red Hat
#5 lore raw

PATCH v5 3/5 optionrom: add new PVH option rom

In reply to Stefano Garzarella

The new pvh.bin option rom can be used with SeaBIOS to boot uncompressed kernel using the x86/HVM direct boot ABI.

pvh.S contains the entry point of the option rom. It runs in real mode, loads the e820 table querying the BIOS, and then it switches to 32bit protected mode and jumps to the pvh_load_kernel() written in pvh_main.c. pvh_load_kernel() loads the cmdline and kernel entry_point using fw_cfg, then it looks for RSDP, fills the hvm_start_info required by x86/HVM ABI, and finally jumps to the kernel entry_point.

---
 .gitignore                   |   4 +
 Makefile                     |   2 +-
 pc-bios/optionrom/Makefile   |   5 +-
 pc-bios/optionrom/pvh.S      | 200 +++++++++++++++++++++++++++++++++++
 pc-bios/optionrom/pvh_main.c | 116 ++++++++++++++++++++
 pc-bios/pvh.bin              | Bin 0 -> 1536 bytes
 6 files changed, 325 insertions(+), 2 deletions(-)
 create mode 100644 pc-bios/optionrom/pvh.S
 create mode 100644 pc-bios/optionrom/pvh_main.c
 create mode 100644 pc-bios/pvh.bin
.gitignore +4 -0
index 0430257313..321095bf1a 100644
@@ -103,6 +103,10 @@
 /pc-bios/optionrom/linuxboot_dma.bin
 /pc-bios/optionrom/linuxboot_dma.raw
 /pc-bios/optionrom/linuxboot_dma.img
+/pc-bios/optionrom/pvh.asm
+/pc-bios/optionrom/pvh.bin
+/pc-bios/optionrom/pvh.raw
+/pc-bios/optionrom/pvh.img
 /pc-bios/optionrom/multiboot.asm
 /pc-bios/optionrom/multiboot.bin
 /pc-bios/optionrom/multiboot.raw
Makefile +1 -1
index a9ac16d94e..dd6d477fb1 100644
@@ -668,7 +668,7 @@ efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
 efi-e1000e.rom efi-vmxnet3.rom \
 qemu-icon.bmp qemu_logo_no_text.svg \
 bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
-multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \
+multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \
 s390-ccw.img s390-netboot.img \
 spapr-rtas.bin slof.bin skiboot.lid \
 palcode-clipper \
pc-bios/optionrom/Makefile +4 -1
index a9a9e5e7eb..e33a24da0d 100644
@@ -37,7 +37,7 @@ Wa = -Wa,
 ASFLAGS += -32
 QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), $(Wa)-32)
 
-build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
+build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
 
 # suppress auto-removal of intermediate files
 .SECONDARY:
@@ -46,6 +46,9 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 %.o: %.S
 	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"AS","$(TARGET_DIR)$@")
 
+pvh.img: pvh.o pvh_main.o
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T $(SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $^,"BUILD","$(TARGET_DIR)$@")
+
 %.img: %.o
 	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T $(SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $<,"BUILD","$(TARGET_DIR)$@")
 
pc-bios/optionrom/pvh.S new file +200 -0

200 lines not on this page · raw message

pc-bios/optionrom/pvh_main.c new file +116 -0

116 lines not on this page · raw message

pc-bios/pvh.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..38a41761014957d50eb55d790b6957888cbeee0a
GIT binary patch
Signature · 1 line
2.20.1
#6 lore raw

Re: [Qemu-devel] [PATCH v5 3/5] optionrom: add new PVH option rom

Quoted 12 lines · Stefano Garzarella

The new pvh.bin option rom can be used with SeaBIOS to boot uncompressed kernel using the x86/HVM direct boot ABI.

pvh.S contains the entry point of the option rom. It runs in real mode, loads the e820 table querying the BIOS, and then it switches to 32bit protected mode and jumps to the pvh_load_kernel() written in pvh_main.c. pvh_load_kernel() loads the cmdline and kernel entry_point using fw_cfg, then it looks for RSDP, fills the hvm_start_info required by x86/HVM ABI, and finally jumps to the kernel entry_point.

Quoted 3 lines

... and, for mingw:

pc-bios/optionrom/pvh_main.c +1 -1
index d1b8b4b..a015e1b 100644
@@ -43,7 +43,7 @@ struct pvh_e820_table {
     struct hvm_memmap_table_entry table[E820_MAXENTRIES];
 };
 
-struct pvh_e820_table pvh_e820 __attribute__ ((aligned));
+struct pvh_e820_table pvh_e820 asm("pvh_e820") __attribute__ ((aligned));
 
 static struct hvm_start_info start_info;
 static struct hvm_modlist_entry ramdisk_mod;

Paolo

#7 lore raw

PATCH v5 4/5 hw/i386/pc: use PVH option rom

In reply to Stefano Garzarella

Use pvh.bin option rom when we are booting an uncompressed kernel using the x86/HVM direct boot ABI.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +5 -0
index 9ed5063de8..2833b130ba 100644
@@ -1252,6 +1252,10 @@ static void load_linux(PCMachineState *pcms,
                                  initrd_size);
             }
 
+            option_rom[nb_option_roms].bootindex = 0;
+            option_rom[nb_option_roms].name = "pvh.bin";
+            nb_option_roms++;
+
             return;
         }
         /* This looks like a multiboot kernel. If it is, let's stop
@@ -1703,6 +1707,7 @@ void xen_load_linux(PCMachineState *pcms)
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
                !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
+               !strcmp(option_rom[i].name, "pvh.bin") ||
                !strcmp(option_rom[i].name, "multiboot.bin"));
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
Signature · 1 line
2.20.1
#8 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Quoted 15 lines · Stefano Garzarella

Use pvh.bin option rom when we are booting an uncompressed kernel using the x86/HVM direct boot ABI.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 9ed5063de8..2833b130ba 100644

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

Quoted 7 lines
hw/i386/pc.c +4 -0
@@ -1252,6 +1252,10 @@ static void load_linux(PCMachineState *pcms,
                                  initrd_size);
             }
 
+            option_rom[nb_option_roms].bootindex = 0;
+            option_rom[nb_option_roms].name = "pvh.bin";
+            nb_option_roms++;
+

We still need to address Michael's comment from v2 about machine-type compatibility:
https://www.mail-archive.com/[email protected]/msg587489.html

A question I've sent is quoted below:

| On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
| > OK but this is guest visible so needs to be guarded by the
| > new machine type.
| 
| Aren't option ROMs treated like other firmware?  i.e.: guest
| visible, but copied during live migration and not considered part
| of guest ABI.
Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Hi Eduardo,

Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Stefano Garzarella

Use pvh.bin option rom when we are booting an uncompressed kernel using the x86/HVM direct boot ABI.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 9ed5063de8..2833b130ba 100644
@@ -1252,6 +1252,10 @@ static void load_linux(PCMachineState *pcms,
                                  initrd_size);
             }
 
Quoted 8 lines

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

Quoted 4 lines
hw/i386/pc.c +4 -0
+            option_rom[nb_option_roms].bootindex = 0;
+            option_rom[nb_option_roms].name = "pvh.bin";
+            nb_option_roms++;
+

We still need to address Michael's comment from v2 about machine-type compatibility:
https://www.mail-archive.com/[email protected]/msg587489.html

Thanks! (Michael sorry to miss it!)

Quoted 10 lines

A question I've sent is quoted below:

| On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
| > OK but this is guest visible so needs to be guarded by the
| > new machine type.
| 
| Aren't option ROMs treated like other firmware?  i.e.: guest
| visible, but copied during live migration and not considered part
| of guest ABI.

I don't know the exact answer, but reading the wiki, I think Michael is right!
(https://wiki.qemu.org/Features/Migration/Troubleshooting#ROMs)

Maybe it is related for PVH feature in general, because if we try to migrate to a QEMU version that doesn't support PVH I'm not sure what is the behaviour.

I'll try to understand better!

Thanks,
Stefano

#10 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Quoted 8 lines · Stefano Garzarella
Quoted 8 lines
| On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
| > OK but this is guest visible so needs to be guarded by the
| > new machine type.
| 
| Aren't option ROMs treated like other firmware?  i.e.: guest
| visible, but copied during live migration and not considered part
| of guest ABI.
Quoted 6 lines

I don't know the exact answer, but reading the wiki, I think Michael is right!
(https://wiki.qemu.org/Features/Migration/Troubleshooting#ROMs)

Maybe it is related for PVH feature in general, because if we try to migrate to a QEMU version that doesn't support PVH I'm not sure what is the behaviour.

As far as I understand, QEMU would fail to migrate to the destination because the PVH option ROM doesn't have a corresponding RAMBlock.

Paolo

#11 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Quoted 12 lines · Paolo Bonzini
Quoted 11 lines · Stefano Garzarella
Quoted 8 lines
| On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
| > OK but this is guest visible so needs to be guarded by the
| > new machine type.
| 
| Aren't option ROMs treated like other firmware?  i.e.: guest
| visible, but copied during live migration and not considered part
| of guest ABI.

I don't know the exact answer, but reading the wiki, I think Michael is right!
(https://wiki.qemu.org/Features/Migration/Troubleshooting#ROMs)

Quoted 7 lines
Quoted 3 lines

Maybe it is related for PVH feature in general, because if we try to migrate to a QEMU version that doesn't support PVH I'm not sure what is the behaviour.

As far as I understand, QEMU would fail to migrate to the destination because the PVH option ROM doesn't have a corresponding RAMBlock.

I tried to migrate from a QEMU with PVH support to a QEMU without PVH, (both with the same pc-q35-4.0 machine) and the migration doesn't fail.

The guest, after the migration, works well, but when I tried to reboot, the guest stuck.

The "info ramblock" on both QEMU produce the same output:

              Block Name    PSize              Offset               Used              Total
                  pc.ram    4 KiB  0x0000000000000000 0x0000000020000000 0x0000000020000000
    /rom@etc/acpi/tables    4 KiB  0x0000000020080000 0x0000000000020000 0x0000000000200000
                 pc.bios    4 KiB  0x0000000020000000 0x0000000000040000 0x0000000000040000
                  pc.rom    4 KiB  0x0000000020040000 0x0000000000020000 0x0000000000020000
   /rom@etc/table-loader    4 KiB  0x0000000020280000 0x0000000000001000 0x0000000000001000
      /rom@etc/acpi/rsdp    4 KiB  0x00000000202c0000 0x0000000000001000 0x0000000000001000

The following patch solves the issue. (Thanks Michael!) Should I send the v6 of series or this patch alone for the review?

Thanks,
Stefano

hw/i386/pc.c +3 -1
index 2833b130ba..3be4a06c4f 100644
@@ -1211,7 +1211,8 @@ static void load_linux(PCMachineState *pcms,
          * saving the PVH entry point used by the x86/HVM direct boot ABI.
          * If load_elfboot() is successful, populate the fw_cfg info.
          */
-        if (load_elfboot(kernel_filename, kernel_size,
+        if (pcmc->pvh_enabled &&
+            load_elfboot(kernel_filename, kernel_size,
                          header, pvh_start_addr, fw_cfg)) {
             fclose(f);
 
@@ -2774,6 +2775,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->acpi_data_size = 0x20000 + 0x8000;
     pcmc->save_tsc_khz = true;
     pcmc->linuxboot_dma_enabled = true;
+    pcmc->pvh_enabled = true;
     assert(!mc->get_hotplug_handler);
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->cpu_index_to_instance_props = pc_cpu_index_to_props;
hw/i386/pc_piix.c +14 -3
index 5088e2f492..e70818fba2 100644
@@ -428,21 +428,32 @@ static void pc_i440fx_machine_options(MachineClass *m)
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
 }
 
-static void pc_i440fx_4_0_machine_options(MachineClass *m)
+static void pc_i440fx_4_1_machine_options(MachineClass *m)
 {
     pc_i440fx_machine_options(m);
     m->alias = "pc";
     m->is_default = 1;
 }
 
+DEFINE_I440FX_MACHINE(v4_1, "pc-i440fx-4.1", NULL,
+                      pc_i440fx_4_1_machine_options);
+
+static void pc_i440fx_4_0_machine_options(MachineClass *m)
+{
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
+    pc_i440fx_4_1_machine_options(m);
+    m->is_default = 0;
+    m->alias = NULL;
+    pcmc->pvh_enabled = false;
+}
+
 DEFINE_I440FX_MACHINE(v4_0, "pc-i440fx-4.0", NULL,
                       pc_i440fx_4_0_machine_options);
 
 static void pc_i440fx_3_1_machine_options(MachineClass *m)
 {
     pc_i440fx_4_0_machine_options(m);
-    m->is_default = 0;
-    m->alias = NULL;
     compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len);
     compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len);
 }
hw/i386/pc_q35.c +13 -2
index b7b7959934..6e843b991b 100644
@@ -365,12 +365,24 @@ static void pc_q35_machine_options(MachineClass *m)
     m->max_cpus = 288;
 }
 
-static void pc_q35_4_0_machine_options(MachineClass *m)
+static void pc_q35_4_1_machine_options(MachineClass *m)
 {
     pc_q35_machine_options(m);
     m->alias = "q35";
 }
 
+DEFINE_Q35_MACHINE(v4_1, "pc-q35-4.1", NULL,
+                   pc_q35_4_1_machine_options);
+
+static void pc_q35_4_0_machine_options(MachineClass *m)
+{
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
+    pc_q35_4_1_machine_options(m);
+    m->alias = NULL;
+    pcmc->pvh_enabled = false;
+}
+
 DEFINE_Q35_MACHINE(v4_0, "pc-q35-4.0", NULL,
                    pc_q35_4_0_machine_options);
 
@@ -378,7 +390,6 @@ static void pc_q35_3_1_machine_options(MachineClass *m)
 {
     pc_q35_4_0_machine_options(m);
     m->default_kernel_irqchip_split = false;
-    m->alias = NULL;
     compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len);
     compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len);
 }
include/hw/i386/pc.h +3 -0
index 0abbe45637..0d04af2021 100644
@@ -133,6 +133,9 @@ struct PCMachineClass {
 
     /* use DMA capable linuxboot option rom */
     bool linuxboot_dma_enabled;
+
+    /* enable PVH feature to load kernels */
+    bool pvh_enabled;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
#12 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Quoted 37 lines · Stefano Garzarella
Quoted 12 lines · Paolo Bonzini
Quoted 11 lines · Stefano Garzarella
Quoted 8 lines
| On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
| > OK but this is guest visible so needs to be guarded by the
| > new machine type.
| 
| Aren't option ROMs treated like other firmware?  i.e.: guest
| visible, but copied during live migration and not considered part
| of guest ABI.

I don't know the exact answer, but reading the wiki, I think Michael is right!
(https://wiki.qemu.org/Features/Migration/Troubleshooting#ROMs)

Quoted 7 lines
Quoted 3 lines

Maybe it is related for PVH feature in general, because if we try to migrate to a QEMU version that doesn't support PVH I'm not sure what is the behaviour.

As far as I understand, QEMU would fail to migrate to the destination because the PVH option ROM doesn't have a corresponding RAMBlock.

I tried to migrate from a QEMU with PVH support to a QEMU without PVH, (both with the same pc-q35-4.0 machine) and the migration doesn't fail.

The guest, after the migration, works well, but when I tried to reboot, the guest stuck.

The "info ramblock" on both QEMU produce the same output:

              Block Name    PSize              Offset               Used              Total
                  pc.ram    4 KiB  0x0000000000000000 0x0000000020000000 0x0000000020000000
    /rom@etc/acpi/tables    4 KiB  0x0000000020080000 0x0000000000020000 0x0000000000200000
                 pc.bios    4 KiB  0x0000000020000000 0x0000000000040000 0x0000000000040000
                  pc.rom    4 KiB  0x0000000020040000 0x0000000000020000 0x0000000000020000
   /rom@etc/table-loader    4 KiB  0x0000000020280000 0x0000000000001000 0x0000000000001000
      /rom@etc/acpi/rsdp    4 KiB  0x00000000202c0000 0x0000000000001000 0x0000000000001000
Quoted 2 lines

The following patch solves the issue. (Thanks Michael!) Should I send the v6 of series or this patch alone for the review?

Send the patch alone, but there's no need to introduce 4.1 since the feature will be included in 4.0.

Paolo

#13 lore raw

Re: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom

Quoted 18 lines · Paolo Bonzini
Quoted 17 lines · Stefano Garzarella

I tried to migrate from a QEMU with PVH support to a QEMU without PVH, (both with the same pc-q35-4.0 machine) and the migration doesn't fail.

The guest, after the migration, works well, but when I tried to reboot, the guest stuck.

The "info ramblock" on both QEMU produce the same output:

              Block Name    PSize              Offset               Used              Total
                  pc.ram    4 KiB  0x0000000000000000 0x0000000020000000 0x0000000020000000
    /rom@etc/acpi/tables    4 KiB  0x0000000020080000 0x0000000000020000 0x0000000000200000
                 pc.bios    4 KiB  0x0000000020000000 0x0000000000040000 0x0000000000040000
                  pc.rom    4 KiB  0x0000000020040000 0x0000000000020000 0x0000000000020000
   /rom@etc/table-loader    4 KiB  0x0000000020280000 0x0000000000001000 0x0000000000001000
      /rom@etc/acpi/rsdp    4 KiB  0x00000000202c0000 0x0000000000001000 0x0000000000001000
Quoted 5 lines
Quoted 2 lines

The following patch solves the issue. (Thanks Michael!) Should I send the v6 of series or this patch alone for the review?

Send the patch alone, but there's no need to introduce 4.1 since the feature will be included in 4.0.

Okay, I'll modify the patch.

Thanks,
Stefano

#14 lore raw

PATCH v5 5/5 optionrom/pvh: load initrd from fw_cfg

In reply to Stefano Garzarella

If we found initrd through fw_cfg, we can load it and use the first module of hvm_start_info to pass initrd address and size to the kernel.

---
 pc-bios/optionrom/pvh_main.c |  21 +++++++++++++++++++--
 pc-bios/pvh.bin              | Bin 1536 -> 1536 bytes
 2 files changed, 19 insertions(+), 2 deletions(-)
pc-bios/optionrom/pvh_main.c +19 -2
index f355476e68..d1b8b4b96e 100644
@@ -46,6 +46,7 @@ struct pvh_e820_table {
 struct pvh_e820_table pvh_e820 __attribute__ ((aligned));
 
 static struct hvm_start_info start_info;
+static struct hvm_modlist_entry ramdisk_mod;
 static uint8_t cmdline_buffer[CMDLINE_BUFSIZE];
 
 
@@ -71,8 +72,8 @@ extern void pvh_load_kernel(void) asm("pvh_load_kernel");
 void pvh_load_kernel(void)
 {
     void *cmdline_addr = &cmdline_buffer;
-    void *kernel_entry;
-    uint32_t cmdline_size, fw_cfg_version = bios_cfg_version();
+    void *kernel_entry, *initrd_addr;
+    uint32_t cmdline_size, initrd_size, fw_cfg_version = bios_cfg_version();
 
     start_info.magic = XEN_HVM_START_MAGIC_VALUE;
     start_info.version = 1;
@@ -110,6 +111,22 @@ void pvh_load_kernel(void)
                         fw_cfg_version);
     start_info.cmdline_paddr = (uintptr_t)cmdline_addr;
 
+    /* Check if we have the initrd to load */
+    bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4, fw_cfg_version);
+    if (initrd_size) {
+        bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4,
+                            fw_cfg_version);
+        bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size,
+                            fw_cfg_version);
+
+        ramdisk_mod.paddr = (uintptr_t)initrd_addr;
+        ramdisk_mod.size = initrd_size;
+
+        /* The first module is always ramdisk. */
+        start_info.modlist_paddr = (uintptr_t)&ramdisk_mod;
+        start_info.nr_modules = 1;
+    }
+
     bios_cfg_read_entry(&kernel_entry, FW_CFG_KERNEL_ENTRY, 4, fw_cfg_version);
 
     asm volatile("jmp *%1" : : "b"(&start_info), "c"(kernel_entry));
pc-bios/pvh.bin binary +0 -0
index 38a41761014957d50eb55d790b6957888cbeee0a..8033080ada2db4c4613fdc3bb5a69d79c7b0c0ca 100644
GIT binary patch
Signature · 1 line
2.20.1
#15 lore raw
In reply to Stefano Garzarella
Quoted 10 lines · Stefano Garzarella

This patch series is based on "[PATCH v3 0/4] QEMU changes to do PVH boot" and provides a PVH option rom that can be used with SeaBIOS to boot uncompressed kernel using the x86/HVM direct boot ABI.

Patches 1 and 2 are to prepare the PVH option rom, moving common functions in the new headers. Patch 3 adds the new PVH option rom. Patch 4 uses it when we are booting an uncompressed kernel using the x86/HVM direct boot ABI. Patch 5 adds the support of loading the initrd in the PVH option rom.

Based-on: <[email protected]>

The linuxboot_dma.bin option ROM went via Paolo's tree, so I guess he will merge this when he's happy, too.

Quoted 53 lines

Changes in v5:
- Patch 5: added R-b's
- Patch 3: updated .gitignore (by Liam)

Changes in v4:
- addressed comments by Paolo:
- Patch 2: linuxboot_dma.c: moved includes after the asm block to avoid compiler error
- Patch 3: Makefile: fixed pvh.img rule

Changes in v3:
- added R-b's
- added Patch 5 to support initrd
- addressed comments by Eric and Liam:
- Patch 3: comments by Liam
- Patch 4: moved Based-on tag in the cover letter (by Eric)
- Patch 3: added pc-bios/pvh.bin binary in the commit

Changes in v2:
- addressed comments by Stefan and Eric:
- Patch 2: moved inludes on top of linuxboot_dma.c and add <stdint.h> in optrom.h
- Patch 4: added check of pvh.bin in xen_load_linux()
- modified commit message of patch 2 to explain better the patch

Stefano Garzarella (5):
linuxboot_dma: remove duplicate definitions of FW_CFG
linuxboot_dma: move common functions in a new header
optionrom: add new PVH option rom hw/i386/pc: use PVH option rom optionrom/pvh: load initrd from fw_cfg

 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |   5 +
 pc-bios/optionrom/Makefile        |   5 +-
 pc-bios/optionrom/linuxboot_dma.c | 114 +++--------------
 pc-bios/optionrom/optrom.h        | 110 ++++++++++++++++
 pc-bios/optionrom/optrom_fw_cfg.h |  92 ++++++++++++++
 pc-bios/optionrom/pvh.S           | 200 ++++++++++++++++++++++++++++++
 pc-bios/optionrom/pvh_main.c      | 133 ++++++++++++++++++++
 pc-bios/pvh.bin                   | Bin 0 -> 1536 bytes
 10 files changed, 568 insertions(+), 97 deletions(-)
 create mode 100644 pc-bios/optionrom/optrom.h
 create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h
 create mode 100644 pc-bios/optionrom/pvh.S
 create mode 100644 pc-bios/optionrom/pvh_main.c
 create mode 100644 pc-bios/pvh.bin
Signature · 1 line
2.20.1