All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus
@ 2026-07-01 14:16 Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero Luigi Leonardi
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Luigi Leonardi @ 2026-07-01 14:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Michael S. Tsirkin, Richard Henderson,
	Sergio Lopez, Gerd Hoffmann, Luigi Leonardi

This series adds support for the uefi-vars-sysbus device on the microvm
machine type, enabling persistent UEFI variable storage.

The uefi-vars-sysbus device is a sysbus device that is attached to the
platform bus, which microvm does not currently support. To address this,
the series adds a platform bus to microvm, following the same
pattern used by the ARM virt machine.

The platform bus is mapped at 0xfec20000 with a 1 MB window, placed
after the IOAPICs. It is created without IRQ lines since the
uefi-vars-sysbus device only requires MMIO.

Patch 1 fixes a crash in the platform bus core when num_irqs is zero,
        which is needed to support an MMIO-only platform bus.
Patch 2 adds the platform bus to microvm with MMIO mapping and FDT
        integration.
Patch 3 allows the uefi-vars-sysbus device to be instantiated on
        microvm.

Corresponding edk2 changes[1]

[1]https://github.com/tianocore/edk2/pull/12751

To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Sergio Lopez <slp@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>

Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
Luigi Leonardi (3):
      hw/core/platform-bus: fix crash when num_irqs is zero
      hw/i386/microvm: add platform bus support
      hw/i386/microvm: add uefi-vars-sysbus support

 hw/core/platform-bus.c    |  4 ++++
 hw/i386/Kconfig           |  1 +
 hw/i386/microvm-dt.c      |  9 +++++++++
 hw/i386/microvm.c         | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/microvm.h |  4 ++++
 5 files changed, 56 insertions(+)
---
base-commit: f38d6ae70f100fc8d3f095a842d2f1ca29262218
change-id: 20260701-microvm_uefi_var-8a434ce7f8b9

Best regards,
-- 
Luigi Leonardi <leonardi@redhat.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero
  2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
@ 2026-07-01 14:16 ` Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 2/3] hw/i386/microvm: add platform bus support Luigi Leonardi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Luigi Leonardi @ 2026-07-01 14:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Michael S. Tsirkin, Richard Henderson,
	Sergio Lopez, Gerd Hoffmann, Luigi Leonardi

bitmap_new(0) returns a zero-size allocation, and the subsequent
bitmap_zero() dereferences it because small_nbits(0) is true.
Skip IRQ initialization entirely when num_irqs is zero, which is
valid for platform buses that only provide MMIO mapping.

This will be the case for the microvm platform bus which initially
has no IRQ lines.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
 hw/core/platform-bus.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c
index a2217a2dee..4f765582e7 100644
--- a/hw/core/platform-bus.c
+++ b/hw/core/platform-bus.c
@@ -194,6 +194,10 @@ static void platform_bus_realize(DeviceState *dev, Error **errp)
                        pbus->mmio_size);
     sysbus_init_mmio(d, &pbus->mmio);
 
+    if (pbus->num_irqs == 0) {
+        return;
+    }
+
     pbus->used_irqs = bitmap_new(pbus->num_irqs);
     pbus->irqs = g_new0(qemu_irq, pbus->num_irqs);
     for (i = 0; i < pbus->num_irqs; i++) {

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] hw/i386/microvm: add platform bus support
  2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero Luigi Leonardi
@ 2026-07-01 14:16 ` Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 3/3] hw/i386/microvm: add uefi-vars-sysbus support Luigi Leonardi
  2026-08-17 15:01 ` [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
  3 siblings, 0 replies; 5+ messages in thread
From: Luigi Leonardi @ 2026-07-01 14:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Michael S. Tsirkin, Richard Henderson,
	Sergio Lopez, Gerd Hoffmann, Luigi Leonardi

Add a platform bus to microvm to support dynamic sysbus devices with
automatic MMIO address allocation. The bus is mapped at 0xfec20000
with a 1 MB window, placed after the IOAPICs.

This is necessary to support the uefi-vars-sysbus device, which
will be attached to microvm using the platform bus.

The platform bus is created without IRQ lines for now; IRQ support can
be added later as needed.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
 hw/i386/Kconfig           |  1 +
 hw/i386/microvm-dt.c      |  9 +++++++++
 hw/i386/microvm.c         | 36 ++++++++++++++++++++++++++++++++++++
 include/hw/i386/microvm.h |  4 ++++
 4 files changed, 50 insertions(+)

diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 12473acaa7..e5f5e11980 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -133,6 +133,7 @@ config MICROVM
     select PCI_EXPRESS_GENERIC_BRIDGE
     select USB_XHCI_SYSBUS
     select I8254
+    select PLATFORM_BUS
 
 config NITRO_ENCLAVE
     default y
diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c
index 45fbb5bbd1..69feddc715 100644
--- a/hw/i386/microvm-dt.c
+++ b/hw/i386/microvm-dt.c
@@ -38,6 +38,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/rtc/mc146818rtc.h"
 #include "hw/core/sysbus.h"
+#include "hw/core/sysbus-fdt.h"
 #include "hw/virtio/virtio-mmio.h"
 #include "hw/usb/xhci.h"
 
@@ -337,6 +338,14 @@ void dt_setup_microvm(MicrovmMachineState *mms)
     qemu_fdt_add_subnode(ms->fdt, "/chosen");
     dt_setup_sys_bus(mms);
 
+    if (mms->platform_bus_dev) {
+        /* Platform bus IRQs are not supported, intc is required but unused */
+        platform_bus_add_all_fdt_nodes(ms->fdt, "/ioapic1",
+                                       MICROVM_PLATFORM_BUS_BASE,
+                                       MICROVM_PLATFORM_BUS_SIZE,
+                                       0);
+    }
+
     /* add to fw_cfg */
     if (debug) {
         fprintf(stderr, "%s: add etc/fdt to fw_cfg\n", __func__);
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 779741ec76..d4836b5e12 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -47,6 +47,7 @@
 #include "hw/virtio/virtio-mmio.h"
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/core/platform-bus.h"
 #include "hw/pci-host/gpex.h"
 #include "hw/usb/xhci.h"
 #include "hw/vfio/types.h"
@@ -146,6 +147,24 @@ static void create_gpex(MicrovmMachineState *mms)
     }
 }
 
+static void create_platform_bus(MicrovmMachineState *mms)
+{
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
+    dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
+    qdev_prop_set_uint32(dev, "num_irqs", 0);
+    qdev_prop_set_uint32(dev, "mmio_size", MICROVM_PLATFORM_BUS_SIZE);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    mms->platform_bus_dev = dev;
+
+    s = SYS_BUS_DEVICE(dev);
+    memory_region_add_subregion(get_system_memory(),
+                                MICROVM_PLATFORM_BUS_BASE,
+                                sysbus_mmio_get_region(s, 0));
+}
+
 static int microvm_ioapics(MicrovmMachineState *mms)
 {
     if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) {
@@ -248,6 +267,8 @@ static void microvm_devices_init(MicrovmMachineState *mms)
         x86ms->pci_irq_mask = 0;
     }
 
+    create_platform_bus(mms);
+
     if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) {
         qemu_irq *i8259;
 
@@ -453,12 +474,27 @@ static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine,
     return NULL;
 }
 
+static void link_one_device(SysBusDevice *sbdev, void *opaque)
+{
+    platform_bus_link_device(PLATFORM_BUS_DEVICE(opaque), sbdev);
+}
+
+static void microvm_link_platform_bus_devices(MicrovmMachineState *mms)
+{
+    if (!mms->platform_bus_dev) {
+        return;
+    }
+
+    foreach_dynamic_sysbus_device(link_one_device, mms->platform_bus_dev);
+}
+
 static void microvm_machine_done(Notifier *notifier, void *data)
 {
     MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState,
                                             machine_done);
     X86MachineState *x86ms = X86_MACHINE(mms);
 
+    microvm_link_platform_bus_devices(mms);
     acpi_setup_microvm(mms);
     dt_setup_microvm(mms);
     fw_cfg_add_e820(x86ms->fw_cfg);
diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h
index 184b7a8c09..bd2897aa78 100644
--- a/include/hw/i386/microvm.h
+++ b/include/hw/i386/microvm.h
@@ -61,6 +61,9 @@
 #define MICROVM_XHCI_BASE     0xfe900000
 #define MICROVM_XHCI_IRQ      10
 
+#define MICROVM_PLATFORM_BUS_BASE 0xfec20000
+#define MICROVM_PLATFORM_BUS_SIZE 0x00100000
+
 #define PCIE_MMIO_BASE        0xc0000000
 #define PCIE_MMIO_SIZE        0x20000000
 #define PCIE_ECAM_BASE        0xe0000000
@@ -101,6 +104,7 @@ struct MicrovmMachineState {
     Notifier machine_done;
     Notifier powerdown_req;
     struct GPEXConfig gpex;
+    DeviceState *platform_bus_dev;
 
     uint32_t ioapic_phandle[2];
 };

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] hw/i386/microvm: add uefi-vars-sysbus support
  2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero Luigi Leonardi
  2026-07-01 14:16 ` [PATCH 2/3] hw/i386/microvm: add platform bus support Luigi Leonardi
@ 2026-07-01 14:16 ` Luigi Leonardi
  2026-08-17 15:01 ` [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
  3 siblings, 0 replies; 5+ messages in thread
From: Luigi Leonardi @ 2026-07-01 14:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Michael S. Tsirkin, Richard Henderson,
	Sergio Lopez, Gerd Hoffmann, Luigi Leonardi

Allow the uefi-vars-sysbus device on microvm.

This is to support persistent UEFI variables on this architecture.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
 hw/i386/microvm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index d4836b5e12..44a5006b5a 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -55,6 +55,7 @@
 #include "elf.h"
 #include "kvm/kvm_i386.h"
 #include "hw/xen/start_info.h"
+#include "hw/uefi/var-service-api.h"
 
 #define MICROVM_QBOOT_FILENAME "qboot.rom"
 #define MICROVM_BIOS_FILENAME  "bios-microvm.bin"
@@ -751,6 +752,7 @@ static void microvm_class_init(ObjectClass *oc, const void *data)
         "Set off to disable adding virtio-mmio devices to the kernel cmdline");
 
     machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
+    machine_class_allow_dynamic_sysbus_dev(mc, TYPE_UEFI_VARS_SYSBUS);
 
     compat_props_add(mc->compat_props, microvm_properties,
                      G_N_ELEMENTS(microvm_properties));

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus
  2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
                   ` (2 preceding siblings ...)
  2026-07-01 14:16 ` [PATCH 3/3] hw/i386/microvm: add uefi-vars-sysbus support Luigi Leonardi
@ 2026-08-17 15:01 ` Luigi Leonardi
  3 siblings, 0 replies; 5+ messages in thread
From: Luigi Leonardi @ 2026-08-17 15:01 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Michael S. Tsirkin, Richard Henderson,
	Sergio Lopez, Gerd Hoffmann

On Wed, Jul 01, 2026 at 04:16:16PM +0200, Luigi Leonardi wrote:
>This series adds support for the uefi-vars-sysbus device on the microvm
>machine type, enabling persistent UEFI variable storage.
>
>The uefi-vars-sysbus device is a sysbus device that is attached to the
>platform bus, which microvm does not currently support. To address this,
>the series adds a platform bus to microvm, following the same
>pattern used by the ARM virt machine.
>
>The platform bus is mapped at 0xfec20000 with a 1 MB window, placed
>after the IOAPICs. It is created without IRQ lines since the
>uefi-vars-sysbus device only requires MMIO.
>
>Patch 1 fixes a crash in the platform bus core when num_irqs is zero,
>        which is needed to support an MMIO-only platform bus.
>Patch 2 adds the platform bus to microvm with MMIO mapping and FDT
>        integration.
>Patch 3 allows the uefi-vars-sysbus device to be instantiated on
>        microvm.
>
>Corresponding edk2 changes[1]
>
>[1]https://github.com/tianocore/edk2/pull/12751
>
>To: qemu-devel@nongnu.org
>Cc: Paolo Bonzini <pbonzini@redhat.com>
>Cc: Michael S. Tsirkin <mst@redhat.com>
>Cc: Richard Henderson <richard.henderson@linaro.org>
>Cc: Sergio Lopez <slp@redhat.com>
>Cc: Gerd Hoffmann <kraxel@redhat.com>
>
>Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
>Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
>---
>Luigi Leonardi (3):
>      hw/core/platform-bus: fix crash when num_irqs is zero
>      hw/i386/microvm: add platform bus support
>      hw/i386/microvm: add uefi-vars-sysbus support
>
> hw/core/platform-bus.c    |  4 ++++
> hw/i386/Kconfig           |  1 +
> hw/i386/microvm-dt.c      |  9 +++++++++
> hw/i386/microvm.c         | 38 ++++++++++++++++++++++++++++++++++++++
> include/hw/i386/microvm.h |  4 ++++
> 5 files changed, 56 insertions(+)
>---
>base-commit: f38d6ae70f100fc8d3f095a842d2f1ca29262218
>change-id: 20260701-microvm_uefi_var-8a434ce7f8b9
>
>Best regards,
>-- 
>Luigi Leonardi <leonardi@redhat.com>
>
>

Gentle ping :)

Thanks,
Luigi



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-17 15:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
2026-07-01 14:16 ` [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero Luigi Leonardi
2026-07-01 14:16 ` [PATCH 2/3] hw/i386/microvm: add platform bus support Luigi Leonardi
2026-07-01 14:16 ` [PATCH 3/3] hw/i386/microvm: add uefi-vars-sysbus support Luigi Leonardi
2026-08-17 15:01 ` [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.