VIRTIO-IOMMU device
v4 cover VIRTIO-IOMMU device
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about the page_size_mask of underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbell
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
The associated VHOST/VFIO adaptation is available on the branch below but is not officially delivered as part of this series.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v2.10.0-virtio-iommu-v4
References:
[1] [RFC] virtio-iommu version 0.4
git://linux-arm.org/virtio-iommu.git branch viommu/v0.4
Testing:
- guest kernel with v0.4 virtio-iommu driver (4kB page)
- tested with guest using virtio-pci-net and vhost-net (,vhost=on/off,iommu_platform,disable-modern=off,disable-legacy=on )
- tested with VFIO and guest assigned with 2 VFs
- tested with DPDK on guest with 2 assigned VFs
Not tested:
- hot-plug/hot-unplug of EP: not implemented
History:
v2-> v4:
- see above
v2 -> v3:
- rebase on top of 2.10-rc0 and especially
[PATCH qemu v9 0/2] memory/iommu: QOM'fy IOMMU MemoryRegion
- add mutex init
- fix as->mappings deletion using g_tree_ref/unref
- when a dev is attached whereas it is already attached to another address space, first detach it
- fix some error values
- page_sizes = TARGET_PAGE_MASK;
- I haven't changed the unmap() semantics yet, waiting for the next virtio-iommu spec revision.
v1 -> v2:
- fix redifinition of viommu_as typedef
Eric Auger (16):
update-linux-headers: import virtio_iommu.h
linux-headers: Update for virtio-iommu
virtio-iommu: add skeleton
virtio-iommu: Decode the command payload
virtio-iommu: Add the iommu regions
virtio-iommu: Register attached devices
virtio-iommu: Implement attach/detach command
virtio-iommu: Implement map/unmap
virtio-iommu: Implement translate
virtio-iommu: Implement probe request
hw/arm/virt: Add 2.11 machine type
hw/arm/virt: Add virtio-iommu to the virt board
memory.h: Add set_page_size_mask IOMMUMemoryRegion callback hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
virtio-iommu: Implement set_page_size_mask
hw/vfio/common: Do not print error when viommu translates into an mmio
region
hw/arm/virt.c | 115 +++- hw/vfio/common.c | 7 +- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 24 + hw/virtio/virtio-iommu.c | 923 ++++++++++++++++++++++++++ include/exec/memory.h | 4 + include/hw/arm/virt.h | 5 + include/hw/vfio/vfio-common.h | 1 + include/hw/virtio/virtio-iommu.h | 61 ++ include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 177 +++++ linux-headers/linux/virtio_iommu.h | 1 + scripts/update-linux-headers.sh | 3 + 13 files changed, 1312 insertions(+), 11 deletions(-) create mode 100644 hw/virtio/virtio-iommu.c create mode 100644 include/hw/virtio/virtio-iommu.h create mode 100644 include/standard-headers/linux/virtio_iommu.h create mode 100644 linux-headers/linux/virtio_iommu.h
Signature · 1 line
2.5.5
RFC v4 1/16 update-linux-headers: import virtio_iommu.h
Update the script to update the virtio_iommu.h header.
--- scripts/update-linux-headers.sh | 3 +++ 1 file changed, 3 insertions(+)
scripts/update-linux-headers.sh +3 -0
@@ -134,6 +134,9 @@ EOF cat <<EOF >$output/linux-headers/linux/virtio_config.h #include "standard-headers/linux/virtio_config.h" EOF +cat <<EOF >$output/linux-headers/linux/virtio_iommu.h +#include "standard-headers/linux/virtio_iommu.h" +EOF cat <<EOF >$output/linux-headers/linux/virtio_ring.h #include "standard-headers/linux/virtio_ring.h" EOF
Signature · 1 line
2.5.5
RFC v4 2/16 linux-headers: Update for virtio-iommu
In reply to Eric AugerThis is a partial linux header update against Jean-Philippe's branch:git://linux-arm.org/linux-jpb.git virtio-iommu/v0.4 (unstable)
---
v3- >v3:
- upgrade the API from v0.1 to v0.4
--- include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 177 ++++++++++++++++++++++++++ linux-headers/linux/virtio_iommu.h | 1 + 3 files changed, 179 insertions(+) create mode 100644 include/standard-headers/linux/virtio_iommu.h create mode 100644 linux-headers/linux/virtio_iommu.h
include/standard-headers/linux/virtio_ids.h +1 -0
@@ -43,5 +43,6 @@#define VIRTIO_ID_INPUT 18/* virtio input */ #define VIRTIO_ID_VSOCK 19/* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20/* virtio crypto */ +#define VIRTIO_ID_IOMMU 61216/* virtio IOMMU (temporary) */ #endif /* _LINUX_VIRTIO_IDS_H */
include/standard-headers/linux/virtio_iommu.h new file +177 -0
177 lines not on this page · raw message
linux-headers/linux/virtio_iommu.h new file +1 -0
@@ -0,0 +1 @@ +#include "standard-headers/linux/virtio_iommu.h"
Signature · 1 line
2.5.5
RFC v4 3/16 virtio-iommu: add skeleton
In reply to Eric AugerThis patchs adds the skeleton for the virtio-iommu device.
---
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
--- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 7 ++ hw/virtio/virtio-iommu.c | 255 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-iommu.h | 59 +++++++++ 4 files changed, 322 insertions(+) create mode 100644 hw/virtio/virtio-iommu.c create mode 100644 include/hw/virtio/virtio-iommu.h
hw/virtio/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ common-obj-y += virtio-mmio.o obj-y += virtio.o virtio-balloon.o obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o +obj-$(CONFIG_LINUX) += virtio-iommu.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o obj-y += virtio-crypto.o obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
hw/virtio/trace-events +7 -0
@@ -25,3 +25,10 @@ virtio_balloon_handle_output(const char *name, uint64_t gpa) "section name: %s g virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages: %d actual: %d" virtio_balloon_set_config(uint32_t actual, uint32_t oldactual) "actual: %d oldactual: %d" virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon target: 0x%"PRIx64" num_pages: %d" + +# hw/virtio/virtio-iommu.c +# +virtio_iommu_set_features(uint64_t features) "features accepted by the driver =0x%"PRIx64 +virtio_iommu_device_reset(void) "reset!" +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, uint8_t ioasid_bits, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" ioasid_bits=%d probe_size=0x%x"
hw/virtio/virtio-iommu.c new file +255 -0
255 lines not on this page · raw message
include/hw/virtio/virtio-iommu.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC v4 4/16 virtio-iommu: Decode the command payload
In reply to Eric AugerThis patch adds the command payload decoding and introduces the functions that will do the actual command handling. Those functions are not yet implemented.
---
v3 -> v4:
- no flags field anymore in struct virtio_iommu_req_unmap
- test reserved on attach/detach, change trace proto
v3 -> v4:
- rebase on v2.10.0.
--- hw/virtio/trace-events | 4 ++ hw/virtio/virtio-iommu.c | 104 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 4 deletions(-)
hw/virtio/trace-events +4 -0
@@ -32,3 +32,7 @@ virtio_iommu_set_features(uint64_t features) "features accepted by the driver =0 virtio_iommu_device_reset(void) "reset!" 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, uint8_t ioasid_bits, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" ioasid_bits=%d probe_size=0x%x" +virtio_iommu_attach(uint32_t as, uint32_t dev) "as=%d dev=%d" +virtio_iommu_detach(uint32_t dev) "dev=%d" +virtio_iommu_map(uint32_t as, uint64_t phys_addr, uint64_t virt_addr, uint64_t size, uint32_t flags) "as= %d phys_addr=0x%"PRIx64" virt_addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d" +virtio_iommu_unmap(uint32_t as, uint64_t virt_addr, uint64_t size) "as= %d virt_addr=0x%"PRIx64" size=0x%"PRIx64
hw/virtio/virtio-iommu.c +100 -4
129 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC v4 5/16 virtio-iommu: Add the iommu regions
In reply to Eric AugerThis patch initializes the iommu memory regions so that PCIe end point transactions get translated. The translation function is not yet implemented at that stage.
---
v3 -> v4:
- add trace_virtio_iommu_init_iommu_mr
v2 -> v3:
- use IOMMUMemoryRegion
- iommu mr name built with BDF
- rename smmu_get_sid into virtio_iommu_get_sid and use PCI_BUILD_BDF
--- hw/virtio/trace-events | 2 + hw/virtio/virtio-iommu.c | 119 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-iommu.h | 2 + 3 files changed, 123 insertions(+)
hw/virtio/trace-events +2 -0
@@ -36,3 +36,5 @@ virtio_iommu_attach(uint32_t as, uint32_t dev) "as=%d dev=%d" virtio_iommu_detach(uint32_t dev) "dev=%d" virtio_iommu_map(uint32_t as, uint64_t phys_addr, uint64_t virt_addr, uint64_t size, uint32_t flags) "as= %d phys_addr=0x%"PRIx64" virt_addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d" virtio_iommu_unmap(uint32_t as, uint64_t virt_addr, uint64_t size) "as= %d virt_addr=0x%"PRIx64" size=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"
hw/virtio/virtio-iommu.c +119 -0
164 lines not on this page · raw message
include/hw/virtio/virtio-iommu.h +2 -0
@@ -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" +#define IOMMU_PCI_BUS_MAX 256#define IOMMU_PCI_DEVFN_MAX 256
Signature · 1 line
2.5.5
RFC v4 6/16 virtio-iommu: Register attached devices
In reply to Eric AugerThis patch introduce address space and device internal datatypes. Both are stored in RB trees. The address space owns a list of devices attached to it.
It is assumed the devid corresponds to the PCI BDF.
---
v3 -> v4:
- new separate patch
--- hw/virtio/trace-events | 4 ++ hw/virtio/virtio-iommu.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+)
hw/virtio/trace-events +4 -0
@@ -38,3 +38,7 @@ virtio_iommu_map(uint32_t as, uint64_t phys_addr, uint64_t virt_addr, uint64_t s virtio_iommu_unmap(uint32_t as, uint64_t virt_addr, uint64_t size) "as= %d virt_addr=0x%"PRIx64" size=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_dev(uint32_t devid) "Alloc devid=%d" +virtio_iommu_put_dev(uint32_t devid) "Free devid=%d" +virtio_iommu_get_as(uint32_t asid) "Alloc asid=%d" +virtio_iommu_put_as(uint32_t asid) "Free asid=%d"
hw/virtio/virtio-iommu.c +120 -0
164 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC v4 7/16 virtio-iommu: Implement attach/detach command
In reply to Eric AugerThis patch implements the device attach/detach to an address space.
--- hw/virtio/virtio-iommu.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
hw/virtio/virtio-iommu.c +32 -6
@@ -110,8 +110,7 @@ static void virtio_iommu_put_dev(gpointer data)g_free (dev); } -viommu_as *virtio_iommu_get_as (VirtIOIOMMU *s,uint32_t asid); -viommu_as *virtio_iommu_get_as (VirtIOIOMMU *s,uint32_t asid) +static viommu_as *virtio_iommu_get_as (VirtIOIOMMU *s,uint32_t asid) {viommu_as *as;
@@ -205,6 +204,8 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,uint32_t asid =le32_to_cpu (req->address_space);uint32_t devid =le32_to_cpu (req->device);uint32_t reserved =le32_to_cpu (req->reserved); +viommu_as *as; +viommu_dev *dev;trace_virtio_iommu_attach (asid, devid);
@@ -212,7 +213,22 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,return VIRTIO_IOMMU_S_INVAL ; } -return VIRTIO_IOMMU_S_UNSUPP ; + dev =virtio_iommu_get_dev (s, devid); +if (dev->as) { +/* +* the device is already attached to an address space, +* detach it first +*/ +virtio_iommu_detach_dev_from_as (dev); + } + + as =virtio_iommu_get_as (s, asid); +QLIST_INSERT_HEAD (&as->device_list, dev, next); + + dev->as = as; +g_tree_ref (as->mappings); + +return VIRTIO_IOMMU_S_OK ; } static int virtio_iommu_detach(VirtIOIOMMU *s,
@@ -220,14 +236,24 @@ static int virtio_iommu_detach(VirtIOIOMMU *s, {uint32_t devid =le32_to_cpu (req->device);uint32_t reserved =le32_to_cpu (req->reserved); - -trace_virtio_iommu_detach (devid); +viommu_dev *dev;if (reserved) {return VIRTIO_IOMMU_S_INVAL ; } -return VIRTIO_IOMMU_S_UNSUPP ; + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (!dev) { +return VIRTIO_IOMMU_S_NOENT ; + } + +if (!dev->as) { +return VIRTIO_IOMMU_S_INVAL ; + } + +virtio_iommu_detach_dev_from_as (dev); +trace_virtio_iommu_detach (devid); +return VIRTIO_IOMMU_S_OK ; } static int virtio_iommu_map(VirtIOIOMMU *s,
Signature · 1 line
2.5.5
RFC v4 8/16 virtio-iommu: Implement map/unmap
In reply to Eric AugerThis patch implements virtio_iommu_map/unmap.
---
v3 -> v4:
- implement unmap semantics as specified in v0.4
--- hw/virtio/trace-events | 3 ++ hw/virtio/virtio-iommu.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 2 deletions(-)
hw/virtio/trace-events +3 -0
@@ -42,3 +42,6 @@ virtio_iommu_get_dev(uint32_t devid) "Alloc devid=%d" virtio_iommu_put_dev(uint32_t devid) "Free devid=%d" virtio_iommu_get_as(uint32_t asid) "Alloc asid=%d" virtio_iommu_put_as(uint32_t asid) "Free asid=%d" +virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap left [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]"
hw/virtio/virtio-iommu.c +89 -2
115 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC v4 9/16 virtio-iommu: Implement translate
In reply to Eric AugerThis patch implements the translate callback
--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)
hw/virtio/trace-events +1 -0
@@ -45,3 +45,4 @@ virtio_iommu_put_as(uint32_t asid) "Free asid=%d" virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap left [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]" +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 +37 -2
@@ -496,19 +496,54 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag) {IOMMUDevice *sdev =container_of (mr, IOMMUDevice, iommu_mr); +VirtIOIOMMU *s = sdev->viommu;uint32_t sid; +viommu_dev *dev; +viommu_mapping *mapping; +viommu_interval interval; + + interval.low = addr; + interval.high = addr +1 ;IOMMUTLBEntry entry = { .target_as = &address_space_memory, .iova = addr, .translated_addr = addr, - .addr_mask = ~(hwaddr )0 , - .perm =IOMMU_NONE , + .addr_mask = (1 <<ctz32 (s->config.page_size_mask)) -1 , + .perm = flag, }; sid =virtio_iommu_get_sid (sdev);trace_virtio_iommu_translate (mr->parent_obj.name, sid, addr, flag); +qemu_mutex_lock (&s->mutex); + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (sid)); +if (!dev) { +/* device cannot be attached to another as */ +printf ("%s sid=%d is not known!!\n" , __func__, sid); + goto unlock; + } + + mapping =g_tree_lookup (dev->as->mappings, (gpointer)(&interval)); +if (!mapping) { +printf ("%s no mapping for 0x%" PRIx64" for sid=%d\n" , __func__, + addr, sid); + goto unlock; + } + +if (((flag &IOMMU_RO ) && !(mapping->flags &VIRTIO_IOMMU_MAP_F_READ )) || + ((flag &IOMMU_WO ) && !(mapping->flags &VIRTIO_IOMMU_MAP_F_WRITE ))) { +error_report ("Permission error on 0x%" PRIx64"(%d): allowed=%d" , + addr, flag, mapping->flags); + entry.perm =IOMMU_NONE ; + goto unlock; + } + entry.translated_addr = addr - mapping->virt_addr + mapping->phys_addr, +trace_virtio_iommu_translate_out (addr, entry.translated_addr, sid); + +unlock: +qemu_mutex_unlock (&s->mutex);return entry; }
Signature · 1 line
2.5.5
RFC v4 10/16 virtio-iommu: Implement probe request
In reply to Eric AugerThis patch implements the PROBE request. At the moment, no reserved regions are returned.
At the moment reserved regions are stored per device.
---
Waiting for clarifications on v0.4 spec
--- hw/virtio/trace-events | 2 + hw/virtio/virtio-iommu.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 2 deletions(-)
hw/virtio/trace-events +2 -0
@@ -46,3 +46,5 @@ virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" +virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) "dev= %d, subtype=%d addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d filled=0x%lx" +virtio_iommu_fill_none_property(uint32_t devid) "devid=%d"
hw/virtio/virtio-iommu.c +171 -2
241 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC v4 11/16 hw/arm/virt: Add 2.11 machine type
In reply to Eric AugerThe new machine type allows virtio-iommu instantiation.
---
--- hw/arm/virt.c | 23 +++++++++++++++++++++-- include/hw/arm/virt.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-)
hw/arm/virt.c +21 -2
@@ -1648,7 +1648,7 @@ static void machvirt_machine_init(void) }type_init (machvirt_machine_init); -static void virt_2_10_instance_init (Object *obj) +static void virt_2_11_instance_init (Object *obj) {VirtMachineState *vms =VIRT_MACHINE (obj);VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms);
@@ -1708,10 +1708,29 @@ static void virt_2_10_instance_init(Object *obj) vms->irqmap = a15irqmap; } +static void virt_machine_2_11_options (MachineClass *mc) +{ +} +DEFINE_VIRT_MACHINE_AS_LATEST(2, 11) + +#define VIRT_COMPAT_2_10 \ + HW_COMPAT_2_10 + +static void virt_2_10_instance_init (Object *obj) +{ +virt_2_11_instance_init (obj); +} +static void virt_machine_2_10_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); + +virt_machine_2_11_options (mc); +SET_MACHINE_COMPAT (mc,VIRT_COMPAT_2_10 ); + + vmc->no_iommu = true; } -DEFINE_VIRT_MACHINE_AS_LATEST(2, 10) +DEFINE_VIRT_MACHINE(2, 10)#define VIRT_COMPAT_2_9 \ HW_COMPAT_2_9
include/hw/arm/virt.h +1 -0
@@ -84,6 +84,7 @@ typedef struct {bool disallow_affinity_adjustment;bool no_its;bool no_pmu; +bool no_iommu;bool claim_edge_triggered_timers; } VirtMachineClass;
Signature · 1 line
2.5.5
RFC v4 12/16 hw/arm/virt: Add virtio-iommu to the virt board
In reply to Eric AugerThe specific virtio-mmio node is inconditionally added on machine init while the binding between this latter and the PCIe host bridge is done on machine init done notifier, only if -device virtio-iommu-device was added to the qemu command line.
---
--- hw/arm/virt.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++---- include/hw/arm/virt.h | 4 +++ 2 files changed, 89 insertions(+), 7 deletions(-)
hw/arm/virt.c +85 -7
@@ -52,6 +52,7 @@#include "hw/arm/fdt.h" #include "hw/intc/arm_gic.h" #include "hw/intc/arm_gicv3_common.h" +#include "hw/virtio/virtio-iommu.h" #include "kvm_arm.h" #include "hw/smbios/smbios.h" #include "qapi/visitor.h"
@@ -139,6 +140,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_FW_CFG] = { 0x09020000, 0x00000018 }, [VIRT_GPIO] = { 0x09030000, 0x00001000 }, [VIRT_SECURE_UART] = { 0x09040000, 0x00001000 }, + [VIRT_IOMMU] = { 0x09050000, 0x00000200 }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -159,6 +161,7 @@ static const int a15irqmap[] = { [VIRT_SECURE_UART] = 8, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ + [VIRT_IOMMU] = 74, [VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ };
@@ -999,7 +1002,81 @@ static void create_pcie_irq_map(const VirtMachineState *vms, 0x7 /* PCI irq */); } -static void create_pcie (const VirtMachineState *vms,qemu_irq *pic) +static int bind_virtio_iommu_device (Object *obj,void *opaque) +{ +VirtMachineState *vms = (VirtMachineState *)opaque; +struct arm_boot_info *info = &vms->bootinfo; +int dtb_size; +void *fdt = info->get_dtb (info, &dtb_size); +Object *dev; + + dev =object_dynamic_cast (obj,TYPE_VIRTIO_IOMMU ); + +if (!dev) { +/* Container, traverse it for children */ +return object_child_foreach (obj, bind_virtio_iommu_device, opaque); + } + +qemu_fdt_setprop_cells (fdt, vms->pcie_host_nodename,"iommu-map" , +0x0 , vms->iommu_phandle,0x0 ,0x10000 ); + +return true; +} + +static +void virtio_iommu_notifier (Notifier *notifier,void *data) +{ +VirtMachineState *vms =container_of (notifier, VirtMachineState, + virtio_iommu_done); +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms); +Object *container; + + +if (vmc->no_iommu) { +return ; + } + + container =container_get (qdev_get_machine (),"/peripheral" ); +bind_virtio_iommu_device (container, vms); + container =container_get (qdev_get_machine (),"/peripheral-anon" ); +bind_virtio_iommu_device (container, vms); +} + +static void create_virtio_iommu (VirtMachineState *vms,qemu_irq *pic) +{ +char *smmu; +const char compat[] ="virtio,mmio" ; +int irq = vms->irqmap[VIRT_IOMMU ]; +hwaddr base = vms->memmap[VIRT_IOMMU ].base; +hwaddr size = vms->memmap[VIRT_IOMMU ].size; +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms); + +if (vmc->no_iommu) { +return ; + } + + vms->iommu_phandle =qemu_fdt_alloc_phandle (vms->fdt); + +sysbus_create_simple ("virtio-mmio" , base, pic[irq]); + + smmu =g_strdup_printf ("/virtio_mmio@%" PRIx64, base); +qemu_fdt_add_subnode (vms->fdt, smmu); +qemu_fdt_setprop (vms->fdt, smmu,"compatible" , compat,sizeof (compat)); +qemu_fdt_setprop_sized_cells (vms->fdt, smmu,"reg" ,2 , base,2 , size); + +qemu_fdt_setprop_cells (vms->fdt, smmu,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI ); + +qemu_fdt_setprop (vms->fdt, smmu,"dma-coherent" ,NULL ,0 ); +qemu_fdt_setprop_cell (vms->fdt, smmu,"#iommu-cells" ,1 ); +qemu_fdt_setprop_cell (vms->fdt, smmu,"phandle" , vms->iommu_phandle); +g_free (smmu); + + vms->virtio_iommu_done.notify = virtio_iommu_notifier; +qemu_add_machine_init_done_notifier (&vms->virtio_iommu_done); +} + +static void create_pcie (VirtMachineState *vms,qemu_irq *pic) {hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO ].base;hwaddr size_mmio = vms->memmap[VIRT_PCIE_MMIO ].size;
@@ -1073,7 +1150,8 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic) } } - nodename =g_strdup_printf ("/pcie@%" PRIx64, base); + vms->pcie_host_nodename =g_strdup_printf ("/pcie@%" PRIx64, base); + nodename = vms->pcie_host_nodename;qemu_fdt_add_subnode (vms->fdt, nodename);qemu_fdt_setprop_string (vms->fdt, nodename,"compatible" ,"pci-host-ecam-generic" );
@@ -1112,7 +1190,6 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic)qemu_fdt_setprop_cell (vms->fdt, nodename,"#interrupt-cells" ,1 );create_pcie_irq_map (vms, vms->gic_phandle, irq, nodename); -g_free (nodename); }static void create_platform_bus (VirtMachineState *vms,qemu_irq *pic)
@@ -1457,16 +1534,16 @@ static void machvirt_init(MachineState *machine)create_rtc (vms, pic); -create_pcie (vms, pic); - -create_gpio (vms, pic); -/* Create mmio transports, so the user can create virtio backends * (which will be automatically plugged in to the transports). If * no backend is created the transport will just sit harmlessly idle. */ create_virtio_devices (vms, pic); +create_pcie (vms, pic); + +create_gpio (vms, pic); + vms->fw_cfg =create_fw_cfg (vms, &address_space_memory);rom_set_fw (vms->fw_cfg);
@@ -1491,6 +1568,7 @@ static void machvirt_init(MachineState *machine)* Notifiers are executed in registration reverse order. */ create_platform_bus (vms, pic); +create_virtio_iommu (vms, pic); }static bool virt_get_secure (Object *obj,Error **errp)
include/hw/arm/virt.h +4 -0
@@ -59,6 +59,7 @@ enum {VIRT_GIC_V2M ,VIRT_GIC_ITS ,VIRT_GIC_REDIST , +VIRT_IOMMU ,VIRT_UART ,VIRT_MMIO , VIRT_RTC,
@@ -91,6 +92,7 @@ typedef struct { typedef struct { MachineState parent; Notifier machine_done; + Notifier virtio_iommu_done; FWCfgState *fw_cfg; bool secure; bool highmem;
@@ -106,6 +108,8 @@ typedef struct {uint32_t clock_phandle;uint32_t gic_phandle;uint32_t msi_phandle; +uint32_t iommu_phandle; +char *pcie_host_nodename;int psci_conduit; } VirtMachineState;
Signature · 1 line
2.5.5
RFC v4 13/16 memory.h: Add set_page_size_mask IOMMUMemoryRegion callback
In reply to Eric AugerThis callback allows to inform the IOMMU memory region about restrictions on the supported page sizes.
--- include/exec/memory.h | 4 ++++ 1 file changed, 4 insertions(+)
include/exec/memory.h +4 -0
@@ -204,6 +204,10 @@ typedef struct IOMMUMemoryRegionClass { IOMMUAccessFlags flag);/* Returns minimum supported page size */ uint64_t (*get_min_page_size)(IOMMUMemoryRegion *iommu); + +/* Limits the supported page sizes to @pgsizes */ +void (*set_page_size_mask)(IOMMUMemoryRegion *iommu,uint64_t pgsizes); +/* Called when IOMMU Notifier flag changed */ void (*notify_flag_changed)(IOMMUMemoryRegion *iommu, IOMMUNotifierFlag old_flags,
Signature · 1 line
2.5.5
RFC v4 14/16 hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
In reply to Eric AugerWe store the page_size_mask in the container and on vfio_listener_region_add(), the information is conveyed to the IOMMUMemoryRegion.
--- hw/vfio/common.c | 5 +++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 6 insertions(+)
hw/vfio/common.c +5 -0
@@ -480,6 +480,7 @@ static void vfio_listener_region_add(MemoryListener *listener,if (memory_region_is_iommu (section->mr)) {VFIOGuestIOMMU *giommu;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); +IOMMUMemoryRegionClass *imrc =IOMMU_MEMORY_REGION_GET_CLASS (iommu_mr);trace_vfio_listener_region_add_iommu (iova, end);/*
@@ -500,6 +501,9 @@ static void vfio_listener_region_add(MemoryListener *listener,IOMMU_NOTIFIER_ALL , section->offset_within_region, int128_get64(llend)); +if (imrc->set_page_size_mask) { + imrc->set_page_size_mask (iommu_mr, container->page_size_mask); + }QLIST_INSERT_HEAD (&container->giommu_list, giommu, giommu_next);memory_region_register_iommu_notifier (section->mr, &giommu->n);
@@ -1024,6 +1028,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,/* Assume 4k IOVA page size */ info.iova_pgsizes =4096 ; } + container->page_size_mask = info.iova_pgsizes;vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {
include/hw/vfio/vfio-common.h +1 -0
@@ -79,6 +79,7 @@ typedef struct VFIOContainer {int fd;/* /dev/vfio/vfio, empowered by the attached groups */ MemoryListener listener;MemoryListener prereg_listener; +uint64_t page_size_mask;/* page sizes supported for this container */ unsigned iommu_type;int error;bool initialized;
Signature · 1 line
2.5.5
RFC v4 15/16 virtio-iommu: Implement set_page_size_mask
In reply to Eric AugerWe implement the set_page_size_mask callback to allow the virtio-iommu to be aware of any restrictions on the page size mask due to an underlying HW IOMMU.
--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
hw/virtio/trace-events +1 -0
@@ -48,3 +48,4 @@ virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRI virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) "dev= %d, subtype=%d addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d filled=0x%lx" virtio_iommu_fill_none_property(uint32_t devid) "devid=%d" +virtio_iommu_set_page_size_mask(const char *iommu_mr, uint64_t mask) "mr=%s page_size_mask=0x%"PRIx64
hw/virtio/virtio-iommu.c +16 -0
@@ -714,6 +714,21 @@ unlock:return entry; } +static void virtio_iommu_set_page_size_mask (IOMMUMemoryRegion *mr, +uint64_t page_size_mask) +{ +IOMMUDevice *sdev =container_of (mr, IOMMUDevice, iommu_mr); +VirtIOIOMMU *s = sdev->viommu; + + s->config.page_size_mask &= page_size_mask; +if (!s->config.page_size_mask) { +error_setg (&error_fatal, +"No compatible page size between guest and host iommus" ); + } + +trace_virtio_iommu_set_page_size_mask (mr->parent_obj.name, page_size_mask); +} +static void virtio_iommu_get_config (VirtIODevice *vdev,uint8_t *config_data) {VirtIOIOMMU *dev =VIRTIO_IOMMU (vdev);
@@ -881,6 +896,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,IOMMUMemoryRegionClass *imrc =IOMMU_MEMORY_REGION_CLASS (klass); imrc->translate = virtio_iommu_translate; + imrc->set_page_size_mask = virtio_iommu_set_page_size_mask; }static const TypeInfo virtio_iommu_info = {
Signature · 1 line
2.5.5
RFC v4 16/16 hw/vfio/common: Do not print error when viommu translates into an mmio region
In reply to Eric AugerOn ARM, the MSI doorbell is translated by the virtual IOMMU. As such address_space_translate() returns the MSI controller MMIO region and we get an "iommu map to non memory area" message. Let's remove this latter.
--- hw/vfio/common.c | 2 -- 1 file changed, 2 deletions(-)
hw/vfio/common.c +0 -2
@@ -326,8 +326,6 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr, iotlb->translated_addr, &xlat, &len, writable);if (!memory_region_is_ram (mr)) { -error_report ("iommu map to non memory area %" HWADDR_PRIx"" , - xlat);return false; }
Signature · 1 line
2.5.5
Re: [Qemu-arm] [RFC v4 09/16] virtio-iommu: Implement translate
In reply to Eric AugerQuoted 69 lines
-----Original Message-----
From: Eric Auger [mailto:[email protected]]
Sent: Tuesday, September 19, 2017 1:17 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jean- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bharat Bhushan <[email protected]>; [email protected]; [email protected]
Subject: [RFC v4 09/16] virtio-iommu: Implement translateThis patch implements the translate callback
Signed-off-by Eric Auger <[email protected]>--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)hw/virtio/trace-events index renamed from hw/virtio/trace-events +0
-0da298c1..9010fbd 100644
hw/virtio/trace-events +0
-0@@ -45,3 +45,4 @@ virtio_iommu_put_as(uint32_t asid) "Free asid=%d" virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap left [0x%"PRIx64",0x%"PRIx64"],new interval=[0x%"PRIx64",0x%"PRIx64"]"
virtio_iommu_unmap_right_interval(uint64_t low,uint64_thigh,uint64_tnext_low,uint64_tnext_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]"
virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high)"Unmap inc
[0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_translate_out(uint64_tvirt_addr,uint64_tphys_addr,uint32_tsid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d"hw/virtio/virtio-iommu.c index renamed from hw/virtio/virtio-iommu.c +0
-06f1a7d1..db46a91 100644
hw/virtio/virtio-iommu.c +9
-2@@ -496,19 +496,54 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag) {IOMMUDevice *sdev =container_of (mr, IOMMUDevice, iommu_mr); +VirtIOIOMMU *s = sdev->viommu;uint32_t sid; +viommu_dev *dev; +viommu_mapping *mapping; +viommu_interval interval; + + interval.low = addr; + interval.high = addr +1 ;IOMMUTLBEntry entry = { .target_as = &address_space_memory, .iova = addr, .translated_addr = addr, - .addr_mask = ~(hwaddr )0 , - .perm =IOMMU_NONE , + .addr_mask = (1 <<ctz32 (s->config.page_size_mask)) -1 , + .perm = flag, }; sid =virtio_iommu_get_sid (sdev);trace_virtio_iommu_translate (mr->parent_obj.name, sid, addr, flag);
hw/virtio/virtio-iommu.c static IOMMUTLBEntry · line 528
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+qemu_mutex_lock (&s->mutex); + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (sid)); +if (!dev) { +/* device cannot be attached to another as */ +printf ("%s sid=%d is not known!!\n" , __func__, sid); + goto unlock; + } + + mapping =g_tree_lookup (dev->as->mappings, (gpointer)(&interval));
Should check of !dev->as before accessing this.
Thanks
-Bharat
Quoted 26 lines
hw/virtio/virtio-iommu.c +7
-0+if (!mapping) { +printf ("%s no mapping for 0x%" PRIx64" for sid=%d\n" , __func__, + addr, sid); + goto unlock; + } + + if (((flag & IOMMU_RO) && !(mapping->flags &
VIRTIO_IOMMU_MAP_F_READ)) ||
+ ((flag &IOMMU_WO) && !(mapping->flags &VIRTIO_IOMMU_MAP_F_WRITE))) {hw/virtio/virtio-iommu.c +6
-0+error_report ("Permission error on 0x%" PRIx64"(%d): allowed=%d" , + addr, flag, mapping->flags); + entry.perm =IOMMU_NONE ; + goto unlock; + } + entry.translated_addr = addr - mapping->virt_addr + mapping-Quoted 1 line
phys_addr,hw/virtio/virtio-iommu.c +4
-1+trace_virtio_iommu_translate_out (addr, entry.translated_addr, sid); + +unlock: +qemu_mutex_unlock (&s->mutex);return entry; } --2.5.5
Re: [Qemu-arm] [RFC v4 06/16] virtio-iommu: Register attached devices
In reply to Eric AugerQuoted 136 lines
-----Original Message-----
From: Eric Auger [mailto:[email protected]]
Sent: Tuesday, September 19, 2017 1:17 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jean- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bharat Bhushan <[email protected]>; [email protected]; [email protected]
Subject: [RFC v4 06/16] virtio-iommu: Register attached devicesThis patch introduce address space and device internal datatypes. Both are stored in RB trees. The address space owns a list of devices attached to it.
It is assumed the devid corresponds to the PCI BDF.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- new separate patch--- hw/virtio/trace-events | 4 ++ hw/virtio/virtio-iommu.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+)hw/virtio/trace-events +0
-0@@ -38,3 +38,7 @@ virtio_iommu_map(uint32_t as, uint64_t phys_addr,
uint64_tvirt_addr,uint64_ts
virtio_iommu_unmap(uint32_t as, uint64_t virt_addr, uint64_t size)"as= %d
virt_addr=0x%"PRIx64" size=0x%"PRIx64
virtio_iommu_translate(const char *name,uint32_trid,uint64_tiova, int
flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d"
virtio_iommu_init_iommu_mr(char *iommu_mr)"init %s"hw/virtio/trace-events +4
-0+virtio_iommu_get_dev(uint32_t devid) "Alloc devid=%d" +virtio_iommu_put_dev(uint32_t devid) "Free devid=%d" +virtio_iommu_get_as(uint32_t asid) "Alloc asid=%d" +virtio_iommu_put_as(uint32_t asid) "Free asid=%d"hw/virtio/virtio-iommu.c +70
-0@@ -32,15 +32,116 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" /* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +typedef struct viommu_as { +uint32_t id; +GTree *mappings; + QLIST_HEAD(, viommu_dev) device_list; +}viommu_as ; + +typedef struct viommu_dev { +uint32_t id; +viommu_as *as; +QLIST_ENTRY (viommu_dev) next; +VirtIOIOMMU *viommu; +}viommu_dev ; + +typedef struct viommu_interval { +uint64_t low; +uint64_t high; +}viommu_interval ; +static inline uint16_t virtio_iommu_get_sid (IOMMUDevice *dev) {return PCI_BUILD_BDF (pci_bus_num (dev->bus), dev->devfn); } +static gint interval_cmp (gconstpointer a,gconstpointer b,gpointer user_data) +{ +viommu_interval *inta = (viommu_interval *)a; +viommu_interval *intb = (viommu_interval *)b; + +if (inta->high <= intb->low) { +return -1 ; + }else if (intb->high <= inta->low) { +return 1 ; + }else { +return 0 ; + } +} + +static void virtio_iommu_detach_dev_from_as (viommu_dev *dev) +{ +QLIST_REMOVE (dev, next); + dev->as =NULL ; +} + +static viommu_dev *virtio_iommu_get_dev (VirtIOIOMMU *s,uint32_t devid) +{ +viommu_dev *dev; + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (dev) { +return dev; + } + dev =g_malloc0 (sizeof (*dev)); + dev->id = devid; + dev->viommu = s; +trace_virtio_iommu_get_dev (devid); +g_tree_insert (s->devices,GUINT_TO_POINTER (devid), dev); +return dev; +} + +static void virtio_iommu_put_dev (gpointer data) +{ +viommu_dev *dev = (viommu_dev *)data; + +if (dev->as) { +virtio_iommu_detach_dev_from_as (dev); +g_tree_unref (dev->as->mappings); + } + +trace_virtio_iommu_put_dev (dev->id); +g_free (dev); +} + +viommu_as *virtio_iommu_get_as (VirtIOIOMMU *s,uint32_t asid);
hw/virtio/virtio-iommu.c line 125
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+viommu_as *virtio_iommu_get_as (VirtIOIOMMU *s,uint32_t asid) +{ +viommu_as *as; + + as =g_tree_lookup (s->address_spaces,GUINT_TO_POINTER (asid)); +if (as) { +return as; + } + as =g_malloc0 (sizeof (*as)); + as->id = asid;
I see now you maintain device-list in address-space in your base patches, but I do not see where it is initialized? Should not that be initialized here (vfio integration patches initialized here).
Thanks
-Bharat
Quoted 81 lines
hw/virtio/virtio-iommu.c +21
-0+ as->mappings =g_tree_new_full ((GCompareDataFunc )interval_cmp, +NULL , (GDestroyNotify )g_free, + (GDestroyNotify )g_free); +g_tree_insert (s->address_spaces,GUINT_TO_POINTER (asid), as); +trace_virtio_iommu_get_as (asid); +return as; +} + +static void virtio_iommu_put_as (gpointer data) +{ +viommu_as *as = (viommu_as *)data; +viommu_dev *iter, *tmp; + + QLIST_FOREACH_SAFE(iter, &as->device_list, next, tmp) { +virtio_iommu_detach_dev_from_as (iter); + } +g_tree_destroy (as->mappings); +trace_virtio_iommu_put_as (as->id); +g_free (as); +} + static AddressSpace *virtio_iommu_find_add_as(PCIBus *bus, void*opaque,
int devfn)
{hw/virtio/virtio-iommu.c +2
-0@@ -70,6 +171,8 @@ static AddressSpace *virtio_iommu_find_add_as (PCIBus *bus, void *opaque, sdev->bus = bus; sdev->devfn = devfn; +virtio_iommu_get_dev (s,PCI_BUILD_BDF (pci_bus_num (bus), devfn)); +trace_virtio_iommu_init_iommu_mr (name);memory_region_init_iommu(&sdev->iommu_mr, sizeof(sdev-Quoted 1 line
iommu_mr),hw/virtio/virtio-iommu.c +17
-0@@ -360,6 +463,12 @@ static inline guint as_uint64_hash(gconstpointer v)return (guint)*(const uint64_t *)v; } +static gint int_cmp (gconstpointer a,gconstpointer b,gpointer user_data) +{ +uint ua =GPOINTER_TO_UINT (a); +uint ub =GPOINTER_TO_UINT (b); +return (ua > ub) - (ua < ub); +}static void virtio_iommu_device_realize (DeviceState *dev,Error **errp) {@@ -375,17 +484,28 @@ static voidvirtio_iommu_device_realize (DeviceState *dev, Error **errp) s->config.page_size_mask = TARGET_PAGE_MASK; s->config.input_range.end =-1UL ; +qemu_mutex_init (&s->mutex); +memset (s->as_by_bus_num,0 ,sizeof (s->as_by_bus_num)); s->as_by_busptr =g_hash_table_new_full (as_uint64_hash, as_uint64_equal, g_free, g_free); + s->address_spaces =g_tree_new_full ((GCompareDataFunc )int_cmp, +NULL ,NULL , virtio_iommu_put_as); + s->devices =g_tree_new_full ((GCompareDataFunc )int_cmp, +NULL ,NULL , virtio_iommu_put_dev); +virtio_iommu_init_as (s); }static void virtio_iommu_device_unrealize (DeviceState *dev,Error **errp) {VirtIODevice *vdev =VIRTIO_DEVICE (dev); +VirtIOIOMMU *s =VIRTIO_IOMMU (dev); + +g_tree_destroy (s->address_spaces); +g_tree_destroy (s->devices);virtio_cleanup (vdev);}
--
2.5.5
Re: [Qemu-arm] [RFC v4 10/16] virtio-iommu: Implement probe request
In reply to Eric AugerHi Eric,
Quoted 9 lines · Eric Auger
This patch implements the PROBE request. At the moment, no reserved regions are returned.
At the moment reserved regions are stored per device.
Signed-off-by Eric Auger <[email protected]>---
[...]
Quoted 48 lines
hw/virtio/virtio-iommu.c +48
-0+ +static int virtio_iommu_fill_property (int devid,int type, +viommu_property_buffer *bufstate) +{ +int ret = -ENOSPC ; + +if (bufstate->filled +4 >=VIOMMU_PROBE_SIZE ) { + bufstate->error = true; + goto out; + } + +switch (type) { +case VIRTIO_IOMMU_PROBE_T_NONE : + ret =virtio_iommu_fill_none_prop (bufstate); +break ; +case VIRTIO_IOMMU_PROBE_T_RESV_MEM : + { +viommu_dev *dev = bufstate->dev; + +g_tree_foreach (dev->reserved_regions, + virtio_iommu_fill_resv_mem_prop, + bufstate); +if (!bufstate->error) { + ret =0 ; + } +break ; + } +default : + ret = -ENOENT ; +break ; + } +out: +if (ret) { +error_report ("%s property of type=%d could not be filled (%d)," +" remaining size = 0x%lx" , + __func__, type, ret, bufstate->filled); + } +return ret; +} + +static int virtio_iommu_probe (VirtIOIOMMU *s, +struct virtio_iommu_req_probe *req, +uint8_t *buf) +{ +uint32_t devid =le32_to_cpu (req->device); +int16_t prop_types =SUPPORTED_PROBE_PROPERTIES , type; +viommu_property_buffer bufstate; +viommu_dev *dev;
hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 492
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+int ret; + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (!dev) { +return -EINVAL ; + } + + bufstate.start = buf; + bufstate.filled =0 ; + bufstate.dev = dev;
bufstate.error is not initialized which may cause false alarm in virtio_iommu_fill_property()
Quoted 17 lines
hw/virtio/virtio-iommu.c +13
-0+ +while ((type =ctz32 (prop_types)) !=32 ) { + ret =virtio_iommu_fill_property (devid,1 << type, &bufstate); +if (ret) { +break ; + } + prop_types &= ~(1 << type); + } +virtio_iommu_fill_property (devid,VIRTIO_IOMMU_PROBE_T_NONE , &bufstate); + +return VIRTIO_IOMMU_S_OK ; +} +#define get_payload_size (req) (\ sizeof((req)) - sizeof(struct virtio_iommu_req_tail))
hw/virtio/virtio-iommu.c static int virtio_iommu_handle_unmap(VirtIOIOMMU *s, · line 568
Quoted 2 lines
hw/virtio/virtio-iommu.c +0
-0@@ -433,6 +567,24 @@ static int virtio_iommu_handle_unmap(VirtIOIOMMU *s,return virtio_iommu_unmap (s, &req); }
Thanks,
Tomasz
Re: [Qemu-arm] [RFC v4 10/16] virtio-iommu: Implement probe request
Quoted 82 lines
-----Original Message-----
From: Tomasz Nowicki [mailto:[email protected]]
Sent: Wednesday, September 27, 2017 4:23 PM
To: Eric Auger <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jean- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bharat Bhushan <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC v4 10/16] virtio-iommu: Implement probe requestHi Eric,
Quoted 9 lines · Eric Auger
This patch implements the PROBE request. At the moment, no reserved regions are returned.
At the moment reserved regions are stored per device.
Signed-off-by Eric Auger <[email protected]>---
[...]
Quoted 52 lines
hw/virtio/virtio-iommu.c +52
-0+ +static int virtio_iommu_fill_property (int devid,int type, +viommu_property_buffer +*bufstate) { +int ret = -ENOSPC ; + +if (bufstate->filled +4 >=VIOMMU_PROBE_SIZE ) { + bufstate->error = true; + goto out; + } + +switch (type) { +case VIRTIO_IOMMU_PROBE_T_NONE : + ret =virtio_iommu_fill_none_prop (bufstate); +break ; +case VIRTIO_IOMMU_PROBE_T_RESV_MEM : + { +viommu_dev *dev = bufstate->dev; + +g_tree_foreach (dev->reserved_regions, + virtio_iommu_fill_resv_mem_prop, + bufstate); +if (!bufstate->error) { + ret =0 ; + } +break ; + } +default : + ret = -ENOENT ; +break ; + } +out: +if (ret) { +error_report ("%s property of type=%d could not be filled (%d)," +" remaining size = 0x%lx" , + __func__, type, ret, bufstate->filled); + } +return ret; +} + +static int virtio_iommu_probe (VirtIOIOMMU *s, +struct virtio_iommu_req_probe *req, +uint8_t *buf) { +uint32_t devid =le32_to_cpu (req->device); +int16_t prop_types =SUPPORTED_PROBE_PROPERTIES , type; +viommu_property_buffer bufstate; +viommu_dev *dev; +int ret; + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (!dev) { +return -EINVAL ;
Quoted 8 lines
hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 492
Quoted 5 lines
hw/virtio/virtio-iommu.c +5
-0+ } + + bufstate.start = buf; + bufstate.filled =0 ; + bufstate.dev = dev;bufstate.error is not initialized which may cause false alarm in
virtio_iommu_fill_property()
I observed below prints
"qemu-system-aarch64: virtio_iommu_fill_property property of type=2 could not be filled (-28), remaining size = 0x0 "
When I initialized the bufstate.error = 0,it goes.
Thanks
-Bharat
Quoted 25 lines
hw/virtio/virtio-iommu.c static int
Quoted 19 lines
hw/virtio/virtio-iommu.c +14
-0+ +while ((type =ctz32 (prop_types)) !=32 ) { + ret =virtio_iommu_fill_property (devid,1 << type, &bufstate); +if (ret) { +break ; + } + prop_types &= ~(1 << type); + } +virtio_iommu_fill_property (devid,VIRTIO_IOMMU_PROBE_T_NONE , + &bufstate); + +return VIRTIO_IOMMU_S_OK ; +} +#define get_payload_size (req) (\ sizeof((req)) - sizeof(struct virtio_iommu_req_tail))@@ -433,6 +567,24 @@ static intvirtio_iommu_handle_unmap(VirtIOIOMMU *s,
hw/virtio/virtio-iommu.c static int virtio_iommu_handle_unmap(VirtIOIOMMU *s, · line 568
Quoted 2 lines
hw/virtio/virtio-iommu.c +0
-0return virtio_iommu_unmap (s, &req); }Thanks,
Tomasz
Hi Eric,
Out of curiosity, I compared your SMMUv3 full emulation against virtio-iommu. For virtio-net device behind the virtio-iommu I get 50% performance of what I can get for SMMUv3 emulation.
Do you have similar observations? Since there is no need to emulate HW behaviour in QEMU I expected virtio-iommu to be faster. I will run some more benchmarks.
Thanks,
Tomasz
Quoted 98 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellThe device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
The associated VHOST/VFIO adaptation is available on the branch below but is not officially delivered as part of this series.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v2.10.0-virtio-iommu-v4References:
[1] [RFC] virtio-iommu version 0.4
git://linux-arm.org/virtio-iommu.gitbranch viommu/v0.4Testing:
- guest kernel with v0.4 virtio-iommu driver (4kB page)
- tested with guest using virtio-pci-net and vhost-net (,vhost=on/off,iommu_platform,disable-modern=off,disable-legacy=on )
- tested with VFIO and guest assigned with 2 VFs
- tested with DPDK on guest with 2 assigned VFsNot tested:
- hot-plug/hot-unplug of EP: not implementedHistory:
v2-> v4:
- see abovev2 -> v3:
- rebase on top of 2.10-rc0 and especially
[PATCH qemu v9 0/2] memory/iommu: QOM'fy IOMMU MemoryRegion
- add mutex init
- fixas->mappingsdeletion using g_tree_ref/unref
- when a dev is attached whereas it is already attached to another address space, first detach it
- fix some error values
-page_sizes=TARGET_PAGE_MASK;
- I haven't changed theunmap()semantics yet, waiting for the next virtio-iommu spec revision.v1 -> v2:
- fix redifinition ofviommu_astypedefEric Auger (16):
update-linux-headers: importvirtio_iommu.h
linux-headers: Update for virtio-iommu
virtio-iommu: add skeleton
virtio-iommu: Decode the command payload
virtio-iommu: Add the iommu regions
virtio-iommu: Register attached devices
virtio-iommu: Implement attach/detach command
virtio-iommu: Implement map/unmap
virtio-iommu: Implement translate
virtio-iommu: Implement probe request
hw/arm/virt: Add 2.11 machine type
hw/arm/virt: Add virtio-iommu to the virt board
memory.h: Addset_page_size_maskIOMMUMemoryRegion callback hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
virtio-iommu: Implementset_page_size_mask
hw/vfio/common: Do not print error when viommu translates into an mmio
regionhw/arm/virt.c | 115 +++- hw/vfio/common.c | 7 +- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 24 + hw/virtio/virtio-iommu.c | 923 ++++++++++++++++++++++++++ include/exec/memory.h | 4 + include/hw/arm/virt.h | 5 + include/hw/vfio/vfio-common.h | 1 + include/hw/virtio/virtio-iommu.h | 61 ++ include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 177 +++++ linux-headers/linux/virtio_iommu.h | 1 + scripts/update-linux-headers.sh | 3 + 13 files changed, 1312 insertions(+), 11 deletions(-)create mode 100644
hw/virtio/virtio-iommu.c
create mode 100644include/hw/virtio/virtio-iommu.hcreate mode 100644include/standard-headers/linux/virtio_iommu.hcreate mode 100644linux-headers/linux/virtio_iommu.h
Hi Tomasz
Quoted 9 lines · Tomasz Nowicki
Hi Eric,
Out of curiosity, I compared your SMMUv3 full emulation against virtio-iommu. For virtio-net device behind the virtio-iommu I get 50% performance of what I can get for SMMUv3 emulation.
Do you have similar observations? Since there is no need to emulate HW behaviour in QEMU I expected virtio-iommu to be faster. I will run some more benchmarks.
No I don't have formal comparative figures at the moment. Benchmarking is also on the top of my todo list though.
One reason could be that virtio-iommu sends requests for each map operations whereas this does not happen for vsmmuv3 (in non caching mode). You could try to turn the vsmmuv3 caching-mode option and I guess you should have more similar perf figures between virtio-iommu and vsmuv3.
Thanks
Eric
Quoted 105 lines
Thanks,
TomaszQuoted 99 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellThe device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
The associated VHOST/VFIO adaptation is available on the branch below but is not officially delivered as part of this series.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v2.10.0-virtio-iommu-v4References:
[1] [RFC] virtio-iommu version 0.4
git://linux-arm.org/virtio-iommu.gitbranch viommu/v0.4Testing:
- guest kernel with v0.4 virtio-iommu driver (4kB page)
- tested with guest using virtio-pci-net and vhost-net (,vhost=on/off,iommu_platform,disable-modern=off,disable-legacy=on )
- tested with VFIO and guest assigned with 2 VFs
- tested with DPDK on guest with 2 assigned VFsNot tested:
- hot-plug/hot-unplug of EP: not implementedHistory:
v2-> v4:
- see abovev2 -> v3:
- rebase on top of 2.10-rc0 and especially
[PATCH qemu v9 0/2] memory/iommu: QOM'fy IOMMU MemoryRegion
- add mutex init
- fixas->mappingsdeletion using g_tree_ref/unref
- when a dev is attached whereas it is already attached to another address space, first detach it
- fix some error values
-page_sizes=TARGET_PAGE_MASK;
- I haven't changed theunmap()semantics yet, waiting for the next virtio-iommu spec revision.v1 -> v2:
- fix redifinition ofviommu_astypedefEric Auger (16):
update-linux-headers: importvirtio_iommu.h
linux-headers: Update for virtio-iommu
virtio-iommu: add skeleton
virtio-iommu: Decode the command payload
virtio-iommu: Add the iommu regions
virtio-iommu: Register attached devices
virtio-iommu: Implement attach/detach command
virtio-iommu: Implement map/unmap
virtio-iommu: Implement translate
virtio-iommu: Implement probe request
hw/arm/virt: Add 2.11 machine type
hw/arm/virt: Add virtio-iommu to the virt board
memory.h: Addset_page_size_maskIOMMUMemoryRegion callback hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
virtio-iommu: Implementset_page_size_mask
hw/vfio/common: Do not print error when viommu translates into an mmio
regionhw/arm/virt.c | 115 +++- hw/vfio/common.c | 7 +- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 24 + hw/virtio/virtio-iommu.c | 923 ++++++++++++++++++++++++++ include/exec/memory.h | 4 + include/hw/arm/virt.h | 5 + include/hw/vfio/vfio-common.h | 1 + include/hw/virtio/virtio-iommu.h | 61 ++ include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 177 +++++ linux-headers/linux/virtio_iommu.h | 1 + scripts/update-linux-headers.sh | 3 + 13 files changed, 1312 insertions(+), 11 deletions(-)create mode 100644
hw/virtio/virtio-iommu.c
create mode 100644include/hw/virtio/virtio-iommu.hcreate mode 100644include/standard-headers/linux/virtio_iommu.hcreate mode 100644linux-headers/linux/virtio_iommu.h
Re: [Qemu-arm] [Qemu-devel] [RFC v4 10/16] virtio-iommu: Implement probe request
In reply to Tomasz NowickiHi Tomasz,
Quoted 68 lines · Tomasz Nowicki
Hi Eric,
Quoted 9 lines · Eric Auger
This patch implements the PROBE request. At the moment, no reserved regions are returned.
At the moment reserved regions are stored per device.
Signed-off-by Eric Auger <[email protected]>---
[...]
Quoted 53 lines
hw/virtio/virtio-iommu.c +53
-0+ +static int virtio_iommu_fill_property (int devid,int type, +viommu_property_buffer *bufstate) +{ +int ret = -ENOSPC ; + +if (bufstate->filled +4 >=VIOMMU_PROBE_SIZE ) { + bufstate->error = true; + goto out; + } + +switch (type) { +case VIRTIO_IOMMU_PROBE_T_NONE : + ret =virtio_iommu_fill_none_prop (bufstate); +break ; +case VIRTIO_IOMMU_PROBE_T_RESV_MEM : + { +viommu_dev *dev = bufstate->dev; + +g_tree_foreach (dev->reserved_regions, + virtio_iommu_fill_resv_mem_prop, + bufstate); +if (!bufstate->error) { + ret =0 ; + } +break ; + } +default : + ret = -ENOENT ; +break ; + } +out: +if (ret) { +error_report ("%s property of type=%d could not be filled (%d)," +" remaining size = 0x%lx" , + __func__, type, ret, bufstate->filled); + } +return ret; +} + +static int virtio_iommu_probe (VirtIOIOMMU *s, +struct virtio_iommu_req_probe *req, +uint8_t *buf) +{ +uint32_t devid =le32_to_cpu (req->device); +int16_t prop_types =SUPPORTED_PROBE_PROPERTIES , type; +viommu_property_buffer bufstate; +viommu_dev *dev; +int ret; + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (!dev) { +return -EINVAL ;
Quoted 8 lines
hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 492
Quoted 5 lines
hw/virtio/virtio-iommu.c +5
-0+ } + + bufstate.start = buf; + bufstate.filled =0 ; + bufstate.dev = dev;bufstate.error is not initialized which may cause false alarm in
virtio_iommu_fill_property()
thanks for spotting that. I owe you several fixes in both vsmmuv3 and virtio-iommu. Thank you for testing, again!
Best Regards
Eric
Quoted 25 lines
Quoted 19 lines
hw/virtio/virtio-iommu.c +9
-0+ +while ((type =ctz32 (prop_types)) !=32 ) { + ret =virtio_iommu_fill_property (devid,1 << type, &bufstate); +if (ret) { +break ; + } + prop_types &= ~(1 << type); + } + virtio_iommu_fill_property(devid, VIRTIO_IOMMU_PROBE_T_NONE,&bufstate);
hw/virtio/virtio-iommu.c +4
-0+ +return VIRTIO_IOMMU_S_OK ; +} +#define get_payload_size (req) (\ sizeof((req)) - sizeof(struct virtio_iommu_req_tail)) @@ -433,6 +567,24 @@ static intvirtio_iommu_handle_unmap(VirtIOIOMMU *s,
Quoted 2 lines
return virtio_iommu_unmap(s, &req);}
Thanks,
Tomasz
Re: [Qemu-arm] [Qemu-devel] [RFC v4 10/16] virtio-iommu: Implement probe request
In reply to Bharat BhushanHi Bharat,
Quoted 91 lines · Bharat Bhushan
Quoted 82 lines
-----Original Message-----
From: Tomasz Nowicki [mailto:[email protected]]
Sent: Wednesday, September 27, 2017 4:23 PM
To: Eric Auger <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jean- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bharat Bhushan <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC v4 10/16] virtio-iommu: Implement probe requestHi Eric,
Quoted 9 lines · Eric Auger
This patch implements the PROBE request. At the moment, no reserved regions are returned.
At the moment reserved regions are stored per device.
Signed-off-by Eric Auger <[email protected]>---
[...]
Quoted 52 lines
hw/virtio/virtio-iommu.c +52
-0+ +static int virtio_iommu_fill_property (int devid,int type, +viommu_property_buffer +*bufstate) { +int ret = -ENOSPC ; + +if (bufstate->filled +4 >=VIOMMU_PROBE_SIZE ) { + bufstate->error = true; + goto out; + } + +switch (type) { +case VIRTIO_IOMMU_PROBE_T_NONE : + ret =virtio_iommu_fill_none_prop (bufstate); +break ; +case VIRTIO_IOMMU_PROBE_T_RESV_MEM : + { +viommu_dev *dev = bufstate->dev; + +g_tree_foreach (dev->reserved_regions, + virtio_iommu_fill_resv_mem_prop, + bufstate); +if (!bufstate->error) { + ret =0 ; + } +break ; + } +default : + ret = -ENOENT ; +break ; + } +out: +if (ret) { +error_report ("%s property of type=%d could not be filled (%d)," +" remaining size = 0x%lx" , + __func__, type, ret, bufstate->filled); + } +return ret; +} + +static int virtio_iommu_probe (VirtIOIOMMU *s, +struct virtio_iommu_req_probe *req, +uint8_t *buf) { +uint32_t devid =le32_to_cpu (req->device); +int16_t prop_types =SUPPORTED_PROBE_PROPERTIES , type; +viommu_property_buffer bufstate; +viommu_dev *dev; +int ret; + + dev =g_tree_lookup (s->devices,GUINT_TO_POINTER (devid)); +if (!dev) { +return -EINVAL ;Quoted 8 lines
hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 492
Quoted 5 lines
hw/virtio/virtio-iommu.c +5
-0+ } + + bufstate.start = buf; + bufstate.filled =0 ; + bufstate.dev = dev;bufstate.error is not initialized which may cause false alarm in
virtio_iommu_fill_property()
Quoted 4 lines
I observed below prints
"qemu-system-aarch64: virtio_iommu_fill_property property of type=2 could not be filled (-28), remaining size = 0x0 "When I initialized the bufstate.error = 0,it goes.
Sure, I will fix that soon.
Best Regards
Eric
Quoted 29 lines
Thanks
-BharatQuoted 25 lines
hw/virtio/virtio-iommu.c static int
Quoted 19 lines
hw/virtio/virtio-iommu.c +14
-0+ +while ((type =ctz32 (prop_types)) !=32 ) { + ret =virtio_iommu_fill_property (devid,1 << type, &bufstate); +if (ret) { +break ; + } + prop_types &= ~(1 << type); + } +virtio_iommu_fill_property (devid,VIRTIO_IOMMU_PROBE_T_NONE , + &bufstate); + +return VIRTIO_IOMMU_S_OK ; +} +#define get_payload_size (req) (\ sizeof((req)) - sizeof(struct virtio_iommu_req_tail))@@ -433,6 +567,24 @@ static intvirtio_iommu_handle_unmap(VirtIOIOMMU *s,
hw/virtio/virtio-iommu.c static int virtio_iommu_handle_unmap(VirtIOIOMMU *s, · line 568
Quoted 2 lines
hw/virtio/virtio-iommu.c +0
-0return virtio_iommu_unmap (s, &req); }Thanks,
Tomasz
Quoted 12 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbell
Quoted 4 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
thanks
-- PMM
Hi Peter,
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbell
Quoted 6 lines
Quoted 4 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Thanks
Eric
Quoted 4 lines
thanks
-- PMM
Quoted 21 lines · Auger Eric
Hi Peter,
Quoted 18 lines · Peter Maydell
Quoted 16 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellThe device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
Quoted 5 lines
Quoted 1 line
Could this work on x86, or is it inherently arm-only?
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Since I have very little familiarity with virtio or iommu code, I'd be much happier if this was reviewed as a generic virtio-iommu by the x86/virtio devs and then the arm specific parts done second...
I'm also not clear on what we're expecting the recommended or normal way to do device passthrough is going to be -- this virtio-mmio, or presenting the guest with an SMMUv3 interface? Do we really need to implement both ?
thanks
-- PMM
Hi Peter,
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Auger Eric
Hi Peter,
Quoted 19 lines · Peter Maydell
Quoted 12 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellQuoted 4 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
Quoted 7 lines
Quoted 3 lines
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Since I have very little familiarity with virtio or iommu code, I'd be much happier if this was reviewed as a generic virtio-iommu by the x86/virtio devs and then the arm specific parts done second...
Understood. I was rather expecting you to review the smmuv3 emulation code which you did, in a comprehensive manner ;-), and many thanks for that.
Note sure this is time yet to get this RFC reviewed as
- the v0.4 virtio-iommu driver it relies on was not officially submitted,
- the virtio-iommu specification review has not really been reviewed,
- the ACPI probing method has not been discussed yet.
Jean-Philippe, please correct me if I am wrong.
So to me, this is pure RFC at the moment.
Quoted 5 lines
I'm also not clear on what we're expecting the recommended or normal way to do device passthrough is going to be -- this virtio-mmio, or presenting the guest with an SMMUv3 interface? Do we really need to implement both ?
I think the KVM forum is the right place to sync as both approaches will be presented and some pros/cons + performance figures will be given.
As we talk about choosing, there is one alternative that was suggested on the ML by Alex & Michael but never really get considered yet and maybe should be: using intel iommu emulation code for ARM. I aknowledge this deserves a thorough impact study on kernel and FW side but I would be happy to get your opinion about the QEMU side. Would you have a by- principle rejection of this idea to instantiate such an Intel device in mach virt or would it be something you would be ready to consider?
Thanks
Eric
Quoted 4 lines
thanks
-- PMM
Quoted 38 lines · Auger Eric
Hi Peter,
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Auger Eric
Hi Peter,
Quoted 19 lines · Peter Maydell
Quoted 12 lines · Eric Auger
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellQuoted 4 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node and the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
Quoted 7 lines
Quoted 3 lines
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Since I have very little familiarity with virtio or iommu code, I'd be much happier if this was reviewed as a generic virtio-iommu by the x86/virtio devs and then the arm specific parts done second...
Understood. I was rather expecting you to review the smmuv3 emulation code which you did, in a comprehensive manner ;-), and many thanks for that.
Quoted 8 lines
Note sure this is time yet to get this RFC reviewed as
- the v0.4 virtio-iommu driver it relies on was not officially submitted,
- the virtio-iommu specification review has not really been reviewed,
- the ACPI probing method has not been discussed yet.Jean-Philippe, please correct me if I am wrong.
So to me, this is pure RFC at the moment.
Yes, having it as an RFC for the moment allowed to break compatibility between versions of the specification. The downside is that it probably doesn't get as many eyeballs as it would without an RFC tag (although I did receive tonnes of helpful comments). Maybe v0.5, that should be published shortly, can be a candidate for mainline.
Thanks,
Jean
Quoted 25 lines
Quoted 4 lines
I'm also not clear on what we're expecting the recommended or normal way to do device passthrough is going to be -- this virtio-mmio, or presenting the guest with an SMMUv3 interface? Do we really need to implement both ?
I think the KVM forum is the right place to sync as both approaches will be presented and some pros/cons + performance figures will be given.
As we talk about choosing, there is one alternative that was suggested on the ML by Alex & Michael but never really get considered yet and maybe should be: using intel iommu emulation code for ARM. I aknowledge this deserves a thorough impact study on kernel and FW side but I would be happy to get your opinion about the QEMU side. Would you have a by- principle rejection of this idea to instantiate such an Intel device in mach virt or would it be something you would be ready to consider?
Thanks
Eric
Quoted 4 lines
thanks
-- PMM
Quoted 61 lines
From: Auger Eric [mailto:[email protected]]
Sent: Thursday, October 12, 2017 6:10 PMHi Peter,
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Auger Eric
Hi Peter,
Quoted 1 line · Peter Maydell
On 19 September 2017 at 08:46, Eric Auger <[email protected]>
Quoted 12 lines · wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node
and
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Since I have very little familiarity with virtio or iommu code, I'd be much happier if this was reviewed as a generic virtio-iommu by the x86/virtio devs and then the arm specific parts done second...
Understood. I was rather expecting you to review the smmuv3 emulation code which you did, in a comprehensive manner ;-), and many thanks for that.
Note sure this is time yet to get this RFC reviewed as
- the v0.4 virtio-iommu driver it relies on was not officially submitted,
- the virtio-iommu specification review has not really been reviewed,
- the ACPI probing method has not been discussed yet.Jean-Philippe, please correct me if I am wrong.
So to me, this is pure RFC at the moment.
Quoted 5 lines
I'm also not clear on what we're expecting the recommended or normal way to do device passthrough is going to be -- this virtio-mmio, or presenting the guest with an SMMUv3 interface? Do we really need to implement both ?
I think the KVM forum is the right place to sync as both approaches will be presented and some pros/cons + performance figures will be given.
Quoted 9 lines
As we talk about choosing, there is one alternative that was suggested on the ML by Alex & Michael but never really get considered yet and maybe should be: using intel iommu emulation code for ARM. I aknowledge
this deserves a thorough impact study on kernel and FW side but I would be happy to get your opinion about the QEMU side. Would you have a by- principle rejection of this idea to instantiate such an Intel device in mach virt or would it be something you would be ready to consider?
bear posting a link to Alex/Michael's comment? interesting to know the rationale...
Thanks
Kevin
Hi Kevin,
Quoted 71 lines · Kevin
Quoted 61 lines
From: Auger Eric [mailto:[email protected]]
Sent: Thursday, October 12, 2017 6:10 PMHi Peter,
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Auger Eric
Hi Peter,
Quoted 1 line · Peter Maydell
On 19 September 2017 at 08:46, Eric Auger <[email protected]>
Quoted 12 lines · wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
This series implements the virtio-iommu device.
This v4 is an upgrade to v0.4 spec [1] and applies on QEMU v2.10.0.
- probe request support although no reserved region is returned at the moment
- unmap semantics less strict, as specified in v0.4
- device registration, attach/detach revisited
- split into smaller patches to ease review
- propose a way to inform the IOMMU mr about thepage_size_maskof underlying HW IOMMU, if any
- remove warning associated with the translation of the MSI doorbellQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The device gets instantiated using the "-device virtio-iommu-device" option. It currently works with ARM virt machine only, as the machine must handle the dt binding between the virtio-mmio "iommu" node
and
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
the PCI host bridge node.
Could this work on x86, or is it inherently arm-only?
Yes this is the goal. At the moment the ACPI probing is not yet properly specified but a Q35 prototype was developed in the Red Hat Virt team. This will be presented at the KVM forum.
Since I have very little familiarity with virtio or iommu code, I'd be much happier if this was reviewed as a generic virtio-iommu by the x86/virtio devs and then the arm specific parts done second...
Understood. I was rather expecting you to review the smmuv3 emulation code which you did, in a comprehensive manner ;-), and many thanks for that.
Note sure this is time yet to get this RFC reviewed as
- the v0.4 virtio-iommu driver it relies on was not officially submitted,
- the virtio-iommu specification review has not really been reviewed,
- the ACPI probing method has not been discussed yet.Jean-Philippe, please correct me if I am wrong.
So to me, this is pure RFC at the moment.
Quoted 5 lines
I'm also not clear on what we're expecting the recommended or normal way to do device passthrough is going to be -- this virtio-mmio, or presenting the guest with an SMMUv3 interface? Do we really need to implement both ?
I think the KVM forum is the right place to sync as both approaches will be presented and some pros/cons + performance figures will be given.
Quoted 9 lines
As we talk about choosing, there is one alternative that was suggested on the ML by Alex & Michael but never really get considered yet and maybe should be: using intel iommu emulation code for ARM. I aknowledge
this deserves a thorough impact study on kernel and FW side but I would be happy to get your opinion about the QEMU side. Would you have a by- principle rejection of this idea to instantiate such an Intel device in mach virt or would it be something you would be ready to consider?
Quoted 2 lines
bear posting a link to Alex/Michael's comment? interesting to know the rationale...
This was suggested here for instance:
https://lkml.org/lkml/2017/7/12/579
I think rationale was
- this is an emulated platform so there is more freedom
- vtd emulation code is rather stable
- it has pieces missing on smmu: cachine mode, IOTLB invalidation command with addr_mask,
- intel iommu driver implements deferred IOTLB Invalidation which boosts perf
But problems I foresee are:
- MSI handling. ARM MSI doorbells can be anywhere in the GPA address space whereas Intel has MSIs within the APIC window: [FEE0_0000h – FEF0_000h]. So I suspect the MSI handling may not work at kernel level.
- intel IOMMU input/output address ranges and page sizes may be different from ARM ones.
- ARM uses ACPI IORT for binding RC <-> IOMMU <-> MSI controller whereas Intel uses other tables
- Intel's dmar kernel code must be compiled/enabled on ARM
So personally I don't think this solution is viable but I prefer this gets discussed on the ML.
Thanks
Eric
Quoted 4 lines
Thanks
Kevin