All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration
@ 2018-11-27  6:52 Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 1/5] hw/vfio/common: Do not print error when viommu translates into an mmio region Bharat Bhushan
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:52 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Bharat Bhushan

This patch series integrates VFIO with virtio-iommu. This is
tested with assigning 2 pci devices to Virtual Machine.

This version is mainly about rebasing on v9 version on
virtio-iommu device framework from Eric Augur.

This patch series allows PCI pass-through using virtio-iommu.

This series is based on:
 - virtio-iommu kernel driver by Jean-Philippe Brucker
    [PATCH v5 0/7] Add virtio-iommu driver
    git://linux-arm.org/kvmtool-jpb.git virtio-iommu/v0.9

 - virtio-iommu device emulation by Eric Augur.
   [RFC,v9,00/17] VIRTIO-IOMMU device
   https://github.com/eauger/qemu/tree/v3.1.0-rc2-virtio-iommu-v0.9

v4->v5:
 - Rebase to v9 version from Eric
 - PCIe device hotplug fix
 - Added Patch 1/5 from Eric previous series (Eric somehow dropped in
   last version.
 - Patch "Translate the MSI doorbell in kvm_arch_fixup_msi_route"
   already integrated with vsmmu3

v3->v4:
 - Rebase to v4 version from Eric
 - Fixes from Eric with DPDK in VM
 - Logical division in multiple patches

v2->v3:
 - This series is based on "[RFC v3 0/8] VIRTIO-IOMMU device"
   Which is based on top of v2.10-rc0 that
 - Fixed issue with two PCI devices
 - Addressed review comments

v1->v2:
  - Added trace events
  - removed vSMMU3 link in patch description

Bharat Bhushan (4):
  virtio-iommu: Add iommu notifier for iommu-map/unmap
  virtio-iommu: Call iommu notifier on attach/detach
  virtio-iommu: add virtio-iommu replay
  virtio-iommu: handle IOMMU Notifier flag changes

Eric Auger (1):
  hw/vfio/common: Do not print error when viommu translates into an mmio
    region

 hw/vfio/common.c                 |   2 -
 hw/virtio/trace-events           |   5 +
 hw/virtio/virtio-iommu.c         | 190 ++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-iommu.h |   6 +
 4 files changed, 198 insertions(+), 5 deletions(-)

-- 
2.19.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH RFC v5 1/5] hw/vfio/common: Do not print error when viommu translates into an mmio region
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
@ 2018-11-27  6:52 ` Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 2/5] virtio-iommu: Add iommu notifier for iommu-map/unmap Bharat Bhushan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:52 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Eric Auger, Bharat Bhushan

From: Eric Auger <eric.auger@redhat.com>

On 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.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
---
v5:
 - Added thi patch from Eric previous series (Eric somehow dropped in
   last version and this is needed for VFIO.

 hw/vfio/common.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7c185e5a2e..fc40543121 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -328,8 +328,6 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr,
                                  &xlat, &len, writable,
                                  MEMTXATTRS_UNSPECIFIED);
     if (!memory_region_is_ram(mr)) {
-        error_report("iommu map to non memory area %"HWADDR_PRIx"",
-                     xlat);
         return false;
     }
 
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH RFC v5 2/5] virtio-iommu: Add iommu notifier for iommu-map/unmap
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 1/5] hw/vfio/common: Do not print error when viommu translates into an mmio region Bharat Bhushan
@ 2018-11-27  6:52 ` Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 3/5] virtio-iommu: Call iommu notifier on attach/detach Bharat Bhushan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:52 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Bharat Bhushan

This patch extends VIRTIO_IOMMU_T_MAP/UNMAP request
handling to notify registered iommu-notifier. These
iommu-notifier maps the requested region in IOMMU using vfio.

Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
---
v4->v5:
 - Rebase to v9 version from Eric
 - PCIe device hotplug fix

 hw/virtio/trace-events           |  2 +
 hw/virtio/virtio-iommu.c         | 74 ++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-iommu.h |  6 +++
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 053a07b3fc..420b1e471b 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -72,3 +72,5 @@ virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid)
 virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end, uint32_t flags, size_t filled) "dev= %d, subtype=%d start=0x%"PRIx64" end=0x%"PRIx64" flags=%d filled=0x%lx"
 virtio_iommu_fill_none_property(uint32_t devid) "devid=%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
+virtio_iommu_notify_map(const char *name, uint64_t iova, uint64_t paddr, uint64_t map_size) "mr=%s iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64""
+virtio_iommu_notify_unmap(const char *name, uint64_t iova, uint64_t map_size) "mr=%s iova=0x%"PRIx64" size=0x%"PRIx64""
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 2ec01f3b9e..613a77521d 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -99,6 +99,38 @@ static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
     }
 }
 
+static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr iova,
+                                    hwaddr paddr, hwaddr size)
+{
+    IOMMUTLBEntry entry;
+
+    trace_virtio_iommu_notify_map(mr->parent_obj.name, iova, paddr, size);
+
+    entry.target_as = &address_space_memory;
+    entry.addr_mask = size - 1;
+    entry.iova = iova;
+    entry.perm = IOMMU_RW;
+    entry.translated_addr = paddr;
+
+    memory_region_notify_iommu(mr, 0, entry);
+}
+
+static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr iova,
+                                      hwaddr size)
+{
+    IOMMUTLBEntry entry;
+
+    trace_virtio_iommu_notify_unmap(mr->parent_obj.name, iova, size);
+
+    entry.target_as = &address_space_memory;
+    entry.addr_mask = size - 1;
+    entry.iova = iova;
+    entry.perm = IOMMU_NONE;
+    entry.translated_addr = 0;
+
+    memory_region_notify_iommu(mr, 0, entry);
+}
+
 static void virtio_iommu_detach_endpoint_from_domain(viommu_endpoint *ep)
 {
     QLIST_REMOVE(ep, next);
@@ -301,9 +333,12 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
     uint64_t virt_start = le64_to_cpu(req->virt_start);
     uint64_t virt_end = le64_to_cpu(req->virt_end);
     uint32_t flags = le32_to_cpu(req->flags);
+    VirtioIOMMUNotifierNode *node;
+    viommu_endpoint *ep;
     viommu_domain *domain;
     viommu_interval *interval;
     viommu_mapping *mapping;
+    uint32_t sid;
 
     interval = g_malloc0(sizeof(*interval));
 
@@ -331,9 +366,40 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
 
     g_tree_insert(domain->mappings, interval, mapping);
 
+    /* All devices in an address-space share mapping */
+    QLIST_FOREACH(node, &s->notifiers_list, next) {
+        QLIST_FOREACH(ep, &domain->endpoint_list, next) {
+            sid = virtio_iommu_get_sid(node->iommu_dev);
+            if (ep->id == sid) {
+                virtio_iommu_notify_map(&node->iommu_dev->iommu_mr,
+                                        virt_start, phys_start, mapping->size);
+            }
+        }
+    }
+
     return VIRTIO_IOMMU_S_OK;
 }
 
+static void virtio_iommu_remove_mapping(VirtIOIOMMU *s, viommu_domain *domain,
+                                        viommu_interval *interval)
+{
+    VirtioIOMMUNotifierNode *node;
+    viommu_endpoint *ep;
+    uint32_t sid;
+
+    g_tree_remove(domain->mappings, (gpointer)(interval));
+    QLIST_FOREACH(node, &s->notifiers_list, next) {
+        QLIST_FOREACH(ep, &domain->endpoint_list, next) {
+            sid = virtio_iommu_get_sid(node->iommu_dev);
+            if (ep->id == sid) {
+                virtio_iommu_notify_unmap(&node->iommu_dev->iommu_mr,
+                                          interval->low,
+                                          interval->high - interval->low + 1);
+            }
+        }
+    }
+}
+
 static int virtio_iommu_unmap(VirtIOIOMMU *s,
                               struct virtio_iommu_req_unmap *req)
 {
@@ -366,18 +432,18 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,
         current.high = high;
 
         if (low == interval.low && size >= mapping->size) {
-            g_tree_remove(domain->mappings, (gpointer)(&current));
+            virtio_iommu_remove_mapping(s, domain, &current);
             interval.low = high + 1;
             trace_virtio_iommu_unmap_left_interval(current.low, current.high,
                 interval.low, interval.high);
         } else if (high == interval.high && size >= mapping->size) {
             trace_virtio_iommu_unmap_right_interval(current.low, current.high,
                 interval.low, interval.high);
-            g_tree_remove(domain->mappings, (gpointer)(&current));
+            virtio_iommu_remove_mapping(s, domain, &current);
             interval.high = low - 1;
         } else if (low > interval.low && high < interval.high) {
             trace_virtio_iommu_unmap_inc_interval(current.low, current.high);
-            g_tree_remove(domain->mappings, (gpointer)(&current));
+            virtio_iommu_remove_mapping(s, domain, &current);
         } else {
             break;
         }
@@ -907,6 +973,8 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
 
+    QLIST_INIT(&s->notifiers_list);
+
     virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU,
                 sizeof(struct virtio_iommu_config));
 
diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h
index 56c8b4e57f..65bda6d6fe 100644
--- a/include/hw/virtio/virtio-iommu.h
+++ b/include/hw/virtio/virtio-iommu.h
@@ -46,6 +46,11 @@ typedef struct IOMMUPciBus {
     IOMMUDevice  *pbdev[0]; /* Parent array is sparse, so dynamically alloc */
 } IOMMUPciBus;
 
+typedef struct VirtioIOMMUNotifierNode {
+    IOMMUDevice *iommu_dev;
+    QLIST_ENTRY(VirtioIOMMUNotifierNode) next;
+} VirtioIOMMUNotifierNode;
+
 typedef struct VirtIOIOMMU {
     VirtIODevice parent_obj;
     VirtQueue *req_vq;
@@ -60,6 +65,7 @@ typedef struct VirtIOIOMMU {
     QemuMutex mutex;
     GTree *endpoints;
     bool msi_bypass;
+    QLIST_HEAD(, VirtioIOMMUNotifierNode) notifiers_list;
 } VirtIOIOMMU;
 
 #endif
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH RFC v5 3/5] virtio-iommu: Call iommu notifier on attach/detach
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 1/5] hw/vfio/common: Do not print error when viommu translates into an mmio region Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 2/5] virtio-iommu: Add iommu notifier for iommu-map/unmap Bharat Bhushan
@ 2018-11-27  6:52 ` Bharat Bhushan
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 4/5] virtio-iommu: add virtio-iommu replay Bharat Bhushan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:52 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Bharat Bhushan, Eric Auger

This patch extend the ATTACH/DETACH command handling to
call iommu-notifier to map/unmap the memory region in IOMMU
using vfio. This replay existing address space mappings on
attach command and remove existing address space mappings
on detach command.

Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v4->v5:
 - Rebase to v9 version from Eric
 - PCIe device hotplug fix

 hw/virtio/virtio-iommu.c | 47 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 613a77521d..7e8149e719 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -131,8 +131,44 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr iova,
     memory_region_notify_iommu(mr, 0, entry);
 }
 
+static gboolean virtio_iommu_mapping_unmap(gpointer key, gpointer value,
+                                           gpointer data)
+{
+    viommu_mapping *mapping = (viommu_mapping *) value;
+    IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+    virtio_iommu_notify_unmap(mr, mapping->virt_addr, mapping->size);
+
+    return false;
+}
+
+static gboolean virtio_iommu_mapping_map(gpointer key, gpointer value,
+                                         gpointer data)
+{
+    viommu_mapping *mapping = (viommu_mapping *) value;
+    IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+    virtio_iommu_notify_map(mr, mapping->virt_addr, mapping->phys_addr,
+                            mapping->size);
+
+    return false;
+}
+
 static void virtio_iommu_detach_endpoint_from_domain(viommu_endpoint *ep)
 {
+    VirtioIOMMUNotifierNode *node;
+    VirtIOIOMMU *s = ep->viommu;
+    viommu_domain *domain = ep->domain;
+    uint32_t sid;
+
+    QLIST_FOREACH(node, &s->notifiers_list, next) {
+        sid = virtio_iommu_get_sid(node->iommu_dev);
+        if (ep->id == sid) {
+            g_tree_foreach(domain->mappings, virtio_iommu_mapping_unmap,
+                           &node->iommu_dev->iommu_mr);
+        }
+    }
+
     QLIST_REMOVE(ep, next);
     ep->domain = NULL;
 }
@@ -280,8 +316,10 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
 {
     uint32_t domain_id = le32_to_cpu(req->domain);
     uint32_t ep_id = le32_to_cpu(req->endpoint);
+    VirtioIOMMUNotifierNode *node;
     viommu_domain *domain;
     viommu_endpoint *ep;
+    uint32_t sid;
 
     trace_virtio_iommu_attach(domain_id, ep_id);
 
@@ -300,6 +338,15 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
     ep->domain = domain;
     g_tree_ref(domain->mappings);
 
+    /* replay existing address space mappings on the associated mr */
+    QLIST_FOREACH(node, &s->notifiers_list, next) {
+        sid = virtio_iommu_get_sid(node->iommu_dev);
+        if (ep->id == sid) {
+            g_tree_foreach(domain->mappings, virtio_iommu_mapping_map,
+                           &node->iommu_dev->iommu_mr);
+        }
+    }
+
     return VIRTIO_IOMMU_S_OK;
 }
 
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH RFC v5 4/5] virtio-iommu: add virtio-iommu replay
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
                   ` (2 preceding siblings ...)
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 3/5] virtio-iommu: Call iommu notifier on attach/detach Bharat Bhushan
@ 2018-11-27  6:52 ` Bharat Bhushan
  2018-11-27  6:53 ` [Qemu-devel] [PATCH RFC v5 5/5] virtio-iommu: handle IOMMU Notifier flag changes Bharat Bhushan
  2020-02-28  9:36 ` [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Auger Eric
  5 siblings, 0 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:52 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Bharat Bhushan

For virtio-iommu, on replay first unmap any previous
iommu-mapping and then map in iommu as per guest iommu
mappings.

Also if virtual iommu do have it own replay then
memory_region_iommu_replay() calls "imrc->translate()",
While virtio-iommu translate() expects device to be
registered before it is called. So having replay of
virtio-iommu helps to take no action if device not yet
probed/attached.

Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
---
v4->v5:
 - Rebase to v9 version from Eric (no change)

 hw/virtio/trace-events   |  1 +
 hw/virtio/virtio-iommu.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 420b1e471b..f29a027258 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -74,3 +74,4 @@ virtio_iommu_fill_none_property(uint32_t devid) "devid=%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
 virtio_iommu_notify_map(const char *name, uint64_t iova, uint64_t paddr, uint64_t map_size) "mr=%s iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64""
 virtio_iommu_notify_unmap(const char *name, uint64_t iova, uint64_t map_size) "mr=%s iova=0x%"PRIx64" size=0x%"PRIx64""
+virtio_iommu_remap(uint64_t iova, uint64_t pa, uint64_t size) "iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64""
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 7e8149e719..c9d8b3aa4c 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -1015,6 +1015,43 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
     return (ua > ub) - (ua < ub);
 }
 
+static gboolean virtio_iommu_remap(gpointer key, gpointer value, gpointer data)
+{
+    viommu_mapping *mapping = (viommu_mapping *) value;
+    IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+    trace_virtio_iommu_remap(mapping->virt_addr, mapping->phys_addr,
+                             mapping->size);
+    /* unmap previous entry and map again */
+    virtio_iommu_notify_unmap(mr, mapping->virt_addr, mapping->size);
+
+    virtio_iommu_notify_map(mr, mapping->virt_addr, mapping->phys_addr,
+                            mapping->size);
+    return false;
+}
+
+static void virtio_iommu_replay(IOMMUMemoryRegion *mr, IOMMUNotifier *n)
+{
+    IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr);
+    VirtIOIOMMU *s = sdev->viommu;
+    uint32_t sid;
+    viommu_endpoint *ep;
+
+    sid = virtio_iommu_get_sid(sdev);
+
+    qemu_mutex_lock(&s->mutex);
+
+    ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(sid));
+    if (!ep || !ep->domain) {
+        goto unlock;
+    }
+
+    g_tree_foreach(ep->domain->mappings, virtio_iommu_remap, mr);
+
+unlock:
+    qemu_mutex_unlock(&s->mutex);
+}
+
 static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1129,6 +1166,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,
     IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass);
 
     imrc->translate = virtio_iommu_translate;
+    imrc->replay = virtio_iommu_replay;
 }
 
 static const TypeInfo virtio_iommu_info = {
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH RFC v5 5/5] virtio-iommu: handle IOMMU Notifier flag changes
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
                   ` (3 preceding siblings ...)
  2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 4/5] virtio-iommu: add virtio-iommu replay Bharat Bhushan
@ 2018-11-27  6:53 ` Bharat Bhushan
  2020-02-28  9:36 ` [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Auger Eric
  5 siblings, 0 replies; 9+ messages in thread
From: Bharat Bhushan @ 2018-11-27  6:53 UTC (permalink / raw)
  To: peter.maydell, alex.williamson, kevin.tian, mst, tn, drjones,
	linu.cherian, linuc.decode, qemu-devel, qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav, Bharat Bhushan

Finally handle the IOMMU Notifier flag changes
for the iommu-memory region.

Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
---
v4->v5:
 - Rebase to v9 version from Eric (no change)

 hw/virtio/trace-events   |  2 ++
 hw/virtio/virtio-iommu.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index f29a027258..8c1d77b0c2 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -75,3 +75,5 @@ virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uin
 virtio_iommu_notify_map(const char *name, uint64_t iova, uint64_t paddr, uint64_t map_size) "mr=%s iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64""
 virtio_iommu_notify_unmap(const char *name, uint64_t iova, uint64_t map_size) "mr=%s iova=0x%"PRIx64" size=0x%"PRIx64""
 virtio_iommu_remap(uint64_t iova, uint64_t pa, uint64_t size) "iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64""
+virtio_iommu_notify_flag_add(const char *iommu) "Add virtio-iommu notifier node for memory region %s"
+virtio_iommu_notify_flag_del(const char *iommu) "Del virtio-iommu notifier node for memory region %s"
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index c9d8b3aa4c..adc37ddf1b 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -1052,6 +1052,36 @@ unlock:
     qemu_mutex_unlock(&s->mutex);
 }
 
+static void virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr,
+                                             IOMMUNotifierFlag old,
+                                             IOMMUNotifierFlag new)
+{
+    IOMMUDevice *sdev = container_of(iommu_mr, IOMMUDevice, iommu_mr);
+    VirtIOIOMMU *s = sdev->viommu;
+    VirtioIOMMUNotifierNode *node = NULL;
+    VirtioIOMMUNotifierNode *next_node = NULL;
+
+    if (old == IOMMU_NOTIFIER_NONE) {
+        trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name);
+        node = g_malloc0(sizeof(*node));
+        node->iommu_dev = sdev;
+        QLIST_INSERT_HEAD(&s->notifiers_list, node, next);
+        return;
+    }
+
+    /* update notifier node with new flags */
+    QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) {
+        if (node->iommu_dev == sdev) {
+            if (new == IOMMU_NOTIFIER_NONE) {
+                trace_virtio_iommu_notify_flag_del(iommu_mr->parent_obj.name);
+                QLIST_REMOVE(node, next);
+                g_free(node);
+            }
+            return;
+        }
+    }
+}
+
 static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1167,6 +1197,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,
 
     imrc->translate = virtio_iommu_translate;
     imrc->replay = virtio_iommu_replay;
+    imrc->notify_flag_changed = virtio_iommu_notify_flag_changed;
 }
 
 static const TypeInfo virtio_iommu_info = {
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration
  2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
                   ` (4 preceding siblings ...)
  2018-11-27  6:53 ` [Qemu-devel] [PATCH RFC v5 5/5] virtio-iommu: handle IOMMU Notifier flag changes Bharat Bhushan
@ 2020-02-28  9:36 ` Auger Eric
  2020-03-02  5:12   ` Bharat Bhushan
  5 siblings, 1 reply; 9+ messages in thread
From: Auger Eric @ 2020-02-28  9:36 UTC (permalink / raw)
  To: Bharat Bhushan, peter.maydell, alex.williamson, kevin.tian, mst,
	Tomasz Nowicki, drjones, linu.cherian, linuc.decode, qemu-devel,
	qemu-arm
  Cc: eric.auger.pro, peterx, bharatb.yadav

Hi Bharat,

On 11/27/18 7:52 AM, Bharat Bhushan wrote:
> This patch series integrates VFIO with virtio-iommu. This is
> tested with assigning 2 pci devices to Virtual Machine.
> 
> This version is mainly about rebasing on v9 version on
> virtio-iommu device framework from Eric Augur.
> 
> This patch series allows PCI pass-through using virtio-iommu.
> 
> This series is based on:
>  - virtio-iommu kernel driver by Jean-Philippe Brucker
>     [PATCH v5 0/7] Add virtio-iommu driver
>     git://linux-arm.org/kvmtool-jpb.git virtio-iommu/v0.9
> 
>  - virtio-iommu device emulation by Eric Augur.
>    [RFC,v9,00/17] VIRTIO-IOMMU device
>    https://github.com/eauger/qemu/tree/v3.1.0-rc2-virtio-iommu-v0.9

Now we have the driver and the base qemu device upstream we may resume
this activity to complete the VFIO integration. Do you intend the
respin? Otherwise let me know if you want me to help.

Thanks

Eric
> 
> v4->v5:
>  - Rebase to v9 version from Eric
>  - PCIe device hotplug fix
>  - Added Patch 1/5 from Eric previous series (Eric somehow dropped in
>    last version.
>  - Patch "Translate the MSI doorbell in kvm_arch_fixup_msi_route"
>    already integrated with vsmmu3
> 
> v3->v4:
>  - Rebase to v4 version from Eric
>  - Fixes from Eric with DPDK in VM
>  - Logical division in multiple patches
> 
> v2->v3:
>  - This series is based on "[RFC v3 0/8] VIRTIO-IOMMU device"
>    Which is based on top of v2.10-rc0 that
>  - Fixed issue with two PCI devices
>  - Addressed review comments
> 
> v1->v2:
>   - Added trace events
>   - removed vSMMU3 link in patch description
> 
> Bharat Bhushan (4):
>   virtio-iommu: Add iommu notifier for iommu-map/unmap
>   virtio-iommu: Call iommu notifier on attach/detach
>   virtio-iommu: add virtio-iommu replay
>   virtio-iommu: handle IOMMU Notifier flag changes
> 
> Eric Auger (1):
>   hw/vfio/common: Do not print error when viommu translates into an mmio
>     region
> 
>  hw/vfio/common.c                 |   2 -
>  hw/virtio/trace-events           |   5 +
>  hw/virtio/virtio-iommu.c         | 190 ++++++++++++++++++++++++++++++-
>  include/hw/virtio/virtio-iommu.h |   6 +
>  4 files changed, 198 insertions(+), 5 deletions(-)
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration
  2020-02-28  9:36 ` [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Auger Eric
@ 2020-03-02  5:12   ` Bharat Bhushan
  2020-03-02  7:00     ` Auger Eric
  0 siblings, 1 reply; 9+ messages in thread
From: Bharat Bhushan @ 2020-03-02  5:12 UTC (permalink / raw)
  To: Auger Eric
  Cc: peter.maydell, kevin.tian, drjones, Tomasz Nowicki, mst,
	alex.williamson, peterx, qemu-devel, Bharat Bhushan, qemu-arm,
	linu.cherian, linuc.decode, eric.auger.pro

[-- Attachment #1: Type: text/plain, Size: 2540 bytes --]

Hi Eric,

On Fri, Feb 28, 2020 at 3:06 PM Auger Eric <eric.auger@redhat.com> wrote:

> Hi Bharat,
>
> On 11/27/18 7:52 AM, Bharat Bhushan wrote:
> > This patch series integrates VFIO with virtio-iommu. This is
> > tested with assigning 2 pci devices to Virtual Machine.
> >
> > This version is mainly about rebasing on v9 version on
> > virtio-iommu device framework from Eric Augur.
> >
> > This patch series allows PCI pass-through using virtio-iommu.
> >
> > This series is based on:
> >  - virtio-iommu kernel driver by Jean-Philippe Brucker
> >     [PATCH v5 0/7] Add virtio-iommu driver
> >     git://linux-arm.org/kvmtool-jpb.git virtio-iommu/v0.9
> >
> >  - virtio-iommu device emulation by Eric Augur.
> >    [RFC,v9,00/17] VIRTIO-IOMMU device
> >    https://github.com/eauger/qemu/tree/v3.1.0-rc2-virtio-iommu-v0.9
>
> Now we have the driver and the base qemu device upstream we may resume
> this activity to complete the VFIO integration. Do you intend the
> respin? Otherwise let me know if you want me to help.
>
>
Yes Eric, I am planning to respin the changes.

Can you please point to latest changes (qemu/Linux both).

Thanks
-Bharat

Thanks
>
> Eric
> >
> > v4->v5:
> >  - Rebase to v9 version from Eric
> >  - PCIe device hotplug fix
> >  - Added Patch 1/5 from Eric previous series (Eric somehow dropped in
> >    last version.
> >  - Patch "Translate the MSI doorbell in kvm_arch_fixup_msi_route"
> >    already integrated with vsmmu3
> >
> > v3->v4:
> >  - Rebase to v4 version from Eric
> >  - Fixes from Eric with DPDK in VM
> >  - Logical division in multiple patches
> >
> > v2->v3:
> >  - This series is based on "[RFC v3 0/8] VIRTIO-IOMMU device"
> >    Which is based on top of v2.10-rc0 that
> >  - Fixed issue with two PCI devices
> >  - Addressed review comments
> >
> > v1->v2:
> >   - Added trace events
> >   - removed vSMMU3 link in patch description
> >
> > Bharat Bhushan (4):
> >   virtio-iommu: Add iommu notifier for iommu-map/unmap
> >   virtio-iommu: Call iommu notifier on attach/detach
> >   virtio-iommu: add virtio-iommu replay
> >   virtio-iommu: handle IOMMU Notifier flag changes
> >
> > Eric Auger (1):
> >   hw/vfio/common: Do not print error when viommu translates into an mmio
> >     region
> >
> >  hw/vfio/common.c                 |   2 -
> >  hw/virtio/trace-events           |   5 +
> >  hw/virtio/virtio-iommu.c         | 190 ++++++++++++++++++++++++++++++-
> >  include/hw/virtio/virtio-iommu.h |   6 +
> >  4 files changed, 198 insertions(+), 5 deletions(-)
> >
>
>

-- 
-Bharat

[-- Attachment #2: Type: text/html, Size: 3890 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration
  2020-03-02  5:12   ` Bharat Bhushan
@ 2020-03-02  7:00     ` Auger Eric
  0 siblings, 0 replies; 9+ messages in thread
From: Auger Eric @ 2020-03-02  7:00 UTC (permalink / raw)
  To: Bharat Bhushan
  Cc: peter.maydell, kevin.tian, drjones, Tomasz Nowicki, mst,
	alex.williamson, peterx, qemu-devel, Bharat Bhushan, qemu-arm,
	linu.cherian, linuc.decode, eric.auger.pro

Hi Bharat,

On 3/2/20 6:12 AM, Bharat Bhushan wrote:
> 
> Hi Eric, 
> 
> On Fri, Feb 28, 2020 at 3:06 PM Auger Eric <eric.auger@redhat.com
> <mailto:eric.auger@redhat.com>> wrote:
> 
>     Hi Bharat,
> 
>     On 11/27/18 7:52 AM, Bharat Bhushan wrote:
>     > This patch series integrates VFIO with virtio-iommu. This is
>     > tested with assigning 2 pci devices to Virtual Machine.
>     >
>     > This version is mainly about rebasing on v9 version on
>     > virtio-iommu device framework from Eric Augur.
>     >
>     > This patch series allows PCI pass-through using virtio-iommu.
>     >
>     > This series is based on:
>     >  - virtio-iommu kernel driver by Jean-Philippe Brucker
>     >     [PATCH v5 0/7] Add virtio-iommu driver
>     >     git://linux-arm.org/kvmtool-jpb.git
>     <http://linux-arm.org/kvmtool-jpb.git> virtio-iommu/v0.9
>     >
>     >  - virtio-iommu device emulation by Eric Augur.
>     >    [RFC,v9,00/17] VIRTIO-IOMMU device
>     >    https://github.com/eauger/qemu/tree/v3.1.0-rc2-virtio-iommu-v0.9
> 
>     Now we have the driver and the base qemu device upstream we may resume
>     this activity to complete the VFIO integration. Do you intend the
>     respin? Otherwise let me know if you want me to help.
> 
> 
> Yes Eric, I am planning to respin the changes.
> 
> Can you please point to latest changes (qemu/Linux both).
the driver and the base qemu device are upstream. This only boots in DT
mode at the moment with machvirt. Use -virtio-iommu-pci to instantiate
the device. About the qemu device, you will find latest changes in the
v16 history log: https://patchwork.kernel.org/cover/11382271/

Thanks

Eric

> 
> Thanks
> -Bharat
> 
>     Thanks
> 
>     Eric
>     >
>     > v4->v5:
>     >  - Rebase to v9 version from Eric
>     >  - PCIe device hotplug fix
>     >  - Added Patch 1/5 from Eric previous series (Eric somehow dropped in
>     >    last version.
>     >  - Patch "Translate the MSI doorbell in kvm_arch_fixup_msi_route"
>     >    already integrated with vsmmu3
>     >
>     > v3->v4:
>     >  - Rebase to v4 version from Eric
>     >  - Fixes from Eric with DPDK in VM
>     >  - Logical division in multiple patches
>     >
>     > v2->v3:
>     >  - This series is based on "[RFC v3 0/8] VIRTIO-IOMMU device"
>     >    Which is based on top of v2.10-rc0 that
>     >  - Fixed issue with two PCI devices
>     >  - Addressed review comments
>     >
>     > v1->v2:
>     >   - Added trace events
>     >   - removed vSMMU3 link in patch description
>     >
>     > Bharat Bhushan (4):
>     >   virtio-iommu: Add iommu notifier for iommu-map/unmap
>     >   virtio-iommu: Call iommu notifier on attach/detach
>     >   virtio-iommu: add virtio-iommu replay
>     >   virtio-iommu: handle IOMMU Notifier flag changes
>     >
>     > Eric Auger (1):
>     >   hw/vfio/common: Do not print error when viommu translates into
>     an mmio
>     >     region
>     >
>     >  hw/vfio/common.c                 |   2 -
>     >  hw/virtio/trace-events           |   5 +
>     >  hw/virtio/virtio-iommu.c         | 190
>     ++++++++++++++++++++++++++++++-
>     >  include/hw/virtio/virtio-iommu.h |   6 +
>     >  4 files changed, 198 insertions(+), 5 deletions(-)
>     >
> 
> 
> 
> -- 
> -Bharat



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-03-02 14:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-27  6:52 [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Bharat Bhushan
2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 1/5] hw/vfio/common: Do not print error when viommu translates into an mmio region Bharat Bhushan
2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 2/5] virtio-iommu: Add iommu notifier for iommu-map/unmap Bharat Bhushan
2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 3/5] virtio-iommu: Call iommu notifier on attach/detach Bharat Bhushan
2018-11-27  6:52 ` [Qemu-devel] [PATCH RFC v5 4/5] virtio-iommu: add virtio-iommu replay Bharat Bhushan
2018-11-27  6:53 ` [Qemu-devel] [PATCH RFC v5 5/5] virtio-iommu: handle IOMMU Notifier flag changes Bharat Bhushan
2020-02-28  9:36 ` [Qemu-devel] [PATCH RFC v5 0/5] virtio-iommu: VFIO integration Auger Eric
2020-03-02  5:12   ` Bharat Bhushan
2020-03-02  7:00     ` Auger Eric

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.