virtio-iommu: Add ACPI support
v2 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.
Changes since [v1]:
* Patch 2, use build_append_int_noprefix() to generate the ACPI table.
* Patch 7, check that only one IOMMU is instantiated on x86.
* Added patch 5 that rejects multiple instantations of virtio-iommu on Arm. It's not crucial to the series but it matches the check added to x86 and is very simple.
* Added patch 8 documenting that interrupt remapping is not supported.
There is an important caveat at the moment: when virtio-iommu is instantiated, device DMA faults until the guest configures the IOMMU. Firmware is therefore unable to access storage devices and load the bootloader and OS. Upcoming patches will align virtio-iommu with other vIOMMUs and let DMA bypass the IOMMU during boot. In the meantime there are several ways to circumvent the problem:
* Use plain old virtio-blk as storage, without enabling the 'iommu_platform' property. DMA from the device bypasses the IOMMU.
* Place the storage device behind a PCI bus that bypasses the IOMMU, using the new 'bypass_iommu' bridge property.
See docs/bypass-iommu.txt
* Use non-PCI storage devices, for example virtio-blk-device on the arm64 virt machine.
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
[v1] https://lore.kernel.org/qemu-devel/[email protected]/
Eric Auger (1):
pc: Allow instantiating a virtio-iommu device
Jean-Philippe Brucker (7):
acpi: Add VIOT structure definitions
hw/acpi: Add VIOT table
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
pc: Add VIOT table for virtio-iommu
docs: Add '-device virtio-iommu' entry
hw/acpi/Kconfig | 4 ++ hw/arm/Kconfig | 1 + hw/i386/Kconfig | 1 + hw/acpi/viot.h | 13 ++++ include/hw/acpi/acpi-defs.h | 60 +++++++++++++++++++ include/hw/i386/pc.h | 2 + hw/acpi/viot.c | 112 +++++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 7 +++ hw/arm/virt.c | 15 +++-- hw/i386/acpi-build.c | 5 ++ hw/i386/pc.c | 28 ++++++++- hw/virtio/virtio-iommu-pci.c | 7 --- hw/acpi/meson.build | 1 + qemu-options.hx | 3 + 14 files changed, 243 insertions(+), 16 deletions(-) create mode 100644 hw/acpi/viot.h create mode 100644 hw/acpi/viot.c
Signature · 1 line
2.33.0
PATCH v2 1/8 acpi: Add VIOT structure definitions
The ACPI Virtual I/O Translation table (VIOT) table describes I/O topology for paravirtual devices. At the moment it describes the relation between virtio-iommu devices and their endpoints. Add the structure definitions for VIOT.
---
Following the latest spec draft, and related acpica change
https://jpbrucker.net/virtio-iommu/viot/viot-v9.pdf
https://github.com/acpica/acpica/commit/fc4e33319c1ee08f20f5c44853dd8426643f6dfd
--- include/hw/acpi/acpi-defs.h | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
include/hw/acpi/acpi-defs.h +60 -0
@@ -618,4 +618,64 @@ struct AcpiIortRC { } QEMU_PACKED;typedef struct AcpiIortRC AcpiIortRC ; +/* +* Virtual I/O Translation Table +*/ +struct AcpiViot { +ACPI_TABLE_HEADER_DEF + uint16_t node_count; +uint16_t node_offset; +uint8_t reserved[8 ]; +}QEMU_PACKED ; +typedef struct AcpiViot AcpiViot ; + +#define ACPI_VIOT_NODE_HEADER_DEF /* Fields common to all nodes */ \ + uint8_t type; \ + uint8_t reserved; \ + uint16_t length; + +/* Values for node Type above */ +enum { +ACPI_VIOT_NODE_PCI_RANGE =0x01 , +ACPI_VIOT_NODE_MMIO =0x02 , +ACPI_VIOT_NODE_VIRTIO_IOMMU_PCI =0x03 , +ACPI_VIOT_NODE_VIRTIO_IOMMU_MMIO =0x04 , +}; + +struct AcpiViotPciRange { +ACPI_VIOT_NODE_HEADER_DEF + uint32_t endpoint_start; +uint16_t segment_start; +uint16_t segment_end; +uint16_t bdf_start; +uint16_t bdf_end; +uint16_t output_node; +uint8_t reserved1[6 ]; +}QEMU_PACKED ; +typedef struct AcpiViotPciRange AcpiViotPciRange ; + +struct AcpiViotMmio { +ACPI_VIOT_NODE_HEADER_DEF + uint32_t endpoint; +uint64_t base_address; +uint16_t output_node; +uint8_t reserved1[6 ]; +}QEMU_PACKED ; +typedef struct AcpiViotMmio AcpiViotMmio ; + +struct AcpiViotVirtioIommuPci { +ACPI_VIOT_NODE_HEADER_DEF + uint16_t segment; +uint16_t bdf; +uint8_t reserved1[8 ]; +}QEMU_PACKED ; +typedef struct AcpiViotVirtioIommuPci AcpiViotVirtioIommuPci ; + +struct AcpiViotVirtioIommuMmio { +ACPI_VIOT_NODE_HEADER_DEF + uint8_t reserved1[4]; +uint64_t base_address; +}QEMU_PACKED ; +typedef struct AcpiViotVirtioIommuMmio AcpiViotVirtioIommuMmio ; +#endif
Signature · 1 line
2.33.0
Re: [PATCH v2 1/8] acpi: Add VIOT structure definitions
Hi Jean,
Quoted 4 lines · Jean-Philippe Brucker
The ACPI Virtual I/O Translation table (VIOT) table describes I/O topology for paravirtual devices. At the moment it describes the relation between virtio-iommu devices and their endpoints. Add the structure definitions for VIOT.
I don't think those additions are needed anymore. Looking at Igor's conversions in [PATCH v2 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables you will see he removes them and hardcode the sizes/offsets in hw/arm/virt-acpu-build.c and removes the associated structs. Even the enum values are not used anymore which is arguable but this seems to be the default style now. Anyway there are some structs like AcpiViotMmio which are not used in this series. Thanks Eric
Quoted 79 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>---
Following the latest spec draft, and related acpica change
https://jpbrucker.net/virtio-iommu/viot/viot-v9.pdf
https://github.com/acpica/acpica/commit/fc4e33319c1ee08f20f5c44853dd8426643f6dfd--- include/hw/acpi/acpi-defs.h | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)include/hw/acpi/acpi-defs.h +60
-0@@ -618,4 +618,64 @@ struct AcpiIortRC { } QEMU_PACKED;typedef struct AcpiIortRC AcpiIortRC ; +/* +* Virtual I/O Translation Table +*/ +struct AcpiViot { +ACPI_TABLE_HEADER_DEF + uint16_t node_count; +uint16_t node_offset; +uint8_t reserved[8 ]; +}QEMU_PACKED ; +typedef struct AcpiViot AcpiViot ; + +#define ACPI_VIOT_NODE_HEADER_DEF /* Fields common to all nodes */ \ + uint8_t type; \ + uint8_t reserved; \ + uint16_t length; + +/* Values for node Type above */ +enum { +ACPI_VIOT_NODE_PCI_RANGE =0x01 , +ACPI_VIOT_NODE_MMIO =0x02 , +ACPI_VIOT_NODE_VIRTIO_IOMMU_PCI =0x03 , +ACPI_VIOT_NODE_VIRTIO_IOMMU_MMIO =0x04 , +}; + +struct AcpiViotPciRange { +ACPI_VIOT_NODE_HEADER_DEF + uint32_t endpoint_start; +uint16_t segment_start; +uint16_t segment_end; +uint16_t bdf_start; +uint16_t bdf_end; +uint16_t output_node; +uint8_t reserved1[6 ]; +}QEMU_PACKED ; +typedef struct AcpiViotPciRange AcpiViotPciRange ; + +struct AcpiViotMmio { +ACPI_VIOT_NODE_HEADER_DEF + uint32_t endpoint; +uint64_t base_address; +uint16_t output_node; +uint8_t reserved1[6 ]; +}QEMU_PACKED ; +typedef struct AcpiViotMmio AcpiViotMmio ; + +struct AcpiViotVirtioIommuPci { +ACPI_VIOT_NODE_HEADER_DEF + uint16_t segment; +uint16_t bdf; +uint8_t reserved1[8 ]; +}QEMU_PACKED ; +typedef struct AcpiViotVirtioIommuPci AcpiViotVirtioIommuPci ; + +struct AcpiViotVirtioIommuMmio { +ACPI_VIOT_NODE_HEADER_DEF + uint8_t reserved1[4]; +uint64_t base_address; +}QEMU_PACKED ; +typedef struct AcpiViotVirtioIommuMmio AcpiViotVirtioIommuMmio ; +#endif
PATCH v2 2/8 hw/acpi: Add VIOT table
In reply to Jean-Philippe BruckerAdd a function that generates a Virtual I/O Translation table (VIOT), describing the topology of paravirtual IOMMUs. The table is created when instantiating a virtio-iommu device. 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/Kconfig | 4 ++ hw/acpi/viot.h | 13 +++++ hw/acpi/viot.c | 112 ++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/meson.build | 1 + 4 files changed, 130 insertions(+) create mode 100644 hw/acpi/viot.h create mode 100644 hw/acpi/viot.c
hw/acpi/Kconfig +4 -0
@@ -41,6 +41,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/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 (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 +112 -0
112 lines not on this page · raw message
hw/acpi/meson.build +1 -0
@@ -16,6 +16,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device acpi_ss.add(when: 'CONFIG_ACPI_HMAT', if_true: files('hmat.c')) acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c'), if_false: files('ghes-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86', if_true: files('piix4.c', 'pcihp.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
Re: [PATCH v2 2/8] hw/acpi: Add VIOT table
Hi Jean,
Quoted 7 lines · Jean-Philippe Brucker
Add a function that generates a Virtual I/O Translation table (VIOT), describing the topology of paravirtual IOMMUs. The table is created when instantiating a virtio-iommu device. 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.
You may consider to add a test for the new VIOT table (However this may be added afterwards). See tests/qtest/bios-tables-test.c for the process and examples.
Quoted 60 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>--- hw/acpi/Kconfig | 4 ++ hw/acpi/viot.h | 13 +++++ hw/acpi/viot.c | 112 ++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/meson.build | 1 + 4 files changed, 130 insertions(+) create mode 100644 hw/acpi/viot.h create mode 100644 hw/acpi/viot.chw/acpi/Kconfig +4
-0@@ -41,6 +41,10 @@ config ACPI_VMGENID default y depends on PC +config ACPI_VIOT + bool + depends on ACPI + config ACPI_HW_REDUCED bool select ACPIhw/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 (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 +9
-0@@ -0,0 +1,112 @@ +/* +* ACPI Virtual I/O Translation table implementation +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "qemu/osdep.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/viot.h"
hw/acpi/viot.c line 19
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" + +struct viot_pci_ranges { +GArray *blob; +size_t count; +uint16_t output_node; +}; + +/* Build PCI range for a given PCI host bridge */
chapter 1.3
Quoted 5 lines
hw/acpi/viot.c new file +5
-0+static int viot_host_bridges (Object *obj,void *opaque) +{ +struct viot_pci_ranges *pci_ranges = opaque; +GArray *blob = pci_ranges->blob; +
hw/acpi/viot.c line 34
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+if (object_dynamic_cast (obj,TYPE_PCI_HOST_BRIDGE )) { +PCIBus *bus =PCI_HOST_BRIDGE (obj)->bus; + +if (bus && !pci_bus_bypass_iommu (bus)) { +int min_bus, max_bus; + +pci_bus_range (bus, &min_bus, &max_bus); + +/* Type */ +build_append_int_noprefix (blob,ACPI_VIOT_NODE_PCI_RANGE ,1 );
s/ACPI_VIOT_NODE_PCI_RANGE/1
hw/acpi/viot.c line 38
Quoted 4 lines
hw/acpi/viot.c new file +4
-0+/* Reserved */ +build_append_int_noprefix (blob,0 ,1 ); +/* Length */ +build_append_int_noprefix (blob,sizeof (AcpiViotPciRange),2 );
hardcode the size
Quoted 15 lines
hw/acpi/viot.c new file +15
-0+/* Endpoint start */ +build_append_int_noprefix (blob,PCI_BUILD_BDF (min_bus,0 ),4 ); +/* PCI Segment start */ +build_append_int_noprefix (blob,0 ,2 ); +/* PCI Segment end */ +build_append_int_noprefix (blob,0 ,2 ); +/* PCI BDF start */ +build_append_int_noprefix (blob,PCI_BUILD_BDF (min_bus,0 ),2 ); +/* PCI BDF end */ +build_append_int_noprefix (blob,PCI_BUILD_BDF (max_bus,0xff ),2 ); +/* Output node */ +build_append_int_noprefix (blob, pci_ranges->output_node,2 ); +/* Reserved */ +build_append_int_noprefix (blob,0 ,6 ); +
hw/acpi/viot.c line 63
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+ pci_ranges->count++; + } + } + +return 0 ; +} + +/* +* Generate a VIOT table with one PCI-based virtio-iommu that manages PCI +* endpoints.
Add a link to the doc + Table refs?
Quoted 9 lines
hw/acpi/viot.c new file +9
-0+*/ +void build_viot (GArray *table_data,BIOSLinker *linker, +uint16_t virtio_iommu_bdf,const char *oem_id, +const char *oem_table_id) +{ +/* virtio-iommu node follows the header */ +int viommu_off =sizeof (AcpiViot); +int viot_start = table_data->len; +struct viot_pci_ranges pci_ranges = {
hw/acpi/viot.c line 82
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+ .output_node = viommu_off, + .blob = g_array_new(false, true, 1), + }; + +/* Build the list of PCI ranges that this viommu manages */ +object_child_foreach_recursive (object_get_root (), viot_host_bridges, + &pci_ranges); + +/* VIOT header */ +acpi_data_push (table_data,sizeof (AcpiTableHeader));
Depending on the order of landing, this may be replaced by Igor's
acpi_init_table() and associated with acpi_table_composed().
hw/acpi/viot.c line 90
Quoted 8 lines
hw/acpi/viot.c new file +8
-0+/* Node count */ +build_append_int_noprefix (table_data, pci_ranges.count +1 ,2 ); +/* Node offset */ +build_append_int_noprefix (table_data, viommu_off,2 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,8 ); + +/* Virtio-iommu based on virtio-pci */
chapter 1.1. By the way may be worth adding table titles in the spec.
hw/acpi/viot.c line 92
Quoted 2 lines
hw/acpi/viot.c new file +2
-0+/* Type */ +build_append_int_noprefix (table_data,ACPI_VIOT_NODE_VIRTIO_IOMMU_PCI ,1 );
s/ACPI_VIOT_NODE_VIRTIO_IOMMU_PCI/3 or put the defines here instead of in the header.
hw/acpi/viot.c line 96
Quoted 4 lines
hw/acpi/viot.c new file +4
-0+/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Length */ +build_append_int_noprefix (table_data,sizeof (AcpiViotVirtioIommuPci),2 );
hardcode the size of AcpiViotVirtioIommuPci
Quoted 4 lines
hw/acpi/viot.c new file +4
-0+/* PCI Segment */ +build_append_int_noprefix (table_data,0 ,2 ); +/* PCI BDF number */ +build_append_int_noprefix (table_data, virtio_iommu_bdf,2 );
hw/acpi/viot.c line 110
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+/* Reserved */ +build_append_int_noprefix (table_data,0 ,8 ); + +/* PCI ranges found above */ +g_array_append_vals (table_data, pci_ranges.blob->data, + pci_ranges.blob->len); +g_array_free (pci_ranges.blob, true); + +build_header (linker, table_data, (void *)(table_data->data + viot_start), +"VIOT" , table_data->len - viot_start,0 , oem_id, oem_table_id);
acpi_table_composed() or whatever its new name
hw/acpi/meson.build acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device · line 19
Quoted 11 lines
hw/acpi/viot.c new file +2
-0+} +hw/acpi/meson.build +1
-0@@ -16,6 +16,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device acpi_ss.add(when: 'CONFIG_ACPI_HMAT', if_true: files('hmat.c')) acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c'), if_false: files('ghes-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86', if_true: files('piix4.c', 'pcihp.c')) +acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c'))
there is a conflict with main now if I did not mess up things
<<<<<<< HEADacpi_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_X86', if_true: files('piix4.c', 'pcihp.c')) acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c'))
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi: Add VIOT table
Thanks
Eric
Quoted 3 lines
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'))
Re: [PATCH v2 2/8] hw/acpi: Add VIOT table
Quoted 11 lines · Eric Auger
Hi Jean,
Quoted 7 lines · Jean-Philippe Brucker
Add a function that generates a Virtual I/O Translation table (VIOT), describing the topology of paravirtual IOMMUs. The table is created when instantiating a virtio-iommu device. 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.
Quoted 3 lines
You may consider to add a test for the new VIOT table (However this may be added afterwards). See
tests/qtest/bios-tables-test.cfor the process and examples.
Sure, it adds 5 patches to the series
Quoted 6 lines
Quoted 3 lines
+/*
+ * Generate a VIOT table with one PCI-based virtio-iommu that manages PCI
+ * endpoints.Add a link to the doc + Table refs?
No, this document is only temporary until the next ACPI release. Although the titles and text should be the same, I don't know the refs in the final document but they will be different
Quoted 22 lines
Quoted 10 lines
+ */
hw/acpi/viot.c new file +8
-0+void build_viot (GArray *table_data,BIOSLinker *linker, +uint16_t virtio_iommu_bdf,const char *oem_id, +const char *oem_table_id) +{ +/* virtio-iommu node follows the header */ +int viommu_off =sizeof (AcpiViot); +int viot_start = table_data->len; +struct viot_pci_ranges pci_ranges = {hw/acpi/viot.c line 82
Quoted 10 lines
hw/acpi/viot.c new file +10
-0+ .output_node = viommu_off, + .blob = g_array_new(false, true, 1), + }; + +/* Build the list of PCI ranges that this viommu manages */ +object_child_foreach_recursive (object_get_root (), viot_host_bridges, + &pci_ranges); + +/* VIOT header */ +acpi_data_push (table_data,sizeof (AcpiTableHeader));Depending on the order of landing, this may be replaced by Igor's
Quoted 1 line
acpi_init_table()and associated withacpi_table_composed().
Ok I'll prepare that as a fixup, and send it or squash it after the ACPI series lands
Quoted 9 lines
<<<<<<< HEAD
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_X86', if_true: files('piix4.c', 'pcihp.c'))acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c'))Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi: Add VIOT table
Indeed, fixed
Thanks,
Jean
PATCH v2 3/8 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/Kconfig | 1 + hw/arm/virt-acpi-build.c | 7 +++++++ 2 files changed, 8 insertions(+)
hw/arm/Kconfig +1 -0
@@ -29,6 +29,7 @@ config ARM_VIRT select ACPI_HW_REDUCED select ACPI_NVDIMM select ACPI_APEI + select ACPI_VIOT config CHEETAH bool
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
@@ -849,6 +850,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 (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,
Signature · 1 line
2.33.0
Re: [PATCH v2 3/8] hw/arm/virt-acpi-build: Add VIOT table for virtio-iommu
Hi Jean,
Quoted 4 lines · Jean-Philippe Brucker
When a virtio-iommu is instantiated, describe it using the ACPI VIOT table.
Signed-off-by Jean-Philippe Brucker <[email protected]>
Thanks
Eric
Quoted 42 lines
--- hw/arm/Kconfig | 1 + hw/arm/virt-acpi-build.c | 7 +++++++ 2 files changed, 8 insertions(+)hw/arm/Kconfig +1
-0@@ -29,6 +29,7 @@ config ARM_VIRT select ACPI_HW_REDUCED select ACPI_NVDIMM select ACPI_APEI + select ACPI_VIOT config CHEETAH boolhw/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@@ -849,6 +850,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 (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,
PATCH v2 4/8 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 | 7 ------- 2 files changed, 2 insertions(+), 15 deletions(-)
hw/arm/virt.c +2 -8
@@ -2551,16 +2551,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 +0 -7
@@ -48,16 +48,9 @@ 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" );return ; }for (int i =0 ; i < s->nb_reserved_regions; i++) {
Signature · 1 line
2.33.0
Re: [PATCH v2 4/8] hw/arm/virt: Remove device tree restriction for virtio-iommu
Hi Jean,
Quoted 5 lines · 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.
Signed-off-by Jean-Philippe Brucker <[email protected]>
Eric
Quoted 49 lines
--- hw/arm/virt.c | 10 ++-------- hw/virtio/virtio-iommu-pci.c | 7 ------- 2 files changed, 2 insertions(+), 15 deletions(-)hw/arm/virt.c +2
-8@@ -2551,16 +2551,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 +0
-7@@ -48,16 +48,9 @@ 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" );return ; }for (int i =0 ; i < s->nb_reserved_regions; i++) {
PATCH v2 5/8 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
@@ -2475,6 +2475,11 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {PCIDevice *pdev =PCI_DEVICE (dev); +if (vms->iommu !=VIRT_IOMMU_NONE ) { +error_setg (errp,"virt machine does not support multiple IOMMUs" ); +return ; + } + vms->iommu =VIRT_IOMMU_VIRTIO ; vms->virtio_iommu_bdf =pci_get_bdf (pdev);create_virtio_iommu_dt_bindings (vms);
Signature · 1 line
2.33.0
Re: [PATCH v2 5/8] hw/arm/virt: Reject instantiation of multiple IOMMUs
Hi Jean,
Quoted 5 lines · 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.
Signed-off-by Jean-Philippe Brucker <[email protected]>
You may add
as the problem already exists with dt.
Thanks
Eric
Quoted 20 lines
--- hw/arm/virt.c | 5 +++++ 1 file changed, 5 insertions(+)hw/arm/virt.c +5
-0@@ -2475,6 +2475,11 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {PCIDevice *pdev =PCI_DEVICE (dev); +if (vms->iommu !=VIRT_IOMMU_NONE ) { +error_setg (errp,"virt machine does not support multiple IOMMUs" ); +return ; + } + vms->iommu =VIRT_IOMMU_VIRTIO ; vms->virtio_iommu_bdf =pci_get_bdf (pdev);create_virtio_iommu_dt_bindings (vms);
PATCH v2 6/8 pc: Add VIOT table for virtio-iommu
In reply to Jean-Philippe BruckerThe ACPI Virtual I/O Translation table (VIOT) describes the relation between a virtio-iommu and the endpoints it manages. When a virtio-iommu device is instantiated, add a VIOT table.
--- hw/i386/Kconfig | 1 + include/hw/i386/pc.h | 2 ++ hw/i386/acpi-build.c | 5 +++++ hw/i386/pc.c | 7 +++++++ 4 files changed, 15 insertions(+)
hw/i386/Kconfig +1 -0
@@ -54,6 +54,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
include/hw/i386/pc.h +2 -0
@@ -45,6 +45,8 @@ typedef struct PCMachineState {bool pit_enabled;bool hpet_enabled;bool default_bus_bypass_iommu; +bool virtio_iommu; +uint16_t virtio_iommu_bdf;uint64_t max_fw_size;/* NUMA information: */
hw/i386/acpi-build.c +5 -0
@@ -71,6 +71,7 @@#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
@@ -2559,6 +2560,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id); } + }else if (pcms->virtio_iommu) { +acpi_add_table (table_offsets, tables_blob); +build_viot (tables_blob, tables->linker, pcms->virtio_iommu_bdf, + 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 +7 -0
@@ -84,6 +84,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"
@@ -1388,6 +1389,12 @@ static void pc_machine_device_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_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +PCMachineState *pcms =PC_MACHINE (hotplug_dev); +PCIDevice *pdev =PCI_DEVICE (dev); + + pcms->virtio_iommu = true; + pcms->virtio_iommu_bdf =pci_get_bdf (pdev); } }
Signature · 1 line
2.33.0
Re: [PATCH v2 6/8] pc: Add VIOT table for virtio-iommu
Hi jean,
Quoted 3 lines · Jean-Philippe Brucker
The ACPI Virtual I/O Translation table (VIOT) describes the relation between a virtio-iommu and the endpoints it manages. When a virtio-iommu device is instantiated, add a VIOT table.
As there is no used of pcms->virtio_iommu and virtio_iommu_bdf yet, maybe squash this into next patch?
Thanks
Eric
Quoted 82 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>--- hw/i386/Kconfig | 1 + include/hw/i386/pc.h | 2 ++ hw/i386/acpi-build.c | 5 +++++ hw/i386/pc.c | 7 +++++++ 4 files changed, 15 insertions(+)hw/i386/Kconfig +1
-0@@ -54,6 +54,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_SMBUSinclude/hw/i386/pc.h +2
-0@@ -45,6 +45,8 @@ typedef struct PCMachineState {bool pit_enabled;bool hpet_enabled;bool default_bus_bypass_iommu; +bool virtio_iommu; +uint16_t virtio_iommu_bdf;uint64_t max_fw_size;/* NUMA information: */ hw/i386/acpi-build.c +5
-0@@ -71,6 +71,7 @@#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 @@ -2559,6 +2560,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_dmar_q35 (tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id); } + }else if (pcms->virtio_iommu) { +acpi_add_table (table_offsets, tables_blob); +build_viot (tables_blob, tables->linker, pcms->virtio_iommu_bdf, + 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 +7
-0@@ -84,6 +84,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" @@ -1388,6 +1389,12 @@ static void pc_machine_device_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_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +PCMachineState *pcms =PC_MACHINE (hotplug_dev); +PCIDevice *pdev =PCI_DEVICE (dev); + + pcms->virtio_iommu = true; + pcms->virtio_iommu_bdf =pci_get_bdf (pdev); } }
Re: [PATCH v2 6/8] pc: Add VIOT table for virtio-iommu
Quoted 8 lines · Eric Auger
Hi jean,
Quoted 3 lines · Jean-Philippe Brucker
The ACPI Virtual I/O Translation table (VIOT) describes the relation between a virtio-iommu and the endpoints it manages. When a virtio-iommu device is instantiated, add a VIOT table.
As there is no used of
pcms->virtio_iommuandvirtio_iommu_bdfyet, maybe squash this into next patch?
Agreed
Thanks,
Jean
PATCH v2 7/8 pc: Allow instantiating a virtio-iommu device
In reply to Jean-Philippe BruckerFrom: Eric Auger <[email protected]>
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/pc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
hw/i386/pc.c +20 -1
@@ -797,6 +797,11 @@ void pc_machine_done(Notifier *notifier, void *data) "irqchip support.");exit (EXIT_FAILURE ); } + +if (pcms->virtio_iommu &&x86_iommu_get_default ()) { +error_report ("QEMU does not support multiple vIOMMUs for x86 yet." ); +exit (EXIT_FAILURE ); + } }void pc_guest_info_init (PCMachineState *pcms)
@@ -1376,6 +1381,14 @@ 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_VIRTIO_IOMMU_PCI )) { +/* Declare the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +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); +g_free (resv_prop_str); } }
@@ -1393,6 +1406,11 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,PCMachineState *pcms =PC_MACHINE (hotplug_dev);PCIDevice *pdev =PCI_DEVICE (dev); +if (pcms->virtio_iommu) { +error_setg (errp, +"QEMU does not support multiple vIOMMUs for x86 yet." ); +return ; + } pcms->virtio_iommu = true; pcms->virtio_iommu_bdf =pci_get_bdf (pdev); }
@@ -1436,7 +1454,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_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); }
Signature · 1 line
2.33.0
Re: [PATCH v2 7/8] pc: Allow instantiating a virtio-iommu device
Hi Jean,
Quoted 6 lines · Jean-Philippe Brucker
From: Eric Auger <[email protected]>
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.
s/bypasses/bypass.
Quoted 6 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.
Signed-off-by Eric Auger <[email protected]>
Feel free to remove my SoB. I have done much here.
Quoted 10 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>--- hw/i386/pc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/i386/pc.c +0
-0
hw/i386/pc.c void pc_machine_done(Notifier *notifier, void *data) · line 805
Quoted 9 lines
hw/i386/pc.c +5
-0@@ -797,6 +797,11 @@ void pc_machine_done(Notifier *notifier, void *data) "irqchip support.");exit (EXIT_FAILURE ); } + +if (pcms->virtio_iommu &&x86_iommu_get_default ()) { +error_report ("QEMU does not support multiple vIOMMUs for x86 yet." ); +exit (EXIT_FAILURE ); + } }
I think you shall detect the case of dual instantiation of intel_iommu and virtio-iommu. Maybe pc_hotplug_allowed() can be used for that. Note that both devices can be refered to in either order.
Quoted 30 lines
hw/i386/pc.c +13
-0void pc_guest_info_init (PCMachineState *pcms)@@ -1376,6 +1381,14 @@ 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_VIRTIO_IOMMU_PCI )) { +/* Declare the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +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); +g_free (resv_prop_str); } }@@ -1393,6 +1406,11 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,PCMachineState *pcms =PC_MACHINE (hotplug_dev);PCIDevice *pdev =PCI_DEVICE (dev); +if (pcms->virtio_iommu) { +error_setg (errp, +"QEMU does not support multiple vIOMMUs for x86 yet." ); +return ; + } pcms->virtio_iommu = true; pcms->virtio_iommu_bdf =pci_get_bdf (pdev); }
hw/i386/pc.c static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, · line 1461
Quoted 9 lines
hw/i386/pc.c +2
-1@@ -1436,7 +1454,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_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); }
Thanks
Eric
Re: [PATCH v2 7/8] pc: Allow instantiating a virtio-iommu device
Quoted 31 lines · Eric Auger
Hi Jean,
Quoted 6 lines · Jean-Philippe Brucker
From: Eric Auger <[email protected]>
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.s/bypasses/bypass.
Quoted 6 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.
Signed-off-by Eric Auger <[email protected]>Feel free to remove my SoB. I have done much here.
Quoted 14 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>--- hw/i386/pc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/i386/pc.c +1
-0@@ -797,6 +797,11 @@ void pc_machine_done(Notifier *notifier, void *data) "irqchip support.");exit (EXIT_FAILURE ); } +
Quoted 8 lines
hw/i386/pc.c void pc_machine_done(Notifier *notifier, void *data) · line 805
Quoted 5 lines
hw/i386/pc.c +4
-0+if (pcms->virtio_iommu &&x86_iommu_get_default ()) { +error_report ("QEMU does not support multiple vIOMMUs for x86 yet." ); +exit (EXIT_FAILURE ); + } }I think you shall detect the case of dual instantiation of
intel_iommuand virtio-iommu.
Those are handled by x86_iommu_set_default() and pc_machine_device_plug_cb() (below) respectively. I considered factoring it but I think it just adds complexity.
Thanks,
Jean
Quoted 45 lines
Maybe
pc_hotplug_allowed()can be used for that. Note that both devices can be refered to in either order.Quoted 30 lines
hw/i386/pc.c +13
-0void pc_guest_info_init (PCMachineState *pcms)@@ -1376,6 +1381,14 @@ 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_VIRTIO_IOMMU_PCI )) { +/* Declare the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +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); +g_free (resv_prop_str); } }@@ -1393,6 +1406,11 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,PCMachineState *pcms =PC_MACHINE (hotplug_dev);PCIDevice *pdev =PCI_DEVICE (dev); +if (pcms->virtio_iommu) { +error_setg (errp, +"QEMU does not support multiple vIOMMUs for x86 yet." ); +return ; + } pcms->virtio_iommu = true; pcms->virtio_iommu_bdf =pci_get_bdf (pdev); }hw/i386/pc.c static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, · line 1461
Quoted 9 lines
hw/i386/pc.c +2
-1@@ -1436,7 +1454,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_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); }Thanks
Eric
Re: [PATCH v2 7/8] pc: Allow instantiating a virtio-iommu device
Hi jean,
Quoted 37 lines · Jean-Philippe Brucker
Quoted 20 lines · Eric Auger
Hi Jean,
Quoted 6 lines · Jean-Philippe Brucker
From: Eric Auger <[email protected]>
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.s/bypasses/bypass.
Quoted 4 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.
Signed-off-by Eric Auger <[email protected]>Feel free to remove my SoB. I have done much here.
Quoted 5 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>--- hw/i386/pc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)Quoted 16 lines
Quoted 5 lines
hw/i386/pc.c +0
-0hw/i386/pc.c void pc_machine_done(Notifier *notifier, void *data) · line 805
Quoted 9 lines
hw/i386/pc.c +5
-0@@ -797,6 +797,11 @@ void pc_machine_done(Notifier *notifier, void *data) "irqchip support.");exit (EXIT_FAILURE ); } + +if (pcms->virtio_iommu &&x86_iommu_get_default ()) { +error_report ("QEMU does not support multiple vIOMMUs for x86 yet." ); +exit (EXIT_FAILURE ); + } }I think you shall detect the case of dual instantiation of
intel_iommuand virtio-iommu.
Quoted 1 line
Those are handled by
x86_iommu_set_default()and
Oh I did not notice the x86_iommu_get_default() stuff.
sorry for the noise
Eric
Quoted 51 lines
pc_machine_device_plug_cb()(below) respectively. I considered factoring it but I think it just adds complexity.Thanks,
JeanQuoted 45 lines
Maybe
pc_hotplug_allowed()can be used for that. Note that both devices can be refered to in either order.Quoted 30 lines
hw/i386/pc.c +13
-0void pc_guest_info_init (PCMachineState *pcms)@@ -1376,6 +1381,14 @@ 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_VIRTIO_IOMMU_PCI )) { +/* Declare the reserved MSI region */ +char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" , +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); +g_free (resv_prop_str); } }@@ -1393,6 +1406,11 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,PCMachineState *pcms =PC_MACHINE (hotplug_dev);PCIDevice *pdev =PCI_DEVICE (dev); +if (pcms->virtio_iommu) { +error_setg (errp, +"QEMU does not support multiple vIOMMUs for x86 yet." ); +return ; + } pcms->virtio_iommu = true; pcms->virtio_iommu_bdf =pci_get_bdf (pdev); }hw/i386/pc.c static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, · line 1461
Quoted 9 lines
hw/i386/pc.c +2
-1@@ -1436,7 +1454,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_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); }Thanks
Eric
PATCH v2 8/8 docs: Add '-device virtio-iommu' entry
In reply to Jean-Philippe BruckerDocument the virtio-iommu device for qemu-system-x86_64. In particular note the lack of interrupt remapping, which may be an important limitation on x86.
--- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+)
qemu-options.hx +3 -0
@@ -976,6 +976,9 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu`` + Enable a paravirtual IOMMU, that manages DMA isolation and remapping + for all PCI devices, but does not support interrupt remapping. ERST DEF("name", HAS_ARG, QEMU_OPTION_name,
Signature · 1 line
2.33.0
Re: [PATCH v2 8/8] docs: Add '-device virtio-iommu' entry
Hi Jean,
Quoted 1 line · Jean-Philippe Brucker
Document the virtio-iommu device for qemu-system-x86_64. In particular
Nit: this is not only for qemu-system-x86_6. This also documents the option usage for aarch64. Only the interrupt remapping note is x86-64 specific.
I think it also would be worth to mention the interaction with the bypass iommu option as you mention "for all devices".
Thanks
Eric
Quoted 23 lines
note the lack of interrupt remapping, which may be an important limitation on x86.
Suggested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+)qemu-options.hx +3
-0@@ -976,6 +976,9 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu`` + Enable a paravirtual IOMMU, that manages DMA isolation and remapping + for all PCI devices, but does not support interrupt remapping. ERST DEF("name", HAS_ARG, QEMU_OPTION_name,
Re: [PATCH v2 8/8] docs: Add '-device virtio-iommu' entry
In reply to Jean-Philippe BruckerQuoted 15 lines · Jean-Philippe Brucker
Document the virtio-iommu device for qemu-system-x86_64. In particular note the lack of interrupt remapping, which may be an important limitation on x86.
Suggested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+)qemu-options.hx +0
-0
qemu-options.hx SRST · line 981
Quoted 6 lines
qemu-options.hx +3
-0@@ -976,6 +976,9 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu`` + Enable a paravirtual IOMMU, that manages DMA isolation and remapping + for all PCI devices, but does not support interrupt remapping.
It would be desirable to document why this is better/worse/equiv to the intel-iommu device documented just before, so that people have a better idea of which they should be trying to use.
I'm going to assume intel-iommu is more likely to "just work" out of the box since it models real hardware that OS are likely to already support ? Is that right though ?
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v2 8/8] docs: Add '-device virtio-iommu' entry
Quoted 27 lines · Daniel P. Berrangé
Quoted 15 lines · Jean-Philippe Brucker
Document the virtio-iommu device for qemu-system-x86_64. In particular note the lack of interrupt remapping, which may be an important limitation on x86.
Suggested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+)qemu-options.hx +0
-0qemu-options.hx SRST · line 981
Quoted 6 lines
qemu-options.hx +3
-0@@ -976,6 +976,9 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu`` + Enable a paravirtual IOMMU, that manages DMA isolation and remapping + for all PCI devices, but does not support interrupt remapping.It would be desirable to document why this is better/worse/equiv to the intel-iommu device documented just before, so that people have a better idea of which they should be trying to use.
Quoted 3 lines
I'm going to assume intel-iommu is more likely to "just work" out of the box since it models real hardware that OS are likely to already support ? Is that right though ?
That's right, and there isn't much point in using virtio-iommu on q35 at the moment, we're still laying the foundation. It only implements caching mode for now so it complements the vSMMU on arm which doesn't have that, but on x86 QEMU it doesn't add anything useful. There are extensions to get better performance for different type of endpoint, and other features, but those are all work in progress.
I thinks I'll just drop the documentation patch until the device is more mature and I have something useful to write here. The other IOMMUs are not described either at the moment. x86 users will just instantiate the intel-iommu as usual if they need an IOMMU.
Thanks,
Jean
Re: [PATCH v2 8/8] docs: Add '-device virtio-iommu' entry
In reply to Jean-Philippe BruckerHi,
Quoted 15 lines · Jean-Philippe Brucker
Document the virtio-iommu device for qemu-system-x86_64. In particular note the lack of interrupt remapping, which may be an important limitation on x86.
Suggested-by Eric Auger <[email protected]>Signed-off-by Jean-Philippe Brucker <[email protected]>--- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+)qemu-options.hx +0
-0
qemu-options.hx SRST · line 981
Quoted 6 lines
qemu-options.hx +3
-0@@ -976,6 +976,9 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu`` + Enable a paravirtual IOMMU, that manages DMA isolation and remapping + for all PCI devices, but does not support interrupt remapping.
maybe you should also document which machines do support the virtio-iommu (as done for intel-iommu). By the way intel-iommu only is supported on q35. Is it the same for the virtio-iommu. I think we should restrict the virtio-iommu to q35 too
Thanks
Eric
Quoted 3 lines
qemu-options.hx +0
-0ERST DEF("name", HAS_ARG, QEMU_OPTION_name,