uio: Add dmabuf import ioctl
Subsystems (2)
cover uio: Add dmabuf import ioctl
Hi,
I'm looking to enable platform independent device driver stacks on Linux. Currently, I have some driver built on top of Linux UIO [1], and possibly there can be more of such drivers: ex, soft IP drivers programmed on FPGA. Some device includes data movers such as DMA, and that requires some mechanism to import external buffers and program the data movers from user space.
Thus this patch set adds a couple of ioctls to import the dmabuf and return required information back to user. This allows the user drivers to use dmabuf compatible external buffers: ex, it's tested with ION allocator.
I'd like to understand if this is right approach which can be used to develop the user space software stacks further, especially because
- adding new ioctls to generic uio
- security concerns from exposing low level information: dma addr For example, vfio isn't option as iommu may not be available for all such devices on all platforms. So any feedback to move forward would be appreciated.
Thanks,
-hyun
[1] https://patchwork.kernel.org/patch/10774761/
Hyun Kwon (1):
uio: Add dma-buf import ioctls
drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.h
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 1/1 uio: Add dma-buf import ioctls
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.h
drivers/uio/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.o
drivers/uio/uio.c +43 -0
79 lines not on this page · raw message
drivers/uio/uio_dmabuf.c new file +210 -0
210 lines not on this page · raw message
drivers/uio/uio_dmabuf.h new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Xilinx, Inc. +* +* Author: Hyun Woo Kwon <[email protected]> +* +* DMA buf support for UIO device +* +*/ + +#ifndef _UIO_DMABUF_H_ +#define _UIO_DMABUF_H_ + +struct uio_device ; +struct list_head ; +struct mutex ; + +long uio_dmabuf_map (struct uio_device *dev,struct list_head *dbufs, +struct mutex *dbufs_lock,void __user *user_args); +long uio_dmabuf_unmap (struct uio_device *dev,struct list_head *dbufs, +struct mutex *dbufs_lock,void __user *user_args); + +int uio_dmabuf_cleanup (struct uio_device *dev,struct list_head *dbufs, +struct mutex *dbufs_lock); + +#endif
include/uapi/linux/uio/uio.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* The header for UIO driver +* +* Copyright (C) 2019 Xilinx, Inc. +* +* Author: Hyun Woo Kwon <[email protected]> +*/ + +#ifndef _UAPI_UIO_UIO_H_ +#define _UAPI_UIO_UIO_H_ + +#include <linux/ioctl.h> +#include <linux/types.h> + +#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4 + +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir; +}; + +#define UIO_IOC_BASE 'U' + +#define UIO_IOC_MAP_DMABUF _IOWR(UIO_IOC_BASE, 0x1, struct uio_dmabuf_args) +#define UIO_IOC_UNMAP_DMABUF _IOWR(UIO_IOC_BASE, 0x2, struct uio_dmabuf_args) + +#endif
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Greg Kroah-Hartman
maintainerRe: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)
We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4
enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;
Why the odd alignment? Are you sure this is the best packing for such a structure?
Why is dbuf_fd __s32? dir can be __u8, right?
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
thanks,
greg k-h
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Quoted 103 lines · Greg Kroah-Hartman
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Quoted 6 lines
Why is
dbuf_fd__s32? dir can be__u8, right?I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Also, exporting dma_addr to userspace is considered a very bad idea. If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of drm_gem.c and merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one with
commit 4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a (tag:
drm-misc-next-fixes-2018-10-03)
Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200
drm/fb_helper: Allow leaking fbdev smem_start
Together with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Hi Daniel,
Thanks for the comment.
Quoted 107 lines · Daniel Vetter
Quoted 105 lines · Greg Kroah-Hartman
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Why is
dbuf_fd__s32? dir can be__u8, right?
Quoted 7 lines
Quoted 4 lines
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.
I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one with
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
Thanks,
-hyun
[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/drivers
Quoted 6 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200
Quoted 10 lines
drm/fb_helper: Allow leaking fbdev
smem_startTogether with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Quoted 144 lines · Hyun Kwon
Hi Daniel,
Thanks for the comment.
Quoted 107 lines · Daniel Vetter
Quoted 105 lines · Greg Kroah-Hartman
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Why is
dbuf_fd__s32? dir can be__u8, right?Quoted 7 lines
Quoted 4 lines
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one with
Quoted 6 lines
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
There's a group of people working on upstreaming a xilinx drm driver already. Which driver are we talking about? Can you pls provide a link to that xilinx drm driver?
Thanks, Daniel
Quoted 22 lines
Thanks,
-hyun[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/driversQuoted 16 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200drm/fb_helper: Allow leaking fbdev
smem_startTogether with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Hi Daniel,
Quoted 152 lines · Daniel Vetter
Quoted 144 lines · Hyun Kwon
Hi Daniel,
Thanks for the comment.
Quoted 107 lines · Daniel Vetter
Quoted 105 lines · Greg Kroah-Hartman
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Why is
dbuf_fd__s32? dir can be__u8, right?Quoted 7 lines
Quoted 4 lines
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one withQuoted 6 lines
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
Quoted 4 lines
There's a group of people working on upstreaming a xilinx drm driver already. Which driver are we talking about? Can you pls provide a link to that xilinx drm driver?
The one I was pushing [1] is implemented purely for display, and not intended for anything other than that as of now. What I'm refering to above is part of Xilinx FPGA (acceleration) runtime [2]. As far as I know, it's planned to be upstreamed, but not yet started. The Xilinx runtime software has its own in-kernel memory manager based on drm_cma_gem with its own ioctls [3].
Thanks,
-hyun
[1] https://patchwork.kernel.org/patch/10513001/
[2] https://github.com/Xilinx/XRT
[3] https://github.com/Xilinx/XRT/tree/master/src/runtime_src/driver/zynq/drm
Quoted 16 lines
Thanks, Daniel
Quoted 14 lines
Thanks,
-hyun[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/driversQuoted 8 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200drm/fb_helper: Allow leaking fbdev
smem_start
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Together with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Quoted 167 lines · Hyun Kwon
Hi Daniel,
Quoted 152 lines · Daniel Vetter
Quoted 144 lines · Hyun Kwon
Hi Daniel,
Thanks for the comment.
Quoted 107 lines · Daniel Vetter
Quoted 105 lines · Greg Kroah-Hartman
Quoted 74 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 4 lines
drivers/uio/uio.c +1
-0@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); } +static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Why is
dbuf_fd__s32? dir can be__u8, right?Quoted 7 lines
Quoted 4 lines
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one withQuoted 6 lines
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
Quoted 4 lines
There's a group of people working on upstreaming a xilinx drm driver already. Which driver are we talking about? Can you pls provide a link to that xilinx drm driver?
The one I was pushing [1] is implemented purely for display, and not intended for anything other than that as of now. What I'm refering to above is part of Xilinx FPGA (acceleration) runtime [2]. As far as I know, it's planned to be upstreamed, but not yet started. The Xilinx runtime software has its own in-kernel memory manager based on
drm_cma_gemwith its own ioctls [3].
Quoted 6 lines
Thanks,
-hyun[1] https://patchwork.kernel.org/patch/10513001/
[2] https://github.com/Xilinx/XRT
[3] https://github.com/Xilinx/XRT/tree/master/src/runtime_src/driver/zynq/drm
I've done a very quick look only, and yes this is kinda what I'd expect. Doing a small drm gem driver for an fpga/accelarator that needs lots of memories is the right architecture, since at the low level of kernel interfaces a gpu really isn't anything else than an accelarater.
And from a very cursory look the gem driver you mentioned (I only scrolled through the ioctl handler quickly) looks reasonable.
-Daniel
Quoted 32 lines
Quoted 32 lines
Thanks, Daniel
Quoted 22 lines
Thanks,
-hyun[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/driversQuoted 16 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200drm/fb_helper: Allow leaking fbdev
smem_startTogether with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Hi Daniel,
Quoted 35 lines · Daniel Vetter
Quoted 34 lines · Hyun Kwon
Hi Daniel,
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Hyun Kwon
Hi Daniel,
Thanks for the comment.
Quoted 24 lines · Daniel Vetter
Quoted 22 lines · Greg Kroah-Hartman
Quoted 20 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +0
-0@@ -1,5 +1,5 @@
[snip]
Quoted 52 lines
Quoted 45 lines
Quoted 33 lines
Quoted 26 lines
Quoted 2 lines
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one withQuoted 6 lines
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
Quoted 4 lines
There's a group of people working on upstreaming a xilinx drm driver already. Which driver are we talking about? Can you pls provide a link to that xilinx drm driver?
The one I was pushing [1] is implemented purely for display, and not intended for anything other than that as of now. What I'm refering to above is part of Xilinx FPGA (acceleration) runtime [2]. As far as I know, it's planned to be upstreamed, but not yet started. The Xilinx runtime software has its own in-kernel memory manager based on
drm_cma_gemwith its own ioctls [3].Quoted 6 lines
Thanks,
-hyun[1] https://patchwork.kernel.org/patch/10513001/
[2] https://github.com/Xilinx/XRT
[3] https://github.com/Xilinx/XRT/tree/master/src/runtime_src/driver/zynq/drm
Quoted 7 lines
I've done a very quick look only, and yes this is kinda what I'd expect. Doing a small drm gem driver for an fpga/accelarator that needs lots of memories is the right architecture, since at the low level of kernel interfaces a gpu really isn't anything else than an accelarater.
And from a very cursory look the gem driver you mentioned (I only scrolled through the ioctl handler quickly) looks reasonable.
Thanks for taking time to look and share input. But still I'd like to understand why it's more reasonable if the similar ioctl exists with drm than with uio. Is it because such drm ioctl is vendor specific?
Thanks,
-hyun
Quoted 29 lines
-Daniel
Quoted 28 lines
Quoted 28 lines
Thanks, Daniel
Quoted 22 lines
Thanks,
-hyun[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/driversQuoted 16 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200drm/fb_helper: Allow leaking fbdev
smem_startTogether with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Quoted 98 lines · Hyun Kwon
Hi Daniel,
Quoted 35 lines · Daniel Vetter
Quoted 34 lines · Hyun Kwon
Hi Daniel,
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Hyun Kwon
Hi Daniel,
Thanks for the comment.
Quoted 24 lines · Daniel Vetter
Quoted 22 lines · Greg Kroah-Hartman
Quoted 20 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +0
-0@@ -1,5 +1,5 @@[snip]
Quoted 57 lines
Quoted 45 lines
Quoted 33 lines
Quoted 26 lines
Quoted 2 lines
Frankly looks like a ploy to sidestep review by graphics folks. We'd ask for the userspace first :-)
Please refer to pull request [1].
For any interest in more details, the libmetal is the abstraction layer which provides platform independent APIs. The backend implementation can be selected per different platforms: ex, rtos, linux, standalone (xilinx),,,. For Linux, it supports UIO / vfio as of now. The actual user space drivers sit on top of libmetal. Such drivers can be found in [2]. This is why I try to avoid any device specific code in Linux kernel.
Quoted 2 lines
Also, exporting
dma_addrto userspace is considered a very bad idea.I agree, hence the RFC to pick some brains. :-) Would it make sense if this call doesn't export the physicall address, but instead takes only the dmabuf fd and register offsets to be programmed?
Quoted 5 lines
If you want to do this properly, you need a minimal in-kernel memory manager, and those tend to be based on top of
drm_gem.cand merged through the gpu tree. The last place where we accidentally leaked a dma addr for gpu buffers was in the fbdev code, and we plugged that one withQuoted 6 lines
Could you please help me understand how having a in-kernel memory manager helps? Isn't it just moving same dmabuf import / paddr export functionality in different modules: kernel memory manager vs uio. In fact, Xilinx does have such memory manager based on drm gem in downstream. But for this time we took the approach of implementing this through generic dmabuf allocator, ION, and enabling the import capability in the UIO infrastructure instead.
Quoted 4 lines
There's a group of people working on upstreaming a xilinx drm driver already. Which driver are we talking about? Can you pls provide a link to that xilinx drm driver?
The one I was pushing [1] is implemented purely for display, and not intended for anything other than that as of now. What I'm refering to above is part of Xilinx FPGA (acceleration) runtime [2]. As far as I know, it's planned to be upstreamed, but not yet started. The Xilinx runtime software has its own in-kernel memory manager based on
drm_cma_gemwith its own ioctls [3].Quoted 6 lines
Thanks,
-hyun[1] https://patchwork.kernel.org/patch/10513001/
[2] https://github.com/Xilinx/XRT
[3] https://github.com/Xilinx/XRT/tree/master/src/runtime_src/driver/zynq/drmI've done a very quick look only, and yes this is kinda what I'd expect. Doing a small drm gem driver for an fpga/accelarator that needs lots of memories is the right architecture, since at the low level of kernel interfaces a gpu really isn't anything else than an accelarater.
Quoted 6 lines
Quoted 2 lines
And from a very cursory look the gem driver you mentioned (I only scrolled through the ioctl handler quickly) looks reasonable.
Thanks for taking time to look and share input. But still I'd like to understand why it's more reasonable if the similar ioctl exists with drm than with uio. Is it because such drm ioctl is vendor specific?
We do have quite a pile of shared infrastructure in drm beyond just the vendor specific ioctl. So putting accelerator drivers there makes sense, whether the programming is a GPU, some neural network folder, an FPGA or something else. The one issue is that we require open source userspace together with your driver, since just the accelerator shim in the kernel alone is fairly useless (both for review and for doing anything with it).
But there's also some kernel maintainers who disagree and happily take drivers originally written for drm and then rewritten for non-drm for upstream to avoid the drm folks (or at least it very much looks like that, and happens fairly regularly).
Cheers, Daniel
Quoted 42 lines
Thanks,
-hyunQuoted 38 lines
-Daniel
Quoted 32 lines
Quoted 32 lines
Thanks, Daniel
Quoted 22 lines
Thanks,
-hyun[1] https://github.com/OpenAMP/libmetal/pull/82/commits/951e2762bd487c98919ad12f2aa81773d8fe7859
[2] https://github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/driversQuoted 16 lines
commit
4be9bd10e22dfc7fc101c5cf5969ef2d3a042d8a(tag:
drm-misc-next-fixes-2018-10-03)Author: Neil Armstrong <[email protected]> Date: Fri Sep 28 14:05:55 2018 +0200drm/fb_helper: Allow leaking fbdev
smem_startTogether with cuse the above patch should be enough to implement a drm driver entirely in userspace at least.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
In reply to Greg Kroah-HartmanHi Greg,
Thanks for the comments.
Quoted 78 lines · Greg Kroah-Hartman
Quoted 77 lines · Hyun Kwon
Add the dmabuf map / unmap interfaces. This allows the user driver to be able to import the external dmabuf and use it from user space.
Signed-off-by Hyun Kwon <[email protected]>--- drivers/uio/Makefile | 2 +- drivers/uio/uio.c | 43 +++++++++ drivers/uio/uio_dmabuf.c | 210 +++++++++++++++++++++++++++++++++++++++++++ drivers/uio/uio_dmabuf.h | 26 ++++++ include/uapi/linux/uio/uio.h | 33 +++++++ 5 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/uio/uio_dmabuf.c create mode 100644 drivers/uio/uio_dmabuf.h create mode 100644 include/uapi/linux/uio/uio.hdrivers/uio/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UIO) += uio.o +obj-$(CONFIG_UIO) += uio.o uio_dmabuf.o obj-$(CONFIG_UIO_CIF) += uio_cif.o obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o obj-$(CONFIG_UIO_DMEM_GENIRQ) += uio_dmem_genirq.odrivers/uio/uio.c +15
-0@@ -24,6 +24,12 @@#include <linux/kobject.h> #include <linux/cdev.h> #include <linux/uio_driver.h> +#include <linux/list.h> +#include <linux/mutex.h> + +#include <uapi/linux/uio/uio.h> + +#include "uio_dmabuf.h" #define UIO_MAX_DEVICES (1U << MINORBITS)@@ -454,6 +460,8 @@ static irqreturn_t uio_interrupt(int irq, void *dev_id)struct uio_listener {struct uio_device *dev;s32 event_count; +struct list_head dbufs; +struct mutex dbufs_lock;/* protect @dbufs */ };static int uio_open (struct inode *inode,struct file *filep)@@ -500,6 +508,9 @@ static int uio_open(struct inode *inode, struct file *filep)if (ret) goto err_infoopen; +INIT_LIST_HEAD (&listener->dbufs); +mutex_init (&listener->dbufs_lock); +return 0 ; err_infoopen:@@ -529,6 +540,10 @@ static int uio_release(struct inode *inode, struct file *filep)struct uio_listener *listener = filep->private_data;struct uio_device *idev = listener->dev; + ret =uio_dmabuf_cleanup (idev, &listener->dbufs, &listener->dbufs_lock); +if (ret) +dev_err (&idev->dev,"failed to clean up the dma bufs\n" ); +mutex_lock (&idev->info_lock);if (idev->info && idev->info->release) ret = idev->info->release (idev->info, inode);@@ -652,6 +667,33 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,return retval ? retval :sizeof (s32); }
Quoted 5 lines
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 670
Quoted 1 line
drivers/uio/uio.c +1
-0+static long uio_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)We have resisted adding a uio ioctl for a long time, can't you do this through sysfs somehow?
The dmabuf is managed as per process resource, so it's hard to do it through sysfs.
Quoted 19 lines
A meta-comment about your ioctl structure:
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 674
Quoted 4 lines
drivers/uio/uio.c +4
-0+#define UIO_DMABUF_DIR_BIDIR 1 +#define UIO_DMABUF_DIR_TO_DEV 2 +#define UIO_DMABUF_DIR_FROM_DEV 3 +#define UIO_DMABUF_DIR_NONE 4enumerated type?
drivers/uio/uio.c static ssize_t uio_write(struct file *filep, const char __user *buf, · line 680
Quoted 6 lines
drivers/uio/uio.c +6
-0+ +struct uio_dmabuf_args { +__s32 dbuf_fd; +__u64 dma_addr; +__u64 size; +__u32 dir;Why the odd alignment? Are you sure this is the best packing for such a structure?
Quoted 1 line
Why is
dbuf_fd__s32? dir can be__u8, right?
The dmabuf fd is defined as int, so __s32 seems correct. Please let me know otherwise. The dir can be __u8. Will fix if there is v2 at all.
Quoted 5 lines
I don't know that dma layer very well, it would be good to get some review from others to see if this really is even a viable thing to do. The fd handling seems a bit "odd" here, but maybe I just do not understand it.
Agreed. So I'm looking forward to feedback or if there's more sensible alternative.
Thanks,
-hyun
Quoted 8 lines
thanks,
greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel