Add optionrom compatible with fw_cfg DMA version
PATCH 1/1 Add optionrom compatible with fw_cfg DMA version
This is an updated version of Marc Marí's Linux DMA patch, based on version 4 from:
https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg05891.html
All I have done for my "4.1" version is:
- Modify it so it compiles against the latest qemu. There was a change to how fw_cfg.h is split (6f061ea10f28c) which broke the patch.
- Run checkpatch and fix several problems.
- Test it.
This patch greatly and transparently improves boot time of the libguestfs appliance on x86, and so I'd like to see it integrated upstream.
Rich.
PATCH 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 | 7 +- pc-bios/optionrom/linuxboot_dma.c | 297 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 315 insertions(+), 5 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot_dma.c
.gitignore +4 -0
@@ -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
@@ -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
@@ -547,7 +547,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
@@ -174,5 +174,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 +5 -2
@@ -13,15 +13,18 @@ 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: %.img: %.o - $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@") + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386 -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 +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 6 lines · Richard W.M. Jones
From: Marc Marí <[email protected]>
This optionrom is based on
linuxboot.S.Signed-off-by Marc Marí <[email protected]>Signed-off-by Richard W.M. Jones <[email protected]>
Quoted 9 lines
--- .gitignore | 4 + hw/i386/pc.c | 9 +- hw/nvram/fw_cfg.c | 2 +- include/hw/nvram/fw_cfg.h | 1 + pc-bios/optionrom/Makefile | 7 +- pc-bios/optionrom/linuxboot_dma.c | 297 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 315 insertions(+), 5 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot_dma.c
It would be great to merge this but there's more work necessary.
I CCed Marc's current email address. He was interning at Red Hat but is now back at university so the Red Hat address is not being read.
Marc: What was still missing from this patch?
Quoted 12 lines
pc-bios/optionrom/Makefile +1
-1@@ -13,15 +13,18 @@ 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
pc-bios/optionrom/Makefile CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin · line 27
Quoted 10 lines
pc-bios/optionrom/Makefile +4
-1+ASFLAGS += -32 + +build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin # suppress auto-removal of intermediate files .SECONDARY: %.img: %.o - $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@") + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386 -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")
Gerd noted in <[email protected]>:
Hmm, that breaks the windows cross build:
make: Entering directory `/home/kraxel/projects/qemu/build-win32' Building optionrom/linuxboot_dma.img
i686-w64-mingw32-ld: unrecognised emulation mode: elf_i386 Supported emulations: i386pe
make[1]: *** [linuxboot_dma.img] Error 1
and then:
Testing shows two more problems:
(1) initrd loading is broken, kernel complains it finds only gibberish:
[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressed archive [ 1.168458] Freeing initrd memory: 32812k freed
(2) going back to non-dma boot via -M pc-$old doesn't work, appearently fw_cfg dma is enabled even for old machine types.
Quoted 5 lines · Stefan Hajnoczi
(1) initrd loading is broken, kernel complains it finds only gibberish:
[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressed archive [ 1.168458] Freeing initrd memory: 32812k freed
That's strange. I certainly never saw anything like this. I wonder if it's because your initrd is particularly large?
Quoted 2 lines
(2) going back to non-dma boot via -M pc-$old doesn't work, appearently
fw_cfgdma is enabled even for old machine types.
IIRC there was a thread about how we accidentally added DMA to old machine types. Does this matter?
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Quoted 9 lines · Richard W.M. Jones
Quoted 5 lines · Stefan Hajnoczi
(1) initrd loading is broken, kernel complains it finds only gibberish:
[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressed archive [ 1.168458] Freeing initrd memory: 32812k freedThat's strange. I certainly never saw anything like this. I wonder if it's because your initrd is particularly large?
I've simply used /boot/initramfs-$version from the host. It's 33M. Not exactly small, but given this is a standard RHEL-7 install I also wouldn't rate this as unusual big.
Quoted 5 lines
Quoted 2 lines
(2) going back to non-dma boot via -M pc-$old doesn't work, appearently
fw_cfgdma is enabled even for old machine types.IIRC there was a thread about how we accidentally added DMA to old machine types. Does this matter?
That one should be fixed meanwhile.
cheers,
Gerd
Quoted 8 lines · Gerd Hoffmann
Quoted 7 lines · Richard W.M. Jones
Quoted 5 lines · Stefan Hajnoczi
(1) initrd loading is broken, kernel complains it finds only gibberish:
[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressed archive [ 1.168458] Freeing initrd memory: 32812k freed
Quoted 6 lines
Quoted 2 lines
That's strange. I certainly never saw anything like this. I wonder if it's because your initrd is particularly large?
I've simply used
/boot/initramfs-$versionfrom the host. It's 33M. Not exactly small, but given this is a standard RHEL-7 install I also wouldn't rate this as unusual big.
The problem here was the GCC asm statement that calls the 0xE801 BIOS function. It wasn't actually reading %bx, %cx, %dx, and so the whole calculation of where to put the initrd was wrong.
The attached patch fixes things for me. I also rewrote the get_e801_addr function to make it a little bit cleaner and clearer.
However don't consider this patch for now. I'm going to post a new version of the whole patch with these changes integrated and the whole lot retested properly, hopefully later today.
Rich.
pc-bios/optionrom/linuxboot_dma.c +23 -20
@@ -174,36 +174,39 @@ static void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len) } } +/* Return top of memory using BIOS function E801. */ static uint32_t get_e801_addr (void ) { -uint32_t eax, ebx, ecx, edx; +uint16_t eax, ebx, ecx, edx;uint32_t ret; - eax =0xe801 ; ebx =0 ; ecx =0 ; edx =0 ; asm("int $0x15\n" - :"+a" (eax) - :"b" (ebx),"c" (ecx),"d" (edx)); + :"=a" (eax),"+b" (ebx),"+c" (ecx),"+d" (edx) + :"a" (0xe801 )); -/* Output could be in AX/BX or CX/DX */ -if ((uint16_t )ecx || (uint16_t )edx) { -if (!(uint16_t )edx) { -/* Add 1 MB and convert to bytes */ - ret = (ecx +1024 ) <<10 ; - }else { -/* Add 16 MB and convert to bytes */ - ret = (edx +256 ) <<16 ; - } +/* Not SeaBIOS, but in theory a BIOS could return CX=DX=0 in which case +* we need to use the result from AX & BX instead. +*/ +if (ecx ==0 && edx ==0 ) { + ecx = eax; + edx = ebx; + } + +if (edx ==0 ) { +/* This is for machines with <= 16MB of RAM, which probably +* would never be the case, but deal with it anyway. +* ECX = extended memory between 1M and 16M, in kilobytes +* Convert it to bytes and return. +*/ + ret = ((uint32_t )ecx +1024 /* 1M in K */ ) <<10 ; }else { -if (!(uint16_t )ebx) { -/* Add 1 MB and convert to bytes */ - ret = (eax +1024 ) <<10 ; - }else { -/* Add 16 MB and convert to bytes */ - ret = (ebx +256 ) <<16 ; - } +/* EDX = extended memory above 16M, in 64K units. +* Convert it to bytes and return. +*/ + ret = ((uint32_t )edx +256 /* 16M in 64K units */ ) <<16 ; }return ret;
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
Quoted 9 lines · Richard W.M. Jones
Quoted 5 lines · Stefan Hajnoczi
(1) initrd loading is broken, kernel complains it finds only gibberish:
[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressed archive [ 1.168458] Freeing initrd memory: 32812k freedThat's strange. I certainly never saw anything like this. I wonder if it's because your initrd is particularly large?
If you search your mailbox for Message-Id <[email protected]> (subject: "Test libguestfs on RHELSA"), you'll find an earlier occurence of the same.
(You had also replied to that email, so you simply didn't remember it this time.)
In that case, the problem was an oversized initrd, relative to the amount of RAM that the guest had. You eliminated (worked around?) the issue in libguestfs commit c24f242521e88.
Of course, without reviewing the patch under discussion (which I won't volunteer for now, apologies), I cannot exclude that the patch makes the kernel *think* that the initrd is too large.
Quoted 5 lines
Quoted 2 lines
(2) going back to non-dma boot via -M pc-$old doesn't work, appearently
fw_cfgdma is enabled even for old machine types.IIRC there was a thread about how we accidentally added DMA to old machine types. Does this matter?
What Gerd said -- see e6915b5f3a87.
(I have so few commits in QEMU that if I look for something I wrote, I can find it simply with "--author=lersek". I don't know if I should smile or cry...)
Thanks
Laszlo
Quoted 3 lines · Laszlo Ersek
(I have so few commits in QEMU that if I look for something I wrote, I can find it simply with "--author=lersek". I don't know if I should smile or cry...)
Actually you are in the top 50. You can't claim to be the 1%, but that's not shabby at all!
Paolo
Quoted 18 lines · On Mon, 4 Apr 2016 16:02:04 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 13 lines · Richard W.M. Jones
From: Marc Marí <[email protected]>
This optionrom is based on
linuxboot.S.Signed-off-by Marc Marí <[email protected]>Signed-off-by Richard W.M. Jones <[email protected]>--- .gitignore | 4 + hw/i386/pc.c | 9 +- hw/nvram/fw_cfg.c | 2 +- include/hw/nvram/fw_cfg.h | 1 + pc-bios/optionrom/Makefile | 7 +- pc-bios/optionrom/linuxboot_dma.c | 297Quoted 3 lines
++++++++++++++++++++++++++++++++++++++ 6 files changed, 315 insertions(+), 5 deletions(-) create mode 100644
pc-bios/optionrom/linuxboot_dma.c
Quoted 6 lines
It would be great to merge this but there's more work necessary.
I CCed Marc's current email address. He was interning at Red Hat but is now back at university so the Red Hat address is not being read.
Marc: What was still missing from this patch?
I'm sorry I have not answered before, it's been a very busy week.
What's missing (as I remember it):
- Debug loading an initrd from the new linuxboot
- Other minor comments in the thread (mainly, compile using mingw).
- Make it possible to disable DMA fw_cfg.
I've been putting this patch at the back of my todo list for too long. Let me address some deadlines for this week, and then I'll finish this patch.
Marc
Quoted 48 lines
Quoted 22 lines
pc-bios/optionrom/Makefile +4
-2@@ -13,15 +13,18 @@ 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.binkvmvapic.bin
# suppress auto-removal of intermediate files .SECONDARY:%.img: %.o
pc-bios/optionrom/Makefile +0
-1- $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e
_start-s -o $@ $<," Building $(TARGET_DIR)$@")pc-bios/optionrom/Makefile
Quoted 2 lines
pc-bios/optionrom/Makefile +1
-1+ $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386 -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")Gerd noted in <[email protected]>:
Hmm, that breaks the windows cross build:
make: Entering directory `/home/kraxel/projects/qemu/build-win32' Building optionrom/linuxboot_dma.img
i686-w64-mingw32-ld: unrecognised emulation mode:elf_i386Supported emulations: i386pe
make[1]: *** [linuxboot_dma.img] Error 1and then:
Testing shows two more problems:
(1) initrd loading is broken, kernel complains it finds only
gibberish:[ 0.934582] Unpacking initramfs... [ 1.166983] Initramfs unpacking failed: junk in compressedarchive [ 1.168458] Freeing initrd memory: 32812k freed
(2) going back to non-dma boot via -M pc-$old doesn't work,
appearentlyfw_cfgdma is enabled even for old machine types.
Quoted 4 lines · Richard W.M. Jones
This is an updated version of Marc Marí's Linux DMA patch, based on version 4 from:
https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg05891.html
Pls feel free to iterate, but pls also remember to post after 2.6 is out as we are in freeze.
Quoted 15 lines
All I have done for my "4.1" version is:
- Modify it so it compiles against the latest qemu. There was a change to how
fw_cfg.his split (6f061ea10f28c) which broke the patch.- Run checkpatch and fix several problems.
- Test it.
This patch greatly and transparently improves boot time of the libguestfs appliance on x86, and so I'd like to see it integrated upstream.
Rich.