Skip to contentSkip to conversation

Load BIOS via toolstack instead of been embedded in hvmloader.

RFC PATCH Superseded Anthony PERARD 3 participants 11 messages Sep 16, 2015 – Sep 25, 2015

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover Load BIOS via toolstack instead of been embedded in hvmloader.

Hi all,

I've start to look at loading the BIOS and the ACPI tables via the toolstack instead of having them embedded in the hvmloader binary. This is done by using the same mechanics as the one used to load extra ACPI tables or SMBIOS.

- libxl load the blob into it's memory and add it to
struct xc_hvm_build_args.bios_module
- libxc load the blob into the guest memory and give back the guest address of the blob.
- libxl store the location of the blob (and it's lenght) into xenstore, in /local/domain/$domid/hvmloader/$blob_name/{address,length} ($blob_name would be "bios" or "acpi_table"; there is already "acpi" and "smbios" that exist)
- hvmloader read the addresses from xenstore and put the blob at the right place.

How this is looking?

Right now, this patch series would only work for SeaBIOS.

TODOs:
- load the bios from the right place.
- have a bios_firmware config option, same for the acpi_tables
- cleanup and factoring the duplication of code

Anthony PERARD (5):
libxc: Load BIOS and ACPI table into guest memory.
libxl: Load guest BIOS and ACPI table from file.
hvmloader: Load BIOS from where libxc left it.
hvmloader: Load ACPI table from here libxc left it.
hvmloader: Keep BIOS and ACPI blob in separated files.

 tools/firmware/Makefile                | 20 ++++++++-
 tools/firmware/hvmloader/acpi/Makefile |  8 ++--
 tools/firmware/hvmloader/config.h      | 11 +----
 tools/firmware/hvmloader/hvmloader.c   | 34 +++++++++------
 tools/firmware/hvmloader/seabios.c     | 33 +++++++-------
 tools/libxc/include/xenguest.h         |  4 ++
 tools/libxc/xc_hvm_build_x86.c         | 46 +++++++++++++++----
 tools/libxl/libxl_dom.c                | 80 ++++++++++++++++++++++++++++++++++
 8 files changed, 185 insertions(+), 51 deletions(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

RFC PATCH 1/5 libxc: Load BIOS and ACPI table into guest memory.

---
 tools/libxc/include/xenguest.h |  4 ++++
 tools/libxc/xc_hvm_build_x86.c | 46 +++++++++++++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 9 deletions(-)
tools/libxc/include/xenguest.h +4 -0
index 1a1a185..42acbfd 100644
@@ -229,6 +229,10 @@ struct xc_hvm_build_args {
     uint64_t lowmem_end;
     uint64_t highmem_end;
     uint64_t mmio_start;
+
+    /* BIOS as module */
+    struct xc_hvm_firmware_module bios_module;
+    struct xc_hvm_firmware_module acpi_table_module;
 };
 
 /**
tools/libxc/xc_hvm_build_x86.c +37 -9

91 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
#2 lore raw

RFC PATCH 2/5 libxl: Load guest BIOS and ACPI table from file.

In reply to Anthony PERARD
---
 tools/libxl/libxl_dom.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
tools/libxl/libxl_dom.c +80 -0
index c2518a3..6c0a257 100644
@@ -790,6 +790,32 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
     return 0;
 }
 
+static int hvm_build_set_xs_values_single_module(libxl__gc *gc,
+                                   uint32_t domid,
+                                   struct xc_hvm_firmware_module *module,
+                                   const char *module_name)
+{
+    char *path = NULL;
+    int ret;
+    if (module->guest_addr_out) {
+        path = GCSPRINTF("/local/domain/%d/hvmloader/%s/address",
+                         domid, module_name);
+
+        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%"PRIx64,
+                              module->guest_addr_out);
+        if (ret)
+            return ret;
+
+        path = GCSPRINTF("/local/domain/%d/hvmloader/%s/length",
+                         domid, module_name);
+
+        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%x", module->length);
+        if (ret)
+            return ret;
+    }
+    return 0;
+}
+
 static int hvm_build_set_xs_values(libxl__gc *gc,
                                    uint32_t domid,
                                    struct xc_hvm_build_args *args)
@@ -797,6 +823,16 @@ static int hvm_build_set_xs_values(libxl__gc *gc,
     char *path = NULL;
     int ret = 0;
 
+    ret = hvm_build_set_xs_values_single_module(gc, domid,
+                                                &args->bios_module,
+                                                "bios");
+    if (ret)
+        goto err;
+    ret = hvm_build_set_xs_values_single_module(gc, domid,
+                                                &args->acpi_table_module,
+                                                "acpi_table");
+    if (ret)
+        goto err;
     if (args->smbios_module.guest_addr_out) {
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_SMBIOS_PT_ADDRESS, domid);
 
@@ -867,6 +903,50 @@ static int libxl__domain_firmware(libxl__gc *gc,
     args->image_file_name = libxl__abs_path(gc, firmware,
                                             libxl__xenfirmwaredir_path());
 
+    // load bios
+    {
+        // XXX select proper bios.
+        const char *bios_bin_filename = libxl__abs_path(gc, "seabios.bin",
+                                            libxl__xenfirmwaredir_path());
+        LOG(DEBUG, "Loading BIOS: %s", bios_bin_filename);
+        data = NULL;
+        e = libxl_read_file_contents(ctx, bios_bin_filename,
+                                     &data, &datalen);
+        if (e) {
+            LOGEV(ERROR, e, "failed to read BIOS firmware file %s",
+                  bios_bin_filename);
+            goto out;
+        }
+        libxl__ptr_add(gc, data);
+        if (datalen) {
+            /* Only accept non-empty files */
+            args->bios_module.data = data;
+            args->bios_module.length = (uint32_t)datalen;
+        }
+    }
+    // load acpi table
+    {
+        // XXX select proper acpi table.
+        const char *acpi_table_filename = libxl__abs_path(gc,
+                                                "dsdt_anycpu_qemu_xen.aml",
+                                                libxl__xenfirmwaredir_path());
+        LOG(DEBUG, "Loading ACPI Table: %s", bios_bin_filename);
+        data = NULL;
+        e = libxl_read_file_contents(ctx, acpi_table_filename,
+                                     &data, &datalen);
+        if (e) {
+            LOGEV(ERROR, e, "failed to read ACPI tables file %s",
+                  acpi_table_filename);
+            goto out;
+        }
+        libxl__ptr_add(gc, data);
+        if (datalen) {
+            /* Only accept non-empty files */
+            args->acpi_table_module.data = data;
+            args->acpi_table_module.length = (uint32_t)datalen;
+        }
+    }
+
     if (info->u.hvm.smbios_firmware) {
         data = NULL;
         e = libxl_read_file_contents(ctx, info->u.hvm.smbios_firmware,
Signature · 1 line
Anthony PERARD
#3 lore raw

RFC PATCH 3/5 hvmloader: Load BIOS from where libxc left it.

In reply to Anthony PERARD
---
 tools/firmware/hvmloader/config.h    |  9 +--------
 tools/firmware/hvmloader/hvmloader.c | 25 +++++++++++++------------
 tools/firmware/hvmloader/seabios.c   | 24 ++++++++++++++----------
 3 files changed, 28 insertions(+), 30 deletions(-)
tools/firmware/hvmloader/config.h +1 -8
index b838cf9..0ddd897 100644
@@ -12,17 +12,10 @@ extern unsigned long igd_opregion_pgbase;
 struct bios_config {
     const char *name;
 
-    /* BIOS ROM image bits */
-    void *image;
-    unsigned int image_size;
-
-    /* Physical address to load at */
-    unsigned int bios_address;
-
     /* ROMS */
     void (*load_roms)(void);
 
-    void (*bios_load)(const struct bios_config *config);
+    void (*bios_load)(const struct bios_config *config, void* addr, uint32_t size);
 
     void (*bios_info_setup)(void);
     void (*bios_info_finish)(void);
tools/firmware/hvmloader/hvmloader.c +13 -12
index 716d03c..04b5076 100644
@@ -253,6 +253,9 @@ int main(void)
 {
     const struct bios_config *bios;
     int acpi_enabled;
+    uint8_t *bios_addr;
+    uint32_t bios_lenght;
+    const char *s;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
     memset((void *)HYPERCALL_PHYSICAL_ADDRESS, 0xc3 /* RET */, PAGE_SIZE);
@@ -286,16 +289,14 @@ int main(void)
         bios->create_smbios_tables();
     }
 
+    // XXX check that the values exist and are correct
+    s = xenstore_read("hvmloader/bios/address", NULL);
+    bios_addr = (uint8_t*)(uint32_t)strtoll(s, NULL, 0);
+    s = xenstore_read("hvmloader/bios/length", NULL);
+    bios_lenght = (uint32_t)strtoll(s, NULL, 0);
+
     printf("Loading %s ...\n", bios->name);
-    if ( bios->bios_load )
-        bios->bios_load(bios);
-    else
-    {
-        BUG_ON(bios->bios_address + bios->image_size >
-               HVMLOADER_PHYSICAL_ADDRESS);
-        memcpy((void *)bios->bios_address, bios->image,
-               bios->image_size);
-    }
+    bios->bios_load(bios, bios_addr, bios_lenght);
 
     if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode )
     {
@@ -333,9 +334,9 @@ int main(void)
     if ( SCRATCH_PHYSICAL_ADDRESS != scratch_start )
         printf(" %05x-%05lx: Scratch space\n",
                SCRATCH_PHYSICAL_ADDRESS, scratch_start);
-    printf(" %05x-%05x: Main BIOS\n",
-           bios->bios_address,
-           bios->bios_address + bios->image_size - 1);
+    /* printf(" %05x-%05x: Main BIOS\n", */
+           /* bios->bios_address, */
+           /* bios->bios_address + bios->image_size - 1); */
 
     if ( bios->e820_setup )
         bios->e820_setup();
tools/firmware/hvmloader/seabios.c +14 -10
index c6b3d9f..28793ca 100644
@@ -27,9 +27,6 @@
 #include "smbios_types.h"
 #include "acpi/acpi2_0.h"
 
-#define ROM_INCLUDE_SEABIOS
-#include "roms.inc"
-
 extern unsigned char dsdt_anycpu_qemu_xen[];
 extern int dsdt_anycpu_qemu_xen_len;
 
@@ -121,6 +118,7 @@ static void seabios_create_pir_tables(void)
     add_table(create_pir_tables());
 }
 
+unsigned int seabios_bios_address = 0;
 static void seabios_setup_e820(void)
 {
     struct seabios_info *info = (void *)BIOS_INFO_PHYSICAL_ADDRESS;
@@ -128,21 +126,27 @@ static void seabios_setup_e820(void)
     info->e820 = (uint32_t)e820;
 
     /* SeaBIOS reserves memory in e820 as necessary so no low reservation. */
-    info->e820_nr = build_e820_table(e820, 0, 0x100000-sizeof(seabios));
+    BUG_ON(seabios_bios_address == 0);
+    info->e820_nr = build_e820_table(e820, 0, seabios_bios_address);
     dump_e820_table(e820, info->e820_nr);
 }
 
-struct bios_config seabios_config = {
-    .name = "SeaBIOS",
+static void seabios_load(const struct bios_config *bios,
+                         void *bios_addr, uint32_t bios_lenght)
+{
+    unsigned int bios_dest = 0x100000 - bios_lenght;
+    seabios_bios_address = 0x100000 - bios_lenght;
 
-    .image = seabios,
-    .image_size = sizeof(seabios),
+    BUG_ON(bios_dest + bios_lenght > HVMLOADER_PHYSICAL_ADDRESS);
+    memcpy((void *)bios_dest, bios_addr, bios_lenght);
+}
 
-    .bios_address = 0x100000 - sizeof(seabios),
+struct bios_config seabios_config = {
+    .name = "SeaBIOS",
 
     .load_roms = NULL,
 
-    .bios_load = NULL,
+    .bios_load = seabios_load,
 
     .bios_info_setup = seabios_setup_bios_info,
     .bios_info_finish = seabios_finish_bios_info,
Signature · 1 line
Anthony PERARD
#4 lore raw

RFC PATCH 4/5 hvmloader: Load ACPI table from here libxc left it.

In reply to Anthony PERARD
---
 tools/firmware/hvmloader/config.h    | 2 +-
 tools/firmware/hvmloader/hvmloader.c | 9 ++++++++-
 tools/firmware/hvmloader/seabios.c   | 9 +++------
 3 files changed, 12 insertions(+), 8 deletions(-)
tools/firmware/hvmloader/config.h +1 -1
index 0ddd897..1df5fd9 100644
@@ -22,7 +22,7 @@ struct bios_config {
 
     void (*e820_setup)(void);
 
-    void (*acpi_build_tables)(void);
+    void (*acpi_build_tables)(void* addr, uint32_t size);
     void (*create_mp_tables)(void);
     void (*create_smbios_tables)(void);
     void (*create_pir_tables)(void);
tools/firmware/hvmloader/hvmloader.c +8 -1
index 04b5076..5b7ae7f 100644
@@ -317,8 +317,15 @@ int main(void)
 
         if ( bios->acpi_build_tables )
         {
+            uint8_t *acpi_table_addr;
+            uint32_t acpi_table_lenght;
             printf("Loading ACPI ...\n");
-            bios->acpi_build_tables();
+            // XXX check that the values exist and are correct
+            s = xenstore_read("hvmloader/acpi_table/address", NULL);
+            acpi_table_addr = (uint8_t*)(uint32_t)strtoll(s, NULL, 0);
+            s = xenstore_read("hvmloader/acpi_table/length", NULL);
+            acpi_table_lenght = (uint32_t)strtoll(s, NULL, 0);
+            bios->acpi_build_tables(acpi_table_addr, acpi_table_lenght);
         }
 
         acpi_enable_sci();
tools/firmware/hvmloader/seabios.c +3 -6
index 28793ca..8ac7a73 100644
@@ -27,9 +27,6 @@
 #include "smbios_types.h"
 #include "acpi/acpi2_0.h"
 
-extern unsigned char dsdt_anycpu_qemu_xen[];
-extern int dsdt_anycpu_qemu_xen_len;
-
 struct seabios_info {
     char signature[14]; /* XenHVMSeaBIOS\0 */
     uint8_t length;     /* Length of this struct */
@@ -87,12 +84,12 @@ static void add_table(uint32_t t)
     info->tables_nr++;
 }
 
-static void seabios_acpi_build_tables(void)
+static void seabios_acpi_build_tables(void* addr, uint32_t size)
 {
     uint32_t rsdp = (uint32_t)scratch_alloc(sizeof(struct acpi_20_rsdp), 0);
     struct acpi_config config = {
-        .dsdt_anycpu = dsdt_anycpu_qemu_xen,
-        .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len,
+        .dsdt_anycpu = addr,
+        .dsdt_anycpu_len = size,
         .dsdt_15cpu = NULL,
         .dsdt_15cpu_len = 0,
     };
Signature · 1 line
Anthony PERARD
#5 lore raw

RFC PATCH 5/5 hvmloader: Keep BIOS and ACPI blob in separated files.

In reply to Anthony PERARD
---
 tools/firmware/Makefile                | 20 +++++++++++++++++++-
 tools/firmware/hvmloader/acpi/Makefile |  8 +++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
tools/firmware/Makefile +19 -1
index 6cc86ce..3912a9d 100644
@@ -19,6 +19,19 @@ SUBDIRS-y += hvmloader
 
 LD32BIT-$(CONFIG_FreeBSD) := LD32BIT_FLAG=-melf_i386_fbsd
 
+SEABIOS_DIR := seabios-dir
+
+ifeq ($(CONFIG_SEABIOS),y)
+ifeq ($(SEABIOS_PATH),)
+	SEABIOS_ROM := $(SEABIOS_DIR)/out/bios.bin
+else
+	SEABIOS_ROM := $(SEABIOS_PATH)
+endif
+ROMS += $(SEABIOS_ROM)
+endif
+
+ACPI_TABLE_QEMU_PC_I440FX = hvmloader/acpi/dsdt_anycpu_qemu_xen.aml
+
 ovmf-dir:
 	GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) ovmf-dir
 	cp ovmf-makefile ovmf-dir/Makefile;
@@ -42,9 +55,14 @@ endif
 
 
 .PHONY: install
-install: all
+install: all $(ROMS)
 	[ -d $(INST_DIR) ] || $(INSTALL_DIR) $(INST_DIR)
+	# hvmloader
 	[ ! -e $(TARGET) ] || $(INSTALL_DATA) $(TARGET) $(INST_DIR)
+ifeq ($(CONFIG_SEABIOS),y)
+	[ ! -e $(SEABIOS_ROM) ] || $(INSTALL_DATA) $(SEABIOS_ROM) $(INST_DIR)/seabios.bin
+endif
+	[ ! -e $(ACPI_TABLE_QEMU_PC_I440FX) ] || $(INSTALL_DATA) $(ACPI_TABLE_QEMU_PC_I440FX) $(INST_DIR)
 
 .PHONY: clean
 clean: subdirs-clean
tools/firmware/hvmloader/acpi/Makefile +5 -3
index d3e882a..e444c8c 100644
@@ -17,13 +17,13 @@
 XEN_ROOT = $(CURDIR)/../../../..
 include $(XEN_ROOT)/tools/firmware/Rules.mk
 
-C_SRC = build.c dsdt_anycpu.c dsdt_15cpu.c static_tables.c dsdt_anycpu_qemu_xen.c
+C_SRC = build.c dsdt_anycpu.c dsdt_15cpu.c static_tables.c
 OBJS  = $(patsubst %.c,%.o,$(C_SRC))
 
 CFLAGS += $(CFLAGS_xeninclude)
 
 vpath iasl $(PATH)
-all: acpi.a
+all: acpi.a dsdt_anycpu_qemu_xen.aml
 
 ssdt_s3.h ssdt_s4.h ssdt_pm.h ssdt_tpm.h: %.h: %.asl iasl
 	iasl -vs -p $* -tc $<
@@ -46,7 +46,9 @@ $(filter dsdt_%.c,$(C_SRC)): %.c: iasl %.asl
 	iasl -vs -p $* -tc $*.asl
 	sed -e 's/AmlCode/$*/g' $*.hex >$@
 	echo "int $*_len=sizeof($*);" >>$@
-	rm -f $*.aml $*.hex
+	rm -f $*.hex
+dsdt_anycpu_qemu_xen.aml: %.aml: iasl %.asl
+	iasl -vs -p $* $*.asl
 
 iasl:
 	@echo
Signature · 1 line
Anthony PERARD
#6 lore raw
In reply to Anthony PERARD
Quoted 18 lines · Anthony PERARD

Hi all,

I've start to look at loading the BIOS and the ACPI tables via the toolstack instead of having them embedded in the hvmloader binary. This is done by using the same mechanics as the one used to load extra ACPI tables or SMBIOS.

- libxl load the blob into it's memory and add it to
struct xc_hvm_build_args.bios_module
- libxc load the blob into the guest memory and give back the guest address of the blob.
- libxl store the location of the blob (and it's lenght) into xenstore, in /local/domain/$domid/hvmloader/$blob_name/{address,length} ($blob_name would be "bios" or "acpi_table"; there is already "acpi" and "smbios" that exist)
- hvmloader read the addresses from xenstore and put the blob at the right place.

Quoted 3 lines

How this is looking?

Right now, this patch series would only work for SeaBIOS.

I highly recommend that you build on top of Rogers DMlite series, which already offers a multiboot-style way of adding extra modules to HVM guests. (That was the way I was planning to do this in some copious free time).

In particular, storing the address/length in xenstore is conceptually incorrect as the information turns stale as soon as hvmloader starts running.

* Modify hvmloader to have a DMLite entry, which gives it a command line and module list
* Modify libxc to be able to take an arbitrary quantity of modules, rather than the currently limit of 1

Once the above work times are in place, the actual splitting-up of hvmloader can occur.

I recommend a command line way of telling hvmloader which module is what, such as a legacy bios image, (other firmware image?), supplemental acpi table, supplemental smbios table, nvram blob? (This last one will require a bit of extra work so the toolstack can pull the blob back out of the guest on destruction)

~Andrew

#7 lore raw
Quoted 19 lines · Andrew Cooper
Quoted 18 lines · Anthony PERARD

Hi all,

I've start to look at loading the BIOS and the ACPI tables via the toolstack instead of having them embedded in the hvmloader binary. This is done by using the same mechanics as the one used to load extra ACPI tables or SMBIOS.

- libxl load the blob into it's memory and add it to
struct xc_hvm_build_args.bios_module
- libxc load the blob into the guest memory and give back the guest address of the blob.
- libxl store the location of the blob (and it's lenght) into xenstore, in /local/domain/$domid/hvmloader/$blob_name/{address,length} ($blob_name would be "bios" or "acpi_table"; there is already "acpi" and "smbios" that exist)
- hvmloader read the addresses from xenstore and put the blob at the right place.

Quoted 8 lines
Quoted 3 lines

How this is looking?

Right now, this patch series would only work for SeaBIOS.

I highly recommend that you build on top of Rogers DMlite series, which already offers a multiboot-style way of adding extra modules to HVM guests. (That was the way I was planning to do this in some copious free time).

Thanks. I will look into this.

Quoted 17 lines

In particular, storing the address/length in xenstore is conceptually incorrect as the information turns stale as soon as hvmloader starts running.

* Modify hvmloader to have a DMLite entry, which gives it a command line and module list
* Modify libxc to be able to take an arbitrary quantity of modules, rather than the currently limit of 1

Once the above work times are in place, the actual splitting-up of hvmloader can occur.

I recommend a command line way of telling hvmloader which module is what, such as a legacy bios image, (other firmware image?), supplemental acpi table, supplemental smbios table, nvram blob? (This last one will require a bit of extra work so the toolstack can pull the blob back out of the guest on destruction)

Signature · 1 line
Anthony PERARD
#8 lore raw
Quoted 8 lines · Anthony PERARD
Quoted 4 lines · Andrew Cooper

I highly recommend that you build on top of Rogers DMlite series, which already offers a multiboot-style way of adding extra modules to HVM guests. (That was the way I was planning to do this in some copious free time).

Thanks. I will look into this.

Given that major seeming change is there anything in this series which is still worth reviewing?

Ian.

#9 lore raw
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Anthony PERARD
Quoted 4 lines · Andrew Cooper

I highly recommend that you build on top of Rogers DMlite series, which already offers a multiboot-style way of adding extra modules to HVM guests. (That was the way I was planning to do this in some copious free time).

Quoted 4 lines
Quoted 1 line

Thanks. I will look into this.

Given that major seeming change is there anything in this series which is still worth reviewing?

No, I already have the amount of review I was looking for.

Thanks,

Signature · 1 line
Anthony PERARD
#10 lore raw
Quoted 11 lines · Anthony PERARD
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Anthony PERARD
Quoted 6 lines · Andrew Cooper

I highly recommend that you build on top of Rogers DMlite series, which
already offers a multiboot-style way of adding extra modules to HVM guests. (That was the way I was planning to do this in some copious
free time).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thanks. I will look into this.

Given that major seeming change is there anything in this series which is
still worth reviewing?

No, I already have the amount of review I was looking for.

OK, I'll await a v2 then, thanks.