Re: [PATCH v3 7/9] xen/gntdev: Add initial support for dma-buf UAPI

2018-06-14 Thread Oleksandr Andrushchenko

On 06/13/2018 04:49 AM, Boris Ostrovsky wrote:



On 06/12/2018 09:41 AM, Oleksandr Andrushchenko wrote:


diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index a09db23e9663..e82660d81d7e 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -48,6 +48,9 @@
  #include 
    #include "gntdev-common.h"
+#ifdef CONFIG_XEN_GNTDEV_DMABUF
+#include "gntdev-dmabuf.h"
+#endif
    MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Derek G. Murray , "
@@ -566,6 +569,15 @@ static int gntdev_open(struct inode *inode, 
struct file *flip)

  INIT_LIST_HEAD(>freeable_maps);
  mutex_init(>lock);
  +#ifdef CONFIG_XEN_GNTDEV_DMABUF
+    priv->dmabuf_priv = gntdev_dmabuf_init();
+    if (IS_ERR(priv->dmabuf_priv)) {
+    ret = PTR_ERR(priv->dmabuf_priv);
+    kfree(priv);
+    return ret;
+    }
+#endif
+
  if (use_ptemod) {
  priv->mm = get_task_mm(current);
  if (!priv->mm) {
@@ -616,8 +628,13 @@ static int gntdev_release(struct inode *inode, 
struct file *flip)

  WARN_ON(!list_empty(>freeable_maps));
  mutex_unlock(>lock);
  +#ifdef CONFIG_XEN_GNTDEV_DMABUF
+    gntdev_dmabuf_fini(priv->dmabuf_priv);
+#endif
+
  if (use_ptemod)
  mmu_notifier_unregister(>mn, priv->mm);
+
  kfree(priv);
  return 0;
  }
@@ -987,6 +1004,107 @@ static long gntdev_ioctl_grant_copy(struct 
gntdev_priv *priv, void __user *u)

  return ret;
  }
  +#ifdef CONFIG_XEN_GNTDEV_DMABUF
+static long
+gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
+  struct ioctl_gntdev_dmabuf_exp_from_refs __user *u)



Didn't we agree that this code moves to gntdev-dmabuf.c ?


Sure, didn't think we want IOCTL's code to be moved as well,
but that does make sense - will move all

-boris


Thank you,
Oleksandr
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v3 7/9] xen/gntdev: Add initial support for dma-buf UAPI

2018-06-13 Thread Boris Ostrovsky



On 06/12/2018 09:41 AM, Oleksandr Andrushchenko wrote:


diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index a09db23e9663..e82660d81d7e 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -48,6 +48,9 @@
  #include 
  
  #include "gntdev-common.h"

+#ifdef CONFIG_XEN_GNTDEV_DMABUF
+#include "gntdev-dmabuf.h"
+#endif
  
  MODULE_LICENSE("GPL");

  MODULE_AUTHOR("Derek G. Murray , "
@@ -566,6 +569,15 @@ static int gntdev_open(struct inode *inode, struct file 
*flip)
INIT_LIST_HEAD(>freeable_maps);
mutex_init(>lock);
  
+#ifdef CONFIG_XEN_GNTDEV_DMABUF

+   priv->dmabuf_priv = gntdev_dmabuf_init();
+   if (IS_ERR(priv->dmabuf_priv)) {
+   ret = PTR_ERR(priv->dmabuf_priv);
+   kfree(priv);
+   return ret;
+   }
+#endif
+
if (use_ptemod) {
priv->mm = get_task_mm(current);
if (!priv->mm) {
@@ -616,8 +628,13 @@ static int gntdev_release(struct inode *inode, struct file 
*flip)
WARN_ON(!list_empty(>freeable_maps));
mutex_unlock(>lock);
  
+#ifdef CONFIG_XEN_GNTDEV_DMABUF

+   gntdev_dmabuf_fini(priv->dmabuf_priv);
+#endif
+
if (use_ptemod)
mmu_notifier_unregister(>mn, priv->mm);
+
kfree(priv);
return 0;
  }
@@ -987,6 +1004,107 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv 
*priv, void __user *u)
return ret;
  }
  
+#ifdef CONFIG_XEN_GNTDEV_DMABUF

+static long
+gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
+ struct ioctl_gntdev_dmabuf_exp_from_refs 
__user *u)



Didn't we agree that this code moves to gntdev-dmabuf.c ?

-boris

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3 7/9] xen/gntdev: Add initial support for dma-buf UAPI

2018-06-12 Thread Oleksandr Andrushchenko
From: Oleksandr Andrushchenko 

Add UAPI and IOCTLs for dma-buf grant device driver extension:
the extension allows userspace processes and kernel modules to
use Xen backed dma-buf implementation. With this extension grant
references to the pages of an imported dma-buf can be exported
for other domain use and grant references coming from a foreign
domain can be converted into a local dma-buf for local export.
Implement basic initialization and stubs for Xen DMA buffers'
support.

Signed-off-by: Oleksandr Andrushchenko 
---
 drivers/xen/Kconfig |  10 +++
 drivers/xen/Makefile|   1 +
 drivers/xen/gntdev-common.h |   6 ++
 drivers/xen/gntdev-dmabuf.c |  72 
 drivers/xen/gntdev-dmabuf.h |  39 +++
 drivers/xen/gntdev.c| 132 
 include/uapi/xen/gntdev.h   |  91 +
 7 files changed, 351 insertions(+)
 create mode 100644 drivers/xen/gntdev-dmabuf.c
 create mode 100644 drivers/xen/gntdev-dmabuf.h

diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 39536ddfbce4..52d64e4b6b81 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -152,6 +152,16 @@ config XEN_GNTDEV
help
  Allows userspace processes to use grants.
 
+config XEN_GNTDEV_DMABUF
+   bool "Add support for dma-buf grant access device driver extension"
+   depends on XEN_GNTDEV && XEN_GRANT_DMA_ALLOC && DMA_SHARED_BUFFER
+   help
+ Allows userspace processes and kernel modules to use Xen backed
+ dma-buf implementation. With this extension grant references to
+ the pages of an imported dma-buf can be exported for other domain
+ use and grant references coming from a foreign domain can be
+ converted into a local dma-buf for local export.
+
 config XEN_GRANT_DEV_ALLOC
tristate "User-space grant reference allocator driver"
depends on XEN
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 3c87b0c3aca6..33afb7b2b227 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -41,5 +41,6 @@ obj-$(CONFIG_XEN_PVCALLS_BACKEND) += pvcalls-back.o
 obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls-front.o
 xen-evtchn-y   := evtchn.o
 xen-gntdev-y   := gntdev.o
+xen-gntdev-$(CONFIG_XEN_GNTDEV_DMABUF) += gntdev-dmabuf.o
 xen-gntalloc-y := gntalloc.o
 xen-privcmd-y  := privcmd.o
diff --git a/drivers/xen/gntdev-common.h b/drivers/xen/gntdev-common.h
index 7a9845a6bee9..a3408fd39b07 100644
--- a/drivers/xen/gntdev-common.h
+++ b/drivers/xen/gntdev-common.h
@@ -16,6 +16,8 @@
 #include 
 #include 
 
+struct gntdev_dmabuf_priv;
+
 struct gntdev_priv {
/* maps with visible offsets in the file descriptor */
struct list_head maps;
@@ -31,6 +33,10 @@ struct gntdev_priv {
/* Device for which DMA memory is allocated. */
struct device *dma_dev;
 #endif
+
+#ifdef CONFIG_XEN_GNTDEV_DMABUF
+   struct gntdev_dmabuf_priv *dmabuf_priv;
+#endif
 };
 
 struct gntdev_unmap_notify {
diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c
new file mode 100644
index ..dc57c6a25525
--- /dev/null
+++ b/drivers/xen/gntdev-dmabuf.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Xen dma-buf functionality for gntdev.
+ *
+ * Copyright (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
+ */
+
+#include 
+
+#include "gntdev-dmabuf.h"
+
+struct gntdev_dmabuf_priv {
+   /* List of exported DMA buffers. */
+   struct list_head exp_list;
+   /* List of wait objects. */
+   struct list_head exp_wait_list;
+   /* This is the lock which protects dma_buf_xxx lists. */
+   struct mutex lock;
+};
+
+/* DMA buffer export support. */
+
+/* Implementation of wait for exported DMA buffer to be released. */
+
+int gntdev_dmabuf_exp_wait_released(struct gntdev_dmabuf_priv *priv, int fd,
+   int wait_to_ms)
+{
+   return -EINVAL;
+}
+
+int gntdev_dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
+   int count, u32 domid, u32 *refs, u32 *fd)
+{
+   *fd = -1;
+   return -EINVAL;
+}
+
+/* DMA buffer import support. */
+
+struct gntdev_dmabuf *
+gntdev_dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
+ int fd, int count, int domid)
+{
+   return ERR_PTR(-ENOMEM);
+}
+
+u32 *gntdev_dmabuf_imp_get_refs(struct gntdev_dmabuf *gntdev_dmabuf)
+{
+   return NULL;
+}
+
+int gntdev_dmabuf_imp_release(struct gntdev_dmabuf_priv *priv, u32 fd)
+{
+   return -EINVAL;
+}
+
+struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void)
+{
+   struct gntdev_dmabuf_priv *priv;
+
+   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return ERR_PTR(-ENOMEM);
+
+   return priv;
+}
+
+void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv)
+{
+