All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hyun Kwon <hyun.kwon@xilinx.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	Hyun Kwon <hyunk@xilinx.com>, Sonal Santan <sonals@xilinx.com>,
	Cyril Chemparathy <cyrilc@xilinx.com>,
	Jiaying Liang <jliang@xilinx.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	Michal Simek <michals@xilinx.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Date: Tue, 26 Feb 2019 14:16:28 -0800	[thread overview]
Message-ID: <20190226221627.GA10631@smtp.xilinx.com> (raw)
In-Reply-To: <20190226115311.GA4094@kroah.com>

Hi Greg,

Thanks for the comments.

On Tue, 2019-02-26 at 03:53:11 -0800, Greg Kroah-Hartman wrote:
> On Sat, Feb 23, 2019 at 12:28:17PM -0800, Hyun Kwon wrote:
> > 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 <hyun.kwon@xilinx.com>
> > ---
> >  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
> > 
> > diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
> > index c285dd2..5da16c7 100644
> > --- a/drivers/uio/Makefile
> > +++ b/drivers/uio/Makefile
> > @@ -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
> > diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> > index 1313422..6841f98 100644
> > --- a/drivers/uio/uio.c
> > +++ b/drivers/uio/uio.c
> > @@ -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);
> >  }
> >  
> > +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.

> A meta-comment about your ioctl structure:
> 
> > +#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?
> 
> > +
> > +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?

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.

> 
> 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

> 
> thanks,
> 
> greg k-h
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Hyun Kwon <hyun.kwon@xilinx.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	Sonal Santan <sonals@xilinx.com>,
	Cyril Chemparathy <cyrilc@xilinx.com>,
	Jiaying Liang <jliang@xilinx.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	Michal Simek <michals@xilinx.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Date: Tue, 26 Feb 2019 14:16:28 -0800	[thread overview]
Message-ID: <20190226221627.GA10631@smtp.xilinx.com> (raw)
In-Reply-To: <20190226115311.GA4094@kroah.com>

Hi Greg,

Thanks for the comments.

On Tue, 2019-02-26 at 03:53:11 -0800, Greg Kroah-Hartman wrote:
> On Sat, Feb 23, 2019 at 12:28:17PM -0800, Hyun Kwon wrote:
> > 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 <hyun.kwon@xilinx.com>
> > ---
> >  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
> > 
> > diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
> > index c285dd2..5da16c7 100644
> > --- a/drivers/uio/Makefile
> > +++ b/drivers/uio/Makefile
> > @@ -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
> > diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> > index 1313422..6841f98 100644
> > --- a/drivers/uio/uio.c
> > +++ b/drivers/uio/uio.c
> > @@ -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);
> >  }
> >  
> > +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.

> A meta-comment about your ioctl structure:
> 
> > +#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?
> 
> > +
> > +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?

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.

> 
> 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

> 
> thanks,
> 
> greg k-h
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Hyun Kwon <hyun.kwon@xilinx.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hyun Kwon <hyunk@xilinx.com>,
	Stefano Stabellini <stefanos@xilinx.com>,
	Sonal Santan <sonals@xilinx.com>,
	Cyril Chemparathy <cyrilc@xilinx.com>,
	Jiaying Liang <jliang@xilinx.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	Michal Simek <michals@xilinx.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls
Date: Tue, 26 Feb 2019 14:16:28 -0800	[thread overview]
Message-ID: <20190226221627.GA10631@smtp.xilinx.com> (raw)
In-Reply-To: <20190226115311.GA4094@kroah.com>

Hi Greg,

Thanks for the comments.

On Tue, 2019-02-26 at 03:53:11 -0800, Greg Kroah-Hartman wrote:
> On Sat, Feb 23, 2019 at 12:28:17PM -0800, Hyun Kwon wrote:
> > 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 <hyun.kwon@xilinx.com>
> > ---
> >  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
> > 
> > diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
> > index c285dd2..5da16c7 100644
> > --- a/drivers/uio/Makefile
> > +++ b/drivers/uio/Makefile
> > @@ -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
> > diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> > index 1313422..6841f98 100644
> > --- a/drivers/uio/uio.c
> > +++ b/drivers/uio/uio.c
> > @@ -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);
> >  }
> >  
> > +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.

> A meta-comment about your ioctl structure:
> 
> > +#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?
> 
> > +
> > +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?

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.

> 
> 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

> 
> thanks,
> 
> greg k-h
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-02-26 22:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23 20:28 [PATCH RFC 0/1] uio: Add dmabuf import ioctl Hyun Kwon
2019-02-23 20:28 ` Hyun Kwon
2019-02-23 20:28 ` Hyun Kwon
2019-02-23 20:28 ` [PATCH RFC 1/1] uio: Add dma-buf import ioctls Hyun Kwon
2019-02-23 20:28   ` Hyun Kwon
2019-02-23 20:28   ` Hyun Kwon
2019-02-26 11:53   ` Greg Kroah-Hartman
2019-02-26 11:53     ` Greg Kroah-Hartman
2019-02-26 12:06     ` Daniel Vetter
2019-02-26 12:06       ` Daniel Vetter
2019-02-26 12:06       ` Daniel Vetter
2019-02-26 22:18       ` Hyun Kwon
2019-02-26 22:18         ` Hyun Kwon
2019-02-26 22:18         ` Hyun Kwon
2019-02-27 14:13         ` Daniel Vetter
2019-02-27 14:13           ` Daniel Vetter
2019-02-27 14:13           ` Daniel Vetter
2019-02-28  0:36           ` Hyun Kwon
2019-02-28  0:36             ` Hyun Kwon
2019-02-28  0:36             ` Hyun Kwon
2019-02-28 10:01             ` Daniel Vetter
2019-02-28 10:01               ` Daniel Vetter
2019-02-28 10:01               ` Daniel Vetter
2019-03-01  0:18               ` Hyun Kwon
2019-03-01  0:18                 ` Hyun Kwon
2019-03-01  0:18                 ` Hyun Kwon
2019-03-01  8:55                 ` Daniel Vetter
2019-03-01  8:55                   ` Daniel Vetter
2019-02-26 22:16     ` Hyun Kwon [this message]
2019-02-26 22:16       ` Hyun Kwon
2019-02-26 22:16       ` Hyun Kwon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190226221627.GA10631@smtp.xilinx.com \
    --to=hyun.kwon@xilinx.com \
    --cc=cyrilc@xilinx.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hyunk@xilinx.com \
    --cc=jliang@xilinx.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=michals@xilinx.com \
    --cc=sonals@xilinx.com \
    --cc=stefanos@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.