[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v8 19/21] vhost: Add reference counting to vhost_iova_tree
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v8 19/21] vhost: Add reference counting to vhost_iova_tree |
Date: |
Thu, 19 May 2022 21:13:04 +0200 |
Now that different vqs can have different ASIDs its easier to track them
using reference counters.
QEMU's glib version still does not have them so we've copied g_rc_box,
so the implementation can be converted to glib's one when the minimum
version is raised.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-iova-tree.h | 5 +++--
hw/virtio/vhost-iova-tree.c | 21 +++++++++++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h
index 1ffcdc5b57..bacd17d99c 100644
--- a/hw/virtio/vhost-iova-tree.h
+++ b/hw/virtio/vhost-iova-tree.h
@@ -16,8 +16,9 @@
typedef struct VhostIOVATree VhostIOVATree;
VhostIOVATree *vhost_iova_tree_new(uint64_t iova_first, uint64_t iova_last);
-void vhost_iova_tree_delete(VhostIOVATree *iova_tree);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete);
+VhostIOVATree *vhost_iova_tree_acquire(VhostIOVATree *iova_tree);
+void vhost_iova_tree_release(VhostIOVATree *iova_tree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_release);
const DMAMap *vhost_iova_tree_find(const VhostIOVATree *iova_tree,
const DMAMap *map);
diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c
index 1a59894385..208476b3db 100644
--- a/hw/virtio/vhost-iova-tree.c
+++ b/hw/virtio/vhost-iova-tree.c
@@ -28,6 +28,9 @@ struct VhostIOVATree {
/* IOVA address to qemu memory maps. */
IOVATree *iova_taddr_map;
+
+ /* Reference count */
+ size_t refcnt;
};
/**
@@ -44,14 +47,28 @@ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first,
hwaddr iova_last)
tree->iova_last = iova_last;
tree->iova_taddr_map = iova_tree_new();
+ tree->refcnt = 1;
return tree;
}
/**
- * Delete an iova tree
+ * Increases the reference count of the iova tree
+ */
+VhostIOVATree *vhost_iova_tree_acquire(VhostIOVATree *iova_tree)
+{
+ ++iova_tree->refcnt;
+ return iova_tree;
+}
+
+/**
+ * Decrease reference counter of iova tree, freeing if it reaches 0
*/
-void vhost_iova_tree_delete(VhostIOVATree *iova_tree)
+void vhost_iova_tree_release(VhostIOVATree *iova_tree)
{
+ if (--iova_tree->refcnt) {
+ return;
+ }
+
iova_tree_destroy(iova_tree->iova_taddr_map);
g_free(iova_tree);
}
--
2.27.0
- [RFC PATCH v8 11/21] vhost: Update kernel headers, (continued)
- [RFC PATCH v8 11/21] vhost: Update kernel headers, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 10/21] vhost: Add vhost_svq_inject, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 12/21] vdpa: delay set_vring_ready after DRIVER_OK, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 13/21] vhost: Add ShadowVirtQueueStart operation, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 14/21] vhost: Make possible to check for device exclusive vq group, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 16/21] vdpa: Add vhost_vdpa_start_control_svq, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 17/21] vdpa: Add asid attribute to vdpa device, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 18/21] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 21/21] vdpa: Add x-cvq-svq, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 15/21] vhost: add vhost_svq_poll, Eugenio Pérez, 2022/05/19
- [RFC PATCH v8 19/21] vhost: Add reference counting to vhost_iova_tree,
Eugenio Pérez <=
- [RFC PATCH v8 20/21] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/05/19