VDUSE will need to munmap() the IOTLB entry on removal
from the cache, as it performs mmap() before insertion.

This patch introduces a callback that VDUSE layer will
implement to achieve this.

Signed-off-by: Maxime Coquelin <maxime.coque...@redhat.com>
---
 lib/vhost/iotlb.c | 12 ++++++++++++
 lib/vhost/vhost.h |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c
index 188dfb8e38..86b0be62b4 100644
--- a/lib/vhost/iotlb.c
+++ b/lib/vhost/iotlb.c
@@ -25,6 +25,15 @@ struct vhost_iotlb_entry {
 
 #define IOTLB_CACHE_SIZE 2048
 
+static void
+vhost_user_iotlb_remove_notify(struct virtio_net *dev, struct 
vhost_iotlb_entry *entry)
+{
+       if (dev->backend_ops->iotlb_remove_notify == NULL)
+               return;
+
+       dev->backend_ops->iotlb_remove_notify(entry->uaddr, entry->uoffset, 
entry->size);
+}
+
 static bool
 vhost_user_iotlb_share_page(struct vhost_iotlb_entry *a, struct 
vhost_iotlb_entry *b)
 {
@@ -198,6 +207,7 @@ vhost_user_iotlb_cache_remove_all(struct virtio_net *dev)
                vhost_user_iotlb_set_dump(node);
 
                TAILQ_REMOVE(&dev->iotlb_list, node, next);
+               vhost_user_iotlb_remove_notify(dev, node);
                vhost_user_iotlb_pool_put(dev, node);
        }
 
@@ -223,6 +233,7 @@ vhost_user_iotlb_cache_random_evict(struct virtio_net *dev)
                        vhost_user_iotlb_clear_dump(node, prev_node, next_node);
 
                        TAILQ_REMOVE(&dev->iotlb_list, node, next);
+                       vhost_user_iotlb_remove_notify(dev, node);
                        vhost_user_iotlb_pool_put(dev, node);
                        dev->iotlb_cache_nr--;
                        break;
@@ -314,6 +325,7 @@ vhost_user_iotlb_cache_remove(struct virtio_net *dev, 
uint64_t iova, uint64_t si
                        vhost_user_iotlb_clear_dump(node, prev_node, next_node);
 
                        TAILQ_REMOVE(&dev->iotlb_list, node, next);
+                       vhost_user_iotlb_remove_notify(dev, node);
                        vhost_user_iotlb_pool_put(dev, node);
                        dev->iotlb_cache_nr--;
                } else {
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index cc5c707205..2ad26f6951 100644
--- a/lib/vhost/vhost.h
+++ b/lib/vhost/vhost.h
@@ -89,10 +89,14 @@
        for (iter = val; iter < num; iter++)
 #endif
 
+struct virtio_net;
+typedef void (*vhost_iotlb_remove_notify)(uint64_t addr, uint64_t off, 
uint64_t size);
+
 /**
  * Structure that contains backend-specific ops.
  */
 struct vhost_backend_ops {
+       vhost_iotlb_remove_notify iotlb_remove_notify;
 };
 
 /**
-- 
2.39.2

Reply via email to