[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 5/5] virtio-iommu: add iommu notifier memory-region
From: |
Bharat Bhushan |
Subject: |
[PATCH v7 5/5] virtio-iommu: add iommu notifier memory-region |
Date: |
Fri, 13 Mar 2020 13:18:11 +0530 |
Finally add notify_flag_changed() to for memory-region
access flag iommu flag change notifier
Finally add the memory notifier
Signed-off-by: Bharat Bhushan <address@hidden>
---
hw/virtio/trace-events | 2 ++
hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 8bae651191..a486adcf6d 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -76,3 +76,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 bcc9895b76..7744410f72 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -803,6 +803,37 @@ unlock:
qemu_mutex_unlock(&s->mutex);
}
+static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr,
+ IOMMUNotifierFlag old,
+ IOMMUNotifierFlag new,
+ Error **errp)
+{
+ 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 0;
+ }
+
+ /* 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 0;
+}
+
static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1020,6 +1051,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.17.1
- [PATCH v7 0/5] virtio-iommu: VFIO integration, Bharat Bhushan, 2020/03/13
- [PATCH v7 5/5] virtio-iommu: add iommu notifier memory-region,
Bharat Bhushan <=
- [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/13
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Auger Eric, 2020/03/13
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Auger Eric, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Auger Eric, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Jean-Philippe Brucker, 2020/03/16
- Re: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach, Bharat Bhushan, 2020/03/17