clear-pkgs-linux-iot-lts2018/0631-hyper_dmabuf-virtio-Co...

101 lines
3.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mateusz Polrola <mateuszx.potrola@intel.com>
Date: Tue, 21 Aug 2018 11:19:52 +0200
Subject: [PATCH] hyper_dmabuf/virtio: Correctly cleanup front end connections
Virtio frontends were not fully cleanup on release of VBS-K handle, this
change adds helper function that allows to find virtio frontend that was
using particular VBS-K handle and clean it up.
Signed-off-by: Mateusz Polrola <mateuszx.potrola@intel.com>
---
.../virtio/hyper_dmabuf_virtio_be_drv.c | 22 +++++++++++++++++++
.../virtio/hyper_dmabuf_virtio_fe_list.c | 14 ++++++++++++
.../virtio/hyper_dmabuf_virtio_fe_list.h | 5 ++++-
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_be_drv.c b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_be_drv.c
index bb16360d06d5..a89d557c7c4c 100644
--- a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_be_drv.c
+++ b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_be_drv.c
@@ -319,6 +319,21 @@ static int vbs_k_open(struct inode *inode, struct file *f)
return 0;
}
+static void cleanup_fe(struct virtio_fe_info *fe_info, void *attr)
+{
+ struct virtio_be_priv *priv = attr;
+ if (fe_info->priv == priv) {
+ acrn_ioreq_del_iorange(fe_info->client_id,
+ priv->dev.io_range_type ? REQ_MMIO : REQ_PORTIO,
+ priv->dev.io_range_start,
+ priv->dev.io_range_start + priv->dev.io_range_len);
+
+ acrn_ioreq_destroy_client(fe_info->client_id);
+ virtio_fe_remove(fe_info->client_id);
+ kfree(fe_info);
+ }
+}
+
static int vbs_k_release(struct inode *inode, struct file *f)
{
struct virtio_be_priv *priv =
@@ -333,6 +348,13 @@ static int vbs_k_release(struct inode *inode, struct file *f)
kfree(priv->pending_tx_req);
virtio_comm_ring_free(&priv->tx_ring);
+
+ /*
+ * Find and cleanup virtio frontend that
+ * has been using released vbs k file
+ */
+ virtio_fe_foreach(cleanup_fe, priv);
+
kfree(priv);
return 0;
}
diff --git a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.c b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.c
index 79b30e286b5e..84b6ed5e96c1 100644
--- a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.c
+++ b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.c
@@ -97,3 +97,17 @@ int virtio_fe_remove(int client_id)
return -ENOENT;
}
+
+void virtio_fe_foreach(
+ void (*func)(struct virtio_fe_info *, void *attr),
+ void *attr)
+{
+ struct virtio_fe_info_entry *info_entry;
+ struct hlist_node *tmp;
+ int bkt;
+
+ hash_for_each_safe(virtio_fe_hash, bkt, tmp,
+ info_entry, node) {
+ func(info_entry->info, attr);
+ }
+}
diff --git a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.h b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.h
index bc7ef843161c..c353c1e5baa1 100644
--- a/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.h
+++ b/drivers/dma-buf/hyper_dmabuf/virtio/hyper_dmabuf_virtio_fe_list.h
@@ -39,10 +39,13 @@ void virtio_fe_table_init(void);
int virtio_fe_add(struct virtio_fe_info *fe_info);
-int virtio_remove_fe(int client_id);
+int virtio_fe_remove(int client_id);
struct virtio_fe_info *virtio_fe_find(int client_id);
struct virtio_fe_info *virtio_fe_find_by_vmid(int vmid);
+void virtio_fe_foreach(void (*func)(struct virtio_fe_info *,
+ void *attr), void *attr);
+
#endif /* __HYPER_DMABUF_VIRTIO_FE_LIST_H__*/
--
https://clearlinux.org