Skip to contentSkip to conversation

Add optionrom compatible with fw_cfg DMA version

PATCH Superseded Richard W.M. Jones 4 participants 6 messages Apr 22, 2016 – Apr 26, 2016

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

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

v4 -> v5:

* Fix the initrd loading problem by fixing the get_e801_addr function so it really reads the values from the BIOS.

Previously the function always returned 16MB, and so it only happened to work for initrd sizes < ~15MB, and broke for anything larger. Now the function is fixed, I tested it on 20MB & 350KB initrds and it worked for both.

* Fix the Win32 cross-compiler issue by making the 'ld -m' (emulator) option conditional on CONFIG_WIN32.

This change was not tested with the cross-compiler. Gerd, could you see if this fixes things?

* Re-test.

It knocks about 700ms off the libguestfs boot time.

Rich.

#1 lore raw

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

From: Marc Marí <[email protected]>

This optionrom is based on linuxboot.S.

---
 .gitignore                        |   4 +
 hw/i386/pc.c                      |   9 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/optionrom/Makefile        |  13 +-
 pc-bios/optionrom/linuxboot_dma.c | 305 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 329 insertions(+), 5 deletions(-)
 create mode 100644 pc-bios/optionrom/linuxboot_dma.c
.gitignore +4 -0
index 88a80ff..101d1e0 100644
@@ -94,6 +94,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
hw/i386/pc.c +7 -2
index 99437e0..e11152d 100644
@@ -999,8 +999,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++;
 }
 
hw/nvram/fw_cfg.c +1 -1
index 999f480..114aea8 100644
@@ -551,7 +551,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 +11 -2
index ce4852a..d44a62a 100644
@@ -13,15 +13,24 @@ 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 += -m32
 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:
 
+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/linuxboot_dma.c new file +305 -0

305 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v5 1/1
#2 lore raw
Quoted 13 lines · On Fri, 22 Apr 2016 14:02:28 +0100 "Richard W.M. Jones" <[email protected]>…

From: Marc Marí <[email protected]>

This optionrom is based on linuxboot.S.

---
 .gitignore                        |   4 +
 hw/i386/pc.c                      |   9 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/optionrom/Makefile        |  13 +-
 pc-bios/optionrom/linuxboot_dma.c | 305
Quoted 3 lines

++++++++++++++++++++++++++++++++++++++ 6 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot_dma.c

Thanks for picking this up and solving the issues!

#3 lore raw
In reply to Richard W.M. Jones
Quoted 10 lines · Richard W.M. Jones
hw/i386/pc.c +0 -2
index 99437e0..e11152d 100644
@@ -999,8 +999,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;

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

Quoted 10 lines
hw/i386/pc.c +7 -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++;
 }
 

Please update xen_load_linux() to avoid assertion failure:

  for (i = 0; i < nb_option_roms; i++) {
      assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
             !strcmp(option_rom[i].name, "multiboot.bin"));
#4 lore raw
In reply to Richard W.M. Jones
Quoted 9 lines · Richard W.M. Jones

v4 -> v5:

* Fix the initrd loading problem by fixing the get_e801_addr function so it really reads the values from the BIOS.

Previously the function always returned 16MB, and so it only happened to work for initrd sizes < ~15MB, and broke for anything larger. Now the function is fixed, I tested it on 20MB & 350KB initrds and it worked for both.

Can confirm it works, and with a big initramfs it is a very noticable speedup.

Quoted 5 lines

* Fix the Win32 cross-compiler issue by making the 'ld -m' (emulator) option conditional on CONFIG_WIN32.

This change was not tested with the cross-compiler. Gerd, could you see if this fixes things?

Yes, it builds fine now.

Only thing I've noticed is that I have to manually copy the rom to pc-bios/, I guess we want place a pre-compiled binary there like we do for the other option roms.

cheers,
Gerd

#5 lore raw
Quoted 17 lines · Gerd Hoffmann
Quoted 9 lines · Richard W.M. Jones

v4 -> v5:

* Fix the initrd loading problem by fixing the get_e801_addr function so it really reads the values from the BIOS.

Previously the function always returned 16MB, and so it only happened to work for initrd sizes < ~15MB, and broke for anything larger. Now the function is fixed, I tested it on 20MB & 350KB initrds and it worked for both.

Can confirm it works, and with a big initramfs it is a very noticable speedup.

Quoted 3 lines

* Fix the Win32 cross-compiler issue by making the 'ld -m' (emulator) option conditional on CONFIG_WIN32.

Quoted 8 lines
Quoted 2 lines

This change was not tested with the cross-compiler. Gerd, could you see if this fixes things?

Yes, it builds fine now.

Only thing I've noticed is that I have to manually copy the rom to pc-bios/, I guess we want place a pre-compiled binary there like we do for the other option roms.

Yes, I noticed this too (on Linux non-cross-compiles). Not sure if that's right or wrong.

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
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org