Message ID | 20201105133923.23821-8-kraxel@redhat.com |
---|---|
State | New |
Headers | show |
Series | microvm: add second ioapic | expand |
On Thu, 5 Nov 2020 14:39:18 +0100 Gerd Hoffmann <kraxel@redhat.com> wrote: > Create second ioapic, route virtio-mmio IRQs to it, > allow more virtio-mmio devices (24 instead of 8). > > Needs ACPI, enabled by default, can be turned off > using -machine ioapic2=off > > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> > --- > include/hw/i386/microvm.h | 2 ++ > hw/i386/microvm.c | 51 ++++++++++++++++++++++++++++++++-- > tests/qtest/bios-tables-test.c | 8 +++--- > 3 files changed, 54 insertions(+), 7 deletions(-) > > diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h > index f1e9db059b85..f25f8374413f 100644 > --- a/include/hw/i386/microvm.h > +++ b/include/hw/i386/microvm.h > @@ -72,6 +72,7 @@ > #define MICROVM_MACHINE_PIC "pic" > #define MICROVM_MACHINE_RTC "rtc" > #define MICROVM_MACHINE_PCIE "pcie" > +#define MICROVM_MACHINE_IOAPIC2 "ioapic2" > #define MICROVM_MACHINE_ISA_SERIAL "isa-serial" > #define MICROVM_MACHINE_OPTION_ROMS "x-option-roms" > #define MICROVM_MACHINE_AUTO_KERNEL_CMDLINE "auto-kernel-cmdline" > @@ -90,6 +91,7 @@ struct MicrovmMachineState { > OnOffAuto pit; > OnOffAuto rtc; > OnOffAuto pcie; > + OnOffAuto ioapic2; > bool isa_serial; > bool option_roms; > bool auto_kernel_cmdline; > diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c > index 829b376a1278..cae0d8fc8692 100644 > --- a/hw/i386/microvm.c > +++ b/hw/i386/microvm.c > @@ -145,30 +145,50 @@ static void create_gpex(MicrovmMachineState *mms) > } > } > > +static int microvm_ioapics(MicrovmMachineState *mms) > +{ > + if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) { > + return 1; > + } > + if (mms->ioapic2 == ON_OFF_AUTO_OFF) { > + return 1; > + } > + return 2; > +} > + > static void microvm_devices_init(MicrovmMachineState *mms) > { > X86MachineState *x86ms = X86_MACHINE(mms); > ISABus *isa_bus; > ISADevice *rtc_state; > GSIState *gsi_state; > + int ioapics; > int i; > > /* Core components */ > - > + ioapics = microvm_ioapics(mms); maby nr_ioapics would be better. > gsi_state = g_malloc0(sizeof(*gsi_state)); > - x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS); > + x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, > + IOAPIC_NUM_PINS * ioapics); > > isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(), > &error_abort); > isa_bus_irqs(isa_bus, x86ms->gsi); > > ioapic_init_gsi(gsi_state, "machine"); > + if (ioapics > 1) { > + x86ms->ioapic2 = ioapic_init_secondary(gsi_state); > + } > > kvmclock_create(true); > > mms->virtio_irq_base = 5; > mms->virtio_num_transports = 8; > - if (x86_machine_is_acpi_enabled(x86ms)) { > + if (x86ms->ioapic2) { > + mms->pcie_irq_base = 16; > + mms->virtio_irq_base = 24; now I see where magic 24 comes from in 3/12 it should be a shared macro or a property that APIC code gets dynamically > + mms->virtio_num_transports = 24; > + } else if (x86_machine_is_acpi_enabled(x86ms)) { > mms->pcie_irq_base = 12; > mms->virtio_irq_base = 16; > } > @@ -544,6 +564,23 @@ static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name, > visit_type_OnOffAuto(v, name, &mms->pcie, errp); > } > > +static void microvm_machine_get_ioapic2(Object *obj, Visitor *v, const char *name, > + void *opaque, Error **errp) > +{ > + MicrovmMachineState *mms = MICROVM_MACHINE(obj); > + OnOffAuto ioapic2 = mms->ioapic2; > + > + visit_type_OnOffAuto(v, name, &ioapic2, errp); > +} > + > +static void microvm_machine_set_ioapic2(Object *obj, Visitor *v, const char *name, > + void *opaque, Error **errp) > +{ > + MicrovmMachineState *mms = MICROVM_MACHINE(obj); > + > + visit_type_OnOffAuto(v, name, &mms->ioapic2, errp); > +} > + > static bool microvm_machine_get_isa_serial(Object *obj, Error **errp) > { > MicrovmMachineState *mms = MICROVM_MACHINE(obj); > @@ -620,6 +657,7 @@ static void microvm_machine_initfn(Object *obj) > mms->pit = ON_OFF_AUTO_AUTO; > mms->rtc = ON_OFF_AUTO_AUTO; > mms->pcie = ON_OFF_AUTO_AUTO; > + mms->ioapic2 = ON_OFF_AUTO_AUTO; > mms->isa_serial = true; > mms->option_roms = true; > mms->auto_kernel_cmdline = true; > @@ -693,6 +731,13 @@ static void microvm_class_init(ObjectClass *oc, void *data) > object_class_property_set_description(oc, MICROVM_MACHINE_PCIE, > "Enable PCIe"); > > + object_class_property_add(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto", > + microvm_machine_get_ioapic2, > + microvm_machine_set_ioapic2, > + NULL, NULL); > + object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2, > + "Enable second IO-APIC"); > + > object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL, > microvm_machine_get_isa_serial, > microvm_machine_set_isa_serial); > diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c > index f23a5335a875..0a0ce76ffcf9 100644 > --- a/tests/qtest/bios-tables-test.c > +++ b/tests/qtest/bios-tables-test.c > @@ -1115,7 +1115,7 @@ static void test_acpi_microvm_tcg(void) > test_data data; > > test_acpi_microvm_prepare(&data); > - test_acpi_one(" -machine microvm,acpi=on,rtc=off", > + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off", > &data); > free_test_data(&data); > } > @@ -1126,7 +1126,7 @@ static void test_acpi_microvm_usb_tcg(void) > > test_acpi_microvm_prepare(&data); > data.variant = ".usb"; > - test_acpi_one(" -machine microvm,acpi=on,usb=on,rtc=off", > + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off", > &data); > free_test_data(&data); > } > @@ -1137,7 +1137,7 @@ static void test_acpi_microvm_rtc_tcg(void) > > test_acpi_microvm_prepare(&data); > data.variant = ".rtc"; > - test_acpi_one(" -machine microvm,acpi=on,rtc=on", > + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on", > &data); > free_test_data(&data); > } > @@ -1149,7 +1149,7 @@ static void test_acpi_microvm_pcie_tcg(void) > test_acpi_microvm_prepare(&data); > data.variant = ".pcie"; > data.tcg_only = true; /* need constant host-phys-bits */ > - test_acpi_one(" -machine microvm,acpi=on,rtc=off,pcie=on", > + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on", > &data); > free_test_data(&data); > }
diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h index f1e9db059b85..f25f8374413f 100644 --- a/include/hw/i386/microvm.h +++ b/include/hw/i386/microvm.h @@ -72,6 +72,7 @@ #define MICROVM_MACHINE_PIC "pic" #define MICROVM_MACHINE_RTC "rtc" #define MICROVM_MACHINE_PCIE "pcie" +#define MICROVM_MACHINE_IOAPIC2 "ioapic2" #define MICROVM_MACHINE_ISA_SERIAL "isa-serial" #define MICROVM_MACHINE_OPTION_ROMS "x-option-roms" #define MICROVM_MACHINE_AUTO_KERNEL_CMDLINE "auto-kernel-cmdline" @@ -90,6 +91,7 @@ struct MicrovmMachineState { OnOffAuto pit; OnOffAuto rtc; OnOffAuto pcie; + OnOffAuto ioapic2; bool isa_serial; bool option_roms; bool auto_kernel_cmdline; diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 829b376a1278..cae0d8fc8692 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -145,30 +145,50 @@ static void create_gpex(MicrovmMachineState *mms) } } +static int microvm_ioapics(MicrovmMachineState *mms) +{ + if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) { + return 1; + } + if (mms->ioapic2 == ON_OFF_AUTO_OFF) { + return 1; + } + return 2; +} + static void microvm_devices_init(MicrovmMachineState *mms) { X86MachineState *x86ms = X86_MACHINE(mms); ISABus *isa_bus; ISADevice *rtc_state; GSIState *gsi_state; + int ioapics; int i; /* Core components */ - + ioapics = microvm_ioapics(mms); gsi_state = g_malloc0(sizeof(*gsi_state)); - x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS); + x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, + IOAPIC_NUM_PINS * ioapics); isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(), &error_abort); isa_bus_irqs(isa_bus, x86ms->gsi); ioapic_init_gsi(gsi_state, "machine"); + if (ioapics > 1) { + x86ms->ioapic2 = ioapic_init_secondary(gsi_state); + } kvmclock_create(true); mms->virtio_irq_base = 5; mms->virtio_num_transports = 8; - if (x86_machine_is_acpi_enabled(x86ms)) { + if (x86ms->ioapic2) { + mms->pcie_irq_base = 16; + mms->virtio_irq_base = 24; + mms->virtio_num_transports = 24; + } else if (x86_machine_is_acpi_enabled(x86ms)) { mms->pcie_irq_base = 12; mms->virtio_irq_base = 16; } @@ -544,6 +564,23 @@ static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name, visit_type_OnOffAuto(v, name, &mms->pcie, errp); } +static void microvm_machine_get_ioapic2(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MicrovmMachineState *mms = MICROVM_MACHINE(obj); + OnOffAuto ioapic2 = mms->ioapic2; + + visit_type_OnOffAuto(v, name, &ioapic2, errp); +} + +static void microvm_machine_set_ioapic2(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MicrovmMachineState *mms = MICROVM_MACHINE(obj); + + visit_type_OnOffAuto(v, name, &mms->ioapic2, errp); +} + static bool microvm_machine_get_isa_serial(Object *obj, Error **errp) { MicrovmMachineState *mms = MICROVM_MACHINE(obj); @@ -620,6 +657,7 @@ static void microvm_machine_initfn(Object *obj) mms->pit = ON_OFF_AUTO_AUTO; mms->rtc = ON_OFF_AUTO_AUTO; mms->pcie = ON_OFF_AUTO_AUTO; + mms->ioapic2 = ON_OFF_AUTO_AUTO; mms->isa_serial = true; mms->option_roms = true; mms->auto_kernel_cmdline = true; @@ -693,6 +731,13 @@ static void microvm_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, MICROVM_MACHINE_PCIE, "Enable PCIe"); + object_class_property_add(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto", + microvm_machine_get_ioapic2, + microvm_machine_set_ioapic2, + NULL, NULL); + object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2, + "Enable second IO-APIC"); + object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL, microvm_machine_get_isa_serial, microvm_machine_set_isa_serial); diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index f23a5335a875..0a0ce76ffcf9 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -1115,7 +1115,7 @@ static void test_acpi_microvm_tcg(void) test_data data; test_acpi_microvm_prepare(&data); - test_acpi_one(" -machine microvm,acpi=on,rtc=off", + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off", &data); free_test_data(&data); } @@ -1126,7 +1126,7 @@ static void test_acpi_microvm_usb_tcg(void) test_acpi_microvm_prepare(&data); data.variant = ".usb"; - test_acpi_one(" -machine microvm,acpi=on,usb=on,rtc=off", + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off", &data); free_test_data(&data); } @@ -1137,7 +1137,7 @@ static void test_acpi_microvm_rtc_tcg(void) test_acpi_microvm_prepare(&data); data.variant = ".rtc"; - test_acpi_one(" -machine microvm,acpi=on,rtc=on", + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on", &data); free_test_data(&data); } @@ -1149,7 +1149,7 @@ static void test_acpi_microvm_pcie_tcg(void) test_acpi_microvm_prepare(&data); data.variant = ".pcie"; data.tcg_only = true; /* need constant host-phys-bits */ - test_acpi_one(" -machine microvm,acpi=on,rtc=off,pcie=on", + test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on", &data); free_test_data(&data); }
Create second ioapic, route virtio-mmio IRQs to it, allow more virtio-mmio devices (24 instead of 8). Needs ACPI, enabled by default, can be turned off using -machine ioapic2=off Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- include/hw/i386/microvm.h | 2 ++ hw/i386/microvm.c | 51 ++++++++++++++++++++++++++++++++-- tests/qtest/bios-tables-test.c | 8 +++--- 3 files changed, 54 insertions(+), 7 deletions(-)