Skip to contentSkip to conversation

microvm: add acpi support

PATCH Superseded Gerd Hoffmann 7 participants 51 messages Mar 19, 2020 – Mar 27, 2020

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover microvm: add acpi support

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

cheers,
Gerd

Gerd Hoffmann (13):
acpi: make build_madt() more generic.
acpi: factor out acpi_dsdt_add_fw_cfg()
microvm: add isa-acpi device
microvm: add minimal acpi support.
microvm: add acpi_dsdt_add_virtio() for x86
microvm: disable virtio-mmio cmdline hack
[testing] seabios: update submodule to experimental microvm branch [testing] seabios: update config & build rules [testing] seabios: update binaries to experimental microvm branch microvm/acpi: add rtc
microvm/acpi: add serial
microvm: make virtio irq base runtime configurable microvm/acpi: use GSI 16-23 for virtio

 include/hw/i386/microvm.h   |   8 +-
 hw/acpi/isa-acpi.c          | 114 +++++++++++++++
 hw/i386/acpi-build.c        | 278 +++++++++++++++++++++++++++++-------
 hw/i386/microvm.c           |  32 +++--
 hw/acpi/Makefile.objs       |   1 +
 pc-bios/bios-256k.bin       | Bin 262144 -> 262144 bytes
 pc-bios/bios-microvm.bin    | Bin 65536 -> 131072 bytes
 pc-bios/bios.bin            | Bin 131072 -> 131072 bytes
 roms/Makefile               |   5 +-
 roms/config.seabios-128k    |   2 +
 roms/config.seabios-microvm |  25 ++++
 roms/seabios                |   2 +-
 12 files changed, 403 insertions(+), 64 deletions(-)
 create mode 100644 hw/acpi/isa-acpi.c
 create mode 100644 roms/config.seabios-microvm
Signature · 1 line
2.18.2
#6 lore raw

PATCH 3/13 microvm: add isa-acpi device

Minimal ACPI device for PCI-less machines like microvm.

---
 hw/acpi/isa-acpi.c    | 114 ++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/Makefile.objs |   1 +
 2 files changed, 115 insertions(+)
 create mode 100644 hw/acpi/isa-acpi.c
hw/acpi/isa-acpi.c new file +114 -0
new file mode 100644
index 000000000000..5d7d770a5c0b
@@ -0,0 +1,114 @@
+#include "qemu/osdep.h"
+#include "hw/i386/pc.h"
+#include "hw/acpi/acpi.h"
+#include "sysemu/runstate.h"
+
+typedef struct ISAACPI {
+    ISADevice base;
+
+    uint32_t io_base;
+    uint16_t sci_irq;
+    uint32_t gpe_base;
+    uint32_t gpe_len;
+
+    qemu_irq irq;
+    MemoryRegion io;
+    ACPIREGS acpi;
+    Notifier powerdown_req;
+} ISAACPI;
+
+#define TYPE_ISA_ACPI "isa-acpi"
+#define ISA_ACPI(obj) \
+    OBJECT_CHECK(ISAACPI, (obj), TYPE_ISA_ACPI)
+
+static void isa_acpi_timer(ACPIREGS *acpi)
+{
+    ISAACPI *s = container_of(acpi, ISAACPI, acpi);
+    acpi_update_sci(&s->acpi, s->irq);
+}
+
+static void isa_acpi_init(Object *obj)
+{
+    ISAACPI *s = ISA_ACPI(obj);
+
+    s->io_base = 0x600;
+    s->sci_irq = 9;
+    s->gpe_base = 0x680;
+    s->gpe_len = 4;
+}
+
+static void isa_acpi_powerdown_req(Notifier *n, void *opaque)
+{
+    ISAACPI *s = container_of(n, ISAACPI, powerdown_req);
+
+    acpi_pm1_evt_power_down(&s->acpi);
+}
+
+static void isa_acpi_add_propeties(ISAACPI *s)
+{
+    static const uint8_t zero;
+
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
+                                  &zero, NULL);
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
+                                  &zero, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
+                                   &s->gpe_base, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
+                                   &s->gpe_len, NULL);
+    object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
+                                   &s->sci_irq, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
+                                   &s->io_base, NULL);
+}
+
+static void isa_acpi_realize(DeviceState *dev, Error **errp)
+{
+    ISADevice *isa = ISA_DEVICE(dev);
+    ISAACPI *s = ISA_ACPI(dev);
+
+    memory_region_init(&s->io, OBJECT(s), "isa-acpi", 64);
+    memory_region_set_enabled(&s->io, true);
+    isa_register_ioport(isa, &s->io, s->io_base);
+    isa_init_irq(isa, &s->irq, s->sci_irq);
+
+    acpi_pm_tmr_init(&s->acpi, isa_acpi_timer, &s->io);
+    acpi_pm1_evt_init(&s->acpi, isa_acpi_timer, &s->io);
+    acpi_pm1_cnt_init(&s->acpi, &s->io, true, true, 0);
+    acpi_gpe_init(&s->acpi, 4);
+
+    s->powerdown_req.notify = isa_acpi_powerdown_req;
+    qemu_register_powerdown_notifier(&s->powerdown_req);
+
+    isa_acpi_add_propeties(s);
+}
+
+static void isa_acpi_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
+
+    dc->realize = isa_acpi_realize;
+    dc->user_creatable = false;
+    dc->hotpluggable = false;
+    adevc->madt_cpu = pc_madt_cpu_entry;
+}
+
+static const TypeInfo isa_acpi_info = {
+    .name          = TYPE_ISA_ACPI,
+    .parent        = TYPE_ISA_DEVICE,
+    .instance_size = sizeof(ISAACPI),
+    .instance_init = isa_acpi_init,
+    .class_init    = isa_acpi_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_ACPI_DEVICE_IF },
+        { }
+    }
+};
+
+static void register_types(void)
+{
+    type_register_static(&isa_acpi_info);
+}
+
+type_init(register_types)
hw/acpi/Makefile.objs +1 -0
index 777da07f4d70..aae53c73ebbd 100644
@@ -14,6 +14,7 @@ common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o
 common-obj-y += acpi_interface.o
 common-obj-y += bios-linker-loader.o
 common-obj-y += aml-build.o utils.o
+common-obj-$(CONFIG_PC) += isa-acpi.o
 common-obj-$(CONFIG_ACPI_PCI) += pci.o
 common-obj-$(CONFIG_TPM) += tpm.o
 
Signature · 1 line
2.18.2
#3 lore raw

PATCH 2/13 acpi: factor out acpi_dsdt_add_fw_cfg()

In reply to Gerd Hoffmann

Add helper function to add fw_cfg device.

---
 hw/i386/acpi-build.c | 50 ++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 23 deletions(-)
hw/i386/acpi-build.c +27 -23
index 1b0684c433e3..9c98b07116cc 100644
@@ -1822,6 +1822,32 @@ static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func)
     aml_append(table, scope);
 }
 
+static void acpi_dsdt_add_fw_cfg(Aml *scope, Object *fw_cfg)
+{
+    /*
+     * when using port i/o, the 8-bit data register *always* overlaps
+     * with half of the 16-bit control register. Hence, the total size
+     * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
+     * DMA control register is located at FW_CFG_DMA_IO_BASE + 4
+     */
+    uint8_t io_size = object_property_get_bool(fw_cfg, "dma_enabled", NULL) ?
+        ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
+        FW_CFG_CTL_SIZE;
+    Aml *dev = aml_device("FWCF");
+    Aml *crs = aml_resource_template();
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+    /* device present, functioning, decoding, not shown in UI */
+    aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+
+    aml_append(crs,
+        aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size));
+
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -2101,30 +2127,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 
     /* create fw_cfg node, unconditionally */
     {
-        /* when using port i/o, the 8-bit data register *always* overlaps
-         * with half of the 16-bit control register. Hence, the total size
-         * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
-         * DMA control register is located at FW_CFG_DMA_IO_BASE + 4 */
-        uint8_t io_size = object_property_get_bool(OBJECT(x86ms->fw_cfg),
-                                                   "dma_enabled", NULL) ?
-                          ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
-                          FW_CFG_CTL_SIZE;
-
         scope = aml_scope("\\_SB.PCI0");
-        dev = aml_device("FWCF");
-
-        aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
-
-        /* device present, functioning, decoding, not shown in UI */
-        aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
-
-        crs = aml_resource_template();
-        aml_append(crs,
-            aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size)
-        );
-        aml_append(dev, aml_name_decl("_CRS", crs));
-
-        aml_append(scope, dev);
+        acpi_dsdt_add_fw_cfg(scope, OBJECT(x86ms->fw_cfg));
         aml_append(dsdt, scope);
     }
 
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/13 acpi: make build_madt() more generic.

In reply to Gerd Hoffmann

Remove PCMachineState dependency from build_madt(). Pass AcpiDeviceIf as separate argument instead of depending on PCMachineState->acpi_dev.

---
 hw/i386/acpi-build.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +7 -7
index 9a19c14e661b..1b0684c433e3 100644
@@ -360,14 +360,13 @@ void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
 }
 
 static void
-build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
+build_madt(GArray *table_data, BIOSLinker *linker,
+           X86MachineState *x86ms, AcpiDeviceIf *adev)
 {
-    MachineClass *mc = MACHINE_GET_CLASS(pcms);
-    X86MachineState *x86ms = X86_MACHINE(pcms);
-    const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(pcms));
+    MachineClass *mc = MACHINE_GET_CLASS(x86ms);
+    const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
     int madt_start = table_data->len;
-    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(pcms->acpi_dev);
-    AcpiDeviceIf *adev = ACPI_DEVICE_IF(pcms->acpi_dev);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
     bool x2apic_mode = false;
 
     AcpiMultipleApicTable *madt;
@@ -2807,7 +2806,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     aml_len += tables_blob->len - fadt;
 
     acpi_add_table(table_offsets, tables_blob);
-    build_madt(tables_blob, tables->linker, pcms);
+    build_madt(tables_blob, tables->linker, x86ms,
+               ACPI_DEVICE_IF(pcms->acpi_dev));
 
     vmgenid_dev = find_vmgenid_dev();
     if (vmgenid_dev) {
Signature · 1 line
2.18.2
#23 lore raw

PATCH 12/13 microvm: make virtio irq base runtime configurable

In reply to Gerd Hoffmann
---
 include/hw/i386/microvm.h |  2 +-
 hw/i386/acpi-build.c      |  6 +++---
 hw/i386/microvm.c         | 11 +++++++----
 3 files changed, 11 insertions(+), 8 deletions(-)
include/hw/i386/microvm.h +1 -1
index 53b2457db752..87828325ec32 100644
@@ -28,7 +28,6 @@
 
 /* Platform virtio definitions */
 #define VIRTIO_MMIO_BASE      0xc0000000
-#define VIRTIO_IRQ_BASE       5
 #define VIRTIO_NUM_TRANSPORTS 8
 #define VIRTIO_CMDLINE_MAXLEN 64
 
@@ -61,6 +60,7 @@ typedef struct {
     ISADevice *rtc_state;
 
     /* Machine state */
+    uint32_t virtio_irq_base;
     bool kernel_cmdline_fixed;
     Notifier machine_done;
     AcpiDeviceIf *acpi_dev;
hw/i386/acpi-build.c +3 -3
index b765c31c80b0..9bddeb77704d 100644
@@ -2755,7 +2755,7 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
     return true;
 }
 
-static void acpi_dsdt_add_virtio(Aml *scope)
+static void acpi_dsdt_add_virtio(Aml *scope, MicrovmMachineState *mms)
 {
     gchar *separator;
     long int index;
@@ -2783,7 +2783,7 @@ static void acpi_dsdt_add_virtio(Aml *scope)
                 continue;
             }
 
-            uint32_t irq = VIRTIO_IRQ_BASE + index;
+            uint32_t irq = mms->virtio_irq_base + index;
             hwaddr base = VIRTIO_MMIO_BASE + index * 512;
             hwaddr size = 512;
 
@@ -2825,7 +2825,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
         aml_append(sb_scope, build_com_device_aml(1, false));
     }
     acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
-    acpi_dsdt_add_virtio(sb_scope);
+    acpi_dsdt_add_virtio(sb_scope, mms);
     aml_append(dsdt, sb_scope);
 
     scope = aml_scope("\\");
hw/i386/microvm.c +7 -4
index 748f9826fb0e..834b10aee0a2 100644
@@ -122,10 +122,11 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     kvmclock_create();
 
+    mms->virtio_irq_base = 8;
     for (i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) {
         sysbus_create_simple("virtio-mmio",
                              VIRTIO_MMIO_BASE + i * 512,
-                             x86ms->gsi[VIRTIO_IRQ_BASE + i]);
+                             x86ms->gsi[mms->virtio_irq_base + i]);
     }
 
     /* Optional and legacy devices */
@@ -265,7 +266,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
     x86ms->ioapic_as = &address_space_memory;
 }
 
-static gchar *microvm_get_mmio_cmdline(gchar *name)
+static gchar *microvm_get_mmio_cmdline(gchar *name, uint32_t virtio_irq_base)
 {
     gchar *cmdline;
     gchar *separator;
@@ -285,7 +286,7 @@ static gchar *microvm_get_mmio_cmdline(gchar *name)
     ret = g_snprintf(cmdline, VIRTIO_CMDLINE_MAXLEN,
                      " virtio_mmio.device=512@0x%lx:%ld",
                      VIRTIO_MMIO_BASE + index * 512,
-                     VIRTIO_IRQ_BASE + index);
+                     virtio_irq_base + index);
     if (ret < 0 || ret >= VIRTIO_CMDLINE_MAXLEN) {
         g_free(cmdline);
         return NULL;
@@ -297,6 +298,7 @@ static gchar *microvm_get_mmio_cmdline(gchar *name)
 static void microvm_fix_kernel_cmdline(MachineState *machine)
 {
     X86MachineState *x86ms = X86_MACHINE(machine);
+    MicrovmMachineState *mms = MICROVM_MACHINE(machine);
     BusState *bus;
     BusChild *kid;
     char *cmdline;
@@ -320,7 +322,8 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)
             BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
 
             if (!QTAILQ_EMPTY(&mmio_bus->children)) {
-                gchar *mmio_cmdline = microvm_get_mmio_cmdline(mmio_bus->name);
+                gchar *mmio_cmdline = microvm_get_mmio_cmdline
+                    (mmio_bus->name, mms->virtio_irq_base);
                 if (mmio_cmdline) {
                     char *newcmd = g_strjoin(NULL, cmdline, mmio_cmdline, NULL);
                     g_free(mmio_cmdline);
Signature · 1 line
2.18.2
#22 lore raw

PATCH 11/13 microvm/acpi: add serial

In reply to Gerd Hoffmann
---
 hw/i386/acpi-build.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
hw/i386/acpi-build.c +21 -15
index 928e0ee2deeb..b765c31c80b0 100644
@@ -1226,7 +1226,7 @@ static Aml *build_lpt_device_aml(void)
     return dev;
 }
 
-static Aml *build_com_device_aml(uint8_t uid)
+static Aml *build_com_device_aml(uint8_t uid, bool sta)
 {
     Aml *dev;
     Aml *crs;
@@ -1250,19 +1250,22 @@ static Aml *build_com_device_aml(uint8_t uid)
     aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0501")));
     aml_append(dev, aml_name_decl("_UID", aml_int(uid)));
 
-    method = aml_method("_STA", 0, AML_NOTSERIALIZED);
-    aml_append(method, aml_store(aml_name("%s", enabled_field), is_present));
-    if_ctx = aml_if(aml_equal(is_present, zero));
-    {
-        aml_append(if_ctx, aml_return(aml_int(0x00)));
+    if (sta) {
+        method = aml_method("_STA", 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_store(aml_name("%s", enabled_field),
+                                         is_present));
+        if_ctx = aml_if(aml_equal(is_present, zero));
+        {
+            aml_append(if_ctx, aml_return(aml_int(0x00)));
+        }
+        aml_append(method, if_ctx);
+        else_ctx = aml_else();
+        {
+            aml_append(else_ctx, aml_return(aml_int(0x0f)));
+        }
+        aml_append(method, else_ctx);
+        aml_append(dev, method);
     }
-    aml_append(method, if_ctx);
-    else_ctx = aml_else();
-    {
-        aml_append(else_ctx, aml_return(aml_int(0x0f)));
-    }
-    aml_append(method, else_ctx);
-    aml_append(dev, method);
 
     crs = aml_resource_template();
     aml_append(crs, aml_io(AML_DECODE16, io_port, io_port, 0x00, 0x08));
@@ -1287,8 +1290,8 @@ static void build_isa_devices_aml(Aml *table)
         aml_append(scope, build_fdc_device_aml(fdc));
     }
     aml_append(scope, build_lpt_device_aml());
-    aml_append(scope, build_com_device_aml(1));
-    aml_append(scope, build_com_device_aml(2));
+    aml_append(scope, build_com_device_aml(1, true));
+    aml_append(scope, build_com_device_aml(2, true));
 
     if (ambiguous) {
         error_report("Multiple ISA busses, unable to define IPMI ACPI data");
@@ -2818,6 +2821,9 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
     if (mms->rtc_state) {
         aml_append(sb_scope, build_rtc_device_aml());
     }
+    if (mms->isa_serial) {
+        aml_append(sb_scope, build_com_device_aml(1, false));
+    }
     acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
     acpi_dsdt_add_virtio(sb_scope);
     aml_append(dsdt, sb_scope);
Signature · 1 line
2.18.2
#10 lore raw

PATCH 4/13 microvm: add minimal acpi support.

In reply to Gerd Hoffmann

$subject says all. Can be disabled using the usual -no-acpi switch.

---
 include/hw/i386/microvm.h |   3 +
 hw/i386/acpi-build.c      | 124 +++++++++++++++++++++++++++++++++++---
 hw/i386/microvm.c         |  14 +++++
 3 files changed, 133 insertions(+), 8 deletions(-)
include/hw/i386/microvm.h +3 -0
index ba68d1f22bb3..da2852a70195 100644
@@ -24,6 +24,7 @@
 
 #include "hw/boards.h"
 #include "hw/i386/x86.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 /* Platform virtio definitions */
 #define VIRTIO_MMIO_BASE      0xc0000000
@@ -58,6 +59,8 @@ typedef struct {
 
     /* Machine state */
     bool kernel_cmdline_fixed;
+    Notifier machine_done;
+    AcpiDeviceIf *acpi_dev;
 } MicrovmMachineState;
 
 #define TYPE_MICROVM_MACHINE   MACHINE_TYPE_NAME("microvm")
hw/i386/acpi-build.c +116 -8

175 lines not on this page · raw message

hw/i386/microvm.c +14 -0
index 38d8e5170323..362d513f38e1 100644
@@ -26,6 +26,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
+#include "acpi-build.h"
 
 #include "hw/loader.h"
 #include "hw/irq.h"
@@ -41,6 +42,7 @@
 #include "hw/i386/e820_memory_layout.h"
 #include "hw/i386/fw_cfg.h"
 #include "hw/virtio/virtio-mmio.h"
+#include "hw/acpi/acpi.h"
 
 #include "cpu.h"
 #include "elf.h"
@@ -128,6 +130,10 @@ static void microvm_devices_init(MicrovmMachineState *mms)
     }
 
     /* Optional and legacy devices */
+    if (acpi_enabled) {
+        ISADevice *acpi = isa_create_simple(isa_bus, "isa-acpi" /* FIXME */);
+        mms->acpi_dev = ACPI_DEVICE_IF(acpi);
+    }
 
     if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) {
         qemu_irq *i8259;
@@ -468,6 +474,11 @@ static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value,
     mms->auto_kernel_cmdline = value;
 }
 
+static void microvm_machine_done(Notifier *notifier, void *data)
+{
+    acpi_setup();
+}
+
 static void microvm_machine_initfn(Object *obj)
 {
     MicrovmMachineState *mms = MICROVM_MACHINE(obj);
@@ -482,6 +493,9 @@ static void microvm_machine_initfn(Object *obj)
 
     /* State */
     mms->kernel_cmdline_fixed = false;
+
+    mms->machine_done.notify = microvm_machine_done;
+    qemu_add_machine_init_done_notifier(&mms->machine_done);
 }
 
 static void microvm_class_init(ObjectClass *oc, void *data)
Signature · 1 line
2.18.2
#19 lore raw

PATCH 8/13 seabios: update config & build rules

In reply to Gerd Hoffmann
---
 roms/Makefile               |  5 ++++-
 roms/config.seabios-128k    |  2 ++
 roms/config.seabios-microvm | 25 +++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 roms/config.seabios-microvm
roms/Makefile +4 -1
index f9acf39954dc..c0dde0a063c6 100644
@@ -72,9 +72,12 @@ default help:
 	@echo "  clean              -- delete the files generated by the previous" \
 	                              "build targets"
 
-bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
+bios: build-seabios-config-seabios-128k \
+		build-seabios-config-seabios-256k \
+		build-seabios-config-seabios-microvm
 	cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
 	cp seabios/builds/seabios-256k/bios.bin ../pc-bios/bios-256k.bin
+	cp seabios/builds/seabios-microvm/bios.bin ../pc-bios/bios-microvm.bin
 
 vgabios seavgabios: $(patsubst %,seavgabios-%,$(vgabios_variants))
 
roms/config.seabios-128k +2 -0
index c43912bf9de4..bbed77cfc5c5 100644
@@ -11,6 +11,8 @@ CONFIG_USB_UAS=n
 CONFIG_SDCARD=n
 CONFIG_TCGBIOS=n
 CONFIG_MPT_SCSI=n
+CONFIG_ESP_SCSI=n
+CONFIG_MEGASAS=n
 CONFIG_PVSCSI=n
 CONFIG_NVME=n
 CONFIG_USE_SMM=n
roms/config.seabios-microvm new file +25 -0
new file mode 100644
index 000000000000..46bb019ada68
@@ -0,0 +1,25 @@
+CONFIG_QEMU=y
+CONFIG_QEMU_HARDWARE=y
+CONFIG_PERMIT_UNALIGNED_PCIROM=y
+CONFIG_ROM_SIZE=128
+CONFIG_XEN=n
+CONFIG_BOOTSPLASH=n
+CONFIG_ATA=n
+CONFIG_AHCI=n
+CONFIG_SDCARD=n
+CONFIG_PVSCSI=n
+CONFIG_ESP_SCSI=n
+CONFIG_LSI_SCSI=n
+CONFIG_MEGASAS=n
+CONFIG_MPT_SCSI=n
+CONFIG_FLOPPY=n
+CONFIG_FLASH_FLOPPY=n
+CONFIG_NVME=n
+CONFIG_PS2PORT=n
+CONFIG_USB=n
+CONFIG_LPT=n
+CONFIG_RTC_TIMER=n
+CONFIG_USE_SMM=n
+CONFIG_PMTIMER=n
+CONFIG_TCGBIOS=n
+CONFIG_HARDWARE_IRQ=n
Signature · 1 line
2.18.2
#21 lore raw

PATCH 10/13 microvm/acpi: add rtc

In reply to Gerd Hoffmann
---
 include/hw/i386/microvm.h | 3 +++
 hw/i386/acpi-build.c      | 3 +++
 hw/i386/microvm.c         | 5 ++---
 3 files changed, 8 insertions(+), 3 deletions(-)
include/hw/i386/microvm.h +3 -0
index da2852a70195..53b2457db752 100644
@@ -57,6 +57,9 @@ typedef struct {
     bool option_roms;
     bool auto_kernel_cmdline;
 
+    /* built-in devices */
+    ISADevice *rtc_state;
+
     /* Machine state */
     bool kernel_cmdline_fixed;
     Notifier machine_done;
hw/i386/acpi-build.c +3 -0
index 80844db24d6b..928e0ee2deeb 100644
@@ -2815,6 +2815,9 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
     build_dbg_aml(dsdt);
 
     sb_scope = aml_scope("_SB");
+    if (mms->rtc_state) {
+        aml_append(sb_scope, build_rtc_device_aml());
+    }
     acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
     acpi_dsdt_add_virtio(sb_scope);
     aml_append(dsdt, sb_scope);
hw/i386/microvm.c +2 -3
index fd753764fc10..748f9826fb0e 100644
@@ -101,7 +101,6 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 {
     X86MachineState *x86ms = X86_MACHINE(mms);
     ISABus *isa_bus;
-    ISADevice *rtc_state;
     GSIState *gsi_state;
     int i;
 
@@ -155,8 +154,8 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     if (mms->rtc == ON_OFF_AUTO_ON ||
         (mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) {
-        rtc_state = mc146818_rtc_init(isa_bus, 2000, NULL);
-        microvm_set_rtc(mms, rtc_state);
+        mms->rtc_state = mc146818_rtc_init(isa_bus, 2000, NULL);
+        microvm_set_rtc(mms, mms->rtc_state);
     }
 
     if (mms->isa_serial) {
Signature · 1 line
2.18.2
#20 lore raw

PATCH 9/13 seabios: update binaries to experimental microvm branch

In reply to Gerd Hoffmann
---
 pc-bios/bios-256k.bin    | Bin 262144 -> 262144 bytes
 pc-bios/bios-microvm.bin | Bin 65536 -> 131072 bytes
 pc-bios/bios.bin         | Bin 131072 -> 131072 bytes
 3 files changed, 0 insertions(+), 0 deletions(-)
pc-bios/bios-256k.bin binary +0 -0
index 4af7f7d5a91bcc19905e1742b0706e034e2a655c..2353030885b29d3daa7186e9ce9bc4cf234cec93 100644
GIT binary patch
pc-bios/bios-microvm.bin binary +0 -0
index 45eabc516692e2d134bbb630d133c7c2dcc9a9b6..e0ad759c3625b06d43443e3b303aceb7bed85984 100644
GIT binary patch
pc-bios/bios.bin binary +0 -0
index 67874c31b8b0284eb292deb2c9ebc191fa2d73b6..c421c0566101486cb80bddca6d1644d623d6b104 100644
GIT binary patch
Signature · 1 line
2.18.2
#24 lore raw

PATCH 13/13 microvm/acpi: use GSI 16-23 for virtio

In reply to Gerd Hoffmann

With ACPI enabled and IO-APIC being properly declared in the ACPI tables we can use interrupt lines 16-23 for virtio and avoid shared interrupts.

With acpi disabled we continue to use lines 8-15.

---
 hw/i386/microvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/microvm.c +1 -1
index 834b10aee0a2..139181daed06 100644
@@ -122,7 +122,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     kvmclock_create();
 
-    mms->virtio_irq_base = 8;
+    mms->virtio_irq_base = acpi_enabled ? 16 : 8;
     for (i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) {
         sysbus_create_simple("virtio-mmio",
                              VIRTIO_MMIO_BASE + i * 512,
Signature · 1 line
2.18.2
#17 lore raw

PATCH 6/13 microvm: disable virtio-mmio cmdline hack

In reply to Gerd Hoffmann

... in case we are using ACPI.

---
 hw/i386/microvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/microvm.c +1 -1
index 362d513f38e1..fd753764fc10 100644
@@ -361,7 +361,7 @@ static void microvm_machine_reset(MachineState *machine)
     CPUState *cs;
     X86CPU *cpu;
 
-    if (machine->kernel_filename != NULL &&
+    if (!acpi_enabled && machine->kernel_filename != NULL &&
         mms->auto_kernel_cmdline && !mms->kernel_cmdline_fixed) {
         microvm_fix_kernel_cmdline(machine);
         mms->kernel_cmdline_fixed = true;
Signature · 1 line
2.18.2
#18 lore raw

PATCH 7/13 seabios: update submodule to experimental microvm branch

In reply to Gerd Hoffmann

https://git.kraxel.org/cgit/seabios/log/?h=microvm

---
 roms/seabios | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
roms/seabios +1 -1
index f21b5a4aeb02..81a6f4b87318 160000
@@ -1 +1 @@
-Subproject commit f21b5a4aeb020f2a5e2c6503f906a9349dd2f069
+Subproject commit 81a6f4b87318a945e3a4cd014c2efa89482a0cd0
Signature · 1 line
2.18.2
#14 lore raw

PATCH 5/13 microvm: add acpi_dsdt_add_virtio() for x86

In reply to Gerd Hoffmann

Makes x86 linux kernel find virtio-mmio devices automatically.

---
 hw/i386/acpi-build.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
hw/i386/acpi-build.c +51 -0
index 0e45a646af56..80844db24d6b 100644
@@ -21,6 +21,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qnum.h"
 #include "acpi-build.h"
@@ -60,6 +61,7 @@
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 #include "hw/i386/microvm.h"
+#include "hw/virtio/virtio-mmio.h"
 
 #include "hw/acpi/aml-build.h"
 #include "hw/acpi/utils.h"
@@ -2750,6 +2752,54 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
     return true;
 }
 
+static void acpi_dsdt_add_virtio(Aml *scope)
+{
+    gchar *separator;
+    long int index;
+    BusState *bus;
+    BusChild *kid;
+
+    bus = sysbus_get_default();
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        DeviceState *dev = kid->child;
+        ObjectClass *class = object_get_class(OBJECT(dev));
+
+        if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) {
+            VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev));
+            VirtioBusState *mmio_virtio_bus = &mmio->bus;
+            BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
+
+            if (QTAILQ_EMPTY(&mmio_bus->children)) {
+                continue;
+            }
+            separator = g_strrstr(mmio_bus->name, ".");
+            if (!separator) {
+                continue;
+            }
+            if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) {
+                continue;
+            }
+
+            uint32_t irq = VIRTIO_IRQ_BASE + index;
+            hwaddr base = VIRTIO_MMIO_BASE + index * 512;
+            hwaddr size = 512;
+
+            Aml *dev = aml_device("VR%02u", (unsigned)index);
+            aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
+            aml_append(dev, aml_name_decl("_UID", aml_int(index)));
+            aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
+
+            Aml *crs = aml_resource_template();
+            aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
+            aml_append(crs,
+                       aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
+                                     AML_EXCLUSIVE, &irq, 1));
+            aml_append(dev, aml_name_decl("_CRS", crs));
+            aml_append(scope, dev);
+        }
+    }
+}
+
 static void
 build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
                    MicrovmMachineState *mms)
@@ -2766,6 +2816,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
 
     sb_scope = aml_scope("_SB");
     acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
+    acpi_dsdt_add_virtio(sb_scope);
     aml_append(dsdt, sb_scope);
 
     scope = aml_scope("\\");
Signature · 1 line
2.18.2
#27 lore raw
In reply to Gerd Hoffmann
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===

  CC      hw/net/vhost_net.o
  CC      hw/net/vhost_net-stub.o
  CC      hw/net/rocker/rocker.o
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:52:46: error: too few arguments to function call, expected 5, have 4
                                  &zero, NULL);
                                             ^

/tmp/qemu-test/src/include/qom/object.h:1687:1: note: 'object_property_add_uint8_ptr' declared here void object_property_add_uint8_ptr(Object *obj, const char *name,
^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:54:46: error: too few arguments to function call, expected 5, have 4

                                  &zero, NULL);
                                             ^

/tmp/qemu-test/src/include/qom/object.h:1687:1: note: 'object_property_add_uint8_ptr' declared here void object_property_add_uint8_ptr(Object *obj, const char *name,
^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:56:54: error: too few arguments to function call, expected 5, have 4

                                   &s->gpe_base, NULL);
                                                     ^

/tmp/qemu-test/src/include/qom/object.h:1730:1: note: 'object_property_add_uint32_ptr' declared here void object_property_add_uint32_ptr(Object *obj, const char *name,
^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:58:53: error: too few arguments to function call, expected 5, have 4

                                   &s->gpe_len, NULL);
                                                    ^

/tmp/qemu-test/src/include/qom/object.h:1730:1: note: 'object_property_add_uint32_ptr' declared here void object_property_add_uint32_ptr(Object *obj, const char *name,
^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:60:53: error: too few arguments to function call, expected 5, have 4

                                   &s->sci_irq, NULL);
                                                    ^

/tmp/qemu-test/src/include/qom/object.h:1708:1: note: 'object_property_add_uint16_ptr' declared here void object_property_add_uint16_ptr(Object *obj, const char *name,
^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:62:53: error: too few arguments to function call, expected 5, have 4

                                   &s->io_base, NULL);
                                                    ^

/tmp/qemu-test/src/include/qom/object.h:1730:1: note: 'object_property_add_uint32_ptr' declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,
^
6 errors generated.
make: *** [/tmp/qemu-test/src/rules.mak:69: hw/acpi/isa-acpi.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=aff630669cd9451e8fc110b2fe62edd1', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=x86_64-softmmu', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-tzpaxn62/src/docker-src.2020-03-19-04.15.28.16361:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-debug']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=aff630669cd9451e8fc110b2fe62edd1
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-tzpaxn62/src'
make: *** [docker-run-test-debug@fedora] Error 2

real 4m0.766s
user 0m8.155s

The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#28 lore raw
In reply to Gerd Hoffmann
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

CC hw/char/pl011.o
CC hw/char/serial.o
/tmp/qemu-test/src/hw/acpi/isa-acpi.c: In function 'isa_acpi_add_propeties':
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:52:35: error: incompatible type for argument 4 of 'object_property_add_uint8_ptr'

                                   &zero, NULL);
                                   ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:52:35: error: too few arguments to function 'object_property_add_uint8_ptr'
                                   &zero, NULL);
                                   ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: declared here
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:54:35: error: incompatible type for argument 4 of 'object_property_add_uint8_ptr'
                                   &zero, NULL);
                                   ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:54:35: error: too few arguments to function 'object_property_add_uint8_ptr'
                                   &zero, NULL);
                                   ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: declared here
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:56:36: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->gpe_base, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:56:36: error: too few arguments to function 'object_property_add_uint32_ptr'
                                    &s->gpe_base, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:58:36: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->gpe_len, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:58:36: error: too few arguments to function 'object_property_add_uint32_ptr'
                                    &s->gpe_len, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:60:36: error: incompatible type for argument 4 of 'object_property_add_uint16_ptr'
                                    &s->sci_irq, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1708:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint16_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:60:36: error: too few arguments to function 'object_property_add_uint16_ptr'
                                    &s->sci_irq, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1708:6: note: declared here
void object_property_add_uint16_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:62:36: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->io_base, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: expected 'ObjectPropertyFlags' but argument is of type 'void *'
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:62:36: error: too few arguments to function 'object_property_add_uint32_ptr'
                                    &s->io_base, NULL);
                                    ^

In file included from /tmp/qemu-test/src/include/exec/memory.h:28:0,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^

make: *** [hw/acpi/isa-acpi.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=f0129bb7ffba4103a5a73a523913e86e', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-8zpl86hn/src/docker-src.2020-03-19-04.20.57.22139:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=f0129bb7ffba4103a5a73a523913e86e
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-8zpl86hn/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 2m8.675s
user 0m7.952s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#29 lore raw
In reply to Gerd Hoffmann
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

CC hw/display/blizzard.o
CC hw/display/exynos4210_fimd.o
/tmp/qemu-test/src/hw/acpi/isa-acpi.c: In function 'isa_acpi_add_propeties':
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:52:42: error: incompatible type for argument 4 of 'object_property_add_uint8_ptr'

                                   &zero, NULL);
                                          ^~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1688:74: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
const uint8_t *v, ObjectPropertyFlags flags,
~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:51:5: error: too few arguments to function 'object_property_add_uint8_ptr'

     object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: declared here
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:54:42: error: incompatible type for argument 4 of 'object_property_add_uint8_ptr'
                                   &zero, NULL);
                                          ^~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1688:74: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
const uint8_t *v, ObjectPropertyFlags flags,
~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:53:5: error: too few arguments to function 'object_property_add_uint8_ptr'

     object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1687:6: note: declared here
void object_property_add_uint8_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:56:50: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->gpe_base, NULL);
                                                  ^~~~
In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1732:57: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
                                     ObjectPropertyFlags flags,
                                     ~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:55:5: error: too few arguments to function 'object_property_add_uint32_ptr'
     object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:58:49: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->gpe_len, NULL);
                                                 ^~~~
In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1732:57: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
                                     ObjectPropertyFlags flags,
                                     ~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:57:5: error: too few arguments to function 'object_property_add_uint32_ptr'
     object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:60:49: error: incompatible type for argument 4 of 'object_property_add_uint16_ptr'
                                    &s->sci_irq, NULL);
                                                 ^~~~
In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1710:57: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
                                     ObjectPropertyFlags flags,
                                     ~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:59:5: error: too few arguments to function 'object_property_add_uint16_ptr'
     object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1708:6: note: declared here
void object_property_add_uint16_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:62:49: error: incompatible type for argument 4 of 'object_property_add_uint32_ptr'
                                    &s->io_base, NULL);
                                                 ^~~~
In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1732:57: note: expected 'ObjectPropertyFlags' {aka 'enum <anonymous>'} but argument is of type 'void *'
                                     ObjectPropertyFlags flags,
                                     ~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/qemu-test/src/hw/acpi/isa-acpi.c:61:5: error: too few arguments to function 'object_property_add_uint32_ptr'
     object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /tmp/qemu-test/src/include/exec/memory.h:28,
---
/tmp/qemu-test/src/include/qom/object.h:1730:6: note: declared here
void object_property_add_uint32_ptr(Object *obj, const char *name,

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

make: *** [/tmp/qemu-test/src/rules.mak:69: hw/acpi/isa-acpi.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=aa63d72af4444bddaa87f3cc7ee3d260', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-jb7l4rgr/src/docker-src.2020-03-19-04.22.07.24398:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=aa63d72af4444bddaa87f3cc7ee3d260
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-jb7l4rgr/src'
make: *** [docker-run-test-mingw@fedora] Error 2

real 2m2.507s
user 0m8.570s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#30 lore raw
In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

Could we change -no-acpi into a "-machine acpi=..." property? Then it can have type OnOffAuto and we can decide whether to enable it by default or not for microvm.

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Paolo

Quoted 11 lines

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

#31 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

Could we change -no-acpi into a "-machine acpi=..." property? Then it can have type OnOffAuto and we can decide whether to enable it by default or not for microvm.

For all machine types not just microvm I guess?

Quoted 3 lines

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Didn't try that yet, will do.

cheers,
Gerd

Reviewed-by on v1 1/13
#2 lore raw

Re: [PATCH 01/13] acpi: make build_madt() more generic.

In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann

Remove PCMachineState dependency from build_madt(). Pass AcpiDeviceIf as separate argument instead of depending on PCMachineState->acpi_dev.

Quoted 39 lines
---
  hw/i386/acpi-build.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +7 -7
index 9a19c14e661b..1b0684c433e3 100644
@@ -360,14 +360,13 @@ void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
  }
 
  static void
-build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
+build_madt(GArray *table_data, BIOSLinker *linker,
+           X86MachineState *x86ms, AcpiDeviceIf *adev)
  {
-    MachineClass *mc = MACHINE_GET_CLASS(pcms);
-    X86MachineState *x86ms = X86_MACHINE(pcms);
-    const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(pcms));
+    MachineClass *mc = MACHINE_GET_CLASS(x86ms);
+    const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
      int madt_start = table_data->len;
-    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(pcms->acpi_dev);
-    AcpiDeviceIf *adev = ACPI_DEVICE_IF(pcms->acpi_dev);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
      bool x2apic_mode = false;
 
      AcpiMultipleApicTable *madt;
@@ -2807,7 +2806,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
      aml_len += tables_blob->len - fadt;
 
      acpi_add_table(table_offsets, tables_blob);
-    build_madt(tables_blob, tables->linker, pcms);
+    build_madt(tables_blob, tables->linker, x86ms,
+               ACPI_DEVICE_IF(pcms->acpi_dev));
 
      vmgenid_dev = find_vmgenid_dev();
      if (vmgenid_dev) {
Reviewed-by on v1 2/13
#4 lore raw

Re: [PATCH 02/13] acpi: factor out acpi_dsdt_add_fw_cfg()

In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Add helper function to add fw_cfg device.

Quoted 74 lines
---
  hw/i386/acpi-build.c | 50 ++++++++++++++++++++++++--------------------
  1 file changed, 27 insertions(+), 23 deletions(-)
hw/i386/acpi-build.c +27 -23
index 1b0684c433e3..9c98b07116cc 100644
@@ -1822,6 +1822,32 @@ static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func)
      aml_append(table, scope);
  }
 
+static void acpi_dsdt_add_fw_cfg(Aml *scope, Object *fw_cfg)
+{
+    /*
+     * when using port i/o, the 8-bit data register *always* overlaps
+     * with half of the 16-bit control register. Hence, the total size
+     * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
+     * DMA control register is located at FW_CFG_DMA_IO_BASE + 4
+     */
+    uint8_t io_size = object_property_get_bool(fw_cfg, "dma_enabled", NULL) ?
+        ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
+        FW_CFG_CTL_SIZE;
+    Aml *dev = aml_device("FWCF");
+    Aml *crs = aml_resource_template();
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+    /* device present, functioning, decoding, not shown in UI */
+    aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+
+    aml_append(crs,
+        aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size));
+
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
  static void
  build_dsdt(GArray *table_data, BIOSLinker *linker,
             AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -2101,30 +2127,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 
      /* create fw_cfg node, unconditionally */
      {
-        /* when using port i/o, the 8-bit data register *always* overlaps
-         * with half of the 16-bit control register. Hence, the total size
-         * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
-         * DMA control register is located at FW_CFG_DMA_IO_BASE + 4 */
-        uint8_t io_size = object_property_get_bool(OBJECT(x86ms->fw_cfg),
-                                                   "dma_enabled", NULL) ?
-                          ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
-                          FW_CFG_CTL_SIZE;
-
          scope = aml_scope("\\_SB.PCI0");
-        dev = aml_device("FWCF");
-
-        aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
-
-        /* device present, functioning, decoding, not shown in UI */
-        aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
-
-        crs = aml_resource_template();
-        aml_append(crs,
-            aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size)
-        );
-        aml_append(dev, aml_name_decl("_CRS", crs));
-
-        aml_append(scope, dev);
+        acpi_dsdt_add_fw_cfg(scope, OBJECT(x86ms->fw_cfg));
          aml_append(dsdt, scope);
      }
 
#32 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

Could we change -no-acpi into a "-machine acpi=..." property? Then it can have type OnOffAuto and we can decide whether to enable it by default or not for microvm.

For all machine types not just microvm I guess?

Yes, please. Strange that no one has noticed it for all this time!

The main reason for not having ACPI was the time that it took to start; this is also why I preferred having device tree, but indeed that would mean no distro kernels (we could probably use U-Boot as the firmware, but still with a custom kernel).

Paolo

Quoted 9 lines
Quoted 3 lines

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Didn't try that yet, will do.

cheers,
Gerd

#33 lore raw

Hi,

Quoted 1 line

The main reason for not having ACPI was the time that it took to start;

Yep, ACPI needs additional boot time. Shouldn't be a big difference though, microvm acpi only declares some devices and has small tables. Also no acpi methods, so no interpreter work. Maybe it is mostly the additional time needed to log the ACPI stuff to the serial console (didn't try yet to time boots with "quiet").

On the other hand you have effects like this:
Without acpi the kernel checks whenever hardware is present:

    # dmesg | grep i8042
    [    0.334403] i8042: PNP: No PS/2 controller found.
    [    0.334619] i8042: Probing ports directly.
    [    1.370573] i8042: No controller found

With acpi the kernel trusts the firmware and doesn't bother probing directly:

    # dmesg | grep i8042
    [    0.345500] i8042: PNP: No PS/2 controller found.

cheers,
Gerd

#5 lore raw

Re: [PATCH 02/13] acpi: factor out acpi_dsdt_add_fw_cfg()

In reply to Gerd Hoffmann
Quoted 12 lines · On Thu, 19 Mar 2020 09:01:06 +0100 Gerd Hoffmann <[email protected]> wrote:

Add helper function to add fw_cfg device.

---
 hw/i386/acpi-build.c | 50 ++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 23 deletions(-)
hw/i386/acpi-build.c +0 -0
index 1b0684c433e3..9c98b07116cc 100644

hw/i386/acpi-build.c static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func) · line 1825

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
@@ -1822,6 +1822,32 @@ static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func)
     aml_append(table, scope);
 }
 
+static void acpi_dsdt_add_fw_cfg(Aml *scope, Object *fw_cfg)

I'd pass fwcfg type as is and then cast to OBJECT inside of this function

Quoted 60 lines
hw/i386/acpi-build.c +26 -23
+{
+    /*
+     * when using port i/o, the 8-bit data register *always* overlaps
+     * with half of the 16-bit control register. Hence, the total size
+     * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
+     * DMA control register is located at FW_CFG_DMA_IO_BASE + 4
+     */
+    uint8_t io_size = object_property_get_bool(fw_cfg, "dma_enabled", NULL) ?
+        ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
+        FW_CFG_CTL_SIZE;
+    Aml *dev = aml_device("FWCF");
+    Aml *crs = aml_resource_template();
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+    /* device present, functioning, decoding, not shown in UI */
+    aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+
+    aml_append(crs,
+        aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size));
+
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -2101,30 +2127,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 
     /* create fw_cfg node, unconditionally */
     {
-        /* when using port i/o, the 8-bit data register *always* overlaps
-         * with half of the 16-bit control register. Hence, the total size
-         * of the i/o region used is FW_CFG_CTL_SIZE; when using DMA, the
-         * DMA control register is located at FW_CFG_DMA_IO_BASE + 4 */
-        uint8_t io_size = object_property_get_bool(OBJECT(x86ms->fw_cfg),
-                                                   "dma_enabled", NULL) ?
-                          ROUND_UP(FW_CFG_CTL_SIZE, 4) + sizeof(dma_addr_t) :
-                          FW_CFG_CTL_SIZE;
-
         scope = aml_scope("\\_SB.PCI0");
-        dev = aml_device("FWCF");
-
-        aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
-
-        /* device present, functioning, decoding, not shown in UI */
-        aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
-
-        crs = aml_resource_template();
-        aml_append(crs,
-            aml_io(AML_DECODE16, FW_CFG_IO_BASE, FW_CFG_IO_BASE, 0x01, io_size)
-        );
-        aml_append(dev, aml_name_decl("_CRS", crs));
-
-        aml_append(scope, dev);
+        acpi_dsdt_add_fw_cfg(scope, OBJECT(x86ms->fw_cfg));
         aml_append(dsdt, scope);
     }
 
#34 lore raw
In reply to Paolo Bonzini

Hi,

Quoted 3 lines

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Hmm, is there some way to do this without modifying default-configs/i386-softmmu.mak in the source tree? So I can have two build trees with different confugurations? Also to reduce the risk that I commit default-config changes by mistake?

thanks,
Gerd

#7 lore raw

Re: [PATCH 03/13] microvm: add isa-acpi device

In reply to Gerd Hoffmann
Quoted 1 line · On Thu, 19 Mar 2020 09:01:07 +0100 Gerd Hoffmann <[email protected]> wrote:

Minimal ACPI device for PCI-less machines like microvm.

it seems that x86 kernel is able to boot on hw-reduced acpi systems (but I haven't really tested any distro kernel, not sure how usable NEMU is)

Maybe reusing hw/acpi/generic_event_device.c (which was borrowed for NEMU effort) would be better since guest won't have to initialize not necessary interfaces and QEMU could implement simpler hw impl compared to full ACPI with GPEs, SCIs & co.

Quoted 140 lines
---
 hw/acpi/isa-acpi.c    | 114 ++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/Makefile.objs |   1 +
 2 files changed, 115 insertions(+)
 create mode 100644 hw/acpi/isa-acpi.c
hw/acpi/isa-acpi.c new file +114 -0
new file mode 100644
index 000000000000..5d7d770a5c0b
@@ -0,0 +1,114 @@
+#include "qemu/osdep.h"
+#include "hw/i386/pc.h"
+#include "hw/acpi/acpi.h"
+#include "sysemu/runstate.h"
+
+typedef struct ISAACPI {
+    ISADevice base;
+
+    uint32_t io_base;
+    uint16_t sci_irq;
+    uint32_t gpe_base;
+    uint32_t gpe_len;
+
+    qemu_irq irq;
+    MemoryRegion io;
+    ACPIREGS acpi;
+    Notifier powerdown_req;
+} ISAACPI;
+
+#define TYPE_ISA_ACPI "isa-acpi"
+#define ISA_ACPI(obj) \
+    OBJECT_CHECK(ISAACPI, (obj), TYPE_ISA_ACPI)
+
+static void isa_acpi_timer(ACPIREGS *acpi)
+{
+    ISAACPI *s = container_of(acpi, ISAACPI, acpi);
+    acpi_update_sci(&s->acpi, s->irq);
+}
+
+static void isa_acpi_init(Object *obj)
+{
+    ISAACPI *s = ISA_ACPI(obj);
+
+    s->io_base = 0x600;
+    s->sci_irq = 9;
+    s->gpe_base = 0x680;
+    s->gpe_len = 4;
+}
+
+static void isa_acpi_powerdown_req(Notifier *n, void *opaque)
+{
+    ISAACPI *s = container_of(n, ISAACPI, powerdown_req);
+
+    acpi_pm1_evt_power_down(&s->acpi);
+}
+
+static void isa_acpi_add_propeties(ISAACPI *s)
+{
+    static const uint8_t zero;
+
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
+                                  &zero, NULL);
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
+                                  &zero, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
+                                   &s->gpe_base, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
+                                   &s->gpe_len, NULL);
+    object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
+                                   &s->sci_irq, NULL);
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
+                                   &s->io_base, NULL);
+}
+
+static void isa_acpi_realize(DeviceState *dev, Error **errp)
+{
+    ISADevice *isa = ISA_DEVICE(dev);
+    ISAACPI *s = ISA_ACPI(dev);
+
+    memory_region_init(&s->io, OBJECT(s), "isa-acpi", 64);
+    memory_region_set_enabled(&s->io, true);
+    isa_register_ioport(isa, &s->io, s->io_base);
+    isa_init_irq(isa, &s->irq, s->sci_irq);
+
+    acpi_pm_tmr_init(&s->acpi, isa_acpi_timer, &s->io);
+    acpi_pm1_evt_init(&s->acpi, isa_acpi_timer, &s->io);
+    acpi_pm1_cnt_init(&s->acpi, &s->io, true, true, 0);
+    acpi_gpe_init(&s->acpi, 4);
+
+    s->powerdown_req.notify = isa_acpi_powerdown_req;
+    qemu_register_powerdown_notifier(&s->powerdown_req);
+
+    isa_acpi_add_propeties(s);
+}
+
+static void isa_acpi_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
+
+    dc->realize = isa_acpi_realize;
+    dc->user_creatable = false;
+    dc->hotpluggable = false;
+    adevc->madt_cpu = pc_madt_cpu_entry;
+}
+
+static const TypeInfo isa_acpi_info = {
+    .name          = TYPE_ISA_ACPI,
+    .parent        = TYPE_ISA_DEVICE,
+    .instance_size = sizeof(ISAACPI),
+    .instance_init = isa_acpi_init,
+    .class_init    = isa_acpi_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_ACPI_DEVICE_IF },
+        { }
+    }
+};
+
+static void register_types(void)
+{
+    type_register_static(&isa_acpi_info);
+}
+
+type_init(register_types)
hw/acpi/Makefile.objs +1 -0
index 777da07f4d70..aae53c73ebbd 100644
@@ -14,6 +14,7 @@ common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o
 common-obj-y += acpi_interface.o
 common-obj-y += bios-linker-loader.o
 common-obj-y += aml-build.o utils.o
+common-obj-$(CONFIG_PC) += isa-acpi.o
 common-obj-$(CONFIG_ACPI_PCI) += pci.o
 common-obj-$(CONFIG_TPM) += tpm.o
 
#11 lore raw

Re: [PATCH 04/13] microvm: add minimal acpi support.

In reply to Gerd Hoffmann
Quoted 49 lines · On Thu, 19 Mar 2020 09:01:08 +0100 Gerd Hoffmann <[email protected]> wrote:

$subject says all. Can be disabled using the usual -no-acpi switch.

---
 include/hw/i386/microvm.h |   3 +
 hw/i386/acpi-build.c      | 124 +++++++++++++++++++++++++++++++++++---
 hw/i386/microvm.c         |  14 +++++
 3 files changed, 133 insertions(+), 8 deletions(-)
include/hw/i386/microvm.h +3 -0
index ba68d1f22bb3..da2852a70195 100644
@@ -24,6 +24,7 @@
 
 #include "hw/boards.h"
 #include "hw/i386/x86.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 /* Platform virtio definitions */
 #define VIRTIO_MMIO_BASE      0xc0000000
@@ -58,6 +59,8 @@ typedef struct {
 
     /* Machine state */
     bool kernel_cmdline_fixed;
+    Notifier machine_done;
+    AcpiDeviceIf *acpi_dev;
 } MicrovmMachineState;
 
 #define TYPE_MICROVM_MACHINE   MACHINE_TYPE_NAME("microvm")
hw/i386/acpi-build.c +4 -0
index 9c98b07116cc..0e45a646af56 100644
@@ -59,6 +59,7 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
+#include "hw/i386/microvm.h"
 
 #include "hw/acpi/aml-build.h"
 #include "hw/acpi/utils.h"
@@ -2749,12 +2750,103 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
     return true;
 }
 
+static void
+build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
+                   MicrovmMachineState *mms)

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2765

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+{
+    X86MachineState *x86ms = X86_MACHINE(mms);
+    Aml *dsdt, *sb_scope, *scope, *pkg;
+
+    dsdt = init_aml_allocator();
+
+    /* Reserve space for header */
+    acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
+
+    build_dbg_aml(dsdt);

I'd drop/comment out as it's usually not used and whoever need to debug aml can enable it when necessary.

Quoted 9 lines
hw/i386/acpi-build.c +9 -0
+
+    sb_scope = aml_scope("_SB");
+    acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
+    aml_append(dsdt, sb_scope);
+
+    scope = aml_scope("\\");
+    pkg = aml_package(4);
+    aml_append(pkg, aml_int(0)); /* PM1a_CNT.SLP_TYP */
+    aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2784

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    aml_append(pkg, aml_int(0)); /* reserved */
+    aml_append(pkg, aml_int(0)); /* reserved */
+    aml_append(scope, aml_name_decl("_S5", pkg));
+    aml_append(dsdt, scope);
+
+    /* copy AML table into ACPI tables blob and patch header there */
+    g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
+    build_header(linker, table_data,
+        (void *)(table_data->data + table_data->len - dsdt->buf->len),
+        "DSDT", dsdt->buf->len, 1, NULL, NULL);

make revision at least 2 or newer (like copy arm/virt 5th rev)

Quoted 38 lines
hw/i386/acpi-build.c +38 -0
+    free_aml_allocator();
+}
+
+static
+void acpi_build_microvm(AcpiBuildTables *tables, MachineState *machine)
+{
+    MicrovmMachineState *mms = MICROVM_MACHINE(machine);
+    GArray *table_offsets;
+    GArray *tables_blob = tables->table_data;
+    AcpiFadtData pmfadt;
+    unsigned facs, dsdt, rsdt;
+
+    init_common_fadt_data(machine, OBJECT(mms->acpi_dev), &pmfadt);
+    pmfadt.smi_cmd = 0;
+
+    table_offsets = g_array_new(false, true /* clear */,
+                                        sizeof(uint32_t));
+    bios_linker_loader_alloc(tables->linker,
+                             ACPI_BUILD_TABLE_FILE, tables_blob,
+                             64 /* Ensure FACS is aligned */,
+                             false /* high memory */);
+
+    facs = tables_blob->len;
+    build_facs(tables_blob);
+
+    dsdt = tables_blob->len;
+    build_dsdt_microvm(tables_blob, tables->linker, mms);
+
+    pmfadt.facs_tbl_offset = &facs;
+    pmfadt.dsdt_tbl_offset = &dsdt;
+    pmfadt.xdsdt_tbl_offset = &dsdt;
+    acpi_add_table(table_offsets, tables_blob);
+    build_fadt(tables_blob, tables->linker, &pmfadt, NULL, NULL);
+
+    acpi_add_table(table_offsets, tables_blob);
+    build_madt(tables_blob, tables->linker, X86_MACHINE(machine),
+               mms->acpi_dev);
+

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2832

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    rsdt = tables_blob->len;
+    build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
+
+    /* RSDP is in FSEG memory, so allocate it separately */
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,

are we interested in 32-bit guests?
if not than maybe use xsdt and newer revision like arm/virt does

Quoted 23 lines
hw/i386/acpi-build.c +13 -2
+        };
+        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
+    }
+
+    acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
+    acpi_align_size(tables->linker->cmd_blob, ACPI_BUILD_ALIGN_SIZE);
+
+    /* Cleanup memory that's no longer used. */
+    g_array_free(table_offsets, true);
+}
+
 static
 void acpi_build(AcpiBuildTables *tables, MachineState *machine)
 {
-    PCMachineState *pcms = PC_MACHINE(machine);
-    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     X86MachineState *x86ms = X86_MACHINE(machine);
+    PCMachineState *pcms;
+    PCMachineClass *pcmc;
     GArray *table_offsets;
     unsigned facs, dsdt, rsdt, fadt;
     AcpiPmInfo pm;

hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables, MachineState *machine) · line 2862

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
@@ -2767,6 +2859,14 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
     Object *vmgenid_dev;
 
+    if (strcmp(object_get_typename(OBJECT(x86ms)), TYPE_MICROVM_MACHINE) == 0) {

maybe use object_dynamic_cast(OBJECT(x86ms)), TYPE_MICROVM_MACHINE)

Quoted 115 lines
hw/i386/acpi-build.c +21 -6
+        acpi_build_microvm(tables, machine);
+        return;
+    } else {
+        pcms = PC_MACHINE(machine);
+        pcmc = PC_MACHINE_GET_CLASS(pcms);
+    }
+
     acpi_get_pm_info(machine, &pm);
     acpi_get_misc_info(&misc);
     acpi_get_pci_holes(&pci_hole, &pci_hole64);
@@ -3009,21 +3109,29 @@ static const VMStateDescription vmstate_acpi_build = {
 
 void acpi_setup(void)
 {
-    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
-    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
-    X86MachineState *x86ms = X86_MACHINE(pcms);
+    X86MachineState *x86ms = X86_MACHINE(qdev_get_machine());
+    PCMachineState *pcms;
+    PCMachineClass *pcmc;
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
     Object *vmgenid_dev;
     TPMIf *tpm;
     static FwCfgTPMConfig tpm_config;
 
+    if (strcmp(object_get_typename(OBJECT(x86ms)), TYPE_MICROVM_MACHINE) == 0) {
+        pcms = NULL;
+        pcmc = NULL;
+    } else {
+        pcms = PC_MACHINE(x86ms);
+        pcmc = PC_MACHINE_GET_CLASS(pcms);
+    }
+
     if (!x86ms->fw_cfg) {
         ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
         return;
     }
 
-    if (!pcms->acpi_build_enabled) {
+    if (pcms && !pcms->acpi_build_enabled) {
         ACPI_BUILD_DPRINTF("ACPI build disabled. Bailing out.\n");
         return;
     }
@@ -3036,7 +3144,7 @@ void acpi_setup(void)
     build_state = g_malloc0(sizeof *build_state);
 
     acpi_build_tables_init(&tables);
-    acpi_build(&tables, MACHINE(pcms));
+    acpi_build(&tables, MACHINE(x86ms));
 
     /* Now expose it all to Guest */
     build_state->table_mr = acpi_add_rom_blob(acpi_build_update,
@@ -3069,7 +3177,7 @@ void acpi_setup(void)
                            tables.vmgenid);
     }
 
-    if (!pcmc->rsdp_in_ram) {
+    if (pcmc && !pcmc->rsdp_in_ram) {
         /*
          * Keep for compatibility with old machine types.
          * Though RSDP is small, its contents isn't immutable, so
hw/i386/microvm.c +14 -0
index 38d8e5170323..362d513f38e1 100644
@@ -26,6 +26,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
+#include "acpi-build.h"
 
 #include "hw/loader.h"
 #include "hw/irq.h"
@@ -41,6 +42,7 @@
 #include "hw/i386/e820_memory_layout.h"
 #include "hw/i386/fw_cfg.h"
 #include "hw/virtio/virtio-mmio.h"
+#include "hw/acpi/acpi.h"
 
 #include "cpu.h"
 #include "elf.h"
@@ -128,6 +130,10 @@ static void microvm_devices_init(MicrovmMachineState *mms)
     }
 
     /* Optional and legacy devices */
+    if (acpi_enabled) {
+        ISADevice *acpi = isa_create_simple(isa_bus, "isa-acpi" /* FIXME */);
+        mms->acpi_dev = ACPI_DEVICE_IF(acpi);
+    }
 
     if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) {
         qemu_irq *i8259;
@@ -468,6 +474,11 @@ static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value,
     mms->auto_kernel_cmdline = value;
 }
 
+static void microvm_machine_done(Notifier *notifier, void *data)
+{
+    acpi_setup();
+}
+
 static void microvm_machine_initfn(Object *obj)
 {
     MicrovmMachineState *mms = MICROVM_MACHINE(obj);
@@ -482,6 +493,9 @@ static void microvm_machine_initfn(Object *obj)
 
     /* State */
     mms->kernel_cmdline_fixed = false;
+
+    mms->machine_done.notify = microvm_machine_done;
+    qemu_add_machine_init_done_notifier(&mms->machine_done);
 }
 
 static void microvm_class_init(ObjectClass *oc, void *data)
#15 lore raw

Re: [PATCH 05/13] microvm: add acpi_dsdt_add_virtio() for x86

In reply to Gerd Hoffmann
Quoted 34 lines · On Thu, 19 Mar 2020 09:01:09 +0100 Gerd Hoffmann <[email protected]> wrote:

Makes x86 linux kernel find virtio-mmio devices automatically.

---
 hw/i386/acpi-build.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
hw/i386/acpi-build.c +5 -0
index 0e45a646af56..80844db24d6b 100644
@@ -21,6 +21,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qnum.h"
 #include "acpi-build.h"
@@ -60,6 +61,7 @@
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 #include "hw/i386/microvm.h"
+#include "hw/virtio/virtio-mmio.h"
 
 #include "hw/acpi/aml-build.h"
 #include "hw/acpi/utils.h"
@@ -2750,6 +2752,54 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
     return true;
 }
 
+static void acpi_dsdt_add_virtio(Aml *scope)
+{
+    gchar *separator;

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2767

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    long int index;
+    BusState *bus;
+    BusChild *kid;
+
+    bus = sysbus_get_default();
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        DeviceState *dev = kid->child;
+        ObjectClass *class = object_get_class(OBJECT(dev));
+
+        if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) {

using object_dynamic_cast() would be cleaner

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+            VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev));
+            VirtioBusState *mmio_virtio_bus = &mmio->bus;
+            BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
+
+            if (QTAILQ_EMPTY(&mmio_bus->children)) {
+                continue;
+            }
+            separator = g_strrstr(mmio_bus->name, ".");

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2785

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+            if (!separator) {
+                continue;
+            }
+            if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) {
+                continue;
+            }
+
+            uint32_t irq = VIRTIO_IRQ_BASE + index;
+            hwaddr base = VIRTIO_MMIO_BASE + index * 512;
+            hwaddr size = 512;

is it possible to fish these values out from device without poking in its guts
like using sysbus_get_connected_irq() and make up something to do get mmio parameters from sysbus device

Quoted 28 lines
hw/i386/acpi-build.c +18 -0
+
+            Aml *dev = aml_device("VR%02u", (unsigned)index);
+            aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
+            aml_append(dev, aml_name_decl("_UID", aml_int(index)));
+            aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
+
+            Aml *crs = aml_resource_template();
+            aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
+            aml_append(crs,
+                       aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
+                                     AML_EXCLUSIVE, &irq, 1));
+            aml_append(dev, aml_name_decl("_CRS", crs));
+            aml_append(scope, dev);
+        }
+    }
+}
+
 static void
 build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
                    MicrovmMachineState *mms)
@@ -2766,6 +2816,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
 
     sb_scope = aml_scope("_SB");
     acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
+    acpi_dsdt_add_virtio(sb_scope);
     aml_append(dsdt, sb_scope);
 
     scope = aml_scope("\\");
#35 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Hmm, is there some way to do this without modifying default-configs/i386-softmmu.mak in the source tree? So I can have two build trees with different confugurations? Also to reduce the risk that I commit default-config changes by mistake?

No, there is no way yet.

Paolo

#16 lore raw

Re: [PATCH 05/13] microvm: add acpi_dsdt_add_virtio() for x86

In reply to Igor Mammedov

Hi,

Quoted 5 lines

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2785

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+            uint32_t irq = VIRTIO_IRQ_BASE + index;
+            hwaddr base = VIRTIO_MMIO_BASE + index * 512;
+            hwaddr size = 512;

is it possible to fish these values out from device without poking in its guts
like using sysbus_get_connected_irq() and make up something to do get mmio parameters from sysbus device

Had a brief look at this while making VIRTIO_IRQ_BASE configurable. The virtio-mmio proxy gets passed an qemu_irq struct on initialization, so it doesn't know what the irq number is ...

cheers,
Gerd

#8 lore raw

Re: [PATCH 03/13] microvm: add isa-acpi device

In reply to Igor Mammedov
Quoted 11 lines · Igor Mammedov
Quoted 1 line · On Thu, 19 Mar 2020 09:01:07 +0100 Gerd Hoffmann <[email protected]> wrote:

Minimal ACPI device for PCI-less machines like microvm.

it seems that x86 kernel is able to boot on hw-reduced acpi systems (but I haven't really tested any distro kernel, not sure how usable NEMU is)

Maybe reusing hw/acpi/generic_event_device.c (which was borrowed for NEMU effort) would be better since guest won't have to initialize not necessary interfaces and QEMU could implement simpler hw impl compared to full ACPI with GPEs, SCIs & co.

I see the generic event device has support for powerdown request events, good. But I'm wondering how entering S5 state (aka poweroff) would work then?

cheers,
Gerd

#36 lore raw
In reply to Paolo Bonzini
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines

Also, can you confirm that it builds without CONFIG_I440FX and CONFIG_Q35? You probably need to add "imply ACPI" and possibly some '#include "config-devices.h"' and '#ifdef CONFIG_ACPI' here and there.

Hmm, is there some way to do this without modifying default-configs/i386-softmmu.mak in the source tree? So I can have two build trees with different confugurations? Also to reduce the risk that I commit default-config changes by mistake?

No, there is no way yet.

Hmm, seems we should have that for better regression testing. master branch doesn't build with pc+q35+isapc turned off:

LINK x86_64-softmmu/qemu-system-x86_64
hw/virtio/virtio-iommu.o: In function `virtio_iommu_get_bdf':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:66: undefined reference to pci_bus_num' hw/virtio/virtio-iommu.o: In function iommu_find_iommu_pcibus':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:84: undefined reference to pci_bus_num' hw/virtio/virtio-iommu.o: In function virtio_iommu_device_realize':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:685: undefined reference to `pci_setup_iommu'
collect2: error: ld returned 1 exit status

[ adding Eric Auger to Cc: ]

cheers,
Gerd

#37 lore raw
Quoted 11 lines · Gerd Hoffmann

Hmm, seems we should have that for better regression testing. master branch doesn't build with pc+q35+isapc turned off:

LINK x86_64-softmmu/qemu-system-x86_64
hw/virtio/virtio-iommu.o: In function `virtio_iommu_get_bdf':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:66: undefined reference to pci_bus_num' hw/virtio/virtio-iommu.o: In function iommu_find_iommu_pcibus':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:84: undefined reference to pci_bus_num' hw/virtio/virtio-iommu.o: In function virtio_iommu_device_realize':
/home/kraxel/projects/qemu/hw/virtio/virtio-iommu.c:685: undefined reference to `pci_setup_iommu'
collect2: error: ld returned 1 exit status

You need to disable virtio-iommu for now, or apply the patch I've just sent and CC you on.

Paolo

#9 lore raw

Re: [PATCH 03/13] microvm: add isa-acpi device

In reply to Gerd Hoffmann
Quoted 8 lines · On Fri, 20 Mar 2020 09:22:58 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 7 lines · Igor Mammedov
Quoted 1 line · On Thu, 19 Mar 2020 09:01:07 +0100 Gerd Hoffmann <[email protected]> wrote:

Minimal ACPI device for PCI-less machines like microvm.

it seems that x86 kernel is able to boot on hw-reduced acpi systems (but I haven't really tested any distro kernel, not sure how usable NEMU is)

Quoted 8 lines
Quoted 4 lines

Maybe reusing hw/acpi/generic_event_device.c (which was borrowed for NEMU effort) would be better since guest won't have to initialize not necessary interfaces and QEMU could implement simpler hw impl compared to full ACPI with GPEs, SCIs & co.

I see the generic event device has support for powerdown request events, good. But I'm wondering how entering S5 state (aka poweroff) would work then?

Relevant parts from spec:
ACPI6.1:
16.1.7 Transitioning from the Working to the Soft Off State
...
4.
or writes the HW-reduced ACPI Sleep Type value for S5 and the SLP_EN bit to the Sleep Control Register.

4.8.3.7 Sleep Control and Status Registers

in kernel handled by acpi_hw_extended_sleep()

From QEMU:

build_fadt_rev5()
build_fadt()

    ...
    /* SLEEP_CONTROL_REG */
    build_append_gas(tbl, AML_AS_SYSTEM_MEMORY, 0 , 0, 0, 0);
    /* SLEEP_STATUS_REG */
    build_append_gas(tbl, AML_AS_SYSTEM_MEMORY, 0 , 0, 0, 0);
    ...
    this is what board should implement (we cloud add an optional MMIO register to
    GED to hanlde shutdown on QEMU side)
    (ARM doesn't use it as it's using arch specific, PSCI method to shutdown machine),
    I'd add relevant fields to AcpiFadtData, fill it in build_fadt_rev5() and use them in build_fadt()

virt_powerdown_req()
acpi_send_event(s->acpi_dev, ACPI_POWER_DOWN_STATUS)

triggers in guest AML generated by:

acpi_dsdt_add_power_button()

build_ged_aml()
...ACPI_POWER_BUTTON_DEVICE... -> tells OSPM to do 16.1.7 using 4.8.3.7

Quoted 5 lines

cheers,
Gerd

#25 lore raw

Re: [PATCH 13/13] microvm/acpi: use GSI 16-23 for virtio

In reply to Gerd Hoffmann
Quoted 2 lines · Gerd Hoffmann

With ACPI enabled and IO-APIC being properly declared in the ACPI tables we can use interrupt lines 16-23 for virtio and avoid shared interrupts.

7 interrupt lines? Is there a specific requirements of which ones should be assigned to what device?

Or perhaps - could you include /proc/interrupts in the commit if that is OK?

Quoted 24 lines

With acpi disabled we continue to use lines 8-15.

---
 hw/i386/microvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/microvm.c +1 -1
index 834b10aee0a2..139181daed06 100644
@@ -122,7 +122,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     kvmclock_create();
 
-    mms->virtio_irq_base = 8;
+    mms->virtio_irq_base = acpi_enabled ? 16 : 8;
     for (i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) {
         sysbus_create_simple("virtio-mmio",
                              VIRTIO_MMIO_BASE + i * 512,
Signature · 1 line
2.18.2
#26 lore raw

Re: [PATCH 13/13] microvm/acpi: use GSI 16-23 for virtio

Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Gerd Hoffmann

With ACPI enabled and IO-APIC being properly declared in the ACPI tables we can use interrupt lines 16-23 for virtio and avoid shared interrupts.

7 interrupt lines? Is there a specific requirements of which ones should be assigned to what device?

8 lines (23 is inclusive), one for each virtio device. It wouldn't give you separate config change or per-queue interrupts (I think virtio-mmio doesn't support that). It only avoids sharing interrupts with legacy pc devices like rtc and acpi.

cheers,
Gerd

#38 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

What is the cost though? How do boot times compare?

Quoted 40 lines

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

cheers,
Gerd

Gerd Hoffmann (13):
acpi: make build_madt() more generic.
acpi: factor out acpi_dsdt_add_fw_cfg()
microvm: add isa-acpi device
microvm: add minimal acpi support.
microvm: add acpi_dsdt_add_virtio() for x86
microvm: disable virtio-mmio cmdline hack
[testing] seabios: update submodule to experimental microvm branch [testing] seabios: update config & build rules [testing] seabios: update binaries to experimental microvm branch microvm/acpi: add rtc
microvm/acpi: add serial
microvm: make virtio irq base runtime configurable microvm/acpi: use GSI 16-23 for virtio

 include/hw/i386/microvm.h   |   8 +-
 hw/acpi/isa-acpi.c          | 114 +++++++++++++++
 hw/i386/acpi-build.c        | 278 +++++++++++++++++++++++++++++-------
 hw/i386/microvm.c           |  32 +++--
 hw/acpi/Makefile.objs       |   1 +
 pc-bios/bios-256k.bin       | Bin 262144 -> 262144 bytes
 pc-bios/bios-microvm.bin    | Bin 65536 -> 131072 bytes
 pc-bios/bios.bin            | Bin 131072 -> 131072 bytes
 roms/Makefile               |   5 +-
 roms/config.seabios-128k    |   2 +
 roms/config.seabios-microvm |  25 ++++
 roms/seabios                |   2 +-
 12 files changed, 403 insertions(+), 64 deletions(-)
 create mode 100644 hw/acpi/isa-acpi.c
 create mode 100644 roms/config.seabios-microvm
Signature · 1 line
2.18.2
#39 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

Quoted 7 lines
Quoted 5 lines

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

What is the cost though? How do boot times compare?

Well, acpi speeds up booting by one second because this delay ...

   [    0.275736] i8042: PNP: No PS/2 controller found.
   [    0.275736] i8042: Probing ports directly.
   [    1.315447] i8042: No controller found

... goes away, at least with standard distro kernels. When building your own you can probably compile out the driver somehow, even though something seems to select SERIO_I8042 so trying to simply flip CONFIG_SERIO_I8042 to 'n' in .config doesn't work. And a runtime switch seems to not be there either ...

So that ruined my plan to just time until the root filesystem is mounted. Decided to use the "i8042: PNP: No PS/2 controller found." line instead for a simple test (just check the kernel log timestamps, three runs each). The ACPI initialization is already done at that point, so it should be useful nevertheless. Here we go:

Without acpi:
0.277710
0.278852
0.279520

With acpi:
0.283917
0.284262
0.284836

So the difference is less than 0.01 seconds on my box.

cheers,
Gerd

#40 lore raw
Quoted 39 lines · On Mon, 23 Mar 2020 13:09:48 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Gerd Hoffmann

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

Quoted 7 lines
Quoted 5 lines

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

What is the cost though? How do boot times compare?

Well, acpi speeds up booting by one second because this delay ...

   [    0.275736] i8042: PNP: No PS/2 controller found.
   [    0.275736] i8042: Probing ports directly.
   [    1.315447] i8042: No controller found

... goes away, at least with standard distro kernels. When building your own you can probably compile out the driver somehow, even though something seems to select SERIO_I8042 so trying to simply flip CONFIG_SERIO_I8042 to 'n' in .config doesn't work. And a runtime switch seems to not be there either ...

So that ruined my plan to just time until the root filesystem is mounted. Decided to use the "i8042: PNP: No PS/2 controller found." line instead for a simple test (just check the kernel log timestamps, three runs each). The ACPI initialization is already done at that point, so it should be useful nevertheless. Here we go:

Without acpi:
0.277710
0.278852
0.279520

Quoted 4 lines

With acpi:
0.283917
0.284262
0.284836

I wonder what would be difference with hw-reduced acpi

Quoted 5 lines

So the difference is less than 0.01 seconds on my box.

cheers,
Gerd

#12 lore raw

Re: [PATCH 04/13] microvm: add minimal acpi support.

In reply to Igor Mammedov

Hi,

Quoted 7 lines

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2832

Quoted 6 lines
hw/i386/acpi-build.c +6 -0
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,

are we interested in 32-bit guests?

Well, sort-of. seabios runs in 32bit mode.

Quoted 1 line

if not than maybe use xsdt and newer revision like arm/virt does

Point being? It's not like we can place the tables above 4G then.

cheers,
Gerd

#41 lore raw
In reply to Igor Mammedov
Quoted 10 lines
Quoted 10 lines

mounted. Decided to use the "i8042: PNP: No PS/2 controller found." line instead for a simple test (just check the kernel log timestamps, three runs each). The ACPI initialization is already done at that point, so it should be useful nevertheless. Here we go:

Without acpi:
0.277710
0.278852
0.279520

Quoted 5 lines
Quoted 4 lines

With acpi:
0.283917
0.284262
0.284836

I wonder what would be difference with hw-reduced acpi

The kernel does a bunch of reads+writes at boot (roughly 20-30), mostly timer ports, so probably while initializing the pm_timer clocksource. Then it stops talking to the acpi hardware, preferring kvmclock clocksouce I guess.

So I expect hw-reduced acpi wouldn't make much of a difference. Actually trying that isn't that high on my priority list.

There is bigger fish to fry, untangling the hw/i386/acpi-build.c monster for starters, so building with ACPI=y + PCI=n works ...

cheers,
Gerd

#42 lore raw
Quoted 16 lines · On Wed, 25 Mar 2020 10:16:36 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 10 lines
Quoted 10 lines

mounted. Decided to use the "i8042: PNP: No PS/2 controller found." line instead for a simple test (just check the kernel log timestamps, three runs each). The ACPI initialization is already done at that point, so it should be useful nevertheless. Here we go:

Without acpi:
0.277710
0.278852
0.279520

Quoted 5 lines
Quoted 4 lines

With acpi:
0.283917
0.284262
0.284836

I wonder what would be difference with hw-reduced acpi

Quoted 7 lines

The kernel does a bunch of reads+writes at boot (roughly 20-30), mostly timer ports, so probably while initializing the pm_timer clocksource. Then it stops talking to the acpi hardware, preferring kvmclock clocksouce I guess.

So I expect hw-reduced acpi wouldn't make much of a difference. Actually trying that isn't that high on my priority list.

there aren't pm timers on hw-reduced, that's the point of it (a bunch of registers that where mandatory with full profile are absent so OS doesn't have to initialize not needed stuff)

Quoted 6 lines

There is bigger fish to fry, untangling the hw/i386/acpi-build.c monster for starters, so building with ACPI=y + PCI=n works ...

cheers,
Gerd

#44 lore raw
In reply to Gerd Hoffmann
Quoted 12 lines · On Thu, 19 Mar 2020 09:01:04 +0100 Gerd Hoffmann <[email protected]> wrote:

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Quoted 3 lines

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

what CLI do you use to test it?

Quoted 35 lines

cheers,
Gerd

Gerd Hoffmann (13):
acpi: make build_madt() more generic.
acpi: factor out acpi_dsdt_add_fw_cfg()
microvm: add isa-acpi device
microvm: add minimal acpi support.
microvm: add acpi_dsdt_add_virtio() for x86
microvm: disable virtio-mmio cmdline hack
[testing] seabios: update submodule to experimental microvm branch [testing] seabios: update config & build rules [testing] seabios: update binaries to experimental microvm branch microvm/acpi: add rtc
microvm/acpi: add serial
microvm: make virtio irq base runtime configurable microvm/acpi: use GSI 16-23 for virtio

 include/hw/i386/microvm.h   |   8 +-
 hw/acpi/isa-acpi.c          | 114 +++++++++++++++
 hw/i386/acpi-build.c        | 278 +++++++++++++++++++++++++++++-------
 hw/i386/microvm.c           |  32 +++--
 hw/acpi/Makefile.objs       |   1 +
 pc-bios/bios-256k.bin       | Bin 262144 -> 262144 bytes
 pc-bios/bios-microvm.bin    | Bin 65536 -> 131072 bytes
 pc-bios/bios.bin            | Bin 131072 -> 131072 bytes
 roms/Makefile               |   5 +-
 roms/config.seabios-128k    |   2 +
 roms/config.seabios-microvm |  25 ++++
 roms/seabios                |   2 +-
 12 files changed, 403 insertions(+), 64 deletions(-)
 create mode 100644 hw/acpi/isa-acpi.c
 create mode 100644 roms/config.seabios-microvm
#45 lore raw
Quoted 15 lines · Igor Mammedov
Quoted 12 lines · On Thu, 19 Mar 2020 09:01:04 +0100 Gerd Hoffmann <[email protected]> wrote:

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Quoted 5 lines
Quoted 3 lines

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

what CLI do you use to test it?

Test script below. "qemu-default" is a wrapper script which starts qemu-system-x86_64 from my build directory. "qemu-firmware" is the same plus isa-debugcon configured for a firmware log on stdout.

Latest bits (with some of the review comments addressed) just pushed to git://git,kraxel.org/qemu sirius/microvm

HTH,
Gerd

============================ cut here ============================ #!/bin/sh

mode="${1}"
shift

back=()
devs=()
args=()
qemu="qemu-firmware -monitor none -boot menu=on"
disk=""
liso=""
krnl=""
karg="console=ttyS0,115200"

case "$mode" in
kernel)

	qemu="qemu-default -nographic"
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	karg="$karg quiet"
	;;
seabios)
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	args+=("-bios" "/home/kraxel/projects/seabios/out-bios-microvm/bios.bin")
	;;
cloud)
	disk="/vmdisk/iso/Fedora-Cloud-Base-31-1.9.x86_64.raw"
	;;
coreos)
	disk="/vmdisk/iso/fedora-coreos-31.20200210.3.0-metal.x86_64.raw"
	;;
live)
	liso="/vmdisk/iso/Fedora-Workstation-Live-x86_64-30-1.2.iso"
	devs+=("-device" "virtio-gpu-device")
	devs+=("-device" "virtio-keyboard-device")
	devs+=("-device" "virtio-tablet-device")
	;;

*)
echo "unknown mode: $mode"
echo "known modes: kernel seabios cloud coreos live" exit 1
;;
esac

if test "$disk" != ""; then

	format="${disk##*.}"
	back+=("-drive" "if=none,id=disk,format=${format},file=${disk}")
	devs+=("-device" "scsi-hd,drive=disk,bootindex=1")
fi
if test "$liso" != ""; then
	back+=("-drive" "if=none,id=cdrom,media=cdrom,readonly,format=raw,file=${liso}")
	devs+=("-device" "scsi-cd,drive=cdrom,bootindex=2")
fi
if test "$krnl" != ""; then
	args+=("-kernel" "$krnl")
	args+=("-append" "$karg")

fi

set -ex

$qemu \
	-enable-kvm \
	-cpu host \
	-M microvm,graphics=off,pit=off,pic=on,rtc=on \
	\
	-m 4G \
	\
	-netdev user,id=net \
	"${back[@]}" \
	\
	-global virtio-mmio.force-legacy=false \
	-device virtio-net-device,netdev=net \
	-device virtio-scsi-device \
	"${devs[@]}" \
	\
	"${args[@]}" \
	"$@"
#46 lore raw
Quoted 20 lines · On Wed, 25 Mar 2020 16:03:39 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov
Quoted 15 lines · On Thu, 19 Mar 2020 09:01:04 +0100 Gerd Hoffmann <[email protected]> wrote:

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

Quoted 8 lines
Quoted 1 line

what CLI do you use to test it?

Test script below. "qemu-default" is a wrapper script which starts qemu-system-x86_64 from my build directory. "qemu-firmware" is the same plus isa-debugcon configured for a firmware log on stdout.

Latest bits (with some of the review comments addressed) just pushed to git://git,kraxel.org/qemu sirius/microvm

thanks, below are test results I got on my system,
spoiler hw-reduced reduces boot time on ~0.02s compared to full blown acpi
----
using timestamp at "Run /init as init process" as measuring point

no acpi
1.967316
1.975272
1.981267
1.974316
1.962452
1.960988

hw reduced acpi
0.893838
0.892573
0.890585
0.900306
0.897902

normal acpi:
0.921647
0.916298
0.923518
0.916298
0.913234

PS:
I just quickly hacked hw-reduced acpi (using arm/virt as model) without implementing power button but I doubt that would affect results noticeably on qemu side it probably also will save some time since there are less things to setup for qemu.

Quoted 84 lines

HTH,
Gerd

============================ cut here ============================ #!/bin/sh

mode="${1}"
shift

back=()
devs=()
args=()
qemu="qemu-firmware -monitor none -boot menu=on"
disk=""
liso=""
krnl=""
karg="console=ttyS0,115200"

case "$mode" in
kernel)

	qemu="qemu-default -nographic"
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	karg="$karg quiet"
	;;
seabios)
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	args+=("-bios" "/home/kraxel/projects/seabios/out-bios-microvm/bios.bin")
	;;
cloud)
	disk="/vmdisk/iso/Fedora-Cloud-Base-31-1.9.x86_64.raw"
	;;
coreos)
	disk="/vmdisk/iso/fedora-coreos-31.20200210.3.0-metal.x86_64.raw"
	;;
live)
	liso="/vmdisk/iso/Fedora-Workstation-Live-x86_64-30-1.2.iso"
	devs+=("-device" "virtio-gpu-device")
	devs+=("-device" "virtio-keyboard-device")
	devs+=("-device" "virtio-tablet-device")
	;;

*)
echo "unknown mode: $mode"
echo "known modes: kernel seabios cloud coreos live" exit 1
;;
esac

if test "$disk" != ""; then

	format="${disk##*.}"
	back+=("-drive" "if=none,id=disk,format=${format},file=${disk}")
	devs+=("-device" "scsi-hd,drive=disk,bootindex=1")
fi
if test "$liso" != ""; then
	back+=("-drive" "if=none,id=cdrom,media=cdrom,readonly,format=raw,file=${liso}")
	devs+=("-device" "scsi-cd,drive=cdrom,bootindex=2")
fi
if test "$krnl" != ""; then
	args+=("-kernel" "$krnl")
	args+=("-append" "$karg")

fi

set -ex

$qemu \
	-enable-kvm \
	-cpu host \
	-M microvm,graphics=off,pit=off,pic=on,rtc=on \
	\
	-m 4G \
	\
	-netdev user,id=net \
	"${back[@]}" \
	\
	-global virtio-mmio.force-legacy=false \
	-device virtio-net-device,netdev=net \
	-device virtio-scsi-device \
	"${devs[@]}" \
	\
	"${args[@]}" \
	"$@"
#43 lore raw
In reply to Gerd Hoffmann
Quoted 21 lines · On Wed, 25 Mar 2020 10:16:36 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 10 lines
Quoted 10 lines

mounted. Decided to use the "i8042: PNP: No PS/2 controller found." line instead for a simple test (just check the kernel log timestamps, three runs each). The ACPI initialization is already done at that point, so it should be useful nevertheless. Here we go:

Without acpi:
0.277710
0.278852
0.279520

Quoted 5 lines
Quoted 4 lines

With acpi:
0.283917
0.284262
0.284836

I wonder what would be difference with hw-reduced acpi

The kernel does a bunch of reads+writes at boot (roughly 20-30), mostly timer ports, so probably while initializing the pm_timer clocksource. Then it stops talking to the acpi hardware, preferring kvmclock clocksouce I guess.

Quoted 5 lines

So I expect hw-reduced acpi wouldn't make much of a difference. Actually trying that isn't that high on my priority list.

There is bigger fish to fry, untangling the hw/i386/acpi-build.c monster for starters, so building with ACPI=y + PCI=n works ...

if you are after reducing start up time it may be better to leave alone acpi-build.c with a bunch of legacy/compat stuff and create microvm specific acpi file, and extract from acpi-build.c only common bits that are necessary to produce tables (i.e. do something similar hw/arm/virt-acpi-build.c)

PS:
side-note: guest kernel insist on finding PCI where it doesn't exists

[    0.301104] ACPI: bus type PCI registered
[    0.301717] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
[    0.302180] PCI: Fatal: No config space access function found

it's probably the first time x86 generic kernel sees machine without PCI, and it probably could be fixed saving another 10-20ms

Quoted 5 lines

cheers,
Gerd

#13 lore raw

Re: [PATCH 04/13] microvm: add minimal acpi support.

In reply to Gerd Hoffmann
Quoted 11 lines · On Wed, 25 Mar 2020 10:04:29 +0100 Gerd Hoffmann <[email protected]> wrote:

Hi,

Quoted 7 lines

hw/i386/acpi-build.c static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) · line 2832

Quoted 6 lines
hw/i386/acpi-build.c +6 -0
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,  

are we interested in 32-bit guests?

Well, sort-of. seabios runs in 32bit mode.

seabios isn't consumer of it though, so as far as being loaded kernel is able to deal with xsdt it should be fine.

Quoted 3 lines
Quoted 1 line

if not than maybe use xsdt and newer revision like arm/virt does

Point being? It's not like we can place the tables above 4G then.

point is to use current standard vs legacy one on new machine

Quoted 4 lines

cheers,
Gerd

#47 lore raw
In reply to Igor Mammedov
Quoted 59 lines · Igor Mammedov
Quoted 20 lines · On Wed, 25 Mar 2020 16:03:39 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov
Quoted 15 lines · On Thu, 19 Mar 2020 09:01:04 +0100 Gerd Hoffmann <[email protected]> wrote:

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

Quoted 8 lines
Quoted 1 line

what CLI do you use to test it?

Test script below. "qemu-default" is a wrapper script which starts qemu-system-x86_64 from my build directory. "qemu-firmware" is the same plus isa-debugcon configured for a firmware log on stdout.

Latest bits (with some of the review comments addressed) just pushed to git://git,kraxel.org/qemu sirius/microvm

thanks, below are test results I got on my system,
spoiler hw-reduced reduces boot time on ~0.02s compared to full blown acpi
----
using timestamp at "Run /init as init process" as measuring point

no acpi
1.967316
1.975272
1.981267
1.974316
1.962452
1.960988

hw reduced acpi
0.893838
0.892573
0.890585
0.900306
0.897902

normal acpi:
0.921647
0.916298
0.923518
0.916298
0.913234

Quoted 5 lines

PS:
I just quickly hacked hw-reduced acpi (using arm/virt as model) without implementing power button but I doubt that would affect results noticeably on qemu side it probably also will save some time since there are less things to setup for qemu.

And no ACPI is faster because of PS/2 probing, right?

Quoted 84 lines
Quoted 84 lines

HTH,
Gerd

============================ cut here ============================ #!/bin/sh

mode="${1}"
shift

back=()
devs=()
args=()
qemu="qemu-firmware -monitor none -boot menu=on"
disk=""
liso=""
krnl=""
karg="console=ttyS0,115200"

case "$mode" in
kernel)

	qemu="qemu-default -nographic"
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	karg="$karg quiet"
	;;
seabios)
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	args+=("-bios" "/home/kraxel/projects/seabios/out-bios-microvm/bios.bin")
	;;
cloud)
	disk="/vmdisk/iso/Fedora-Cloud-Base-31-1.9.x86_64.raw"
	;;
coreos)
	disk="/vmdisk/iso/fedora-coreos-31.20200210.3.0-metal.x86_64.raw"
	;;
live)
	liso="/vmdisk/iso/Fedora-Workstation-Live-x86_64-30-1.2.iso"
	devs+=("-device" "virtio-gpu-device")
	devs+=("-device" "virtio-keyboard-device")
	devs+=("-device" "virtio-tablet-device")
	;;

*)
echo "unknown mode: $mode"
echo "known modes: kernel seabios cloud coreos live" exit 1
;;
esac

if test "$disk" != ""; then

	format="${disk##*.}"
	back+=("-drive" "if=none,id=disk,format=${format},file=${disk}")
	devs+=("-device" "scsi-hd,drive=disk,bootindex=1")
fi
if test "$liso" != ""; then
	back+=("-drive" "if=none,id=cdrom,media=cdrom,readonly,format=raw,file=${liso}")
	devs+=("-device" "scsi-cd,drive=cdrom,bootindex=2")
fi
if test "$krnl" != ""; then
	args+=("-kernel" "$krnl")
	args+=("-append" "$karg")

fi

set -ex

$qemu \
	-enable-kvm \
	-cpu host \
	-M microvm,graphics=off,pit=off,pic=on,rtc=on \
	\
	-m 4G \
	\
	-netdev user,id=net \
	"${back[@]}" \
	\
	-global virtio-mmio.force-legacy=false \
	-device virtio-net-device,netdev=net \
	-device virtio-scsi-device \
	"${devs[@]}" \
	\
	"${args[@]}" \
	"$@"
#48 lore raw
Quoted 60 lines · On Thu, 26 Mar 2020 03:33:35 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 59 lines · Igor Mammedov
Quoted 20 lines · On Wed, 25 Mar 2020 16:03:39 +0100 Gerd Hoffmann <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov
Quoted 15 lines · On Thu, 19 Mar 2020 09:01:04 +0100 Gerd Hoffmann <[email protected]> wrote:

I know that not supporting ACPI in microvm is intentional. If you still don't want ACPI this is perfectly fine, you can use the usual -no-acpi switch to toggle ACPI support.

These are the advantages you are going to loose then:

(1) virtio-mmio device discovery without command line hacks (tweaking the command line is a problem when not using direct kernel boot).
(2) Better IO-APIC support, we can use IRQ lines 16-23.
(3) ACPI power button (aka powerdown request) works.
(4) machine poweroff (aka S5 state) works.

Together with seabios patches for virtio-mmio support this allows to boot standard fedora images (cloud, coreos, workstation live) with the microvm machine type.

Quoted 8 lines
Quoted 1 line

what CLI do you use to test it?

Test script below. "qemu-default" is a wrapper script which starts qemu-system-x86_64 from my build directory. "qemu-firmware" is the same plus isa-debugcon configured for a firmware log on stdout.

Latest bits (with some of the review comments addressed) just pushed to git://git,kraxel.org/qemu sirius/microvm

thanks, below are test results I got on my system,
spoiler hw-reduced reduces boot time on ~0.02s compared to full blown acpi
----
using timestamp at "Run /init as init process" as measuring point

no acpi
1.967316
1.975272
1.981267
1.974316
1.962452
1.960988

hw reduced acpi
0.893838
0.892573
0.890585
0.900306
0.897902

normal acpi:
0.921647
0.916298
0.923518
0.916298
0.913234

Quoted 7 lines
Quoted 5 lines

PS:
I just quickly hacked hw-reduced acpi (using arm/virt as model) without implementing power button but I doubt that would affect results noticeably on qemu side it probably also will save some time since there are less things to setup for qemu.

And no ACPI is faster because of PS/2 probing, right?

I suppose you've meant -slower- because of ...

if I compare at 'i8042: PNP: No PS/2 controller found.' to rule out probing, then no-api and hw-reduced are about in the same ballpark (3-4ms difference in favor of no-acpi).

no-acpi
0.765785
0.783540
0.785269
0.777751
0.774474
0.770611
0.789309

hw-reduced
0.788733
0.775982
0.793132
0.769077
0.774771
0.775191
0.771170

Quoted 87 lines
Quoted 85 lines
Quoted 85 lines

HTH,
Gerd

============================ cut here ============================ #!/bin/sh

mode="${1}"
shift

back=()
devs=()
args=()
qemu="qemu-firmware -monitor none -boot menu=on"
disk=""
liso=""
krnl=""
karg="console=ttyS0,115200"

case "$mode" in
kernel)

	qemu="qemu-default -nographic"
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	karg="$karg quiet"
	;;
seabios)
	disk="/vmdisk/imagefish/rhel-8.1.0-ks-x86_64-testboot-sys-disk.qcow2"
	krnl="$HOME/build/linux-sirius-x86_64-qemu/arch/x86/boot/bzImage"
	karg="$karg root=/dev/sda4"
	args+=("-bios" "/home/kraxel/projects/seabios/out-bios-microvm/bios.bin")
	;;
cloud)
	disk="/vmdisk/iso/Fedora-Cloud-Base-31-1.9.x86_64.raw"
	;;
coreos)
	disk="/vmdisk/iso/fedora-coreos-31.20200210.3.0-metal.x86_64.raw"
	;;
live)
	liso="/vmdisk/iso/Fedora-Workstation-Live-x86_64-30-1.2.iso"
	devs+=("-device" "virtio-gpu-device")
	devs+=("-device" "virtio-keyboard-device")
	devs+=("-device" "virtio-tablet-device")
	;;

*)
echo "unknown mode: $mode"
echo "known modes: kernel seabios cloud coreos live" exit 1
;;
esac

if test "$disk" != ""; then

	format="${disk##*.}"
	back+=("-drive" "if=none,id=disk,format=${format},file=${disk}")
	devs+=("-device" "scsi-hd,drive=disk,bootindex=1")
fi
if test "$liso" != ""; then
	back+=("-drive" "if=none,id=cdrom,media=cdrom,readonly,format=raw,file=${liso}")
	devs+=("-device" "scsi-cd,drive=cdrom,bootindex=2")
fi
if test "$krnl" != ""; then
	args+=("-kernel" "$krnl")
	args+=("-append" "$karg")

fi

set -ex

$qemu \
	-enable-kvm \
	-cpu host \
	-M microvm,graphics=off,pit=off,pic=on,rtc=on \
	\
	-m 4G \
	\
	-netdev user,id=net \
	"${back[@]}" \
	\
	-global virtio-mmio.force-legacy=false \
	-device virtio-net-device,netdev=net \
	-device virtio-scsi-device \
	"${devs[@]}" \
	\
	"${args[@]}" \
	"$@"  
#50 lore raw
Quoted 5 lines · On Fri, 27 Mar 2020 13:06:28 +0100 Gerd Hoffmann <[email protected]> wrote:

Hi,

Quoted 1 line

I just quickly hacked hw-reduced acpi (using arm/virt as model)

Can you send the patch or push a branch nevertheless?

It's no suitable for patch but I pushed it to my github repo

https://github.com/imammedo/qemu.git microvm_acpi

I just copy-pasted a bunch of code for test.

from cleanup point of view

we probably can generalize acpi_ram_update/acpi_build_update/acpi_build_reset/AcpiBuildState across arm/pc/microvm and make a shared acpi_setup for arm + microvm somewhere in hw/acpi/

the rest of common with pc things, I've copy-pasted, could be moved
to hw/i386/x86_acpi.c and I'd rename acpi-build.c to pc_acpi.c to make naming consistent

Quoted 4 lines

thanks,
Gerd