Skip to contentSkip to conversation

Add optionrom compatible with fw_cfg DMA version

PATCH In review Paolo Bonzini 2 participants 2 messages Jul 13, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 Add optionrom compatible with fw_cfg DMA version

From: Marc Marí <[email protected]>

This optionrom is based on linuxboot.S.

Message-Id: <[email protected]>

[Add -fno-toplevel-reorder, support clang without -m16. - Paolo]
---
 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |  10 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/optionrom/Makefile        |  30 +++-
 pc-bios/optionrom/code16gcc.h     |   3 +
 pc-bios/optionrom/linuxboot_dma.c | 291 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 335 insertions(+), 8 deletions(-)
 create mode 100644 pc-bios/optionrom/code16gcc.h
 create mode 100644 pc-bios/optionrom/linuxboot_dma.c
.gitignore +4 -0
index 9b6a968..88ec249 100644
@@ -95,6 +95,10 @@
 /pc-bios/optionrom/linuxboot.bin
 /pc-bios/optionrom/linuxboot.raw
 /pc-bios/optionrom/linuxboot.img
+/pc-bios/optionrom/linuxboot_dma.asm
+/pc-bios/optionrom/linuxboot_dma.bin
+/pc-bios/optionrom/linuxboot_dma.raw
+/pc-bios/optionrom/linuxboot_dma.img
 /pc-bios/optionrom/multiboot.asm
 /pc-bios/optionrom/multiboot.bin
 /pc-bios/optionrom/multiboot.raw
Makefile +1 -1
index 4570637..0d7647f 100644
@@ -419,7 +419,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 petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
-multiboot.bin linuxboot.bin kvmvapic.bin \
+multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \
 s390-ccw.img \
 spapr-rtas.bin slof.bin \
 palcode-clipper \
hw/i386/pc.c +8 -2
index f56e225..1b8baa8 100644
@@ -998,8 +998,13 @@ static void load_linux(PCMachineState *pcms,
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
 
-    option_rom[nb_option_roms].name = "linuxboot.bin";
-    option_rom[nb_option_roms].bootindex = 0;
+    if (fw_cfg_dma_enabled(fw_cfg)) {
+        option_rom[nb_option_roms].name = "linuxboot_dma.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    } else {
+        option_rom[nb_option_roms].name = "linuxboot.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    }
     nb_option_roms++;
 }
 
@@ -1291,6 +1296,7 @@ void xen_load_linux(PCMachineState *pcms)
     load_linux(pcms, fw_cfg);
     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, "multiboot.bin"));
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
hw/nvram/fw_cfg.c +1 -1
index 74a0079..2873030 100644
@@ -552,7 +552,7 @@ static bool is_version_1(void *opaque, int version_id)
     return version_id == 1;
 }
 
-static bool fw_cfg_dma_enabled(void *opaque)
+bool fw_cfg_dma_enabled(void *opaque)
 {
     FWCfgState *s = opaque;
 
include/hw/nvram/fw_cfg.h +1 -0
index d008112..5c27a1f 100644
@@ -182,5 +182,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
                                  hwaddr dma_addr, AddressSpace *dma_as);
 
 FWCfgState *fw_cfg_find(void);
+bool fw_cfg_dma_enabled(void *opaque);
 
 #endif
pc-bios/optionrom/Makefile +26 -4
index 2cdda87..1a82c34 100644
@@ -10,21 +10,43 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 .PHONY : all clean build-all
 
 CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
-CFLAGS += -I$(SRC_PATH)
 CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
 CFLAGS += $(CFLAGS_NOPIE)
+CFLAGS += $(call cc-option, $(CFLAGS), -m16)
+ifeq ($(filter -m16, $(CFLAGS)),)
+# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
+# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
+# respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
+# but it places all asm blocks at the beginning and we're relying on it for
+# the option ROM header.  So just force clang not to use the integrated
+# assembler, which doesn't support .code16gcc.
+CFLAGS += -m32 -include $(SRC_PATH)/pc-bios/optionrom/code16gcc.h
+CFLAGS += $(call cc-option, $(CFLAGS), -fno-toplevel-reorder)
+CFLAGS += $(call cc-option, $(CFLAGS), -no-integrated-as)
+endif
+
+QEMU_INCLUDES += -I$(SRC_PATH)
 QEMU_CFLAGS = $(CFLAGS)
 
-build-all: multiboot.bin linuxboot.bin kvmvapic.bin
+ASFLAGS += -32
+
+build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 
 # suppress auto-removal of intermediate files
 .SECONDARY:
 
+
 %.o: %.S
-	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+
+ifdef CONFIG_WIN32
+LD_EMULATION = i386pe
+else
+LD_EMULATION = elf_i386
+endif
 
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
pc-bios/optionrom/code16gcc.h new file +3 -0
new file mode 100644
index 0000000..9c8d25d
@@ -0,0 +1,3 @@
+asm(
+".code16gcc\n"
+);
pc-bios/optionrom/linuxboot_dma.c new file +291 -0

291 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

Thanks for reposting this Paolo.

I tested it by applying it on top of qemu. In libguestfs sources we have a benchmark program called utils/boot-benchmark/boot-benchmark.

Using the qemu package from Fedora (qemu-2.6.0-3.fc24.x86_64):

  $ killall -STOP firefox
  $ ./boot-benchmark
  Result: 2341.7ms ±10.9ms

With the unpatched upstream qemu:

  $ LIBGUESTFS_HV=~/d/qemu/x86_64-softmmu/qemu-system-x86_64 ./boot-benchmark 
  Result: 2282.3ms ±1.7ms

With the patched upstream qemu:

  $ LIBGUESTFS_HV=~/d/qemu/x86_64-softmmu/qemu-system-x86_64 ./boot-benchmark 
  Result: 1452.4ms ±0.9ms

So the patch works and makes a significant difference.

Note I still had to do by hand:

  $ cp pc-bios/optionrom/linuxboot_dma.bin pc-bios/

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html