multiboot: Use DMA instead port-based transfer
v2 cover multiboot: Use DMA instead port-based transfer
An updated version of the patch at
https://patchew.org/QEMU/[email protected]/,
which includes the necessary glue for compatibility with older machine types. When fw_cfg DMA is disabled, the existing ROM is used instead.
Marcus Hähnel (1):
optionrom: add a DMA-enabled multiboot ROM
Paolo Bonzini (2):
target/i386: move linuxboot_dma_enabled to X86MachineState target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine
types
hw/i386/microvm.c | 5 ++- hw/i386/multiboot.c | 10 ++++- hw/i386/multiboot.h | 4 +- hw/i386/pc.c | 8 ++-- hw/i386/pc_piix.c | 3 +- hw/i386/pc_q35.c | 3 +- hw/i386/x86.c | 7 ++-- include/hw/i386/pc.h | 3 -- include/hw/i386/x86.h | 5 ++- pc-bios/meson.build | 1 + pc-bios/multiboot_dma.bin | Bin 0 -> 1024 bytes pc-bios/optionrom/Makefile | 4 +- pc-bios/optionrom/multiboot.S | 4 +- pc-bios/optionrom/multiboot_dma.S | 2 + pc-bios/optionrom/optionrom.h | 66 ++++++++++++++++++++++++++++++ 15 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 pc-bios/multiboot_dma.bin create mode 100644 pc-bios/optionrom/multiboot_dma.S
Signature · 1 line
2.31.1
PATCH v2 1/3 target/i386: move linuxboot_dma_enabled to X86MachineState
This removes a parameter from x86_load_linux, and will avoid code duplication between the linux and multiboot cases once multiboot starts to support DMA.
--- hw/i386/microvm.c | 5 ++++- hw/i386/pc.c | 5 ++--- hw/i386/pc_piix.c | 3 ++- hw/i386/pc_q35.c | 3 ++- hw/i386/x86.c | 5 +++-- include/hw/i386/pc.h | 3 --- include/hw/i386/x86.h | 5 +++-- 7 files changed, 16 insertions(+), 13 deletions(-)
hw/i386/microvm.c +4 -1
@@ -331,7 +331,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)rom_set_fw (fw_cfg);if (machine->kernel_filename !=NULL ) { -x86_load_linux (x86ms, fw_cfg,0 , true, true); +x86_load_linux (x86ms, fw_cfg,0 , true); }if (mms->option_roms) {
@@ -667,6 +667,7 @@ static void microvm_machine_initfn(Object *obj)static void microvm_class_init (ObjectClass *oc,void *data) { +X86MachineClass *x86mc =X86_MACHINE_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);
@@ -697,6 +698,8 @@ static void microvm_class_init(ObjectClass *oc, void *data) hc->unplug_request = microvm_device_unplug_request_cb; hc->unplug = microvm_device_unplug_cb; + x86mc->fwcfg_dma_enabled = true; + object_class_property_add(oc, MICROVM_MACHINE_PIC, "OnOffAuto", microvm_machine_get_pic, microvm_machine_set_pic,
hw/i386/pc.c +2 -3
@@ -775,7 +775,7 @@ void xen_load_linux(PCMachineState *pcms)rom_set_fw (fw_cfg);x86_load_linux (x86ms, fw_cfg, pcmc->acpi_data_size, - pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled); + pcmc->pvh_enabled);for (i =0 ; i < nb_option_roms; i++) { assert(!strcmp(option_rom[i].name, "linuxboot.bin") || !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -927,7 +927,7 @@ void pc_memory_init(PCMachineState *pcms,if (linux_boot) {x86_load_linux (x86ms, fw_cfg, pcmc->acpi_data_size, - pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled); + pcmc->pvh_enabled); }for (i =0 ; i < nb_option_roms; i++) {
@@ -1664,7 +1664,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)/* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size =0x20000 +0x8000 ; - pcmc->linuxboot_dma_enabled = true; pcmc->pvh_enabled = true; pcmc->kvmclock_create_always = true;assert (!mc->get_hotplug_handler);
hw/i386/pc_piix.c +2 -1
@@ -620,11 +620,12 @@ DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,static void pc_i440fx_2_6_machine_options (MachineClass *m) { +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_2_7_machine_options (m); pcmc->legacy_cpu_hotplug = true; - pcmc->linuxboot_dma_enabled = false; + x86mc->fwcfg_dma_enabled = false;compat_props_add (m->compat_props, hw_compat_2_6, hw_compat_2_6_len);compat_props_add (m->compat_props, pc_compat_2_6, pc_compat_2_6_len); }
hw/i386/pc_q35.c +2 -1
@@ -573,11 +573,12 @@ DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,static void pc_q35_2_6_machine_options (MachineClass *m) { +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_2_7_machine_options (m); pcmc->legacy_cpu_hotplug = true; - pcmc->linuxboot_dma_enabled = false; + x86mc->fwcfg_dma_enabled = false;compat_props_add (m->compat_props, hw_compat_2_6, hw_compat_2_6_len);compat_props_add (m->compat_props, pc_compat_2_6, pc_compat_2_6_len); }
hw/i386/x86.c +3 -2
@@ -764,9 +764,9 @@ static bool load_elfboot(const char *kernel_filename,void x86_load_linux (X86MachineState *x86ms,FWCfgState *fw_cfg,int acpi_data_size, -bool pvh_enabled, -bool linuxboot_dma_enabled) +bool pvh_enabled) { +bool linuxboot_dma_enabled =X86_MACHINE_GET_CLASS (x86ms)->fwcfg_dma_enabled;uint16_t protocol;int setup_size, kernel_size, cmdline_size;int dtb_size, setup_data_offset;
@@ -1332,6 +1332,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; x86mc->compat_apic_id_mode = false; x86mc->save_tsc_khz = true; + x86mc->fwcfg_dma_enabled = true; nc->nmi_monitor_handler = x86_nmi; object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto",
include/hw/i386/pc.h +0 -3
@@ -116,9 +116,6 @@ struct PCMachineClass {/* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug; -/* use DMA capable linuxboot option rom */ -bool linuxboot_dma_enabled; -/* use PVH to load kernels that support this feature */ bool pvh_enabled;
include/hw/i386/x86.h +3 -2
@@ -38,6 +38,8 @@ struct X86MachineClass {bool save_tsc_khz;/* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; +/* use DMA capable linuxboot option rom */ +bool fwcfg_dma_enabled; };struct X86MachineState {
@@ -120,8 +122,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,void x86_load_linux (X86MachineState *x86ms,FWCfgState *fw_cfg,int acpi_data_size, -bool pvh_enabled, -bool linuxboot_dma_enabled); +bool pvh_enabled);bool x86_machine_is_smm_enabled (const X86MachineState *x86ms);bool x86_machine_is_acpi_enabled (const X86MachineState *x86ms);
Signature · 1 line
2.31.1
Re: [PATCH 1/3] target/i386: move linuxboot_dma_enabled to X86MachineState
Quoted 5 lines · Paolo Bonzini
This removes a parameter from
x86_load_linux, and will avoid code duplication between the linux and multiboot cases once multiboot starts to support DMA.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 9 lines
--- hw/i386/microvm.c | 5 ++++- hw/i386/pc.c | 5 ++--- hw/i386/pc_piix.c | 3 ++- hw/i386/pc_q35.c | 3 ++- hw/i386/x86.c | 5 +++-- include/hw/i386/pc.h | 3 --- include/hw/i386/x86.h | 5 +++-- 7 files changed, 16 insertions(+), 13 deletions(-)
PATCH v2 2/3 optionrom: add a DMA-enabled multiboot ROM
In reply to Paolo BonziniFrom: Marcus Hähnel <[email protected]>
Add a new option rom for the multiboot loader, using DMA transfers to copy data instead of "rep insb".
This significantly lowers QEMU's startup latency by a factor of about 40, for example, going from 30sec to 0.8sec when loading modules of 120MB in size.
[Modified to keep the non-DMA code depending on #ifdef USE_FW_CFG_DMA;
do not write below stack. - Paolo]
--- pc-bios/meson.build | 1 + pc-bios/multiboot_dma.bin | Bin 0 -> 1024 bytes pc-bios/optionrom/Makefile | 4 +- pc-bios/optionrom/multiboot.S | 4 +- pc-bios/optionrom/multiboot_dma.S | 2 + pc-bios/optionrom/optionrom.h | 66 ++++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 pc-bios/multiboot_dma.bin create mode 100644 pc-bios/optionrom/multiboot_dma.S
pc-bios/meson.build +1 -0
@@ -63,6 +63,7 @@ blobs = files( 'petalogix-s3adsp1800.dtb', 'petalogix-ml605.dtb', 'multiboot.bin', + 'multiboot_dma.bin', 'linuxboot.bin', 'linuxboot_dma.bin', 'kvmvapic.bin',
pc-bios/multiboot_dma.bin new file binary +0 -0
pc-bios/optionrom/Makefile +1 -3
@@ -2,7 +2,7 @@ include config.mak SRC_DIR := $(TOPSRC_DIR)/pc-bios/optionrom VPATH = $(SRC_DIR) -all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin +all: multiboot.bin multiboot_dma.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin # Dummy command so that make thinks it has done something @true
@@ -41,8 +41,6 @@ override CFLAGS += $(call cc-option, $(Wa)-32) LD_I386_EMULATION ?= elf_i386 override LDFLAGS = -m $(LD_I386_EMULATION) -T $(SRC_DIR)/flat.lds -all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin - pvh.img: pvh.o pvh_main.o %.o: %.S
pc-bios/optionrom/multiboot.S +2 -2
@@ -68,7 +68,7 @@ run_multiboot: mov %eax, %es /* Read the bootinfo struct into RAM */ - read_fw_blob(FW_CFG_INITRD) + read_fw_blob_dma(FW_CFG_INITRD) /* FS = bootinfo_struct */ read_fw FW_CFG_INITRD_ADDR
@@ -188,7 +188,7 @@ prot_mode: movl %eax, %gs /* Read the kernel and modules into RAM */ - read_fw_blob(FW_CFG_KERNEL) + read_fw_blob_dma(FW_CFG_KERNEL) /* Jump off to the kernel */ read_fw FW_CFG_KERNEL_ENTRY
pc-bios/optionrom/multiboot_dma.S new file +2 -0
@@ -0,0 +1,2 @@ +#define USE_FW_CFG_DMA 1 +#include "multiboot.S"
pc-bios/optionrom/optionrom.h +66 -0
78 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 2/3] optionrom: add a DMA-enabled multiboot ROM
pc-bios/multiboot_dma.bin
Quoted 40 lines · Paolo Bonzini
From: Marcus Hähnel <[email protected]>
Add a new option rom for the multiboot loader, using DMA transfers to copy data instead of "rep insb".
This significantly lowers QEMU's startup latency by a factor of about 40, for example, going from 30sec to 0.8sec when loading modules of 120MB in size.
Signed-off-by Marcus Hähnel <[email protected]>Signed-off-by Adam Lackorzynski <[email protected]>[Modified to keep the non-DMA code depending on #ifdef
USE_FW_CFG_DMA;
do not write below stack. - Paolo]Signed-off-by Paolo Bonzini <[email protected]>--- pc-bios/meson.build | 1 + pc-bios/multiboot_dma.bin | Bin 0 -> 1024 bytes pc-bios/optionrom/Makefile | 4 +- pc-bios/optionrom/multiboot.S | 4 +- pc-bios/optionrom/multiboot_dma.S | 2 + pc-bios/optionrom/optionrom.h | 66 ++++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 pc-bios/multiboot_dma.bin create mode 100644 pc-bios/optionrom/multiboot_dma.Spc-bios/multiboot_dma.bin new file binary +0
-0
Ideally this should be generated on CI as artifact, archived and we commit the CI generated file.
Quoted 37 lines
pc-bios/optionrom/optionrom.h +22
-0@@ -37,6 +37,17 @@#define BIOS_CFG_IOPORT_CFG 0x510#define BIOS_CFG_IOPORT_DATA 0x511 +#define FW_CFG_DMA_CTL_ERROR 0x01 +#define FW_CFG_DMA_CTL_READ 0x02 +#define FW_CFG_DMA_CTL_SKIP 0x04 +#define FW_CFG_DMA_CTL_SELECT 0x08 +#define FW_CFG_DMA_CTL_WRITE 0x10 + +#define FW_CFG_DMA_SIGNATURE 0x51454d5520434647ULL/* "QEMU CFG" */ + +#define BIOS_CFG_DMA_ADDR_HIGH 0x514 +#define BIOS_CFG_DMA_ADDR_LOW 0x518 +/* Break the translation block flow so -d cpu shows us values */ #define DEBUG_HERE \ jmp 1f; \@@ -62,6 +73,61 @@ bswap %eax .endm + +/* +* Read data from the fw_cfg device using DMA. +* Clobbers: %edx, %eax, ADDR, SIZE, memory[%esp-16] to memory[%esp] +*/ +.macro read_fw_dma VAR, SIZE, ADDR + /* Address */ + bswapl \ADDR + pushl \ADDR + +/* We only support 32 bit target addresses */
pc-bios/optionrom/optionrom.h line 96
Quoted 10 lines
pc-bios/optionrom/optionrom.h +10
-0+ xorl %eax, %eax + pushl %eax + mov $BIOS_CFG_DMA_ADDR_HIGH, %dx + outl %eax, (%dx) + +/* Size */ + bswapl \SIZE + pushl \SIZE + +/* Control */
Indent off.
Quoted 4 lines
pc-bios/optionrom/optionrom.h +4
-0+ movl $(\VAR << 16) | (FW_CFG_DMA_CTL_READ | FW_CFG_DMA_CTL_SELECT), %eax + bswapl %eax + pushl %eax +
pc-bios/optionrom/optionrom.h line 110
Quoted 10 lines
pc-bios/optionrom/optionrom.h +10
-0+ movl %esp, %eax /* Address of the struct we generated */ + bswapl %eax + mov $BIOS_CFG_DMA_ADDR_LOW, %dx + outl %eax, (%dx) /* Initiate DMA */ + +1: mov (%esp), %eax /* Wait for completion */ + bswapl %eax + testl $~FW_CFG_DMA_CTL_ERROR, %eax + jnz 1b + addl $16, %esp
Indent off.
PATCH v2 3/3 target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine types
In reply to Paolo BonziniAs long as fw_cfg supports DMA, the new ROM can be used also on older machine types because it has the same size as the existing one.
--- hw/i386/multiboot.c | 10 ++++++++-- hw/i386/multiboot.h | 4 +++- hw/i386/pc.c | 3 ++- hw/i386/x86.c | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-)
hw/i386/multiboot.c +8 -2
@@ -143,7 +143,8 @@ static void mb_add_mod(MultibootState *s, s->mb_mods_count++; } -int load_multiboot(FWCfgState *fw_cfg, +int load_multiboot(X86MachineState *x86ms, + FWCfgState *fw_cfg, FILE *f, const char *kernel_filename, const char *initrd_filename,
@@ -151,6 +152,7 @@ int load_multiboot(FWCfgState *fw_cfg,int kernel_file_size, uint8_t *header) { + bool multiboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled;int i, is_multiboot =0 ;uint32_t flags =0 ;uint32_t mh_entry_addr;
@@ -401,7 +403,11 @@ int load_multiboot(FWCfgState *fw_cfg,fw_cfg_add_bytes (fw_cfg,FW_CFG_INITRD_DATA , mb_bootinfo_data,sizeof (bootinfo)); - option_rom[nb_option_roms].name ="multiboot.bin" ; +if (multiboot_dma_enabled) { + option_rom[nb_option_roms].name ="multiboot_dma.bin" ; + }else { + option_rom[nb_option_roms].name ="multiboot.bin" ; + } option_rom[nb_option_roms].bootindex =0 ; nb_option_roms++;
hw/i386/multiboot.h +3 -1
@@ -2,8 +2,10 @@#define QEMU_MULTIBOOT_H #include "hw/nvram/fw_cfg.h" +#include "hw/i386/x86.h" -int load_multiboot(FWCfgState *fw_cfg, +int load_multiboot(X86MachineState *x86ms, + FWCfgState *fw_cfg, FILE *f, const char *kernel_filename, const char *initrd_filename,
hw/i386/pc.c +2 -1
@@ -780,7 +780,8 @@ void xen_load_linux(PCMachineState *pcms)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" )); + !strcmp (option_rom[i].name,"multiboot.bin" ) || + !strcmp (option_rom[i].name,"multiboot_dma.bin" ));rom_add_option (option_rom[i].name, option_rom[i].bootindex); } x86ms->fw_cfg = fw_cfg;
hw/i386/x86.c +1 -1
@@ -814,7 +814,7 @@ void x86_load_linux(X86MachineState *x86ms,* PVH), so we try multiboot first since we check the multiboot magic * header before to load it. */ -if (load_multiboot (fw_cfg, f, kernel_filename, initrd_filename, +if (load_multiboot (x86ms, fw_cfg, f, kernel_filename, initrd_filename, kernel_cmdline, kernel_size, header)) {return ; }
Signature · 1 line
2.31.1
Re: [PATCH 3/3] target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine types
Quoted 10 lines · Paolo Bonzini
As long as
fw_cfgsupports DMA, the new ROM can be used also on older machine types because it has the same size as the existing one.Signed-off-by Paolo Bonzini <[email protected]>--- hw/i386/multiboot.c | 10 ++++++++-- hw/i386/multiboot.h | 4 +++- hw/i386/pc.c | 3 ++- hw/i386/x86.c | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-)
Quoted 30 lines · Paolo Bonzini
An updated version of the patch at
https://patchew.org/QEMU/[email protected]/,
which includes the necessary glue for compatibility with older machine types. Whenfw_cfgDMA is disabled, the existing ROM is used instead.Marcus Hähnel (1):
optionrom: add a DMA-enabled multiboot ROMPaolo Bonzini (2):
target/i386: movelinuxboot_dma_enabledto X86MachineState target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine
typeshw/i386/microvm.c | 5 ++- hw/i386/multiboot.c | 10 ++++- hw/i386/multiboot.h | 4 +- hw/i386/pc.c | 8 ++-- hw/i386/pc_piix.c | 3 +- hw/i386/pc_q35.c | 3 +- hw/i386/x86.c | 7 ++-- include/hw/i386/pc.h | 3 -- include/hw/i386/x86.h | 5 ++- pc-bios/meson.build | 1 + pc-bios/multiboot_dma.bin | Bin 0 -> 1024 bytes pc-bios/optionrom/Makefile | 4 +- pc-bios/optionrom/multiboot.S | 4 +- pc-bios/optionrom/multiboot_dma.S | 2 + pc-bios/optionrom/optionrom.h | 66 ++++++++++++++++++++++++++++++ 15 files changed, 102 insertions(+), 23 deletions(-)
Quoted 7 lines
create mode 100644 pc-bios/multiboot_dma.bin create mode 100644
pc-bios/optionrom/multiboot_dma.SSignature · 1 line
2.31.1