Skip to contentSkip to conversation

VIRTIO-IOMMU device

PATCH In review Eric Auger 7 participants 25 messages Feb 14, 2020 – Mar 5, 2020

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

v16 cover VIRTIO-IOMMU device

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Non DT mode is not yet supported as it has non resolved kernel dependencies [1].

This feature targets 5.0.

Integration with vhost devices and vfio devices is not part of this series. Please follow Bharat's respins [2].

Best Regards

Eric

This series can be found at:
https://github.com/eauger/qemu/tree/v4.2-virtio-iommu-v16

References:
[1] [RFC 00/13] virtio-iommu on non-devicetree platforms
[2] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration

Testing:
- tested with guest using virtio-net-pci (,vhost=off,iommu_platform,disable-modern=off,disable-legacy=on) and virtio-blk-pci
- migration

History:

v15 -> v16:
- Collected Jean, Peter and Michael's R-bs
- last patches without R-b is the one related to hw/arm/virt.c
+ the last patch, added in this version
- Made the virtio-iommu-pci not hotpluggable (I dared to leave the R-b though)
- Renamed create_virtio_iommu into create_virtio_iommu_dt_bindings
- added entry in maintenance file

v14 -> v15:
- removed x-dt-binding and just kept check on hotplug_handler
- removed "tests: Add virtio-iommu test" as the check on hotplug_handler fails on PC machine
- destroy mappings in put_domain and remove g_tree_destroy(domain->mappings) in virtio_iommu_detach

v13 -> v14:
- added "virtio-iommu-pci: Introduce the x-dt-binding option"
- Removed the mappings gtree ref counting and simply delete the gtree when the last EP is detached from the domain

Eric Auger (10):
virtio-iommu: Add skeleton
virtio-iommu: Decode the command payload
virtio-iommu: Implement attach/detach command
virtio-iommu: Implement map/unmap
virtio-iommu: Implement translate
virtio-iommu: Implement fault reporting
virtio-iommu: Support migration
virtio-iommu-pci: Add virtio iommu pci support hw/arm/virt: Add the virtio-iommu device tree mappings
MAINTAINERS: add virtio-iommu related files

 MAINTAINERS                      |   6 +
 hw/arm/virt.c                    |  57 +-
 hw/virtio/Kconfig                |   5 +
 hw/virtio/Makefile.objs          |   2 +
 hw/virtio/trace-events           |  20 +
 hw/virtio/virtio-iommu-pci.c     | 104 ++++
 hw/virtio/virtio-iommu.c         | 890 +++++++++++++++++++++++++++++++
 include/hw/arm/virt.h            |   2 +
 include/hw/pci/pci.h             |   1 +
 include/hw/virtio/virtio-iommu.h |  61 +++
 qdev-monitor.c                   |   1 +
 11 files changed, 1142 insertions(+), 7 deletions(-)
 create mode 100644 hw/virtio/virtio-iommu-pci.c
 create mode 100644 hw/virtio/virtio-iommu.c
 create mode 100644 include/hw/virtio/virtio-iommu.h
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v16 1/10 virtio-iommu: Add skeleton

This patchs adds the skeleton for the virtio-iommu device.

---

v13 -> v14:
- use device_class_set_props
- updated copyright's year

v12 -> v13
- removed IOMMU_PCI_BUS_MAX and IOMMU_PCI_DEVFN_MAX

v11 -> v12:
- remove s_by_bus_num
- drop set_features (rely on default implementation) and acked_features

v9 -> v10:
- mutex initialized here
- initialize tail
- included hw/qdev-properties.h
- removed g_memdup
- removed s->config.domain_range.start = 0;

v9 -> v10:
- expose VIRTIO_IOMMU_F_MMIO feature
- s/domain_bits/domain_range struct
- change error codes
- enforce unmigratable
- Kconfig

v7 -> v8:
- expose VIRTIO_IOMMU_F_BYPASS and VIRTIO_F_VERSION_1 features
- set_config dummy implementation + tracing
- add trace in get_features
- set the features on realize() and store the acked ones
- remove inclusion of linux/virtio_iommu.h

v6 -> v7:
- removed qapi-event.h include
- add primary_bus and associated property

v4 -> v5:
- use the new v0.5 terminology (domain, endpoint)
- add the event virtqueue

v3 -> v4:
- use page_size_mask instead of page_sizes
- added set_features()
- added some traces (reset, set_status, set_features)
- empty virtio_iommu_set_config() as the driver MUST NOT write to device configuration fields
- add get_config trace

v2 -> v3:
- rebase on 2.10-rc0, ie. use IOMMUMemoryRegion and remove iommu_ops.
- advertise VIRTIO_IOMMU_F_MAP_UNMAP feature
- page_sizes set to TARGET_PAGE_SIZE

Conflicts:
hw/virtio/trace-events

---
 hw/virtio/Kconfig                |   5 +
 hw/virtio/Makefile.objs          |   1 +
 hw/virtio/trace-events           |   7 +
 hw/virtio/virtio-iommu.c         | 265 +++++++++++++++++++++++++++++++
 include/hw/virtio/virtio-iommu.h |  57 +++++++
 5 files changed, 335 insertions(+)
 create mode 100644 hw/virtio/virtio-iommu.c
 create mode 100644 include/hw/virtio/virtio-iommu.h
hw/virtio/Kconfig +5 -0
index f87def27a6..d29525b36f 100644
@@ -9,6 +9,11 @@ config VIRTIO_RNG
     default y
     depends on VIRTIO
 
+config VIRTIO_IOMMU
+    bool
+    default y
+    depends on VIRTIO
+
 config VIRTIO_PCI
     bool
     default y if PCI_DEVICES
hw/virtio/Makefile.objs +1 -0
index de0f5fc39b..2fd9da7410 100644
@@ -16,6 +16,7 @@ obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) += virtio-crypto-p
 obj-$(CONFIG_VIRTIO_PMEM) += virtio-pmem.o
 common-obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_VIRTIO_PCI)) += virtio-pmem-pci.o
 obj-$(call land,$(CONFIG_VHOST_USER_FS),$(CONFIG_VIRTIO_PCI)) += vhost-user-fs-pci.o
+obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 
 ifeq ($(CONFIG_VIRTIO_PCI),y)
hw/virtio/trace-events +7 -0
index e28ba48da6..02d93d7f63 100644
@@ -53,3 +53,10 @@ virtio_mmio_write_offset(uint64_t offset, uint64_t value) "virtio_mmio_write off
 virtio_mmio_guest_page(uint64_t size, int shift) "guest page size 0x%" PRIx64 " shift %d"
 virtio_mmio_queue_write(uint64_t value, int max_size) "mmio_queue write 0x%" PRIx64 " max %d"
 virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d"
+
+# hw/virtio/virtio-iommu.c
+virtio_iommu_device_reset(void) "reset!"
+virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64
+virtio_iommu_device_status(uint8_t status) "driver status = %d"
+virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x"
+virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x"
hw/virtio/virtio-iommu.c new file +265 -0

265 lines not on this page · raw message

include/hw/virtio/virtio-iommu.h new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#2 lore raw

PATCH v16 2/10 virtio-iommu: Decode the command payload

In reply to Eric Auger

This patch adds the command payload decoding and introduces the functions that will do the actual command handling. Those functions are not yet implemented.

---

v11 -> v12:
- ADded Jean and Peter's R-b

v10 -> v11:
- use a macro for handle command functions

v9 -> v10:
- make virtio_iommu_handle_* more compact and
remove get_payload_size

v7 -> v8:
- handle new domain parameter in detach
- remove reserved checks

v5 -> v6:
- change map/unmap semantics (remove size)

v4 -> v5:
- adopt new v0.5 terminology

v3 -> v4:
- no flags field anymore in struct virtio_iommu_req_unmap
- test reserved on attach/detach, change trace proto
- rebase on v2.10.0.

---
 hw/virtio/trace-events   |  4 +++
 hw/virtio/virtio-iommu.c | 76 +++++++++++++++++++++++++++++++++-------
 2 files changed, 68 insertions(+), 12 deletions(-)
hw/virtio/trace-events +4 -0
index 02d93d7f63..f7141aa2f6 100644
@@ -60,3 +60,7 @@ virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx6
 virtio_iommu_device_status(uint8_t status) "driver status = %d"
 virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x"
 virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x"
+virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
+virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
+virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d"
+virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
hw/virtio/virtio-iommu.c +64 -12

95 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#5 lore raw

PATCH v16 5/10 virtio-iommu: Implement translate

In reply to Eric Auger

This patch implements the translate callback

---

v11 -> v12:
- Added Jean's R-b
- s/qemu_log_mask/error_report_once

v10 -> v11:
- take into account the new value struct and use
g_tree_lookup_extended
- switched to error_report_once

v6 -> v7:
- implemented bypass-mode

v5 -> v6:
- replace error_report by qemu_log_mask

v4 -> v5:
- check the device domain is not NULL
- s/printf/error_report
- set flags to IOMMU_NONE in case of all translation faults

---
 hw/virtio/trace-events   |  1 +
 hw/virtio/virtio-iommu.c | 60 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)
hw/virtio/trace-events +1 -0
index 22162d6583..095aa8b509 100644
@@ -71,3 +71,4 @@ virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d"
 virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d"
 virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d"
 virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d"
+virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d"
hw/virtio/virtio-iommu.c +59 -1

78 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#3 lore raw

PATCH v16 3/10 virtio-iommu: Implement attach/detach command

In reply to Eric Auger

This patch implements the endpoint attach/detach to/from a domain.

Domain and endpoint internal datatypes are introduced. Both are stored in RB trees. The domain owns a list of endpoints attached to it. Also helpers to get/put end points and domains are introduced.

As for the IOMMU memory regions, a callback is called on PCI bus enumeration that initializes for a given device on the bus hierarchy an IOMMU memory region. The PCI bus hierarchy is stored locally in IOMMUPciBus and IOMMUDevice objects.

At the time of the enumeration, the bus number may not be computed yet.

So operations that will need to retrieve the IOMMUdevice and its IOMMU memory region from the bus number and devfn, once the bus number is garanteed to be frozen, use an array of IOMMUPciBus, lazily populated.

---
v14 -> v15:
- destroy mappings in put_domain and remove g_tree_destroy(domain->mappings) in virtio_iommu_detach

v13 -> v14:
- in virtio_iommu_put_endpoint, if the EP is attached to a domain, call virtio_iommu_detach_endpoint_from_domain()
- remove domain ref counting and simply delete the mappings gtree when the last EP is detached from the domain
- in virtio_iommu_detach_endpoint_from_domain(), return if the ep's domain is unset.

v12 -> v13:
- squashed v12 4, 5, 6 into this patch
- rename virtio_iommu_get_sid into virtio_iommu_get_bdf

v11 -> v12:
- check the device is protected by the iommu on attach
- on detach, check the domain id the device is attached to matches the one used in the detach command
- fix mapping ref counter and destroy the domain when no end-points are attached anymore

---
 hw/virtio/trace-events           |   6 +
 hw/virtio/virtio-iommu.c         | 311 ++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-iommu.h |   3 +
 3 files changed, 318 insertions(+), 2 deletions(-)
hw/virtio/trace-events +6 -0
index f7141aa2f6..15595f8cd7 100644
@@ -64,3 +64,9 @@ virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
 virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
 virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d"
 virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
+virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d"
+virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s"
+virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d"
+virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d"
+virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d"
+virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d"
hw/virtio/virtio-iommu.c +309 -2

395 lines not on this page · raw message

include/hw/virtio/virtio-iommu.h +3 -0
index d24ba63305..ae88f730cf 100644
@@ -28,6 +28,8 @@
 #define VIRTIO_IOMMU(obj) \
         OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU)
 
+#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
+
 typedef struct IOMMUDevice {
     void         *viommu;
     PCIBus       *bus;
@@ -48,6 +50,7 @@ typedef struct VirtIOIOMMU {
     struct virtio_iommu_config config;
     uint64_t features;
     GHashTable *as_by_busptr;
+    IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
     PCIBus *primary_bus;
     GTree *domains;
     QemuMutex mutex;
Signature · 1 line
2.20.1
author
#6 lore raw

PATCH v16 6/10 virtio-iommu: Implement fault reporting

In reply to Eric Auger

The event queue allows to report asynchronous errors. The translate function now injects faults when relevant.

---
v13 -> v14:
- remove loop
- add Peter's R-b

v12 -> v13:
- return on virtio_error()

v11 -> v12:
- reporting the addr associated with the fault and set the VIRTIO_IOMMU_FAULT_F_ADDRESS flag.
- added cpu_to_le<n>

v10 -> v11:
- change a virtio_error into an error_report_once (no buffer available for output faults)

---
 hw/virtio/trace-events   |  1 +
 hw/virtio/virtio-iommu.c | 70 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 66 insertions(+), 5 deletions(-)
hw/virtio/trace-events +1 -0
index 095aa8b509..e83500bee9 100644
@@ -72,3 +72,4 @@ virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d"
 virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d"
 virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d"
 virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d"
+virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64
hw/virtio/virtio-iommu.c +65 -5

107 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#4 lore raw

PATCH v16 4/10 virtio-iommu: Implement map/unmap

In reply to Eric Auger

This patch implements virtio_iommu_map/unmap.

---

v11 -> v12:
- check unmanaged managed flags on map
- removed 2 qemu_log_mask in unmap()
- fix leak

v10 -> v11:
- revisit the implementation of unmap according to Peter's suggestion
- removed virt_addr and size from viommu_mapping struct
- use g_tree_lookup_extended()
- return VIRTIO_IOMMU_S_RANGE in case a mapping were
to be split on unmap (instead of INVAL)

v5 -> v6:
- use new v0.6 fields
- replace error_report by qemu_log_mask

v3 -> v4:
- implement unmap semantics as specified in v0.4

---
 hw/virtio/trace-events   |  1 +
 hw/virtio/virtio-iommu.c | 63 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)
hw/virtio/trace-events +1 -0
index 15595f8cd7..22162d6583 100644
@@ -64,6 +64,7 @@ virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
 virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
 virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d"
 virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
+virtio_iommu_unmap_done(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
 virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d"
 virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s"
 virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d"
hw/virtio/virtio-iommu.c +61 -2

93 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#7 lore raw

PATCH v16 7/10 virtio-iommu: Support migration

In reply to Eric Auger

Add Migration support. We rely on recently added gtree and qlist migration. We only migrate the domain gtree. The endpoint gtree is re-constructed in a post-load operation.

---

v15 -> v16:
- added Juan's R-b

v11 -> v12:
- do not migrate the endpoint gtree but reconstruct it from the domain gtree (Peter's suggestion)
- add MIG_PRI_IOMMU

---
 hw/virtio/virtio-iommu.c | 109 +++++++++++++++++++++++++++++++++++----
 1 file changed, 99 insertions(+), 10 deletions(-)
hw/virtio/virtio-iommu.c +99 -10
index 8509f64004..4cee8083bc 100644
@@ -643,16 +643,6 @@ static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f,
     return f;
 }
 
-/*
- * Migration is not yet supported: most of the state consists
- * of balanced binary trees which are not yet ready for getting
- * migrated
- */
-static const VMStateDescription vmstate_virtio_iommu_device = {
-    .name = "virtio-iommu-device",
-    .unmigratable = 1,
-};
-
 static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
 {
     guint ua = GPOINTER_TO_UINT(a);
@@ -736,9 +726,108 @@ static void virtio_iommu_instance_init(Object *obj)
 {
 }
 
+#define VMSTATE_INTERVAL                               \
+{                                                      \
+    .name = "interval",                                \
+    .version_id = 1,                                   \
+    .minimum_version_id = 1,                           \
+    .fields = (VMStateField[]) {                       \
+        VMSTATE_UINT64(low, VirtIOIOMMUInterval),      \
+        VMSTATE_UINT64(high, VirtIOIOMMUInterval),     \
+        VMSTATE_END_OF_LIST()                          \
+    }                                                  \
+}
+
+#define VMSTATE_MAPPING                               \
+{                                                     \
+    .name = "mapping",                                \
+    .version_id = 1,                                  \
+    .minimum_version_id = 1,                          \
+    .fields = (VMStateField[]) {                      \
+        VMSTATE_UINT64(phys_addr, VirtIOIOMMUMapping),\
+        VMSTATE_UINT32(flags, VirtIOIOMMUMapping),    \
+        VMSTATE_END_OF_LIST()                         \
+    },                                                \
+}
+
+static const VMStateDescription vmstate_interval_mapping[2] = {
+    VMSTATE_MAPPING,   /* value */
+    VMSTATE_INTERVAL   /* key   */
+};
+
+static int domain_preload(void *opaque)
+{
+    VirtIOIOMMUDomain *domain = opaque;
+
+    domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp,
+                                       NULL, g_free, g_free);
+    return 0;
+}
+
+static const VMStateDescription vmstate_endpoint = {
+    .name = "endpoint",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(id, VirtIOIOMMUEndpoint),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_domain = {
+    .name = "domain",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .pre_load = domain_preload,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(id, VirtIOIOMMUDomain),
+        VMSTATE_GTREE_V(mappings, VirtIOIOMMUDomain, 1,
+                        vmstate_interval_mapping,
+                        VirtIOIOMMUInterval, VirtIOIOMMUMapping),
+        VMSTATE_QLIST_V(endpoint_list, VirtIOIOMMUDomain, 1,
+                        vmstate_endpoint, VirtIOIOMMUEndpoint, next),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static gboolean reconstruct_endpoints(gpointer key, gpointer value,
+                                      gpointer data)
+{
+    VirtIOIOMMU *s = (VirtIOIOMMU *)data;
+    VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value;
+    VirtIOIOMMUEndpoint *iter;
+
+    QLIST_FOREACH(iter, &d->endpoint_list, next) {
+        iter->domain = d;
+        g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter);
+    }
+    return false; /* continue the domain traversal */
+}
+
+static int iommu_post_load(void *opaque, int version_id)
+{
+    VirtIOIOMMU *s = opaque;
+
+    g_tree_foreach(s->domains, reconstruct_endpoints, s);
+    return 0;
+}
+
+static const VMStateDescription vmstate_virtio_iommu_device = {
+    .name = "virtio-iommu-device",
+    .minimum_version_id = 1,
+    .version_id = 1,
+    .post_load = iommu_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_GTREE_DIRECT_KEY_V(domains, VirtIOIOMMU, 1,
+                                   &vmstate_domain, VirtIOIOMMUDomain),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
 static const VMStateDescription vmstate_virtio_iommu = {
     .name = "virtio-iommu",
     .minimum_version_id = 1,
+    .priority = MIG_PRI_IOMMU,
     .version_id = 1,
     .fields = (VMStateField[]) {
         VMSTATE_VIRTIO_DEVICE,
Signature · 1 line
2.20.1
author
#8 lore raw

PATCH v16 8/10 virtio-iommu-pci: Add virtio iommu pci support

In reply to Eric Auger

This patch adds virtio-iommu-pci, which is the pci proxy for the virtio-iommu device.

Currently non DT integration is not yet supported by the kernel. So the machine must implement a hotplug handler for the virtio-iommu-pci device that creates the device tree iommu-map bindings as documented in kernel documentation:

Documentation/devicetree/bindings/virtio/iommu.txt

---
v15 -> v16:
- made the device not hotpluggable

v14 -> v15:
- checker whether the machine implements a hotplug handler for the virtio-iommu-pci

v13 -> v14:
- add device_class_set_props

v11 -> v12:
- added Jean's R-b
- remove the array of intervals. Will be introduced later?

v10 -> v11:
- add the reserved_regions array property

v9 -> v10:
- include "hw/qdev-properties.h" header

v8 -> v9:
- add the msi-bypass property
- create virtio-iommu-pci.c

---
 hw/virtio/Makefile.objs          |   1 +
 hw/virtio/virtio-iommu-pci.c     | 104 +++++++++++++++++++++++++++++++
 include/hw/pci/pci.h             |   1 +
 include/hw/virtio/virtio-iommu.h |   1 +
 qdev-monitor.c                   |   1 +
 5 files changed, 108 insertions(+)
 create mode 100644 hw/virtio/virtio-iommu-pci.c
hw/virtio/Makefile.objs +1 -0
index 2fd9da7410..4e4d39a0a4 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
+obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu-pci.o
 obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
 obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio-blk-pci.o
hw/virtio/virtio-iommu-pci.c new file +104 -0

104 lines not on this page · raw message

include/hw/pci/pci.h +1 -0
index 2acd8321af..cfedf5a995 100644
@@ -86,6 +86,7 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
 #define PCI_DEVICE_ID_VIRTIO_PMEM        0x1013
+#define PCI_DEVICE_ID_VIRTIO_IOMMU       0x1014
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
include/hw/virtio/virtio-iommu.h +1 -0
index ae88f730cf..6f67f1020a 100644
@@ -25,6 +25,7 @@
 #include "hw/pci/pci.h"
 
 #define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
+#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-device-base"
 #define VIRTIO_IOMMU(obj) \
         OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU)
 
qdev-monitor.c +1 -0
index 8ce71a206b..dbbe92dfa1 100644
@@ -67,6 +67,7 @@ static const QDevAlias qdev_alias_table[] = {
     { "virtio-input-host-ccw", "virtio-input-host", QEMU_ARCH_S390X },
     { "virtio-input-host-pci", "virtio-input-host",
             QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
+    { "virtio-iommu-pci", "virtio-iommu", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
     { "virtio-keyboard-ccw", "virtio-keyboard", QEMU_ARCH_S390X },
     { "virtio-keyboard-pci", "virtio-keyboard",
             QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
Signature · 1 line
2.20.1
author
#9 lore raw

PATCH v16 9/10 hw/arm/virt: Add the virtio-iommu device tree mappings

In reply to Eric Auger

Adds the "virtio,pci-iommu" node in the host bridge node and the RID mapping, excluding the IOMMU RID.

This is done in the virtio-iommu-pci hotplug handler which gets called only if no firmware is loaded or if -no-acpi is passed on the command line. As non DT integration is not yet supported by the kernel we must make sure we are in DT mode. This limitation will be removed as soon as the topology description feature gets supported.

---

v15 -> v16:
- rename create_virtio_iommu into create_virtio_iommu_dt_bindings

v14 -> v15:
- only support the hotplug handler for virtio-iommu-pci if dt can be guaranteed

v11 -> v12:
- Added Jean's R-b

v10 -> v11:
- remove msi_bypass

v8 -> v9:
- disable msi-bypass property
- addition of the subnode is handled is the hotplug handler and IOMMU RID is notimposed anymore

v6 -> v7:
- align to the smmu instantiation code

v4 -> v5:
- VirtMachineClass no_iommu added in this patch
- Use object_resolve_path_type

---
 hw/arm/virt.c         | 57 +++++++++++++++++++++++++++++++++++++------
 include/hw/arm/virt.h |  2 ++
 2 files changed, 52 insertions(+), 7 deletions(-)
hw/arm/virt.c +50 -7
index f788fe27d6..cfe317922f 100644
@@ -32,6 +32,7 @@
 #include "qemu-common.h"
 #include "qemu/units.h"
 #include "qemu/option.h"
+#include "monitor/qdev.h"
 #include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "hw/boards.h"
@@ -54,6 +55,7 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "hw/pci-host/gpex.h"
+#include "hw/virtio/virtio-pci.h"
 #include "hw/arm/sysbus-fdt.h"
 #include "hw/platform-bus.h"
 #include "hw/qdev-properties.h"
@@ -71,6 +73,7 @@
 #include "hw/mem/pc-dimm.h"
 #include "hw/mem/nvdimm.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/virtio/virtio-iommu.h"
 
 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
     static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -1180,6 +1183,30 @@ static void create_smmu(const VirtMachineState *vms,
     g_free(node);
 }
 
+static void create_virtio_iommu_dt_bindings(VirtMachineState *vms, Error **errp)
+{
+    const char compat[] = "virtio,pci-iommu";
+    uint16_t bdf = vms->virtio_iommu_bdf;
+    char *node;
+
+    vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt);
+
+    node = g_strdup_printf("%s/virtio_iommu@%d", vms->pciehb_nodename, bdf);
+    qemu_fdt_add_subnode(vms->fdt, node);
+    qemu_fdt_setprop(vms->fdt, node, "compatible", compat, sizeof(compat));
+    qemu_fdt_setprop_sized_cells(vms->fdt, node, "reg",
+                                 1, bdf << 8, 1, 0, 1, 0,
+                                 1, 0, 1, 0);
+
+    qemu_fdt_setprop_cell(vms->fdt, node, "#iommu-cells", 1);
+    qemu_fdt_setprop_cell(vms->fdt, node, "phandle", vms->iommu_phandle);
+    g_free(node);
+
+    qemu_fdt_setprop_cells(vms->fdt, vms->pciehb_nodename, "iommu-map",
+                           0x0, vms->iommu_phandle, 0x0, bdf,
+                           bdf + 1, vms->iommu_phandle, bdf + 1, 0xffff - bdf);
+}
+
 static void create_pcie(VirtMachineState *vms)
 {
     hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO].base;
@@ -1258,7 +1285,7 @@ static void create_pcie(VirtMachineState *vms)
         }
     }
 
-    nodename = g_strdup_printf("/pcie@%" PRIx64, base);
+    nodename = vms->pciehb_nodename = g_strdup_printf("/pcie@%" PRIx64, base);
     qemu_fdt_add_subnode(vms->fdt, nodename);
     qemu_fdt_setprop_string(vms->fdt, nodename,
                             "compatible", "pci-host-ecam-generic");
@@ -1301,13 +1328,16 @@ static void create_pcie(VirtMachineState *vms)
     if (vms->iommu) {
         vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt);
 
-        create_smmu(vms, pci->bus);
-
-        qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map",
-                               0x0, vms->iommu_phandle, 0x0, 0x10000);
+        switch (vms->iommu) {
+        case VIRT_IOMMU_SMMUV3:
+            create_smmu(vms, pci->bus);
+            qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map",
+                                   0x0, vms->iommu_phandle, 0x0, 0x10000);
+            break;
+        default:
+            g_assert_not_reached();
+        }
     }
-
-    g_free(nodename);
 }
 
 static void create_platform_bus(VirtMachineState *vms)
@@ -1976,6 +2006,13 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         virt_memory_plug(hotplug_dev, dev, errp);
     }
+    if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
+        PCIDevice *pdev = PCI_DEVICE(dev);
+
+        vms->iommu = VIRT_IOMMU_VIRTIO;
+        vms->virtio_iommu_bdf = pci_get_bdf(pdev);
+        create_virtio_iommu_dt_bindings(vms, errp);
+    }
 }
 
 static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
@@ -1992,7 +2029,13 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
        (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) {
         return HOTPLUG_HANDLER(machine);
     }
+    if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
+        VirtMachineState *vms = VIRT_MACHINE(machine);
 
+        if (!vms->bootinfo.firmware_loaded || !acpi_enabled) {
+            return HOTPLUG_HANDLER(machine);
+        }
+    }
     return NULL;
 }
 
include/hw/arm/virt.h +2 -0
index 71508bf40c..02f500cb8e 100644
@@ -125,8 +125,10 @@ typedef struct {
     bool virt;
     int32_t gic_version;
     VirtIOMMUType iommu;
+    uint16_t virtio_iommu_bdf;
     struct arm_boot_info bootinfo;
     MemMapEntry *memmap;
+    char *pciehb_nodename;
     const int *irqmap;
     int smp_cpus;
     void *fdt;
Signature · 1 line
2.20.1
author
#11 lore raw

PATCH v16 10/10 MAINTAINERS: add virtio-iommu related files

In reply to Eric Auger

Add a new "virtio-iommu" section with the new files related to this device.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index c7717df720..b7a7a18737 100644
@@ -1623,6 +1623,12 @@ F: hw/input/virtio-input*.c
 F: include/hw/virtio/virtio-input.h
 F: contrib/vhost-user-input/*
 
+virtio-iommu
+M: Eric Auger <[email protected]>
+S: Maintained
+F: hw/virtio/virtio-iommu*.c
+F: include/hw/virtio/virtio-iommu.h
+
 virtio-serial
 M: Laurent Vivier <[email protected]>
 R: Amit Shah <[email protected]>
Signature · 1 line
2.20.1
Reviewed-by on v16 10/10
#12 lore raw

Re: [PATCH v16 10/10] MAINTAINERS: add virtio-iommu related files

Quoted 17 lines · Eric Auger

Add a new "virtio-iommu" section with the new files related to this device.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +0 -0
index c7717df720..b7a7a18737 100644
@@ -1623,6 +1623,12 @@ F: hw/input/virtio-input*.c
 F: include/hw/virtio/virtio-input.h
 F: contrib/vhost-user-input/*
 

MAINTAINERS F: hw/input/virtio-input*.c

Quoted 10 lines
MAINTAINERS +6 -1
+virtio-iommu
+M: Eric Auger <[email protected]>
+S: Maintained
+F: hw/virtio/virtio-iommu*.c
+F: include/hw/virtio/virtio-iommu.h
+
 virtio-serial
 M: Laurent Vivier <[email protected]>
 R: Amit Shah <[email protected]>
--

thanks
-- PMM

Reviewed-by on v16 9/10
#10 lore raw

Re: [PATCH v16 09/10] hw/arm/virt: Add the virtio-iommu device tree mappings

In reply to Eric Auger
Quoted 4 lines · Eric Auger

Adds the "virtio,pci-iommu" node in the host bridge node and the RID mapping, excluding the IOMMU RID.

Quoted 8 lines

This is done in the virtio-iommu-pci hotplug handler which gets called only if no firmware is loaded or if -no-acpi is passed on the command line. As non DT integration is not yet supported by the kernel we must make sure we are in DT mode. This limitation will be removed as soon as the topology description feature gets supported.

thanks
-- PMM

#13 lore raw
In reply to Eric Auger
Quoted 10 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Quoted 7 lines

Non DT mode is not yet supported as it has non resolved kernel dependencies [1].

This feature targets 5.0.

Integration with vhost devices and vfio devices is not part of this series. Please follow Bharat's respins [2].

I think everything here has reviewed-by tags now -- does anybody still want more time to review it, and what is the preference for how it goes into master?

thanks
-- PMM

#14 lore raw
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Quoted 7 lines

Non DT mode is not yet supported as it has non resolved kernel dependencies [1].

This feature targets 5.0.

Integration with vhost devices and vfio devices is not part of this series. Please follow Bharat's respins [2].

Quoted 6 lines

I think everything here has reviewed-by tags now -- does anybody still want more time to review it, and what is the preference for how it goes into master?

thanks
-- PMM

I guess I'll pick it up, most code seems to be virtio related.

Thanks everyone!

Signature · 1 line
MST
#15 lore raw
In reply to Eric Auger
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

You mention Arm here, but can this virtio-iommu-pci be used on ppc64, s390x, x86_64 too ? If so, is it a better choice than using intel-iommu on x86_64 ? Anything else that is relevant for management applications to know about when using this ?

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 :|
author
#16 lore raw

Hi Daniel,

Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

not yet in qemu.

Quoted 3 lines

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

Maybe if you want to catch up on the topic, looking at the very first kernel RFC may be a good starting point. Motivation, pros & cons were discussed in that thread (hey, April 2017!)
https://lists.linuxfoundation.org/pipermail/iommu/2017-April/021217.html

on ARM we have SMMUv3 emulation. But the VFIO integration is not possible because SMMU does not have any "caching mode" and my nested paging kernel series is blocked. So the only solution to integrate with VFIO is looming virtio-iommu.

In general the pros that were put forward are: virtio-iommu is architecture agnostic, removes the burden to accurately model complex device states, driver can support virtualization specific optimizations without being constrained by production driver maintenance. Cons is perf and mem footprint if we do not consider any optimization.

You can have a look at

http://events17.linuxfoundation.org/sites/events/files/slides/viommu_arm.pdf

Quoted 3 lines

You mention Arm here, but can this virtio-iommu-pci be used on ppc64, s390x, x86_64 too ?

Not Yet. At the moment we are stuck with the non DT integration at kernel level. We can instantiate the device in machvirt with DT boot only.

Work is ongoing on kernel, by Jean-Philippe to support non DT integration:

[1] [PATCH 0/3] virtio-iommu on non-devicetree platforms
(https://www.spinics.net/lists/linux-virtualization/msg41391.html)

This does nor rely on ACPI anymore.

Originally the plan was to integrate with ACPI (IORT) but Michael pushed to pass the binding info between the protected devices and the IOMMU through the PCI cfg space. Also this could serve environments where we do not have ACPI. I think some people are reluctant to expose the virtio-iommu in the [IORT] ACPI table.

But definitively the end goal is to support the virtio-iommu for other archs. Integration with x86 is already working based on IORT or [1].

If so, is it a better choice than

Quoted 1 line

using intel-iommu on x86_64?

Anything else that is relevant

Quoted 1 line

for management applications to know about when using this ?

I think We are still at the early stage and this would be premature even if feasible.

Hope it helps

Thanks

Eric

Quoted 5 lines

Regards,
Daniel

#17 lore raw

Hi Eric

Quoted 37 lines · Auger Eric

Hi Daniel,

Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

not yet in qemu.

Quoted 3 lines

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

Maybe if you want to catch up on the topic, looking at the very first kernel RFC may be a good starting point. Motivation, pros & cons were discussed in that thread (hey, April 2017!)
https://lists.linuxfoundation.org/pipermail/iommu/2017-April/021217.html

on ARM we have SMMUv3 emulation. But the VFIO integration is not possible because SMMU does not have any "caching mode" and my nested paging kernel series is blocked. So the only solution to integrate with VFIO is looming virtio-iommu.

In general the pros that were put forward are: virtio-iommu is architecture agnostic, removes the burden to accurately model complex device states, driver can support virtualization specific optimizations without being constrained by production driver maintenance. Cons is perf and mem footprint if we do not consider any optimization.

Quoted 4 lines

You can have a look at

http://events17.linuxfoundation.org/sites/events/files/slides/viommu_arm.pdf

Thanks for the patches.

Could I ask one question?
To support vSVA and pasid in guest, which direction you recommend, virtio-iommu or vSMMU (your nested paging)

Do we still have any obstacles?
Would you mind give some breakdown.
Jean mentioned PASID still not supported in QEMU.

Thanks

author
#18 lore raw

Hi Zhangfei,

Quoted 44 lines · Zhangfei Gao

Hi Eric

Quoted 37 lines · Auger Eric

Hi Daniel,

Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

not yet in qemu.

Quoted 3 lines

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

Maybe if you want to catch up on the topic, looking at the very first kernel RFC may be a good starting point. Motivation, pros & cons were discussed in that thread (hey, April 2017!)
https://lists.linuxfoundation.org/pipermail/iommu/2017-April/021217.html

on ARM we have SMMUv3 emulation. But the VFIO integration is not possible because SMMU does not have any "caching mode" and my nested paging kernel series is blocked. So the only solution to integrate with VFIO is looming virtio-iommu.

In general the pros that were put forward are: virtio-iommu is architecture agnostic, removes the burden to accurately model complex device states, driver can support virtualization specific optimizations without being constrained by production driver maintenance. Cons is perf and mem footprint if we do not consider any optimization.

Quoted 4 lines

You can have a look at

http://events17.linuxfoundation.org/sites/events/files/slides/viommu_arm.pdf

Quoted 7 lines

Thanks for the patches.

Could I ask one question?
To support vSVA and pasid in guest, which direction you recommend, virtio-iommu or vSMMU (your nested paging)

Do we still have any obstacles?

you can ask the question but not sure I can answer ;-)

1) SMMUv3 2stage implementation is blocked by Will at kernel level.

Despite this situation I may/can respin as Marvell said they were interested in this effort. If you are also interested in (I know you tested it several times and I am grateful to you for that), please reply to:
[PATCH v9 00/14] SMMUv3 Nested Stage Setup (IOMMU part)
(https://patchwork.kernel.org/cover/11039871/) and say you are interested in that work so that maintainers are aware there are potential users.

At the moment I have not supported multiple CDs because it introduced other dependencies.

2) virtio-iommu

So only virtio-iommu dt boot on machvirt is currently supported. For non DT, Jean respinned his kernel series
"[PATCH v2 0/3] virtio-iommu on x86 and non-devicetree platforms" as you may know. However non DT integration still is controversial. Michael is pushing for putting the binding info the PCI config space. Joerg yesterday challenged this solution and said he would prefer ACPI integration. ACPI support depends on ACPI spec update & vote anyway.

To support PASID at virtio-iommu level you also need virtio-iommu API extensions to be proposed and written + kernel works. So that's a long road. I will let Jean-Philippe comment on that.

I would just say that Intel is working on nested paging solution with their emulated intel-iommu. We can help them getting that upstream and partly benefit from this work.

Quoted 2 lines

Would you mind give some breakdown.
Jean mentioned PASID still not supported in QEMU.

Do you mean support of multiple CDs in the emulated SMMU? That's a thing I could implement quite easily. What is more tricky is how to test it.

Thanks

Eric

Quoted 3 lines

Thanks

#19 lore raw
Quoted 84 lines · Auger Eric

Hi Zhangfei,

Quoted 44 lines · Zhangfei Gao

Hi Eric

Quoted 37 lines · Auger Eric

Hi Daniel,

Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

not yet in qemu.

Quoted 3 lines

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

Maybe if you want to catch up on the topic, looking at the very first kernel RFC may be a good starting point. Motivation, pros & cons were discussed in that thread (hey, April 2017!)
https://lists.linuxfoundation.org/pipermail/iommu/2017-April/021217.html

on ARM we have SMMUv3 emulation. But the VFIO integration is not possible because SMMU does not have any "caching mode" and my nested paging kernel series is blocked. So the only solution to integrate with VFIO is looming virtio-iommu.

In general the pros that were put forward are: virtio-iommu is architecture agnostic, removes the burden to accurately model complex device states, driver can support virtualization specific optimizations without being constrained by production driver maintenance. Cons is perf and mem footprint if we do not consider any optimization.

Quoted 4 lines

You can have a look at

http://events17.linuxfoundation.org/sites/events/files/slides/viommu_arm.pdf

Quoted 7 lines

Thanks for the patches.

Could I ask one question?
To support vSVA and pasid in guest, which direction you recommend, virtio-iommu or vSMMU (your nested paging)

Do we still have any obstacles?

you can ask the question but not sure I can answer ;-)

1) SMMUv3 2stage implementation is blocked by Will at kernel level.

Despite this situation I may/can respin as Marvell said they were interested in this effort. If you are also interested in (I know you tested it several times and I am grateful to you for that), please reply to:
[PATCH v9 00/14] SMMUv3 Nested Stage Setup (IOMMU part)
(https://patchwork.kernel.org/cover/11039871/) and say you are interested in that work so that maintainers are aware there are potential users.

At the moment I have not supported multiple CDs because it introduced other dependencies.

2) virtio-iommu

So only virtio-iommu dt boot on machvirt is currently supported. For non DT, Jean respinned his kernel series
"[PATCH v2 0/3] virtio-iommu on x86 and non-devicetree platforms" as you may know. However non DT integration still is controversial. Michael is pushing for putting the binding info the PCI config space. Joerg yesterday challenged this solution and said he would prefer ACPI integration. ACPI support depends on ACPI spec update & vote anyway.

To support PASID at virtio-iommu level you also need virtio-iommu API extensions to be proposed and written + kernel works. So that's a long road. I will let Jean-Philippe comment on that.

Quoted 8 lines

I would just say that Intel is working on nested paging solution with their emulated intel-iommu. We can help them getting that upstream and partly benefit from this work.

Quoted 2 lines

Would you mind give some breakdown.
Jean mentioned PASID still not supported in QEMU.

Do you mean support of multiple CDs in the emulated SMMU? That's a thing I could implement quite easily. What is more tricky is how to test it.

Thanks Eric

Discussed with Jean before, here are some obstacles for vSVA via nested paging. Do you think they are still big issues?

Copy "
* PASID support in QEMU, I don't think there is anything yet // this is not a big issue as your comments.

* Page response support in VFIO and QEMU. With Eric's series we can inject recoverable faults into the guest, but there is no channel for the guest to RESUME the stall after fixing it.

* We can't use DVM in nested mode unless the VMID is shared with the CPU. For that we'll need the host SMMU driver to hook into the KVM VMID allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command queue. "

Thanks

author
#20 lore raw

Hi Zhangfei,

Quoted 99 lines · Zhangfei Gao
Quoted 84 lines · Auger Eric

Hi Zhangfei,

Quoted 44 lines · Zhangfei Gao

Hi Eric

Quoted 37 lines · Auger Eric

Hi Daniel,

Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Eric Auger

This series implements the QEMU virtio-iommu device.

This matches the v0.12 spec (voted) and the corresponding virtio-iommu driver upstreamed in 5.3. All kernel dependencies are resolved for DT integration. The virtio-iommu can be instantiated in ARM virt using:

"-device virtio-iommu-pci".

Is there any more documentation besides this ?

not yet in qemu.

Quoted 3 lines

I'm wondering on the intended usage of this, and its relation or pros/cons vs other iommu devices

Maybe if you want to catch up on the topic, looking at the very first kernel RFC may be a good starting point. Motivation, pros & cons were discussed in that thread (hey, April 2017!)
https://lists.linuxfoundation.org/pipermail/iommu/2017-April/021217.html

on ARM we have SMMUv3 emulation. But the VFIO integration is not possible because SMMU does not have any "caching mode" and my nested paging kernel series is blocked. So the only solution to integrate with VFIO is looming virtio-iommu.

In general the pros that were put forward are: virtio-iommu is architecture agnostic, removes the burden to accurately model complex device states, driver can support virtualization specific optimizations without being constrained by production driver maintenance. Cons is perf and mem footprint if we do not consider any optimization.

Quoted 4 lines

You can have a look at

http://events17.linuxfoundation.org/sites/events/files/slides/viommu_arm.pdf

Quoted 7 lines

Thanks for the patches.

Could I ask one question?
To support vSVA and pasid in guest, which direction you recommend, virtio-iommu or vSMMU (your nested paging)

Do we still have any obstacles?

you can ask the question but not sure I can answer ;-)

1) SMMUv3 2stage implementation is blocked by Will at kernel level.

Despite this situation I may/can respin as Marvell said they were interested in this effort. If you are also interested in (I know you tested it several times and I am grateful to you for that), please reply to:
[PATCH v9 00/14] SMMUv3 Nested Stage Setup (IOMMU part)
(https://patchwork.kernel.org/cover/11039871/) and say you are interested in that work so that maintainers are aware there are potential users.

At the moment I have not supported multiple CDs because it introduced other dependencies.

2) virtio-iommu

So only virtio-iommu dt boot on machvirt is currently supported. For non DT, Jean respinned his kernel series
"[PATCH v2 0/3] virtio-iommu on x86 and non-devicetree platforms" as you may know. However non DT integration still is controversial. Michael is pushing for putting the binding info the PCI config space. Joerg yesterday challenged this solution and said he would prefer ACPI integration. ACPI support depends on ACPI spec update & vote anyway.

To support PASID at virtio-iommu level you also need virtio-iommu API extensions to be proposed and written + kernel works. So that's a long road. I will let Jean-Philippe comment on that.

Quoted 8 lines

I would just say that Intel is working on nested paging solution with their emulated intel-iommu. We can help them getting that upstream and partly benefit from this work.

Quoted 2 lines

Would you mind give some breakdown.
Jean mentioned PASID still not supported in QEMU.

Do you mean support of multiple CDs in the emulated SMMU? That's a thing I could implement quite easily. What is more tricky is how to test it.

Thanks Eric

Discussed with Jean before, here are some obstacles for vSVA via nested paging. Do you think they are still big issues?

Quoted 7 lines

Copy "
* PASID support in QEMU, I don't think there is anything yet // this is not a big issue as your comments.

* Page response support in VFIO and QEMU. With Eric's series we can inject recoverable faults into the guest, but there is no channel for the guest to RESUME the stall after fixing it.

I guess this matches a command sent through the SMMUv3 command queue (CMD_PRI_RESP) that should be trapped by QEMU and injected to the physical SMMU, right?

I think everybody misses that injection path and that's not specific to virtio-iommu. PRS is not currently addressed by in-flight Intel's kernel series ([PATCH V9 00/10] Nested Shared Virtual Address (SVA) VT-d support) either.

I think the topic is complex enough to separate the concerns and try to move forward in incremental steps hence my efforts to push for simple nested use case. Can't you support vSVA without PRS first (I think this Intel's strategy too)

Quoted 7 lines

* We can't use DVM in nested mode unless the VMID is shared with the CPU. For that we'll need the host SMMU driver to hook into the KVM VMID allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command queue. "

OK.

From the above arguments I am not sure there are technical blockers with nested paging implementation. For sure there are things that are not supported, because I did not address this topic yet.

If I were to work on this, you did not answer bout the testing feasibility.

Thanks

Eric

Quoted 3 lines

Thanks

#21 lore raw
Quoted 11 lines · Auger Eric
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

Could I ask one question?
To support vSVA and pasid in guest, which direction you recommend, virtio-iommu or vSMMU (your nested paging)

Do we still have any obstacles?

you can ask the question but not sure I can answer ;-)

1) SMMUv3 2stage implementation is blocked by Will at kernel level.

Despite this situation I may/can respin as Marvell said they were interested in this effort.

Do you know if they want vSVA as well or only nested translation?

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

If you are also interested in (I know you
tested it several times and I am grateful to you for that), please reply to:
[PATCH v9 00/14] SMMUv3 Nested Stage Setup (IOMMU part)
(https://patchwork.kernel.org/cover/11039871/) and say you are interested in that work so that maintainers are aware there are potential users.

At the moment I have not supported multiple CDs because it introduced other dependencies.

2) virtio-iommu

So only virtio-iommu dt boot on machvirt is currently supported. For non DT, Jean respinned his kernel series
"[PATCH v2 0/3] virtio-iommu on x86 and non-devicetree platforms" as you may know. However non DT integration still is controversial. Michael is pushing for putting the binding info the PCI config space. Joerg yesterday challenged this solution and said he would prefer ACPI integration. ACPI support depends on ACPI spec update & vote anyway.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

To support PASID at virtio-iommu level you also need virtio-iommu API extensions to be proposed and written + kernel works. So that's a long road. I will let Jean-Philippe comment on that.

Yeah, let's put that stuff on hold. vSVA with virtio-iommu requires about the same amount of work in the host kernel as vSMMU, minus the NESTED_MSI stuff. The device implementation would be simpler, but the guest driver is difficult (I'd need to extract the CD table code from the SMMU driver again). And obtaining better performance than vSMMU would then require upstreaming vhost-iommu. I do have incomplete drafts and prototypes but I'll put them aside until users (other than hardware validation) show up and actually need performance or things like unpinned stage-2.

Quoted 30 lines
Quoted 14 lines
Quoted 8 lines

I would just say that Intel is working on nested paging solution with their emulated intel-iommu. We can help them getting that upstream and partly benefit from this work.

Quoted 2 lines

Would you mind give some breakdown.
Jean mentioned PASID still not supported in QEMU.

Do you mean support of multiple CDs in the emulated SMMU? That's a thing I could implement quite easily. What is more tricky is how to test it.

Thanks Eric

Discussed with Jean before, here are some obstacles for vSVA via nested paging. Do you think they are still big issues?

Quoted 7 lines

Copy "
* PASID support in QEMU, I don't think there is anything yet // this is not a big issue as your comments.

* Page response support in VFIO and QEMU. With Eric's series we can inject recoverable faults into the guest, but there is no channel for the guest to RESUME the stall after fixing it.

I guess this matches a command sent through the SMMUv3 command queue (CMD_PRI_RESP) that should be trapped by QEMU and injected to the physical SMMU, right?

I think everybody misses that injection path and that's not specific to virtio-iommu. PRS is not currently addressed by in-flight Intel's kernel series ([PATCH V9 00/10] Nested Shared Virtual Address (SVA) VT-d support) either.

Quoted 4 lines

I think the topic is complex enough to separate the concerns and try to move forward in incremental steps hence my efforts to push for simple nested use case. Can't you support vSVA without PRS first (I think this Intel's strategy too)

Not really, for sharing guest process address spaces you need I/O page faults. You can test PASID alone without PRI by using auxiliary domains in the guest, so I'd advise to start with that, but it requires modifications to the device driver.

Quoted 7 lines
Quoted 7 lines

* We can't use DVM in nested mode unless the VMID is shared with the CPU. For that we'll need the host SMMU driver to hook into the KVM VMID allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command queue. "

Hm we're already mandating DVM for host SVA, so I'd say mandate it for vSVA as well. We'd avoid a ton of context switches, especially for the zip accelerator which doesn't require ATC invalidations. The host needs to pin the VMID allocated by KVM and write it in the endpoint's STE.

Thanks,
Jean

Quoted 15 lines

OK.

From the above arguments I am not sure there are technical blockers with nested paging implementation. For sure there are things that are not supported, because I did not address this topic yet.

If I were to work on this, you did not answer bout the testing feasibility.

Thanks

Eric

Quoted 3 lines

Thanks

#22 lore raw
Quoted 3 lines

From: Jean-Philippe Brucker <[email protected]>
Sent: Thursday, March 5, 2020 12:47 AM

[...]

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

* We can't use DVM in nested mode unless the VMID is shared with the CPU. For that we'll need the host SMMU driver to hook into the KVM

VMID

Quoted 3 lines
Quoted 3 lines

allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command

Quoted 8 lines

queue.

Quoted 1 line
Quoted 1 line

"

Hm we're already mandating DVM for host SVA, so I'd say mandate it for vSVA as well. We'd avoid a ton of context switches, especially for the zip accelerator which doesn't require ATC invalidations. The host needs to pin the VMID allocated by KVM and write it in the endpoint's STE.

Curious... what is DVM and how is it related to SVA? Is it SMMU specific?

#23 lore raw
Quoted 14 lines · Kevin
Quoted 3 lines

From: Jean-Philippe Brucker <[email protected]>
Sent: Thursday, March 5, 2020 12:47 AM

[...]

Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

* We can't use DVM in nested mode unless the VMID is shared with the CPU. For that we'll need the host SMMU driver to hook into the KVM

VMID

Quoted 3 lines
Quoted 3 lines

allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command

queue.

Quoted 1 line
Quoted 1 line

"

Quoted 7 lines
Quoted 5 lines

Hm we're already mandating DVM for host SVA, so I'd say mandate it for vSVA as well. We'd avoid a ton of context switches, especially for the zip accelerator which doesn't require ATC invalidations. The host needs to pin the VMID allocated by KVM and write it in the endpoint's STE.

Curious... what is DVM and how is it related to SVA? Is it SMMU specific?

Yes it stands for "Distributed Virtual Memory", an Arm interconnect protocol. When sharing a process address space, TLB invalidations from the CPU are broadcasted to the SMMU, so we don't have to send commands through the SMMU queue to invalidate IOTLBs. However ATCs from PCIe endpoints do not participate in DVM and still have to be invalidated by hand.

Thanks,
Jean

#24 lore raw
Quoted 28 lines

From: Jean-Philippe Brucker <[email protected]>
Sent: Thursday, March 5, 2020 3:34 PM

Quoted 6 lines · Kevin
Quoted 3 lines

From: Jean-Philippe Brucker <[email protected]>
Sent: Thursday, March 5, 2020 12:47 AM

[...]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

* We can't use DVM in nested mode unless the VMID is shared with

the

Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line

CPU. For that we'll need the host SMMU driver to hook into the KVM

VMID

Quoted 3 lines
Quoted 3 lines

allocator, just like we do for the ASID allocator. I haven't yet investigated how to do that. It's possible to do vSVA without DVM though, by sending all TLB invalidations through the SMMU command

queue.

Quoted 1 line
Quoted 1 line

"

Hm we're already mandating DVM for host SVA, so I'd say mandate it for vSVA as well. We'd avoid a ton of context switches, especially for the zip accelerator which doesn't require ATC invalidations. The host needs to

pin

Quoted 4 lines
Quoted 2 lines

the VMID allocated by KVM and write it in the endpoint's STE.

Curious... what is DVM and how is it related to SVA? Is it SMMU specific?

Quoted 8 lines

Yes it stands for "Distributed Virtual Memory", an Arm interconnect protocol. When sharing a process address space, TLB invalidations from the CPU are broadcasted to the SMMU, so we don't have to send commands through
the SMMU queue to invalidate IOTLBs. However ATCs from PCIe endpoints do
not participate in DVM and still have to be invalidated by hand.

ah, got it. Thanks for explanation!