[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v3 17/31] virtio-iommu: Add replay() memory region callback
From: |
Michael S. Tsirkin |
Subject: |
[PULL v3 17/31] virtio-iommu: Add replay() memory region callback |
Date: |
Wed, 4 Nov 2020 13:42:05 -0500 |
From: Bharat Bhushan <bbhushan2@marvell.com>
Implement the replay callback to setup all mappings for a new memory
region.
Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Message-Id: <20201030180510.747225-6-jean-philippe@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-iommu.c | 40 ++++++++++++++++++++++++++++++++++++++++
hw/virtio/trace-events | 1 +
2 files changed, 41 insertions(+)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 7b64892351..985257c88f 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -847,6 +847,45 @@ 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)
+{
+ VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value;
+ VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key;
+ IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+ trace_virtio_iommu_remap(mr->parent_obj.name, interval->low,
interval->high,
+ mapping->phys_addr);
+ virtio_iommu_notify_map(mr, interval->low, interval->high,
+ mapping->phys_addr, mapping->flags);
+ 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;
+ VirtIOIOMMUEndpoint *ep;
+
+ sid = virtio_iommu_get_bdf(sdev);
+
+ qemu_mutex_lock(&s->mutex);
+
+ if (!s->endpoints) {
+ goto unlock;
+ }
+
+ 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);
@@ -1076,6 +1115,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 = {
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index b87a397406..ea3c3b25ad 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -108,6 +108,7 @@ virtio_iommu_report_fault(uint8_t reason, uint32_t flags,
uint32_t endpoint, uin
virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t
start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64
virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t
virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64"
virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d"
virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t
virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
+virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end,
uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64"
phys_start=0x%"PRIx64
# virtio-mem.c
virtio_mem_send_response(uint16_t type) "type=%" PRIu16
--
MST
- [PULL v3 06/31] memory-device: Add get_min_alignment() callback, (continued)
- [PULL v3 06/31] memory-device: Add get_min_alignment() callback, Michael S. Tsirkin, 2020/11/04
- [PULL v3 08/31] hw/acpi : Don't use '#' flag of printf format, Michael S. Tsirkin, 2020/11/04
- [PULL v3 07/31] virito-mem: Implement get_min_alignment(), Michael S. Tsirkin, 2020/11/04
- [PULL v3 09/31] hw/acpi : add space before the open parenthesis '(', Michael S. Tsirkin, 2020/11/04
- [PULL v3 11/31] hw/virtio/vhost-backend: Fix Coverity CID 1432871, Michael S. Tsirkin, 2020/11/04
- [PULL v3 12/31] hw/smbios: Fix leaked fd in save_opt_one() error path, Michael S. Tsirkin, 2020/11/04
- [PULL v3 13/31] virtio-iommu: Fix virtio_iommu_mr(), Michael S. Tsirkin, 2020/11/04
- [PULL v3 14/31] virtio-iommu: Store memory region in endpoint struct, Michael S. Tsirkin, 2020/11/04
- [PULL v3 15/31] virtio-iommu: Add memory notifiers for map/unmap, Michael S. Tsirkin, 2020/11/04
- [PULL v3 16/31] virtio-iommu: Call memory notifiers in attach/detach, Michael S. Tsirkin, 2020/11/04
- [PULL v3 17/31] virtio-iommu: Add replay() memory region callback,
Michael S. Tsirkin <=
- [PULL v3 19/31] memory: Add interface to set iommu page size mask, Michael S. Tsirkin, 2020/11/04
- [PULL v3 20/31] vfio: Set IOMMU page size as per host supported page size, Michael S. Tsirkin, 2020/11/04
- [PULL v3 21/31] virtio-iommu: Set supported page size mask, Michael S. Tsirkin, 2020/11/04
- [PULL v3 22/31] vfio: Don't issue full 2^64 unmap, Michael S. Tsirkin, 2020/11/04
- [PULL v3 23/31] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup, Michael S. Tsirkin, 2020/11/04
- [PULL v3 24/31] net: Add vhost-vdpa in show_netdevs(), Michael S. Tsirkin, 2020/11/04
- [PULL v3 25/31] Revert "vhost-blk: set features before setting inflight feature", Michael S. Tsirkin, 2020/11/04
- [PULL v3 26/31] vhost-blk: set features before setting inflight feature, Michael S. Tsirkin, 2020/11/04
- [PULL v3 27/31] libvhost-user: follow QEMU comment style, Michael S. Tsirkin, 2020/11/04
- [PULL v3 28/31] configure: introduce --enable-vhost-user-blk-server, Michael S. Tsirkin, 2020/11/04