[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v7 07/25] vhost: Add reference counting to vhost_iova_tree
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v7 07/25] vhost: Add reference counting to vhost_iova_tree |
Date: |
Wed, 13 Apr 2022 18:31:48 +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 6a4f24e0f9..2fc825d7b1 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_iova(const VhostIOVATree *iova_tree,
const DMAMap *map);
diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c
index 55fed1fefb..31445cbdfc 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 v7 06/25] vdpa: Send all updates in memory listener commit, (continued)
- [RFC PATCH v7 06/25] vdpa: Send all updates in memory listener commit, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 08/25] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 09/25] vhost: move descriptor translation to vhost_svq_vring_write_descs, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 10/25] vdpa: Fix index calculus at vhost_vdpa_svqs_start, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 07/25] vhost: Add reference counting to vhost_iova_tree,
Eugenio Pérez <=
- [RFC PATCH v7 11/25] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 12/25] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 13/25] virtio: Make virtqueue_alloc_element non-static, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 03/25] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 15/25] vhost: Add custom used buffer callback, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 14/25] vhost: Add SVQElement, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 16/25] vdpa: control virtqueue support on shadow virtqueue, Eugenio Pérez, 2022/04/13