virtio-iommu: Add ACPI support
v5 cover virtio-iommu: Add ACPI support
Allow instantiating a virtio-iommu device on ACPI systems by adding a Virtual I/O Translation table (VIOT). Enable x86 support for VIOT.
Patches 5-8 need acks from Arm maintainers in order for this to go through the x86 tree.
Changes since v4 [1]:
* New patch 2 removes unnecessary x86_iommu_get_type().
* Patch 3 now moves the IOMMU variable into PCMachineState, in addition to the check for duplicate IOMMUs.
* Fixed assertion error in patch 6.
* Addressed the other comments.
* Added more review and test tags, thanks!
The boot-bypass series [2] isn't a hard requirement for this series but will be needed for complete support. In the meantime, storage accessed by firmware needs to bypass the IOMMU some other way, using either a virtio-blk device without the iommu_platform property, or a bypass bridge (docs/iommu-bypass.txt).
You can find a description of the VIOT table, which will be included in next ACPI version, here: https://jpbrucker.net/virtio-iommu/viot/viot-v9.pdf
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/
Jean-Philippe Brucker (12):
hw/acpi: Add VIOT table
hw/i386/pc: Remove x86_iommu_get_type()
hw/i386/pc: Move IOMMU singleton into PCMachineState hw/i386/pc: Allow instantiating a virtio-iommu device hw/arm/virt-acpi-build: Add VIOT table for virtio-iommu hw/arm/virt: Remove device tree restriction for virtio-iommu hw/arm/virt: Reject instantiation of multiple IOMMUs hw/arm/virt: Use object_property_set instead of qdev_prop_set tests/acpi: allow updates of VIOT expected data files tests/acpi: add test cases for VIOT
tests/acpi: add expected blob for VIOT test on virt machine tests/acpi: add expected blobs for VIOT test on q35 machine
hw/acpi/viot.h | 13 ++++ include/hw/i386/pc.h | 1 + include/hw/i386/x86-iommu.h | 12 ---- hw/acpi/viot.c | 114 +++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 7 ++ hw/arm/virt.c | 20 +++--- hw/i386/acpi-build.c | 28 ++++---- hw/i386/amd_iommu.c | 2 - hw/i386/intel_iommu.c | 3 - hw/i386/pc.c | 26 +++++++- hw/i386/x86-iommu-stub.c | 5 -- hw/i386/x86-iommu.c | 31 +++------ hw/virtio/virtio-iommu-pci.c | 12 +--- tests/qtest/bios-tables-test.c | 38 +++++++++++ hw/acpi/Kconfig | 4 ++ hw/acpi/meson.build | 1 + hw/arm/Kconfig | 1 + hw/i386/Kconfig | 1 + tests/data/acpi/q35/DSDT.viot | Bin 0 -> 9398 bytes tests/data/acpi/q35/VIOT.viot | Bin 0 -> 112 bytes tests/data/acpi/virt/VIOT | Bin 0 -> 88 bytes 21 files changed, 242 insertions(+), 77 deletions(-) create mode 100644 hw/acpi/viot.h create mode 100644 hw/acpi/viot.c create mode 100644 tests/data/acpi/q35/DSDT.viot create mode 100644 tests/data/acpi/q35/VIOT.viot create mode 100644 tests/data/acpi/virt/VIOT
Signature · 1 line
2.33.0
PATCH v5 1/12 hw/acpi: Add VIOT table
Add a function that generates a Virtual I/O Translation table (VIOT), describing the topology of paravirtual IOMMUs. The table is created if a virtio-iommu device is present. It contains a virtio-iommu node and PCI Range nodes for endpoints managed by the IOMMU. By default, a single node describes all PCI devices. When passing the "default_bus_bypass_iommu" machine option and "bypass_iommu" PXB option, only buses that do not bypass the IOMMU are described by PCI Range nodes.
--- hw/acpi/viot.h | 13 +++++ hw/acpi/viot.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/Kconfig | 4 ++ hw/acpi/meson.build | 1 + 4 files changed, 132 insertions(+) create mode 100644 hw/acpi/viot.h create mode 100644 hw/acpi/viot.c
hw/acpi/viot.h new file +13 -0
@@ -0,0 +1,13 @@ +/* +* ACPI Virtual I/O Translation Table implementation +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef VIOT_H +#define VIOT_H + +void build_viot (MachineState *ms,GArray *table_data,BIOSLinker *linker, +uint16_t virtio_iommu_bdf,const char *oem_id, +const char *oem_table_id); + +#endif /* VIOT_H */
hw/acpi/viot.c new file +114 -0
114 lines not on this page · raw message
hw/acpi/Kconfig +4 -0
@@ -51,6 +51,10 @@ config ACPI_VMGENID default y depends on PC +config ACPI_VIOT + bool + depends on ACPI + config ACPI_HW_REDUCED bool select ACPI
hw/acpi/meson.build +1 -0
@@ -20,6 +20,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c'), if_false: files( acpi_ss.add(when: 'CONFIG_ACPI_PIIX4', if_true: files('piix4.c')) acpi_ss.add(when: 'CONFIG_ACPI_PCIHP', if_true: files('pcihp.c')) acpi_ss.add(when: 'CONFIG_ACPI_PCIHP', if_false: files('acpi-pci-hotplug-stub.c')) +acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c')) acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c'))
Signature · 1 line
2.33.0
PATCH v5 2/12 hw/i386/pc: Remove x86_iommu_get_type()
In reply to Jean-Philippe BruckerTo generate the IOMMU ACPI table, acpi-build.c can use base QEMU types instead of a special IommuType value.
--- include/hw/i386/x86-iommu.h | 12 ------------ hw/i386/acpi-build.c | 20 +++++++++----------- hw/i386/amd_iommu.c | 2 -- hw/i386/intel_iommu.c | 3 --- hw/i386/x86-iommu-stub.c | 5 ----- hw/i386/x86-iommu.c | 5 ----- 6 files changed, 9 insertions(+), 38 deletions(-)
include/hw/i386/x86-iommu.h +0 -12
@@ -33,12 +33,6 @@ OBJECT_DECLARE_TYPE(X86IOMMUState, X86IOMMUClass, X86_IOMMU_DEVICE)typedef struct X86IOMMUIrq X86IOMMUIrq ;typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage ; -typedef enum IommuType { -TYPE_INTEL , -TYPE_AMD , -TYPE_NONE -}IommuType ; -struct X86IOMMUClass {SysBusDeviceClass parent;/* Intel/AMD specific realize() hook */
@@ -71,7 +65,6 @@ struct X86IOMMUState {OnOffAuto intr_supported;/* Whether vIOMMU supports IR */ bool dt_supported;/* Whether vIOMMU supports DT */ bool pt_supported;/* Whether vIOMMU supports pass-through */ -IommuType type;/* IOMMU type - AMD/Intel */ QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ };
@@ -140,11 +133,6 @@ struct X86IOMMU_MSIMessage {*/ X86IOMMUState *x86_iommu_get_default (void ); -/* -* x86_iommu_get_type - get IOMMU type -*/ -IommuType x86_iommu_get_type (void ); -/** * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry * Cache) notifiers
hw/i386/acpi-build.c +9 -11
@@ -2488,6 +2488,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); +X86IOMMUState *iommu =x86_iommu_get_default ();GArray *table_offsets;unsigned facs, dsdt, rsdt, fadt;AcpiPmInfo pm;
@@ -2604,17 +2605,14 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_mcfg (tables_blob, tables->linker, &mcfg, x86ms->oem_id, x86ms->oem_table_id); } -if (x86_iommu_get_default ()) { -IommuType IOMMUType =x86_iommu_get_type (); -if (IOMMUType ==TYPE_AMD ) { -acpi_add_table (table_offsets, tables_blob); -build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - }else if (IOMMUType ==TYPE_INTEL ) { -acpi_add_table (table_offsets, tables_blob); -build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - } +if (object_dynamic_cast (OBJECT (iommu),TYPE_AMD_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); + }else if (object_dynamic_cast (OBJECT (iommu),TYPE_INTEL_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); }if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker,
hw/i386/amd_iommu.c +0 -2
@@ -1538,7 +1538,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) {int ret =0 ;AMDVIState *s =AMD_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);MachineState *ms =MACHINE (qdev_get_machine ());PCMachineState *pcms =PC_MACHINE (ms);X86MachineState *x86ms =X86_MACHINE (ms);
@@ -1548,7 +1547,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) amdvi_uint64_equal, g_free, g_free);/* This device should take care of IOMMU PCI properties */ - x86_iommu->type =TYPE_AMD ;if (!qdev_realize (DEVICE (&s->pci), &bus->qbus, errp)) {return ; }
hw/i386/intel_iommu.c +0 -3
@@ -3806,9 +3806,6 @@ static void vtd_realize(DeviceState *dev, Error **errp)X86MachineState *x86ms =X86_MACHINE (ms);PCIBus *bus = pcms->bus;IntelIOMMUState *s =INTEL_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev); - - x86_iommu->type =TYPE_INTEL ;if (!vtd_decide_config (s, errp)) {return ;
hw/i386/x86-iommu-stub.c +0 -5
@@ -36,8 +36,3 @@ bool x86_iommu_ir_supported(X86IOMMUState *s) {return false; } - -IommuType x86_iommu_get_type (void ) -{ -abort (); -}
hw/i386/x86-iommu.c +0 -5
@@ -98,11 +98,6 @@ X86IOMMUState *x86_iommu_get_default(void)return x86_iommu_default; } -IommuType x86_iommu_get_type (void ) -{ -return x86_iommu_default->type; -} -static void x86_iommu_realize (DeviceState *dev,Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);
Signature · 1 line
2.33.0
Re: [PATCH v5 02/12] hw/i386/pc: Remove x86_iommu_get_type()
Hi Jean,
Quoted 4 lines · Jean-Philippe Brucker
To generate the IOMMU ACPI table,
acpi-build.ccan use base QEMU types instead of a special IommuType value.Signed-off-by Jean-Philippe Brucker <[email protected]>
Looks good to me
Thanks
Eric
Quoted 147 lines
--- include/hw/i386/x86-iommu.h | 12 ------------ hw/i386/acpi-build.c | 20 +++++++++----------- hw/i386/amd_iommu.c | 2 -- hw/i386/intel_iommu.c | 3 --- hw/i386/x86-iommu-stub.c | 5 ----- hw/i386/x86-iommu.c | 5 ----- 6 files changed, 9 insertions(+), 38 deletions(-)include/hw/i386/x86-iommu.h +0
-12@@ -33,12 +33,6 @@ OBJECT_DECLARE_TYPE(X86IOMMUState, X86IOMMUClass, X86_IOMMU_DEVICE)typedef struct X86IOMMUIrq X86IOMMUIrq ;typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage ; -typedef enum IommuType { -TYPE_INTEL , -TYPE_AMD , -TYPE_NONE -}IommuType ; -struct X86IOMMUClass {SysBusDeviceClass parent;/* Intel/AMD specific realize() hook */ @@ -71,7 +65,6 @@ struct X86IOMMUState {OnOffAuto intr_supported;/* Whether vIOMMU supports IR */ bool dt_supported;/* Whether vIOMMU supports DT */ bool pt_supported;/* Whether vIOMMU supports pass-through */ -IommuType type;/* IOMMU type - AMD/Intel */ QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ };@@ -140,11 +133,6 @@ struct X86IOMMU_MSIMessage {*/ X86IOMMUState *x86_iommu_get_default (void ); -/* -* x86_iommu_get_type - get IOMMU type -*/ -IommuType x86_iommu_get_type (void ); -/** * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry * Cache) notifiers hw/i386/acpi-build.c +9
-11@@ -2488,6 +2488,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); +X86IOMMUState *iommu =x86_iommu_get_default ();GArray *table_offsets;unsigned facs, dsdt, rsdt, fadt;AcpiPmInfo pm;@@ -2604,17 +2605,14 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_mcfg (tables_blob, tables->linker, &mcfg, x86ms->oem_id, x86ms->oem_table_id); } -if (x86_iommu_get_default ()) { -IommuType IOMMUType =x86_iommu_get_type (); -if (IOMMUType ==TYPE_AMD ) { -acpi_add_table (table_offsets, tables_blob); -build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - }else if (IOMMUType ==TYPE_INTEL ) { -acpi_add_table (table_offsets, tables_blob); -build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - } +if (object_dynamic_cast (OBJECT (iommu),TYPE_AMD_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); + }else if (object_dynamic_cast (OBJECT (iommu),TYPE_INTEL_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); }if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker,hw/i386/amd_iommu.c +0
-2@@ -1538,7 +1538,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) {int ret =0 ;AMDVIState *s =AMD_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);MachineState *ms =MACHINE (qdev_get_machine ());PCMachineState *pcms =PC_MACHINE (ms);X86MachineState *x86ms =X86_MACHINE (ms);@@ -1548,7 +1547,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) amdvi_uint64_equal, g_free, g_free);/* This device should take care of IOMMU PCI properties */ - x86_iommu->type =TYPE_AMD ;if (!qdev_realize (DEVICE (&s->pci), &bus->qbus, errp)) {return ; }hw/i386/intel_iommu.c +0
-3@@ -3806,9 +3806,6 @@ static void vtd_realize(DeviceState *dev, Error **errp)X86MachineState *x86ms =X86_MACHINE (ms);PCIBus *bus = pcms->bus;IntelIOMMUState *s =INTEL_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev); - - x86_iommu->type =TYPE_INTEL ;if (!vtd_decide_config (s, errp)) {return ;hw/i386/x86-iommu-stub.c +0
-5@@ -36,8 +36,3 @@ bool x86_iommu_ir_supported(X86IOMMUState *s) {return false; } - -IommuType x86_iommu_get_type (void ) -{ -abort (); -}hw/i386/x86-iommu.c +0
-5@@ -98,11 +98,6 @@ X86IOMMUState *x86_iommu_get_default(void)return x86_iommu_default; } -IommuType x86_iommu_get_type (void ) -{ -return x86_iommu_default->type; -} -static void x86_iommu_realize (DeviceState *dev,Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);
Re: [PATCH v5 02/12] hw/i386/pc: Remove x86_iommu_get_type()
In reply to Jean-Philippe BruckerQuoted 4 lines · On Wed, 20 Oct 2021 18:27:36 +0100 Jean-Philippe Brucker…
To generate the IOMMU ACPI table,
acpi-build.ccan use base QEMU types instead of a special IommuType value.Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 147 lines
--- include/hw/i386/x86-iommu.h | 12 ------------ hw/i386/acpi-build.c | 20 +++++++++----------- hw/i386/amd_iommu.c | 2 -- hw/i386/intel_iommu.c | 3 --- hw/i386/x86-iommu-stub.c | 5 ----- hw/i386/x86-iommu.c | 5 ----- 6 files changed, 9 insertions(+), 38 deletions(-)include/hw/i386/x86-iommu.h +0
-12@@ -33,12 +33,6 @@ OBJECT_DECLARE_TYPE(X86IOMMUState, X86IOMMUClass, X86_IOMMU_DEVICE)typedef struct X86IOMMUIrq X86IOMMUIrq ;typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage ; -typedef enum IommuType { -TYPE_INTEL , -TYPE_AMD , -TYPE_NONE -}IommuType ; -struct X86IOMMUClass {SysBusDeviceClass parent;/* Intel/AMD specific realize() hook */ @@ -71,7 +65,6 @@ struct X86IOMMUState {OnOffAuto intr_supported;/* Whether vIOMMU supports IR */ bool dt_supported;/* Whether vIOMMU supports DT */ bool pt_supported;/* Whether vIOMMU supports pass-through */ -IommuType type;/* IOMMU type - AMD/Intel */ QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ };@@ -140,11 +133,6 @@ struct X86IOMMU_MSIMessage {*/ X86IOMMUState *x86_iommu_get_default (void ); -/* -* x86_iommu_get_type - get IOMMU type -*/ -IommuType x86_iommu_get_type (void ); -/** * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry * Cache) notifiers hw/i386/acpi-build.c +9
-11@@ -2488,6 +2488,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); +X86IOMMUState *iommu =x86_iommu_get_default ();GArray *table_offsets;unsigned facs, dsdt, rsdt, fadt;AcpiPmInfo pm;@@ -2604,17 +2605,14 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_mcfg (tables_blob, tables->linker, &mcfg, x86ms->oem_id, x86ms->oem_table_id); } -if (x86_iommu_get_default ()) { -IommuType IOMMUType =x86_iommu_get_type (); -if (IOMMUType ==TYPE_AMD ) { -acpi_add_table (table_offsets, tables_blob); -build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - }else if (IOMMUType ==TYPE_INTEL ) { -acpi_add_table (table_offsets, tables_blob); -build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, - x86ms->oem_table_id); - } +if (object_dynamic_cast (OBJECT (iommu),TYPE_AMD_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); + }else if (object_dynamic_cast (OBJECT (iommu),TYPE_INTEL_IOMMU_DEVICE )) { +acpi_add_table (table_offsets, tables_blob); +build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); }if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker,hw/i386/amd_iommu.c +0
-2@@ -1538,7 +1538,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) {int ret =0 ;AMDVIState *s =AMD_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);MachineState *ms =MACHINE (qdev_get_machine ());PCMachineState *pcms =PC_MACHINE (ms);X86MachineState *x86ms =X86_MACHINE (ms);@@ -1548,7 +1547,6 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) amdvi_uint64_equal, g_free, g_free);/* This device should take care of IOMMU PCI properties */ - x86_iommu->type =TYPE_AMD ;if (!qdev_realize (DEVICE (&s->pci), &bus->qbus, errp)) {return ; }hw/i386/intel_iommu.c +0
-3@@ -3806,9 +3806,6 @@ static void vtd_realize(DeviceState *dev, Error **errp)X86MachineState *x86ms =X86_MACHINE (ms);PCIBus *bus = pcms->bus;IntelIOMMUState *s =INTEL_IOMMU_DEVICE (dev); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev); - - x86_iommu->type =TYPE_INTEL ;if (!vtd_decide_config (s, errp)) {return ;hw/i386/x86-iommu-stub.c +0
-5@@ -36,8 +36,3 @@ bool x86_iommu_ir_supported(X86IOMMUState *s) {return false; } - -IommuType x86_iommu_get_type (void ) -{ -abort (); -}hw/i386/x86-iommu.c +0
-5@@ -98,11 +98,6 @@ X86IOMMUState *x86_iommu_get_default(void)return x86_iommu_default; } -IommuType x86_iommu_get_type (void ) -{ -return x86_iommu_default->type; -} -static void x86_iommu_realize (DeviceState *dev,Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);
PATCH v5 3/12 hw/i386/pc: Move IOMMU singleton into PCMachineState
In reply to Jean-Philippe BruckerWe're about to support a third vIOMMU for x86, virtio-iommu which doesn't inherit X86IOMMUState. Move the IOMMU singleton into PCMachineState, so it can be shared between all three vIOMMUs.
The x86_iommu_get_default() helper is still needed by KVM and IOAPIC to fetch the default IRQ-remapping IOMMU. Since virtio-iommu doesn't support IRQ remapping, this interface doesn't need to change for the moment. We could later replace X86IOMMUState with an "IRQ remapping IOMMU" interface if necessary.
--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 12 +++++++++++- hw/i386/x86-iommu.c | 26 ++++++++------------------ 3 files changed, 20 insertions(+), 19 deletions(-)
include/hw/i386/pc.h +1 -0
@@ -35,6 +35,7 @@ typedef struct PCMachineState {I2CBus *smbus;PFlashCFI01 *flash[2 ];ISADevice *pcspk; +DeviceState *iommu;/* Configuration options: */ uint64_t max_ram_below_4g;
hw/i386/pc.c +11 -1
@@ -1330,6 +1330,15 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) {pc_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) { +PCMachineState *pcms =PC_MACHINE (hotplug_dev); + +if (pcms->iommu) { +error_setg (errp,"QEMU does not support multiple vIOMMUs " +"for x86 yet." ); +return ; + } + pcms->iommu = dev; } }
@@ -1384,7 +1393,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) ||object_dynamic_cast (OBJECT (dev),TYPE_CPU ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) || -object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI ) || +object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) {return HOTPLUG_HANDLER (machine); }
hw/i386/x86-iommu.c +8 -18
@@ -77,25 +77,17 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) msg_out->data = msg.msi_data; } -/* Default X86 IOMMU device */ -static X86IOMMUState *x86_iommu_default =NULL ; - -static void x86_iommu_set_default (X86IOMMUState *x86_iommu) +X86IOMMUState *x86_iommu_get_default (void ) { -assert (x86_iommu); +MachineState *ms =MACHINE (qdev_get_machine ()); +PCMachineState *pcms = +PC_MACHINE (object_dynamic_cast (OBJECT (ms),TYPE_PC_MACHINE )); -if (x86_iommu_default) { -error_report ("QEMU does not support multiple vIOMMUs " -"for x86 yet." ); -exit (1 ); +if (pcms && +object_dynamic_cast (OBJECT (pcms->iommu),TYPE_X86_IOMMU_DEVICE )) { +return X86_IOMMU_DEVICE (pcms->iommu); } - - x86_iommu_default = x86_iommu; -} - -X86IOMMUState *x86_iommu_get_default (void ) -{ -return x86_iommu_default; +return NULL ; }static void x86_iommu_realize (DeviceState *dev,Error **errp)
@@ -131,8 +123,6 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)if (x86_class->realize) { x86_class->realize (dev, errp); } - -x86_iommu_set_default (X86_IOMMU_DEVICE (dev)); }static Property x86_iommu_properties[] = {
Signature · 1 line
2.33.0
Re: [PATCH v5 03/12] hw/i386/pc: Move IOMMU singleton into PCMachineState
Quoted 11 lines · Jean-Philippe Brucker
We're about to support a third vIOMMU for x86, virtio-iommu which doesn't inherit X86IOMMUState. Move the IOMMU singleton into PCMachineState, so it can be shared between all three vIOMMUs.
The
x86_iommu_get_default()helper is still needed by KVM and IOAPIC to fetch the default IRQ-remapping IOMMU. Since virtio-iommu doesn't support IRQ remapping, this interface doesn't need to change for the moment. We could later replace X86IOMMUState with an "IRQ remapping IOMMU" interface if necessary.Signed-off-by Jean-Philippe Brucker <[email protected]>
Eric
Quoted 95 lines
--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 12 +++++++++++- hw/i386/x86-iommu.c | 26 ++++++++------------------ 3 files changed, 20 insertions(+), 19 deletions(-)include/hw/i386/pc.h +1
-0@@ -35,6 +35,7 @@ typedef struct PCMachineState {I2CBus *smbus;PFlashCFI01 *flash[2 ];ISADevice *pcspk; +DeviceState *iommu;/* Configuration options: */ uint64_t max_ram_below_4g;hw/i386/pc.c +11
-1@@ -1330,6 +1330,15 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) {pc_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) { +PCMachineState *pcms =PC_MACHINE (hotplug_dev); + +if (pcms->iommu) { +error_setg (errp,"QEMU does not support multiple vIOMMUs " +"for x86 yet." ); +return ; + } + pcms->iommu = dev; } }@@ -1384,7 +1393,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) ||object_dynamic_cast (OBJECT (dev),TYPE_CPU ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) || -object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI ) || +object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) {return HOTPLUG_HANDLER (machine); }hw/i386/x86-iommu.c +8
-18@@ -77,25 +77,17 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) msg_out->data = msg.msi_data; } -/* Default X86 IOMMU device */ -static X86IOMMUState *x86_iommu_default =NULL ; - -static void x86_iommu_set_default (X86IOMMUState *x86_iommu) +X86IOMMUState *x86_iommu_get_default (void ) { -assert (x86_iommu); +MachineState *ms =MACHINE (qdev_get_machine ()); +PCMachineState *pcms = +PC_MACHINE (object_dynamic_cast (OBJECT (ms),TYPE_PC_MACHINE )); -if (x86_iommu_default) { -error_report ("QEMU does not support multiple vIOMMUs " -"for x86 yet." ); -exit (1 ); +if (pcms && +object_dynamic_cast (OBJECT (pcms->iommu),TYPE_X86_IOMMU_DEVICE )) { +return X86_IOMMU_DEVICE (pcms->iommu); } - - x86_iommu_default = x86_iommu; -} - -X86IOMMUState *x86_iommu_get_default (void ) -{ -return x86_iommu_default; +return NULL ; }static void x86_iommu_realize (DeviceState *dev,Error **errp)@@ -131,8 +123,6 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)if (x86_class->realize) { x86_class->realize (dev, errp); } - -x86_iommu_set_default (X86_IOMMU_DEVICE (dev)); }static Property x86_iommu_properties[] = {
Re: [PATCH v5 03/12] hw/i386/pc: Move IOMMU singleton into PCMachineState
In reply to Jean-Philippe BruckerQuoted 11 lines · On Wed, 20 Oct 2021 18:27:37 +0100 Jean-Philippe Brucker…
We're about to support a third vIOMMU for x86, virtio-iommu which doesn't inherit X86IOMMUState. Move the IOMMU singleton into PCMachineState, so it can be shared between all three vIOMMUs.
The
x86_iommu_get_default()helper is still needed by KVM and IOAPIC to fetch the default IRQ-remapping IOMMU. Since virtio-iommu doesn't support IRQ remapping, this interface doesn't need to change for the moment. We could later replace X86IOMMUState with an "IRQ remapping IOMMU" interface if necessary.Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 95 lines
--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 12 +++++++++++- hw/i386/x86-iommu.c | 26 ++++++++------------------ 3 files changed, 20 insertions(+), 19 deletions(-)include/hw/i386/pc.h +1
-0@@ -35,6 +35,7 @@ typedef struct PCMachineState {I2CBus *smbus;PFlashCFI01 *flash[2 ];ISADevice *pcspk; +DeviceState *iommu;/* Configuration options: */ uint64_t max_ram_below_4g;hw/i386/pc.c +11
-1@@ -1330,6 +1330,15 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) {pc_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) { +PCMachineState *pcms =PC_MACHINE (hotplug_dev); + +if (pcms->iommu) { +error_setg (errp,"QEMU does not support multiple vIOMMUs " +"for x86 yet." ); +return ; + } + pcms->iommu = dev; } }@@ -1384,7 +1393,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) ||object_dynamic_cast (OBJECT (dev),TYPE_CPU ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) || -object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI ) || +object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) {return HOTPLUG_HANDLER (machine); }hw/i386/x86-iommu.c +8
-18@@ -77,25 +77,17 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) msg_out->data = msg.msi_data; } -/* Default X86 IOMMU device */ -static X86IOMMUState *x86_iommu_default =NULL ; - -static void x86_iommu_set_default (X86IOMMUState *x86_iommu) +X86IOMMUState *x86_iommu_get_default (void ) { -assert (x86_iommu); +MachineState *ms =MACHINE (qdev_get_machine ()); +PCMachineState *pcms = +PC_MACHINE (object_dynamic_cast (OBJECT (ms),TYPE_PC_MACHINE )); -if (x86_iommu_default) { -error_report ("QEMU does not support multiple vIOMMUs " -"for x86 yet." ); -exit (1 ); +if (pcms && +object_dynamic_cast (OBJECT (pcms->iommu),TYPE_X86_IOMMU_DEVICE )) { +return X86_IOMMU_DEVICE (pcms->iommu); } - - x86_iommu_default = x86_iommu; -} - -X86IOMMUState *x86_iommu_get_default (void ) -{ -return x86_iommu_default; +return NULL ; }static void x86_iommu_realize (DeviceState *dev,Error **errp)@@ -131,8 +123,6 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)if (x86_class->realize) { x86_class->realize (dev, errp); } - -x86_iommu_set_default (X86_IOMMU_DEVICE (dev)); }static Property x86_iommu_properties[] = {
PATCH v5 4/12 hw/i386/pc: Allow instantiating a virtio-iommu device
In reply to Jean-Philippe BruckerAllow instantiating a virtio-iommu device by adding an ACPI Virtual I/O Translation table (VIOT), which describes the relation between the virtio-iommu and the endpoints it manages.
Add a hotplug handler for virtio-iommu on x86 and set the necessary reserved region property. On x86, the [0xfee00000, 0xfeefffff] DMA region is reserved for MSIs. DMA transactions to this range either trigger IRQ remapping in the IOMMU or bypasses IOMMU translation.
Although virtio-iommu does not support IRQ remapping it must be informed of the reserved region so that it can forward DMA transactions targeting this region.
--- hw/i386/acpi-build.c | 10 +++++++++- hw/i386/pc.c | 16 +++++++++++++++- hw/i386/Kconfig | 1 + 3 files changed, 25 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +9 -1
@@ -68,9 +68,11 @@#include "qom/qom-qobject.h" #include "hw/i386/amd_iommu.h" #include "hw/i386/intel_iommu.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/acpi/ipmi.h" #include "hw/acpi/hmat.h" +#include "hw/acpi/viot.h" /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows
@@ -2488,7 +2490,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -X86IOMMUState *iommu =x86_iommu_get_default (); +DeviceState *iommu = pcms->iommu;GArray *table_offsets;unsigned facs, dsdt, rsdt, fadt;AcpiPmInfo pm;
@@ -2613,6 +2615,12 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id); + }else if (object_dynamic_cast (OBJECT (iommu),TYPE_VIRTIO_IOMMU_PCI )) { +PCIDevice *pdev =PCI_DEVICE (iommu); + +acpi_add_table (table_offsets, tables_blob); +build_viot (machine, tables_blob, tables->linker,pci_get_bdf (pdev), + x86ms->oem_id, x86ms->oem_table_id); }if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker,
hw/i386/pc.c +15 -1
@@ -83,6 +83,7 @@#include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" #include "standard-headers/asm-x86/bootparam.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/virtio/virtio-pmem-pci.h" #include "hw/virtio/virtio-mem-pci.h" #include "hw/mem/memory-device.h"
@@ -1330,7 +1331,19 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) {pc_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); - }else if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) { + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +/* Declare the APIC range as the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +VIRTIO_IOMMU_RESV_MEM_T_MSI ); + +object_property_set_uint (OBJECT (dev),"len-reserved-regions" ,1 , errp); +object_property_set_str (OBJECT (dev),"reserved-regions[0]" , + resv_prop_str, errp); +g_free (resv_prop_str); + } + +if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE ) || +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {PCMachineState *pcms =PC_MACHINE (hotplug_dev);if (pcms->iommu) {
@@ -1394,6 +1407,7 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, object_dynamic_cast(OBJECT(dev), TYPE_CPU) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {return HOTPLUG_HANDLER (machine); }
hw/i386/Kconfig +1 -0
@@ -59,6 +59,7 @@ config PC_ACPI select ACPI_X86 select ACPI_CPU_HOTPLUG select ACPI_MEMORY_HOTPLUG + select ACPI_VIOT select SMBUS_EEPROM select PFLASH_CFI01 depends on ACPI_SMBUS
Signature · 1 line
2.33.0
Re: [PATCH v5 04/12] hw/i386/pc: Allow instantiating a virtio-iommu device
Quoted 8 lines · On Wed, 20 Oct 2021 18:27:38 +0100 Jean-Philippe Brucker…
Allow instantiating a virtio-iommu device by adding an ACPI Virtual I/O Translation table (VIOT), which describes the relation between the virtio-iommu and the endpoints it manages.
Add a hotplug handler for virtio-iommu on x86 and set the necessary reserved region property. On x86, the [
0xfee00000,0xfeefffff] DMA region is reserved for MSIs. DMA transactions to this range either trigger IRQ remapping in the IOMMU or bypasses IOMMU translation.
shouldn't above be "IO remapping"?
Quoted 7 lines
Although virtio-iommu does not support IRQ remapping it must be informed of the reserved region so that it can forward DMA transactions targeting this region.
Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 97 lines
--- hw/i386/acpi-build.c | 10 +++++++++- hw/i386/pc.c | 16 +++++++++++++++- hw/i386/Kconfig | 1 + 3 files changed, 25 insertions(+), 2 deletions(-)hw/i386/acpi-build.c +9
-1@@ -68,9 +68,11 @@#include "qom/qom-qobject.h" #include "hw/i386/amd_iommu.h" #include "hw/i386/intel_iommu.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/acpi/ipmi.h" #include "hw/acpi/hmat.h" +#include "hw/acpi/viot.h" /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows @@ -2488,7 +2490,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -X86IOMMUState *iommu =x86_iommu_get_default (); +DeviceState *iommu = pcms->iommu;GArray *table_offsets;unsigned facs, dsdt, rsdt, fadt;AcpiPmInfo pm;@@ -2613,6 +2615,12 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id); + }else if (object_dynamic_cast (OBJECT (iommu),TYPE_VIRTIO_IOMMU_PCI )) { +PCIDevice *pdev =PCI_DEVICE (iommu); + +acpi_add_table (table_offsets, tables_blob); +build_viot (machine, tables_blob, tables->linker,pci_get_bdf (pdev), + x86ms->oem_id, x86ms->oem_table_id); }if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker,hw/i386/pc.c +15
-1@@ -83,6 +83,7 @@#include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" #include "standard-headers/asm-x86/bootparam.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/virtio/virtio-pmem-pci.h" #include "hw/virtio/virtio-mem-pci.h" #include "hw/mem/memory-device.h" @@ -1330,7 +1331,19 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_PMEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) {pc_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); - }else if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE )) { + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +/* Declare the APIC range as the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +VIRTIO_IOMMU_RESV_MEM_T_MSI ); + +object_property_set_uint (OBJECT (dev),"len-reserved-regions" ,1 , errp); +object_property_set_str (OBJECT (dev),"reserved-regions[0]" , + resv_prop_str, errp); +g_free (resv_prop_str); + } + +if (object_dynamic_cast (OBJECT (dev),TYPE_X86_IOMMU_DEVICE ) || +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {PCMachineState *pcms =PC_MACHINE (hotplug_dev);if (pcms->iommu) {@@ -1394,6 +1407,7 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, object_dynamic_cast(OBJECT(dev), TYPE_CPU) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {return HOTPLUG_HANDLER (machine); }hw/i386/Kconfig +1
-0@@ -59,6 +59,7 @@ config PC_ACPI select ACPI_X86 select ACPI_CPU_HOTPLUG select ACPI_MEMORY_HOTPLUG + select ACPI_VIOT select SMBUS_EEPROM select PFLASH_CFI01 depends on ACPI_SMBUS
Re: [PATCH v5 04/12] hw/i386/pc: Allow instantiating a virtio-iommu device
Quoted 7 lines · Igor Mammedov
Quoted 4 lines · On Wed, 20 Oct 2021 18:27:38 +0100 Jean-Philippe Brucker…
Allow instantiating a virtio-iommu device by adding an ACPI Virtual I/O Translation table (VIOT), which describes the relation between the virtio-iommu and the endpoints it manages.
Quoted 6 lines
Quoted 4 lines
Add a hotplug handler for virtio-iommu on x86 and set the necessary reserved region property. On x86, the [
0xfee00000,0xfeefffff] DMA region is reserved for MSIs. DMA transactions to this range either trigger IRQ remapping in the IOMMU or bypasses IOMMU translation.shouldn't above be "IO remapping"?
No it is IRQ remapping: DMA writes to this address range are interrupt requests and the IOMMU may either perform interrupt remapping or pass it to the APIC directly
Quoted 10 lines
Quoted 8 lines
Although virtio-iommu does not support IRQ remapping it must be informed of the reserved region so that it can forward DMA transactions targeting this region.
Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>Reviewed-by Igor Mammedov <[email protected]>
Thanks!
Jean
PATCH v5 5/12 hw/arm/virt-acpi-build: Add VIOT table for virtio-iommu
In reply to Jean-Philippe BruckerWhen a virtio-iommu is instantiated, describe it using the ACPI VIOT table.
--- hw/arm/virt-acpi-build.c | 7 +++++++ hw/arm/Kconfig | 1 + 2 files changed, 8 insertions(+)
hw/arm/virt-acpi-build.c +7 -0
@@ -55,6 +55,7 @@#include "kvm_arm.h" #include "migration/vmstate.h" #include "hw/acpi/ghes.h" +#include "hw/acpi/viot.h" #define ARM_SPI_BASE 32
@@ -934,6 +935,12 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) }#endif +if (vms->iommu ==VIRT_IOMMU_VIRTIO ) { +acpi_add_table (table_offsets, tables_blob); +build_viot (ms, tables_blob, tables->linker, vms->virtio_iommu_bdf, + vms->oem_id, vms->oem_table_id); + } +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, vms->oem_id,
hw/arm/Kconfig +1 -0
@@ -27,6 +27,7 @@ config ARM_VIRT select DIMM select ACPI_HW_REDUCED select ACPI_APEI + select ACPI_VIOT config CHEETAH bool
Signature · 1 line
2.33.0
Re: [PATCH v5 05/12] hw/arm/virt-acpi-build: Add VIOT table for virtio-iommu
Quoted 5 lines · On Wed, 20 Oct 2021 18:27:39 +0100 Jean-Philippe Brucker…
When a virtio-iommu is instantiated, describe it using the ACPI VIOT table.
Reviewed-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 42 lines
--- hw/arm/virt-acpi-build.c | 7 +++++++ hw/arm/Kconfig | 1 + 2 files changed, 8 insertions(+)hw/arm/virt-acpi-build.c +7
-0@@ -55,6 +55,7 @@#include "kvm_arm.h" #include "migration/vmstate.h" #include "hw/acpi/ghes.h" +#include "hw/acpi/viot.h" #define ARM_SPI_BASE 32@@ -934,6 +935,12 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) }#endif +if (vms->iommu ==VIRT_IOMMU_VIRTIO ) { +acpi_add_table (table_offsets, tables_blob); +build_viot (ms, tables_blob, tables->linker, vms->virtio_iommu_bdf, + vms->oem_id, vms->oem_table_id); + } +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, vms->oem_id,hw/arm/Kconfig +1
-0@@ -27,6 +27,7 @@ config ARM_VIRT select DIMM select ACPI_HW_REDUCED select ACPI_APEI + select ACPI_VIOT config CHEETAH bool
PATCH v5 6/12 hw/arm/virt: Remove device tree restriction for virtio-iommu
In reply to Jean-Philippe Bruckervirtio-iommu is now supported with ACPI VIOT as well as device tree. Remove the restriction that prevents from instantiating a virtio-iommu device under ACPI.
--- hw/arm/virt.c | 10 ++-------- hw/virtio/virtio-iommu-pci.c | 12 ++---------- 2 files changed, 4 insertions(+), 18 deletions(-)
hw/arm/virt.c +2 -8
@@ -2561,16 +2561,10 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,MachineClass *mc =MACHINE_GET_CLASS (machine);if (device_is_dynamic_sysbus (mc, dev) || - (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ))) { +object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); } -if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { -VirtMachineState *vms =VIRT_MACHINE (machine); - -if (!vms->bootinfo.firmware_loaded || !virt_is_acpi_enabled (vms)) { -return HOTPLUG_HANDLER (machine); - } - }return NULL ; }
hw/virtio/virtio-iommu-pci.c +2 -10
@@ -48,16 +48,8 @@ static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOIOMMU *s =VIRTIO_IOMMU (vdev);if (!qdev_get_machine_hotplug_handler (DEVICE (vpci_dev))) { -MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); - -error_setg (errp, -"%s machine fails to create iommu-map device tree bindings" , - mc->name); -error_append_hint (errp, -"Check your machine implements a hotplug handler " -"for the virtio-iommu-pci device\n" ); -error_append_hint (errp,"Check the guest is booted without FW or with " -"-no-acpi\n" ); +error_setg (errp,"Check your machine implements a hotplug handler " +"for the virtio-iommu-pci device" );return ; }for (int i =0 ; i < s->nb_reserved_regions; i++) {
Signature · 1 line
2.33.0
Re: [PATCH v5 06/12] hw/arm/virt: Remove device tree restriction for virtio-iommu
Quoted 6 lines · On Wed, 20 Oct 2021 18:27:40 +0100 Jean-Philippe Brucker…
virtio-iommu is now supported with ACPI VIOT as well as device tree. Remove the restriction that prevents from instantiating a virtio-iommu device under ACPI.
Reviewed-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 51 lines
--- hw/arm/virt.c | 10 ++-------- hw/virtio/virtio-iommu-pci.c | 12 ++---------- 2 files changed, 4 insertions(+), 18 deletions(-)hw/arm/virt.c +2
-8@@ -2561,16 +2561,10 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,MachineClass *mc =MACHINE_GET_CLASS (machine);if (device_is_dynamic_sysbus (mc, dev) || - (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ))) { +object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); } -if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { -VirtMachineState *vms =VIRT_MACHINE (machine); - -if (!vms->bootinfo.firmware_loaded || !virt_is_acpi_enabled (vms)) { -return HOTPLUG_HANDLER (machine); - } - }return NULL ; }hw/virtio/virtio-iommu-pci.c +2
-10@@ -48,16 +48,8 @@ static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOIOMMU *s =VIRTIO_IOMMU (vdev);if (!qdev_get_machine_hotplug_handler (DEVICE (vpci_dev))) { -MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); - -error_setg (errp, -"%s machine fails to create iommu-map device tree bindings" , - mc->name); -error_append_hint (errp, -"Check your machine implements a hotplug handler " -"for the virtio-iommu-pci device\n" ); -error_append_hint (errp,"Check the guest is booted without FW or with " -"-no-acpi\n" ); +error_setg (errp,"Check your machine implements a hotplug handler " +"for the virtio-iommu-pci device" );return ; }for (int i =0 ; i < s->nb_reserved_regions; i++) {
PATCH v5 7/12 hw/arm/virt: Reject instantiation of multiple IOMMUs
In reply to Jean-Philippe BruckerWe do not support instantiating multiple IOMMUs. Before adding a virtio-iommu, check that no other IOMMU is present. This will detect both "iommu=smmuv3" machine parameter and another virtio-iommu instance.
--- hw/arm/virt.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/arm/virt.c +5 -0
@@ -2441,6 +2441,11 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,hwaddr db_start =0 , db_end =0 ;char *resv_prop_str; +if (vms->iommu !=VIRT_IOMMU_NONE ) { +error_setg (errp,"virt machine does not support multiple IOMMUs" ); +return ; + } +switch (vms->msi_controller) {case VIRT_MSI_CTRL_NONE :return ;
Signature · 1 line
2.33.0
Re: [PATCH v5 07/12] hw/arm/virt: Reject instantiation of multiple IOMMUs
Quoted 8 lines · On Wed, 20 Oct 2021 18:27:41 +0100 Jean-Philippe Brucker…
We do not support instantiating multiple IOMMUs. Before adding a virtio-iommu, check that no other IOMMU is present. This will detect both "iommu=smmuv3" machine parameter and another virtio-iommu instance.
Fixes 70e89132c9 ("hw/arm/virt: Add the virtio-iommu device tree mappings")Reviewed-by Eric Auger <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>
Quoted 20 lines
--- hw/arm/virt.c | 5 +++++ 1 file changed, 5 insertions(+)hw/arm/virt.c +5
-0@@ -2441,6 +2441,11 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,hwaddr db_start =0 , db_end =0 ;char *resv_prop_str; +if (vms->iommu !=VIRT_IOMMU_NONE ) { +error_setg (errp,"virt machine does not support multiple IOMMUs" ); +return ; + } +switch (vms->msi_controller) {case VIRT_MSI_CTRL_NONE :return ;
PATCH v5 8/12 hw/arm/virt: Use object_property_set instead of qdev_prop_set
In reply to Jean-Philippe BruckerTo propagate errors to the caller of the pre_plug callback, use the object_poperty_set*() functions directly instead of the qdev_prop_set*() helpers.
--- hw/arm/virt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/arm/virt.c +3 -2
@@ -2465,8 +2465,9 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, db_start, db_end, VIRTIO_IOMMU_RESV_MEM_T_MSI); -qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); -qdev_prop_set_string (dev,"reserved-regions[0]" , resv_prop_str); +object_property_set_uint (OBJECT (dev),"len-reserved-regions" ,1 , errp); +object_property_set_str (OBJECT (dev),"reserved-regions[0]" , + resv_prop_str, errp);g_free (resv_prop_str); } }
Signature · 1 line
2.33.0
PATCH v5 9/12 tests/acpi: allow updates of VIOT expected data files
In reply to Jean-Philippe BruckerCreate empty data files and allow updates for the upcoming VIOT tests.
--- tests/qtest/bios-tables-test-allowed-diff.h | 3 +++ tests/data/acpi/q35/DSDT.viot | 0 tests/data/acpi/q35/VIOT.viot | 0 tests/data/acpi/virt/VIOT | 0 4 files changed, 3 insertions(+) create mode 100644 tests/data/acpi/q35/DSDT.viot create mode 100644 tests/data/acpi/q35/VIOT.viot create mode 100644 tests/data/acpi/virt/VIOT
tests/qtest/bios-tables-test-allowed-diff.h +3 -0
@@ -1 +1,4 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/virt/VIOT" , +"tests/data/acpi/q35/DSDT.viot" , +"tests/data/acpi/q35/VIOT.viot",
tests/data/acpi/q35/DSDT.viot new file +0 -0
tests/data/acpi/q35/VIOT.viot new file +0 -0
tests/data/acpi/virt/VIOT new file +0 -0
Signature · 1 line
2.33.0
Re: [PATCH v5 09/12] tests/acpi: allow updates of VIOT expected data files
Quoted 3 lines · Jean-Philippe Brucker
Create empty data files and allow updates for the upcoming VIOT tests.
Signed-off-by Jean-Philippe Brucker <[email protected]>
Eric
Quoted 28 lines
--- tests/qtest/bios-tables-test-allowed-diff.h | 3 +++ tests/data/acpi/q35/DSDT.viot | 0 tests/data/acpi/q35/VIOT.viot | 0 tests/data/acpi/virt/VIOT | 0 4 files changed, 3 insertions(+) create mode 100644 tests/data/acpi/q35/DSDT.viot create mode 100644 tests/data/acpi/q35/VIOT.viot create mode 100644 tests/data/acpi/virt/VIOTtests/qtest/bios-tables-test-allowed-diff.h +3
-0@@ -1 +1,4 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/virt/VIOT" , +"tests/data/acpi/q35/DSDT.viot" , +"tests/data/acpi/q35/VIOT.viot",tests/data/acpi/q35/DSDT.viot new file +0
-0tests/data/acpi/q35/VIOT.viot new file +0
-0tests/data/acpi/virt/VIOT new file +0
-0
Re: [PATCH v5 09/12] tests/acpi: allow updates of VIOT expected data files
In reply to Jean-Philippe Bruckertests/data/acpi/virt/VIOT
Quoted 31 lines · On Wed, 20 Oct 2021 18:27:43 +0100 Jean-Philippe Brucker…
Create empty data files and allow updates for the upcoming VIOT tests.
Signed-off-by Jean-Philippe Brucker <[email protected]>--- tests/qtest/bios-tables-test-allowed-diff.h | 3 +++ tests/data/acpi/q35/DSDT.viot | 0 tests/data/acpi/q35/VIOT.viot | 0 tests/data/acpi/virt/VIOT | 0 4 files changed, 3 insertions(+) create mode 100644 tests/data/acpi/q35/DSDT.viot create mode 100644 tests/data/acpi/q35/VIOT.viot create mode 100644 tests/data/acpi/virt/VIOTtests/qtest/bios-tables-test-allowed-diff.h +3
-0@@ -1 +1,4 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/virt/VIOT" , +"tests/data/acpi/q35/DSDT.viot" , +"tests/data/acpi/q35/VIOT.viot",tests/data/acpi/q35/DSDT.viot new file +0
-0tests/data/acpi/q35/VIOT.viot new file +0
-0tests/data/acpi/virt/VIOT new file +0
-0
PATCH v5 10/12 tests/acpi: add test cases for VIOT
In reply to Jean-Philippe BruckerAdd two test cases for VIOT, one on the q35 machine and the other on virt. To test complex topologies the q35 test has two PCIe buses that bypass the IOMMU (and are therefore not described by VIOT), and two buses that are translated by virtio-iommu.
--- tests/qtest/bios-tables-test.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tests/qtest/bios-tables-test.c +38 -0
@@ -1403,6 +1403,42 @@ static void test_acpi_virt_tcg(void)free_test_data (&data); } +static void test_acpi_q35_viot (void ) +{ +test_data data = { + .machine =MACHINE_Q35 , + .variant =".viot" , + }; + +/* +* To keep things interesting, two buses bypass the IOMMU. +* VIOT should only describes the other two buses. +*/ +test_acpi_one ("-machine default_bus_bypass_iommu=on " +"-device virtio-iommu-pci " +"-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 " +"-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on " +"-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0" , + &data); +free_test_data (&data); +} + +static void test_acpi_virt_viot (void ) +{ +test_data data = { + .machine ="virt" , + .uefi_fl1 ="pc-bios/edk2-aarch64-code.fd" , + .uefi_fl2 ="pc-bios/edk2-arm-vars.fd" , + .cd ="tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2" , + .ram_start =0x40000000ULL , + .scan_len =128ULL *1024 *1024 , + }; + +test_acpi_one ("-cpu cortex-a57 " +"-device virtio-iommu-pci" , &data); +free_test_data (&data); +} +static void test_oem_fields (test_data *data) {int i;
@@ -1567,12 +1603,14 @@ int main(int argc, char *argv[])if (strcmp (arch,"x86_64" ) ==0 ) {qtest_add_func ("acpi/microvm/pcie" , test_acpi_microvm_pcie_tcg); } +qtest_add_func ("acpi/q35/viot" , test_acpi_q35_viot); }else if (strcmp (arch,"aarch64" ) ==0 ) {qtest_add_func ("acpi/virt" , test_acpi_virt_tcg);qtest_add_func ("acpi/virt/numamem" , test_acpi_virt_tcg_numamem);qtest_add_func ("acpi/virt/memhp" , test_acpi_virt_tcg_memhp);qtest_add_func ("acpi/virt/pxb" , test_acpi_virt_tcg_pxb);qtest_add_func ("acpi/virt/oem-fields" , test_acpi_oem_fields_virt); +qtest_add_func ("acpi/virt/viot" , test_acpi_virt_viot); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
2.33.0
Re: [PATCH v5 10/12] tests/acpi: add test cases for VIOT
Hi Jean,
Quoted 22 lines · Jean-Philippe Brucker
Add two test cases for VIOT, one on the q35 machine and the other on virt. To test complex topologies the q35 test has two PCIe buses that bypass the IOMMU (and are therefore not described by VIOT), and two buses that are translated by virtio-iommu.
Reviewed-by Eric Auger <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- tests/qtest/bios-tables-test.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)tests/qtest/bios-tables-test.c +2
-0@@ -1403,6 +1403,42 @@ static void test_acpi_virt_tcg(void)free_test_data (&data); } +static void test_acpi_q35_viot (void ) +{
tests/qtest/bios-tables-test.c static void test_acpi_virt_tcg(void) · line 1417
Quoted 10 lines
tests/qtest/bios-tables-test.c +10
-0+test_data data = { + .machine =MACHINE_Q35 , + .variant =".viot" , + }; + +/* +* To keep things interesting, two buses bypass the IOMMU. +* VIOT should only describes the other two buses. +*/ + test_acpi_one("-machine default_bus_bypass_iommu=on "
Just a reminder that we still have a dependency on the default_bus_bypass_iommu fix here. Otherwise those tests will fail. So the fix needs to be upstreamed along with that series.
Eric
Quoted 42 lines
tests/qtest/bios-tables-test.c +26
-0+"-device virtio-iommu-pci " +"-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 " +"-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on " +"-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0" , + &data); +free_test_data (&data); +} + +static void test_acpi_virt_viot (void ) +{ +test_data data = { + .machine ="virt" , + .uefi_fl1 ="pc-bios/edk2-aarch64-code.fd" , + .uefi_fl2 ="pc-bios/edk2-arm-vars.fd" , + .cd ="tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2" , + .ram_start =0x40000000ULL , + .scan_len =128ULL *1024 *1024 , + }; + +test_acpi_one ("-cpu cortex-a57 " +"-device virtio-iommu-pci" , &data); +free_test_data (&data); +} +static void test_oem_fields (test_data *data) {int i;@@ -1567,12 +1603,14 @@ int main(int argc, char *argv[])if (strcmp (arch,"x86_64" ) ==0 ) {qtest_add_func ("acpi/microvm/pcie" , test_acpi_microvm_pcie_tcg); } +qtest_add_func ("acpi/q35/viot" , test_acpi_q35_viot); }else if (strcmp (arch,"aarch64" ) ==0 ) {qtest_add_func ("acpi/virt" , test_acpi_virt_tcg);qtest_add_func ("acpi/virt/numamem" , test_acpi_virt_tcg_numamem);qtest_add_func ("acpi/virt/memhp" , test_acpi_virt_tcg_memhp);qtest_add_func ("acpi/virt/pxb" , test_acpi_virt_tcg_pxb);qtest_add_func ("acpi/virt/oem-fields" , test_acpi_oem_fields_virt); +qtest_add_func ("acpi/virt/viot" , test_acpi_virt_viot); } ret =g_test_run ();boot_sector_cleanup (disk);
Re: [PATCH v5 10/12] tests/acpi: add test cases for VIOT
Quoted 23 lines · Eric Auger
Hi Jean,
Quoted 20 lines · Jean-Philippe Brucker
Add two test cases for VIOT, one on the q35 machine and the other on virt. To test complex topologies the q35 test has two PCIe buses that bypass the IOMMU (and are therefore not described by VIOT), and two buses that are translated by virtio-iommu.
Reviewed-by Eric Auger <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- tests/qtest/bios-tables-test.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)tests/qtest/bios-tables-test.c +0
-0@@ -1403,6 +1403,42 @@ static void test_acpi_virt_tcg(void)free_test_data (&data); }
Quoted 15 lines
tests/qtest/bios-tables-test.c static void test_acpi_virt_tcg(void) · line 1417
Quoted 12 lines
tests/qtest/bios-tables-test.c +12
-0+static void test_acpi_q35_viot (void ) +{ +test_data data = { + .machine =MACHINE_Q35 , + .variant =".viot" , + }; + +/* +* To keep things interesting, two buses bypass the IOMMU. +* VIOT should only describes the other two buses. +*/ + test_acpi_one("-machine default_bus_bypass_iommu=on "Just a reminder that we still have a dependency on the
default_bus_bypass_iommufix here. Otherwise those tests will fail. So the fix needs to be upstreamed along with that series.
Thanks for the reminder, the fix is now queued (for x86, which this patch relies on) so should be good to go. I'm planning to fix the conflict you reported and resend only the x86 parts, so they get be merged this cycle
Thanks,
Jean
Re: [PATCH v5 10/12] tests/acpi: add test cases for VIOT
In reply to Jean-Philippe BruckerHi Jean,
Quoted 8 lines · Jean-Philippe Brucker
Add two test cases for VIOT, one on the q35 machine and the other on virt. To test complex topologies the q35 test has two PCIe buses that bypass the IOMMU (and are therefore not described by VIOT), and two buses that are translated by virtio-iommu.
Reviewed-by Eric Auger <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>
small conflict to be resolved since
220ffd949b ("tests: bios-tables-test: use qtest_has_accel() API to register TCG only tests")
Eric
Quoted 66 lines
--- tests/qtest/bios-tables-test.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)tests/qtest/bios-tables-test.c +38
-0@@ -1403,6 +1403,42 @@ static void test_acpi_virt_tcg(void)free_test_data (&data); } +static void test_acpi_q35_viot (void ) +{ +test_data data = { + .machine =MACHINE_Q35 , + .variant =".viot" , + }; + +/* +* To keep things interesting, two buses bypass the IOMMU. +* VIOT should only describes the other two buses. +*/ +test_acpi_one ("-machine default_bus_bypass_iommu=on " +"-device virtio-iommu-pci " +"-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 " +"-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on " +"-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0" , + &data); +free_test_data (&data); +} + +static void test_acpi_virt_viot (void ) +{ +test_data data = { + .machine ="virt" , + .uefi_fl1 ="pc-bios/edk2-aarch64-code.fd" , + .uefi_fl2 ="pc-bios/edk2-arm-vars.fd" , + .cd ="tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2" , + .ram_start =0x40000000ULL , + .scan_len =128ULL *1024 *1024 , + }; + +test_acpi_one ("-cpu cortex-a57 " +"-device virtio-iommu-pci" , &data); +free_test_data (&data); +} +static void test_oem_fields (test_data *data) {int i;@@ -1567,12 +1603,14 @@ int main(int argc, char *argv[])if (strcmp (arch,"x86_64" ) ==0 ) {qtest_add_func ("acpi/microvm/pcie" , test_acpi_microvm_pcie_tcg); } +qtest_add_func ("acpi/q35/viot" , test_acpi_q35_viot); }else if (strcmp (arch,"aarch64" ) ==0 ) {qtest_add_func ("acpi/virt" , test_acpi_virt_tcg);qtest_add_func ("acpi/virt/numamem" , test_acpi_virt_tcg_numamem);qtest_add_func ("acpi/virt/memhp" , test_acpi_virt_tcg_memhp);qtest_add_func ("acpi/virt/pxb" , test_acpi_virt_tcg_pxb);qtest_add_func ("acpi/virt/oem-fields" , test_acpi_oem_fields_virt); +qtest_add_func ("acpi/virt/viot" , test_acpi_virt_viot); } ret =g_test_run ();boot_sector_cleanup (disk);
PATCH v5 11/12 tests/acpi: add expected blob for VIOT test on virt machine
In reply to Jean-Philippe BruckerThe VIOT blob contains the following:
[000h 0000 4] Signature : "VIOT" [Virtual I/O Translation Table] [004h 0004 4] Table Length : 00000058 [008h 0008 1] Revision : 00 [009h 0009 1] Checksum : 66 [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPC " [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 2] Node count : 0002 [026h 0038 2] Node offset : 0030 [028h 0040 8] Reserved : 0000000000000000
[030h 0048 1] Type : 03 [VirtIO-PCI IOMMU] [031h 0049 1] Reserved : 00 [032h 0050 2] Length : 0010
[034h 0052 2] PCI Segment : 0000 [036h 0054 2] PCI BDF number : 0008 [038h 0056 8] Reserved : 0000000000000000
[040h 0064 1] Type : 01 [PCI Range] [041h 0065 1] Reserved : 00 [042h 0066 2] Length : 0018
[044h 0068 4] Endpoint start : 00000000 [048h 0072 2] PCI Segment start : 0000 [04Ah 0074 2] PCI Segment end : 0000 [04Ch 0076 2] PCI BDF start : 0000 [04Eh 0078 2] PCI BDF end : 00FF [050h 0080 2] Output node : 0030 [052h 0082 6] Reserved : 000000000000
--- tests/qtest/bios-tables-test-allowed-diff.h | 1 - tests/data/acpi/virt/VIOT | Bin 0 -> 88 bytes 2 files changed, 1 deletion(-)
tests/qtest/bios-tables-test-allowed-diff.h +0 -1
@@ -1,4 +1,3 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/virt/VIOT" ,"tests/data/acpi/q35/DSDT.viot" , "tests/data/acpi/q35/VIOT.viot",
tests/data/acpi/virt/VIOT binary +0 -0
Signature · 1 line
2.33.0
PATCH v5 12/12 tests/acpi: add expected blobs for VIOT test on q35 machine
In reply to Jean-Philippe BruckerAdd expected blobs of the VIOT and DSDT table for the VIOT test on the q35 machine.
Since the test instantiates a virtio device and two PCIe expander bridges, DSDT.viot has more blocks than the base DSDT.
The VIOT table generated for the q35 test is:
[000h 0000 4] Signature : "VIOT" [Virtual I/O Translation Table] [004h 0004 4] Table Length : 00000070 [008h 0008 1] Revision : 00 [009h 0009 1] Checksum : 3D [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPC " [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 2] Node count : 0003 [026h 0038 2] Node offset : 0030 [028h 0040 8] Reserved : 0000000000000000
[030h 0048 1] Type : 03 [VirtIO-PCI IOMMU] [031h 0049 1] Reserved : 00 [032h 0050 2] Length : 0010
[034h 0052 2] PCI Segment : 0000 [036h 0054 2] PCI BDF number : 0010 [038h 0056 8] Reserved : 0000000000000000
[040h 0064 1] Type : 01 [PCI Range] [041h 0065 1] Reserved : 00 [042h 0066 2] Length : 0018
[044h 0068 4] Endpoint start : 00003000 [048h 0072 2] PCI Segment start : 0000 [04Ah 0074 2] PCI Segment end : 0000 [04Ch 0076 2] PCI BDF start : 3000 [04Eh 0078 2] PCI BDF end : 30FF [050h 0080 2] Output node : 0030 [052h 0082 6] Reserved : 000000000000
[058h 0088 1] Type : 01 [PCI Range] [059h 0089 1] Reserved : 00 [05Ah 0090 2] Length : 0018
[05Ch 0092 4] Endpoint start : 00001000 [060h 0096 2] PCI Segment start : 0000 [062h 0098 2] PCI Segment end : 0000 [064h 0100 2] PCI BDF start : 1000 [066h 0102 2] PCI BDF end : 10FF [068h 0104 2] Output node : 0030 [06Ah 0106 6] Reserved : 000000000000
And the DSDT diff is:
@@ -5,13 +5,13 @@
*
* Disassembling to symbolic ASL+ operators
*
- * Disassembly of tests/data/acpi/q35/DSDT, Wed Oct 20 16:33:00 2021
+ * Disassembly of /tmp/aml-4TWUB1, Wed Oct 20 16:16:49 2021 *
* Original Table Header:
* Signature "DSDT"
- * Length 0x00002061 (8289)
+ * Length 0x000024B6 (9398)
* Revision 0x01 **** 32-bit table (V1), no 64-bit math support
- * Checksum 0xF9
+ * Checksum 0xA6
* OEM ID "BOCHS "
* OEM Table ID "BXPC "
* OEM Revision 0x00000001 (1)
@@ -3114,6 +3114,339 @@
}
}+ Scope (\_SB)
+ {
+ Device (PC30)
+ {
+ Name (_UID, 0x30) // _UID: Unique ID
+ Name (_BBN, 0x30) // _BBN: BIOS Bus Number
+ Name (_HID, EisaId ("PNP0A08") /* PCI Express Bus */) // _HID: Hardware ID
+ Name (_CID, EisaId ("PNP0A03") /* PCI Bus */) // _CID: Compatible ID
+ Method (_OSC, 4, NotSerialized) // _OSC: Operating System Capabilities
+ {
+ CreateDWordField (Arg3, Zero, CDW1)
+ If ((Arg0 == ToUUID ("33db4d5b-1ff7-401c-9657-7441c03dd766") /* PCI Host Bridge Device */))
+ {
+ CreateDWordField (Arg3, 0x04, CDW2)
+ CreateDWordField (Arg3, 0x08, CDW3)
+ Local0 = CDW3 /* \_SB_.PC30._OSC.CDW3 */
+ Local0 &= 0x1F
+ If ((Arg1 != One))
+ {+ CDW1 |= 0x08
+ }
+
+ If ((CDW3 != Local0))
+ {
+ CDW1 |= 0x10
+ }
+
+ CDW3 = Local0
+ }
+ Else
+ {+ CDW1 |= 0x04
+ }
+
+ Return (Arg3)
+ }
+
+ Method (_PRT, 0, NotSerialized) // _PRT: PCI Routing Table
+ {
+ Local0 = Package (0x80){}
+ Local1 = Zero
+ While ((Local1 < 0x80))
+ {
+ Local2 = (Local1 >> 0x02)
+ Local3 = ((Local1 + Local2) & 0x03)
+ If ((Local3 == Zero))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero,
+ Zero,
+ LNKD,
+ Zero+ }
+ }
+
+ If ((Local3 == One))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKA, + Zero
+ }
+ }
+
+ If ((Local3 == 0x02))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKB, + Zero
+ }
+ }
+
+ If ((Local3 == 0x03))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKC, + Zero + } + } + + Local4 [Zero] = ((Local2 << 0x10) | 0xFFFF) + Local4 [One] = (Local1 & 0x03) + Local0 [Local1] = Local4 + Local1++
+ }
+
+ Return (Local0)
+ }
+
+ Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
+ {
+ WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
+ 0x0000, // Granularity + 0x0030, // Range Minimum + 0x0030, // Range Maximum + 0x0000, // Translation Offset + 0x0001, // Length + ,, )
+ })
+ }
+ }
+
+ Scope (\_SB)
+ {
+ Device (PC20)
+ {
+ Name (_UID, 0x20) // _UID: Unique ID
+ Name (_BBN, 0x20) // _BBN: BIOS Bus Number
+ Name (_HID, EisaId ("PNP0A08") /* PCI Express Bus */) // _HID: Hardware ID
+ Name (_CID, EisaId ("PNP0A03") /* PCI Bus */) // _CID: Compatible ID
+ Method (_OSC, 4, NotSerialized) // _OSC: Operating System Capabilities
+ {
+ CreateDWordField (Arg3, Zero, CDW1)
+ If ((Arg0 == ToUUID ("33db4d5b-1ff7-401c-9657-7441c03dd766") /* PCI Host Bridge Device */))
+ {
+ CreateDWordField (Arg3, 0x04, CDW2)
+ CreateDWordField (Arg3, 0x08, CDW3)
+ Local0 = CDW3 /* \_SB_.PC20._OSC.CDW3 */
+ Local0 &= 0x1F
+ If ((Arg1 != One))
+ {+ CDW1 |= 0x08
+ }
+
+ If ((CDW3 != Local0))
+ {
+ CDW1 |= 0x10
+ }
+
+ CDW3 = Local0
+ }
+ Else
+ {+ CDW1 |= 0x04
+ }
+
+ Return (Arg3)
+ }
+
+ Method (_PRT, 0, NotSerialized) // _PRT: PCI Routing Table
+ {
+ Local0 = Package (0x80){}
+ Local1 = Zero
+ While ((Local1 < 0x80))
+ {
+ Local2 = (Local1 >> 0x02)
+ Local3 = ((Local1 + Local2) & 0x03)
+ If ((Local3 == Zero))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero,
+ Zero,
+ LNKD,
+ Zero+ }
+ }
+
+ If ((Local3 == One))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKA, + Zero
+ }
+ }
+
+ If ((Local3 == 0x02))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKB, + Zero
+ }
+ }
+
+ If ((Local3 == 0x03))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKC, + Zero + } + } + + Local4 [Zero] = ((Local2 << 0x10) | 0xFFFF) + Local4 [One] = (Local1 & 0x03) + Local0 [Local1] = Local4 + Local1++
+ }
+
+ Return (Local0)
+ }
+
+ Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
+ {
+ WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
+ 0x0000, // Granularity + 0x0020, // Range Minimum + 0x0020, // Range Maximum + 0x0000, // Translation Offset + 0x0001, // Length + ,, )
+ })
+ }
+ }
+
+ Scope (\_SB)
+ {
+ Device (PC10)
+ {
+ Name (_UID, 0x10) // _UID: Unique ID
+ Name (_BBN, 0x10) // _BBN: BIOS Bus Number
+ Name (_HID, EisaId ("PNP0A08") /* PCI Express Bus */) // _HID: Hardware ID
+ Name (_CID, EisaId ("PNP0A03") /* PCI Bus */) // _CID: Compatible ID
+ Method (_OSC, 4, NotSerialized) // _OSC: Operating System Capabilities
+ {
+ CreateDWordField (Arg3, Zero, CDW1)
+ If ((Arg0 == ToUUID ("33db4d5b-1ff7-401c-9657-7441c03dd766") /* PCI Host Bridge Device */))
+ {
+ CreateDWordField (Arg3, 0x04, CDW2)
+ CreateDWordField (Arg3, 0x08, CDW3)
+ Local0 = CDW3 /* \_SB_.PC10._OSC.CDW3 */
+ Local0 &= 0x1F
+ If ((Arg1 != One))
+ {+ CDW1 |= 0x08
+ }
+
+ If ((CDW3 != Local0))
+ {
+ CDW1 |= 0x10
+ }
+
+ CDW3 = Local0
+ }
+ Else
+ {+ CDW1 |= 0x04
+ }
+
+ Return (Arg3)
+ }
+
+ Method (_PRT, 0, NotSerialized) // _PRT: PCI Routing Table
+ {
+ Local0 = Package (0x80){}
+ Local1 = Zero
+ While ((Local1 < 0x80))
+ {
+ Local2 = (Local1 >> 0x02)
+ Local3 = ((Local1 + Local2) & 0x03)
+ If ((Local3 == Zero))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero,
+ Zero,
+ LNKD,
+ Zero+ }
+ }
+
+ If ((Local3 == One))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKA, + Zero
+ }
+ }
+
+ If ((Local3 == 0x02))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKB, + Zero
+ }
+ }
+
+ If ((Local3 == 0x03))
+ {
+ Local4 = Package (0x04)
+ {
+ Zero, + Zero, + LNKC, + Zero + } + } + + Local4 [Zero] = ((Local2 << 0x10) | 0xFFFF) + Local4 [One] = (Local1 & 0x03) + Local0 [Local1] = Local4 + Local1++
+ }
+
+ Return (Local0)
+ }
+
+ Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
+ {
+ WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
+ 0x0000, // Granularity + 0x0010, // Range Minimum + 0x0010, // Range Maximum + 0x0000, // Translation Offset + 0x0001, // Length + ,, )
+ })
+ }
+ }
+
Scope (\_SB.PCI0)
{
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
@@ -3121,9 +3454,9 @@
WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
0x0000, // Granularity
0x0000, // Range Minimum
- 0x00FF, // Range Maximum
+ 0x000F, // Range Maximum
0x0000, // Translation Offset
- 0x0100, // Length
+ 0x0010, // Length
,, )
IO (Decode16,
0x0CF8, // Range Minimum
@@ -3278,6 +3611,26 @@
}
}+ Device (S10)
+ {
+ Name (_ADR, 0x00020000) // _ADR: Address
+ }
+
+ Device (S18)
+ {
+ Name (_ADR, 0x00030000) // _ADR: Address
+ }
+
+ Device (S20)
+ {
+ Name (_ADR, 0x00040000) // _ADR: Address
+ }
+
+ Device (S28)
+ {
+ Name (_ADR, 0x00050000) // _ADR: Address
+ }
+
Method (PCNT, 0, NotSerialized)
{
}--- tests/qtest/bios-tables-test-allowed-diff.h | 2 -- tests/data/acpi/q35/DSDT.viot | Bin 0 -> 9398 bytes tests/data/acpi/q35/VIOT.viot | Bin 0 -> 112 bytes 3 files changed, 2 deletions(-)
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/q35/DSDT.viot" , -"tests/data/acpi/q35/VIOT.viot",
tests/data/acpi/q35/DSDT.viot binary +0 -0
tests/data/acpi/q35/VIOT.viot binary +0 -0
Signature · 1 line
2.33.0