On Tue, Jul 01, 2025 at 02:18:15PM +0200, Oliver Steffen wrote:
From: Gerd Hoffmann <kra...@redhat.com>
I would mention SVSM in the commit title.
Add virtio-mmio slots to the q35 machine model, intended to be used by
an SVSM.
Disabled by default, enable using '-machine q35,x-svsm-virtio-mmio=on'.
I guess we should remove the `x-` after the RFC, right?
And add some documentation.
In the future, we may have several things to configure for SVSM. Should
we think of some specific object (e.g., svsm-cfg), or rather add
properties to the machine type as in this case?
When enabled it is possible to plug up to 4 virtio devices into the
slots virtio-mmio using '-device virtio-${kind}-device'.
The devices can be found at base address 0xfef00000, each slot on a
Disclaimer: I don't have much experience in allocating mmio addresses,
but why that address?
Should we make it configurable/dynamic?
Thanks,
Stefano
separate page. No IRQ is wired up, the SVSM has to drive the devices
in polling mode.
The base addresses are communicated to the SVSM via the etc/hardware-info
fw_cfg file.
Signed-off-by: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Oliver Steffen <ostef...@redhat.com>
---
hw/i386/pc.c | 18 +++++++++++++++++-
hw/i386/pc_q35.c | 15 +++++++++++++++
include/hw/i386/pc.h | 1 +
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 432ab288a8..e1dbf8846d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1584,6 +1584,21 @@ static void pc_machine_set_smbios_ep(Object *obj,
Visitor *v, const char *name,
visit_type_SmbiosEntryPointType(v, name, &pcms->smbios_entry_point_type,
errp);
}
+static bool pc_machine_get_svsm_virtio_mmio(Object *obj, Error **errp)
+{
+ PCMachineState *pcms = PC_MACHINE(obj);
+
+ return pcms->svsm_virtio_mmio;
+}
+
+static void pc_machine_set_svsm_virtio_mmio(Object *obj, bool value,
+ Error **errp)
+{
+ PCMachineState *pcms = PC_MACHINE(obj);
+
+ pcms->svsm_virtio_mmio = value;
+}
+
static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
@@ -1844,7 +1859,8 @@ static void pc_machine_class_init(ObjectClass *oc, const
void *data)
"Set IGVM configuration");
#endif
-
+ object_class_property_add_bool(oc, "x-svsm-virtio-mmio",
+ pc_machine_get_svsm_virtio_mmio, pc_machine_set_svsm_virtio_mmio);
}
static const TypeInfo pc_machine_info = {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index cf871cfdad..b8511ae52a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -60,7 +60,9 @@
#include "hw/mem/nvdimm.h"
#include "hw/uefi/var-service-api.h"
#include "hw/i386/acpi-build.h"
+#include "hw/uefi/hardware-info.h"
#include "target/i386/cpu.h"
+#include "exec/target_page.h"
/* ICH9 AHCI has 6 ports */
#define MAX_SATA_PORTS 6
@@ -335,6 +337,19 @@ static void pc_q35_init(MachineState *machine)
}
}
#endif
+
+ if (pcms->svsm_virtio_mmio) {
+ for (int dev = 0; dev < 4; dev++) {
+ HARDWARE_INFO_SIMPLE_DEVICE hwinfo = {
+ .mmio_address = cpu_to_le64(0xfef00000 + dev *
TARGET_PAGE_SIZE),
+ };
+ sysbus_create_simple("virtio-mmio", hwinfo.mmio_address,
+ /* no irq */ NULL);
+ hardware_info_register(HardwareInfoVirtioMmioSvsm,
+ &hwinfo, sizeof(hwinfo));
+ }
+ }
+
}
#define DEFINE_Q35_MACHINE(major, minor) \
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 79b72c54dd..9c9f947087 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -51,6 +51,7 @@ typedef struct PCMachineState {
bool i8042_enabled;
bool default_bus_bypass_iommu;
bool fd_bootchk;
+ bool svsm_virtio_mmio;
uint64_t max_fw_size;
/* ACPI Memory hotplug IO base address */
--
2.50.0