Skip to contentSkip to conversation

xen: dma-buf support for grant device

PATCH In review Oleksandr Andrushchenko 5 participants 93 messages May 25, 2018 – Jun 1, 2018 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#80 lore raw

PATCH 8/8 xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

In reply to Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

Allow creating grant device context for use by kernel modules which require functionality, provided by gntdev. Export symbols for dma-buf API provided by the module.

---
 drivers/xen/gntdev.c    | 116 ++++++++++++++++++++++++++--------------
 include/xen/grant_dev.h |  37 +++++++++++++
 2 files changed, 113 insertions(+), 40 deletions(-)
 create mode 100644 include/xen/grant_dev.h
drivers/xen/gntdev.c +76 -40
index d8b6168f2cd9..912056f3e909 100644
@@ -684,14 +684,33 @@ static const struct mmu_notifier_ops gntdev_mmu_ops = {
 
 /* ------------------------------------------------------------------ */
 
-static int gntdev_open(struct inode *inode, struct file *flip)
+void gntdev_free_context(struct gntdev_priv *priv)
+{
+	struct grant_map *map;
+
+	pr_debug("priv %p\n", priv);
+
+	mutex_lock(&priv->lock);
+	while (!list_empty(&priv->maps)) {
+		map = list_entry(priv->maps.next, struct grant_map, next);
+		list_del(&map->next);
+		gntdev_put_map(NULL /* already removed */, map);
+	}
+	WARN_ON(!list_empty(&priv->freeable_maps));
+
+	mutex_unlock(&priv->lock);
+
+	kfree(priv);
+}
+EXPORT_SYMBOL(gntdev_free_context);
+
+struct gntdev_priv *gntdev_alloc_context(struct device *dev)
 {
 	struct gntdev_priv *priv;
-	int ret = 0;
 
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&priv->maps);
 	INIT_LIST_HEAD(&priv->freeable_maps);
@@ -704,6 +723,32 @@ static int gntdev_open(struct inode *inode, struct file *flip)
 	INIT_LIST_HEAD(&priv->dmabuf_imp_list);
 #endif
 
+#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
+	priv->dma_dev = dev;
+
+	/*
+	 * The device is not spawn from a device tree, so arch_setup_dma_ops
+	 * is not called, thus leaving the device with dummy DMA ops.
+	 * Fix this call of_dma_configure() with a NULL node to set
+	 * default DMA ops.
+	 */
+	of_dma_configure(priv->dma_dev, NULL);
+#endif
+	pr_debug("priv %p\n", priv);
+
+	return priv;
+}
+EXPORT_SYMBOL(gntdev_alloc_context);
+
+static int gntdev_open(struct inode *inode, struct file *flip)
+{
+	struct gntdev_priv *priv;
+	int ret = 0;
+
+	priv = gntdev_alloc_context(gntdev_miscdev.this_device);
+	if (IS_ERR(priv))
+		return PTR_ERR(priv);
+
 	if (use_ptemod) {
 		priv->mm = get_task_mm(current);
 		if (!priv->mm) {
@@ -716,23 +761,11 @@ static int gntdev_open(struct inode *inode, struct file *flip)
 	}
 
 	if (ret) {
-		kfree(priv);
+		gntdev_free_context(priv);
 		return ret;
 	}
 
 	flip->private_data = priv;
-#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
-	priv->dma_dev = gntdev_miscdev.this_device;
-
-	/*
-	 * The device is not spawn from a device tree, so arch_setup_dma_ops
-	 * is not called, thus leaving the device with dummy DMA ops.
-	 * Fix this call of_dma_configure() with a NULL node to set
-	 * default DMA ops.
-	 */
-	of_dma_configure(priv->dma_dev, NULL);
-#endif
-	pr_debug("priv %p\n", priv);
 
 	return 0;
 }
@@ -740,22 +773,11 @@ static int gntdev_open(struct inode *inode, struct file *flip)
 static int gntdev_release(struct inode *inode, struct file *flip)
 {
 	struct gntdev_priv *priv = flip->private_data;
-	struct grant_map *map;
-
-	pr_debug("priv %p\n", priv);
-
-	mutex_lock(&priv->lock);
-	while (!list_empty(&priv->maps)) {
-		map = list_entry(priv->maps.next, struct grant_map, next);
-		list_del(&map->next);
-		gntdev_put_map(NULL /* already removed */, map);
-	}
-	WARN_ON(!list_empty(&priv->freeable_maps));
-	mutex_unlock(&priv->lock);
 
 	if (use_ptemod)
 		mmu_notifier_unregister(&priv->mn, priv->mm);
-	kfree(priv);
+
+	gntdev_free_context(priv);
 	return 0;
 }
 
@@ -1210,7 +1232,7 @@ dmabuf_exp_wait_obj_get_by_fd(struct gntdev_priv *priv, int fd)
 	return ret;
 }
 
-static int dmabuf_exp_wait_released(struct gntdev_priv *priv, int fd,
+int gntdev_dmabuf_exp_wait_released(struct gntdev_priv *priv, int fd,
 				    int wait_to_ms)
 {
 	struct xen_dmabuf *xen_dmabuf;
@@ -1242,6 +1264,7 @@ static int dmabuf_exp_wait_released(struct gntdev_priv *priv, int fd,
 	dmabuf_exp_wait_obj_free(priv, obj);
 	return ret;
 }
+EXPORT_SYMBOL(gntdev_dmabuf_exp_wait_released);
 
 /* ------------------------------------------------------------------ */
 /* DMA buffer export support.                                         */
@@ -1511,7 +1534,7 @@ dmabuf_exp_alloc_backing_storage(struct gntdev_priv *priv, int dmabuf_flags,
 	return map;
 }
 
-static int dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
+int gntdev_dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
 				int count, u32 domid, u32 *refs, u32 *fd)
 {
 	struct grant_map *map;
@@ -1557,6 +1580,7 @@ static int dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
 	gntdev_remove_map(priv, map);
 	return ret;
 }
+EXPORT_SYMBOL(gntdev_dmabuf_exp_from_refs);
 
 /* ------------------------------------------------------------------ */
 /* DMA buffer import support.                                         */
@@ -1646,8 +1670,9 @@ static struct xen_dmabuf *dmabuf_imp_alloc_storage(int count)
 	return ERR_PTR(-ENOMEM);
 }
 
-static struct xen_dmabuf *
-dmabuf_imp_to_refs(struct gntdev_priv *priv, int fd, int count, int domid)
+struct xen_dmabuf *
+gntdev_dmabuf_imp_to_refs(struct gntdev_priv *priv, int fd,
+			  int count, int domid)
 {
 	struct xen_dmabuf *xen_dmabuf, *ret;
 	struct dma_buf *dma_buf;
@@ -1736,6 +1761,16 @@ dmabuf_imp_to_refs(struct gntdev_priv *priv, int fd, int count, int domid)
 	dma_buf_put(dma_buf);
 	return ret;
 }
+EXPORT_SYMBOL(gntdev_dmabuf_imp_to_refs);
+
+u32 *gntdev_dmabuf_imp_get_refs(struct xen_dmabuf *xen_dmabuf)
+{
+	if (xen_dmabuf)
+		return xen_dmabuf->u.imp.refs;
+
+	return NULL;
+}
+EXPORT_SYMBOL(gntdev_dmabuf_imp_get_refs);
 
 /*
  * Find the hyper dma-buf by its file descriptor and remove
@@ -1759,7 +1794,7 @@ dmabuf_imp_find_unlink(struct gntdev_priv *priv, int fd)
 	return ret;
 }
 
-static int dmabuf_imp_release(struct gntdev_priv *priv, u32 fd)
+int gntdev_dmabuf_imp_release(struct gntdev_priv *priv, u32 fd)
 {
 	struct xen_dmabuf *xen_dmabuf;
 	struct dma_buf_attachment *attach;
@@ -1785,6 +1820,7 @@ static int dmabuf_imp_release(struct gntdev_priv *priv, u32 fd)
 	dmabuf_imp_free_storage(xen_dmabuf);
 	return 0;
 }
+EXPORT_SYMBOL(gntdev_dmabuf_imp_release);
 
 /* ------------------------------------------------------------------ */
 /* DMA buffer IOCTL support.                                          */
@@ -1810,8 +1846,8 @@ gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv,
 		goto out;
 	}
 
-	ret = dmabuf_exp_from_refs(priv, op.flags, op.count,
-				   op.domid, refs, &op.fd);
+	ret = gntdev_dmabuf_exp_from_refs(priv, op.flags, op.count,
+					  op.domid, refs, &op.fd);
 	if (ret)
 		goto out;
 
@@ -1832,7 +1868,7 @@ gntdev_ioctl_dmabuf_exp_wait_released(struct gntdev_priv *priv,
 	if (copy_from_user(&op, u, sizeof(op)) != 0)
 		return -EFAULT;
 
-	return dmabuf_exp_wait_released(priv, op.fd, op.wait_to_ms);
+	return gntdev_dmabuf_exp_wait_released(priv, op.fd, op.wait_to_ms);
 }
 
 static long
@@ -1846,7 +1882,7 @@ gntdev_ioctl_dmabuf_imp_to_refs(struct gntdev_priv *priv,
 	if (copy_from_user(&op, u, sizeof(op)) != 0)
 		return -EFAULT;
 
-	xen_dmabuf = dmabuf_imp_to_refs(priv, op.fd, op.count, op.domid);
+	xen_dmabuf = gntdev_dmabuf_imp_to_refs(priv, op.fd, op.count, op.domid);
 	if (IS_ERR(xen_dmabuf))
 		return PTR_ERR(xen_dmabuf);
 
@@ -1858,7 +1894,7 @@ gntdev_ioctl_dmabuf_imp_to_refs(struct gntdev_priv *priv,
 	return 0;
 
 out_release:
-	dmabuf_imp_release(priv, op.fd);
+	gntdev_dmabuf_imp_release(priv, op.fd);
 	return ret;
 }
 
@@ -1871,7 +1907,7 @@ gntdev_ioctl_dmabuf_imp_release(struct gntdev_priv *priv,
 	if (copy_from_user(&op, u, sizeof(op)) != 0)
 		return -EFAULT;
 
-	return dmabuf_imp_release(priv, op.fd);
+	return gntdev_dmabuf_imp_release(priv, op.fd);
 }
 #endif
 
include/xen/grant_dev.h new file +37 -0
new file mode 100644
index 000000000000..faccc9170174
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+
+/*
+ * Grant device kernel API
+ *
+ * Copyright (C) 2018 EPAM Systems Inc.
+ *
+ * Author: Oleksandr Andrushchenko <[email protected]>
+ */
+
+#ifndef _GRANT_DEV_H
+#define _GRANT_DEV_H
+
+#include <linux/types.h>
+
+struct device;
+struct gntdev_priv;
+#ifdef CONFIG_XEN_GNTDEV_DMABUF
+struct xen_dmabuf;
+#endif
+
+struct gntdev_priv *gntdev_alloc_context(struct device *dev);
+void gntdev_free_context(struct gntdev_priv *priv);
+
+#ifdef CONFIG_XEN_GNTDEV_DMABUF
+int gntdev_dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
+				int count, u32 domid, u32 *refs, u32 *fd);
+int gntdev_dmabuf_exp_wait_released(struct gntdev_priv *priv, int fd,
+				    int wait_to_ms);
+
+struct xen_dmabuf *gntdev_dmabuf_imp_to_refs(struct gntdev_priv *priv,
+					     int fd, int count, int domid);
+u32 *gntdev_dmabuf_imp_get_refs(struct xen_dmabuf *xen_dmabuf);
+int gntdev_dmabuf_imp_release(struct gntdev_priv *priv, u32 fd);
+#endif
+
+#endif
Signature · 7 lines
2.17.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#81 lore raw
In reply to Oleksandr Andrushchenko
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 4 lines
  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025 ++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c. I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

You essentially only share file_operations entry points with original gntdev code, right?

-boris

Quoted 11 lines
  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +
  10 files changed, 1527 insertions(+), 103 deletions(-)

create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

#82 lore raw
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 7 lines
Quoted 4 lines

  drivers/xen/Kconfig           |   23 + drivers/xen/Makefile          |    1 + drivers/xen/balloon.c         |   71 +-- drivers/xen/gntdev.c          | 1025 ++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 2 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c, so finally I decided to put it all together.

Quoted 2 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release callback which makes some cross-dependencies between modules which seemed to be not cute (gntdev keeps its all structs and functions inside, so I cannot easily access those w/o helpers).

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 7 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

Quoted 5 lines
  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#83 lore raw
Quoted 29 lines · Oleksandr Andrushchenko
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 8 lines
Quoted 5 lines

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 2 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c, so finally I decided to put it all together.

Quoted 8 lines
Quoted 2 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release callback which makes some cross-dependencies between modules which seemed to be not cute (gntdev keeps its all structs and functions inside, so I cannot easily access those w/o helpers).

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]? If this is what you meant.

Thank you,
Oleksandr

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

[1] https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#84 lore raw
Quoted 43 lines · Oleksandr Andrushchenko
Quoted 42 lines · Oleksandr Andrushchenko
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 8 lines
Quoted 5 lines

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 5 lines
Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]?
If this is what you meant.

I looked at final gntdev.c code and I think at least one of the chunks there ("DMA buffer export support. ") can also be moved out. It still have a bit too many ifdefs but it looks better to my eye than jamming everything into a single file (and I think more code can be moved out, but we can talk about it when you post the patches so that we can see context).

BTW, I believe it won't build with !CONFIG_XEN_GNTDEV_DMABUF --- gntdev_remove_map() is defined under this option and is referenced later without it.

-boris

Quoted 20 lines

Thank you,
Oleksandr

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

Quoted 2 lines

[1]
https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#85 lore raw
In reply to Oleksandr Andrushchenko
Quoted 43 lines · Oleksandr Andrushchenko
Quoted 42 lines · Oleksandr Andrushchenko
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 8 lines
Quoted 5 lines

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 5 lines
Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]?
If this is what you meant.

I looked at final gntdev.c code and I think at least one of the chunks there ("DMA buffer export support. ") can also be moved out. It still have a bit too many ifdefs but it looks better to my eye than jamming everything into a single file (and I think more code can be moved out, but we can talk about it when you post the patches so that we can see context).

BTW, I believe it won't build with !CONFIG_XEN_GNTDEV_DMABUF --- gntdev_remove_map() is defined under this option and is referenced later without it.

-boris

Quoted 22 lines

Thank you,
Oleksandr

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

[1]
https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2

#86 lore raw
Quoted 47 lines · Boris Ostrovsky
Quoted 40 lines · Oleksandr Andrushchenko
Quoted 39 lines · Oleksandr Andrushchenko
Quoted 13 lines · Boris Ostrovsky
Quoted 10 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 7 lines
Quoted 5 lines
   drivers/xen/Kconfig           |   23 +
   drivers/xen/Makefile          |    1 +
   drivers/xen/balloon.c         |   71 +--
   drivers/xen/gntdev.c          | 1025

++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 5 lines
Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]?
If this is what you meant.

Quoted 6 lines

I looked at final gntdev.c code and I think at least one of the chunks there ("DMA buffer export support. ") can also be moved out. It still have a bit too many ifdefs but it looks better to my eye than jamming everything into a single file (and I think more code can be moved out, but we can talk about it when you post the patches so that we can see context).

Sure, will send v2 after I re-check all the patches and run some smoke tests again

Quoted 4 lines

BTW, I believe it won't build with !CONFIG_XEN_GNTDEV_DMABUF --- gntdev_remove_map() is defined under this option and is referenced later without it.

Will check, thank you

Quoted 23 lines

-boris

Quoted 19 lines

Thank you,
Oleksandr

Quoted 15 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 11 lines
Quoted 11 lines
   drivers/xen/grant-table.c     |  176 +++++-
   drivers/xen/mem-reservation.c |  134 +++++
   include/uapi/xen/gntdev.h     |  106 ++++
   include/xen/grant_dev.h       |   37 ++
   include/xen/grant_table.h     |   28 +
   include/xen/mem_reservation.h |   29 +
   10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

[1]
https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#87 lore raw
In reply to Boris Ostrovsky
Quoted 47 lines · Boris Ostrovsky
Quoted 40 lines · Oleksandr Andrushchenko
Quoted 39 lines · Oleksandr Andrushchenko
Quoted 13 lines · Boris Ostrovsky
Quoted 10 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 7 lines
Quoted 5 lines
   drivers/xen/Kconfig           |   23 +
   drivers/xen/Makefile          |    1 +
   drivers/xen/balloon.c         |   71 +--
   drivers/xen/gntdev.c          | 1025

++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 5 lines
Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]?
If this is what you meant.

Quoted 6 lines

I looked at final gntdev.c code and I think at least one of the chunks there ("DMA buffer export support. ") can also be moved out. It still have a bit too many ifdefs but it looks better to my eye than jamming everything into a single file (and I think more code can be moved out, but we can talk about it when you post the patches so that we can see context).

Sure, will send v2 after I re-check all the patches and run some smoke tests again

Quoted 4 lines

BTW, I believe it won't build with !CONFIG_XEN_GNTDEV_DMABUF --- gntdev_remove_map() is defined under this option and is referenced later without it.

Will check, thank you

Quoted 23 lines

-boris

Quoted 19 lines

Thank you,
Oleksandr

Quoted 15 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 11 lines
Quoted 11 lines
   drivers/xen/grant-table.c     |  176 +++++-
   drivers/xen/mem-reservation.c |  134 +++++
   include/uapi/xen/gntdev.h     |  106 ++++
   include/xen/grant_dev.h       |   37 ++
   include/xen/grant_table.h     |   28 +
   include/xen/mem_reservation.h |   29 +
   10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

[1]
https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#88 lore raw
In reply to Oleksandr Andrushchenko
Quoted 29 lines · Oleksandr Andrushchenko
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 8 lines
Quoted 5 lines

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 2 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c, so finally I decided to put it all together.

Quoted 8 lines
Quoted 2 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release callback which makes some cross-dependencies between modules which seemed to be not cute (gntdev keeps its all structs and functions inside, so I cannot easily access those w/o helpers).

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Could you please take a quick look at the way I re-structured the sources here [1]? If this is what you meant.

Thank you,
Oleksandr

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

[1] https://github.com/andr2000/linux/commits/xen_tip_linux_next_xen_dma_buf_v2

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#89 lore raw
In reply to Oleksandr Andrushchenko
Quoted 23 lines · Oleksandr Andrushchenko
Quoted 22 lines · Boris Ostrovsky
Quoted 16 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

Quoted 2 lines
Quoted 1 line

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Yes, source only. The driver stays the same.

Quoted 17 lines
Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Yes, please try it. Maybe even have gntdev_common.c, gntdev_mem.c (??) and gntdev_dma.c.

-boris

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#90 lore raw
In reply to Oleksandr Andrushchenko
Quoted 23 lines · Oleksandr Andrushchenko
Quoted 22 lines · Boris Ostrovsky
Quoted 16 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025
++++++++++++++++++++++++++++++++-

Quoted 2 lines
Quoted 1 line

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Yes, source only. The driver stays the same.

Quoted 17 lines
Quoted 3 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c,
so finally I decided to put it all together.

Quoted 3 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release
callback which makes some cross-dependencies between modules which seemed to be not cute
(gntdev keeps its all structs and functions inside, so I cannot easily access those w/o
helpers).

Quoted 2 lines

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Yes, please try it. Maybe even have gntdev_common.c, gntdev_mem.c (??) and gntdev_dma.c.

-boris

Quoted 17 lines
Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 12 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

#91 lore raw
In reply to Boris Ostrovsky
Quoted 15 lines · Boris Ostrovsky
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
   xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 7 lines
Quoted 4 lines

  drivers/xen/Kconfig           |   23 + drivers/xen/Makefile          |    1 + drivers/xen/balloon.c         |   71 +-- drivers/xen/gntdev.c          | 1025 ++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c.

I assume you mean as a separate file (part of gntdev driver)?

Quoted 2 lines

I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

I tried to do that, but there are some dependencies between the gntdev.c and gntdev_dma.c, so finally I decided to put it all together.

Quoted 2 lines

You essentially only share file_operations entry points with original gntdev code, right?

fops + mappings done by gntdev (struct grant_map) and I need to release map on dma_buf .release callback which makes some cross-dependencies between modules which seemed to be not cute (gntdev keeps its all structs and functions inside, so I cannot easily access those w/o helpers).

But I'll try one more time and move all DMA specific stuff into gntdev_dma.c

Quoted 2 lines

-boris

Thank you,
Oleksandr

Quoted 12 lines
Quoted 7 lines

  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +

Quoted 5 lines
  10 files changed, 1527 insertions(+), 103 deletions(-)

  create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#92 lore raw
In reply to Oleksandr Andrushchenko
Quoted 11 lines · Oleksandr Andrushchenko

Oleksandr Andrushchenko (8):
xen/grant-table: Make set/clear page private code shared xen/balloon: Move common memory reservation routines to a module xen/grant-table: Allow allocating buffers suitable for DMA xen/gntdev: Allow mappings for DMA buffers xen/gntdev: Add initial support for dma-buf UAPI xen/gntdev: Implement dma-buf export functionality xen/gntdev: Implement dma-buf import functionality xen/gntdev: Expose gntdev's dma-buf API for in-kernel use

Quoted 4 lines
  drivers/xen/Kconfig           |   23 +
  drivers/xen/Makefile          |    1 +
  drivers/xen/balloon.c         |   71 +--
  drivers/xen/gntdev.c          | 1025 ++++++++++++++++++++++++++++++++-

I think this calls for gntdev_dma.c. I only had a quick look over gntdev changes but they very much are concentrated in dma-specific routines.

You essentially only share file_operations entry points with original gntdev code, right?

-boris

Quoted 11 lines
  drivers/xen/grant-table.c     |  176 +++++-
  drivers/xen/mem-reservation.c |  134 +++++
  include/uapi/xen/gntdev.h     |  106 ++++
  include/xen/grant_dev.h       |   37 ++
  include/xen/grant_table.h     |   28 +
  include/xen/mem_reservation.h |   29 +
  10 files changed, 1527 insertions(+), 103 deletions(-)

create mode 100644 drivers/xen/mem-reservation.c create mode 100644 include/xen/grant_dev.h create mode 100644 include/xen/mem_reservation.h

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel