From: Bharat Bhushan <Bharat.Bhushan@nxp.com>
To: eric.auger@redhat.com, eric.auger.pro@gmail.com,
peter.maydell@linaro.org, alex.williamson@redhat.com,
mst@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: wei@redhat.com, kevin.tian@intel.com, marc.zyngier@arm.com,
tn@semihalf.com, will.deacon@arm.com, drjones@redhat.com,
robin.murphy@arm.com, christoffer.dall@linaro.org,
bharatb.yadav@gmail.com, Bharat Bhushan <Bharat.Bhushan@nxp.com>
Subject: [Qemu-devel] [PATCH v4 3/5] virtio-iommu: Call iommu notifier for attach/detach
Date: Wed, 27 Sep 2017 12:03:18 +0530 [thread overview]
Message-ID: <1506494000-31982-4-git-send-email-Bharat.Bhushan@nxp.com> (raw)
In-Reply-To: <1506494000-31982-1-git-send-email-Bharat.Bhushan@nxp.com>
iommu-notifier are called when a device is attached
or detached to as address-space.
This is needed for VFIO.
Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v3->v4:
Follwoig fixes by Eric
- Return "false" from virtio_iommu_mapping_unmap/map()
- Calling virtio_iommu_notify_unmap/map() for all device in as
hw/virtio/virtio-iommu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 085e972..ff91bce 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -127,8 +127,42 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr iova,
memory_region_notify_iommu(mr, 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_dev_from_as(viommu_dev *dev)
{
+ VirtioIOMMUNotifierNode *node;
+ VirtIOIOMMU *s = dev->viommu;
+ viommu_as *as = dev->as;
+
+ QLIST_FOREACH(node, &s->notifiers_list, next) {
+ if (dev->id == node->iommu_dev->devfn) {
+ g_tree_foreach(as->mappings, virtio_iommu_mapping_unmap,
+ &node->iommu_dev->iommu_mr);
+ }
+ }
+
QLIST_REMOVE(dev, next);
dev->as = NULL;
}
@@ -260,6 +294,7 @@ 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);
+ VirtioIOMMUNotifierNode *node;
viommu_as *as;
viommu_dev *dev;
@@ -284,6 +319,14 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
dev->as = as;
g_tree_ref(as->mappings);
+ /* replay existing address space mappings on the associated mr */
+ QLIST_FOREACH(node, &s->notifiers_list, next) {
+ if (devid == node->iommu_dev->devfn) {
+ g_tree_foreach(as->mappings, virtio_iommu_mapping_map,
+ &node->iommu_dev->iommu_mr);
+ }
+ }
+
return VIRTIO_IOMMU_S_OK;
}
--
1.9.3
next prev parent reply other threads:[~2017-09-27 6:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 6:33 [Qemu-devel] [PATCH v4 0/5] virtio-iommu: VFIO integration Bharat Bhushan
2017-09-27 6:33 ` [Qemu-devel] [PATCH v4 1/5] target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route Bharat Bhushan
2017-09-27 6:33 ` [Qemu-devel] [PATCH v4 2/5] virtio-iommu: Add iommu notifier for map/unmap Bharat Bhushan
2017-09-27 6:33 ` Bharat Bhushan [this message]
2017-09-27 6:33 ` [Qemu-devel] [PATCH v4 4/5] virtio-iommu: add iommu replay Bharat Bhushan
2017-09-27 6:33 ` [Qemu-devel] [PATCH v4 5/5] virtio-iommu: add iommu notifier memory-region Bharat Bhushan
2017-09-27 6:46 ` [Qemu-devel] [PATCH v4 0/5] virtio-iommu: VFIO integration Bharat Bhushan
2017-09-27 7:01 ` Peter Xu
2017-09-27 8:32 ` Bharat Bhushan
2017-09-27 7:41 ` [Qemu-devel] [Qemu-arm] " Linu Cherian
2017-09-27 8:30 ` Bharat Bhushan
2017-09-27 8:55 ` Auger Eric
2017-09-27 9:05 ` Linu Cherian
2017-09-27 9:21 ` Linu Cherian
2017-09-27 9:24 ` Auger Eric
2017-10-04 11:49 ` Linu Cherian
2017-10-05 10:46 ` Auger Eric
2017-10-05 11:54 ` Auger Eric
2017-10-05 12:13 ` Auger Eric
2017-10-05 17:02 ` Auger Eric
2017-10-06 3:46 ` Bharat Bhushan
2017-10-06 7:24 ` Auger Eric
2017-10-06 8:41 ` Linu Cherian
2017-10-10 6:42 ` Bharat Bhushan
2017-10-11 9:42 ` Auger Eric
2017-09-27 8:58 ` Linu Cherian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1506494000-31982-4-git-send-email-Bharat.Bhushan@nxp.com \
--to=bharat.bhushan@nxp.com \
--cc=alex.williamson@redhat.com \
--cc=bharatb.yadav@gmail.com \
--cc=christoffer.dall@linaro.org \
--cc=drjones@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=eric.auger@redhat.com \
--cc=kevin.tian@intel.com \
--cc=marc.zyngier@arm.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=robin.murphy@arm.com \
--cc=tn@semihalf.com \
--cc=wei@redhat.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).