clear-pkgs-linux-iot-lts2018/0861-drivers-hyper_dmabuf-R...

56 lines
2.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zhao Yakui <yakui.zhao@intel.com>
Date: Thu, 10 Jan 2019 15:17:59 +0800
Subject: [PATCH] drivers/hyper_dmabuf: Reuse the exported dma_buf to avoid
creating multiple dma_buf for one importer
After the imported hyper_dmabuf is added to the BE, the
IOCTL_HYPER_DMABUF_EXPORT_REMOTE iotcl will export one dma_buf based on
the imported ID info. When the ioctl is called twice for the same ID,
it will try to create two dma_buf structure and then sync with the FE
driver. In fact one dma_buf is enough for the same imported ID info. And
the different file_fd is returned for the same dma_buf when the ioctl
is called twice.
Change-Id: I15df88ed7c79ff2c96e877a95414f97899751a0d
Tracked-On: projectacrn/acrn-hypervisor#2237
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu, Shuo <shuo.a.liu@intel.com>
Acked-by: Dongwon Kim <dongwon.kim@intel.com>
Tracked-On: PKT-1657
---
.../dma-buf/hyper_dmabuf/hyper_dmabuf_ioctl.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ioctl.c b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ioctl.c
index 62f83cc..8fc3a56 100644
--- a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ioctl.c
+++ b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ioctl.c
@@ -450,6 +450,23 @@ static int hyper_dmabuf_export_fd_ioctl(struct file *filp, void *data)
mutex_lock(&hy_drv_priv->lock);
+ if (imported->dma_buf) {
+ if (imported->valid == false) {
+ mutex_unlock(&hy_drv_priv->lock);
+ dev_err(hy_drv_priv->dev,
+ "Buffer is released {id:%d key:%d %d %d}, cannot import\n",
+ imported->hid.id, imported->hid.rng_key[0],
+ imported->hid.rng_key[1], imported->hid.rng_key[2]);
+ return -EINVAL;
+ }
+ get_dma_buf(imported->dma_buf);
+ export_fd_attr->fd = dma_buf_fd(imported->dma_buf,
+ export_fd_attr->flags);
+ mutex_unlock(&hy_drv_priv->lock);
+ dev_dbg(hy_drv_priv->dev, "%s exit\n", __func__);
+ return 0;
+ }
+
imported->importers++;
/* send notification for export_fd to exporter */
--
https://clearlinux.org