Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp511141img; Tue, 26 Feb 2019 04:07:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IbFZQSY1V0CdaE7QsEX7pzh5HM9g6n1DD7DyzpMSoDn88zik9JRTSKkaI4Vw2pzvFnITFfC X-Received: by 2002:a65:6683:: with SMTP id b3mr24031601pgw.423.1551182824531; Tue, 26 Feb 2019 04:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551182824; cv=none; d=google.com; s=arc-20160816; b=pkrEdjoViSYcxdyZ9uJCLs9+nFhqBuw91lNX1dpV3QzSMgwWU7LArwvf0YU0l92gz3 yzUsUGK/1Rfsy3MxKKy3tewcgi4NyMj/XXQRF4b2LteHq5jdyc770sI5EJNKVFEDEWag fZKfschVPkb4tXQGhb2FAkV1Y4le0KP3Wu3M8MBp6Ad1yLrFk7OZpt3RVyvzczvQxrxo QXrdsvdLD9WSmBmR2qO7ltntcQqoRIHhBWcbMWEi9UdFDyEjTNINhzhaWscUrsNRMbXz 0vigH/ZAM4iohf/79biOaDDwXno1hQCzeV96jxSF8lpOhuNwmV0LMjgSAXZbAiuUWl0I j7BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=g5Ov+RxKwl/mKZYYxN4XrdesfyZ+XBCP+/DRAcMvDBk=; b=MzEjVu8p0at8nQ1g+R1jTKwVOaIf9udCP09ejHpu/4TPUMQQnLiKYf8xe62oJ1sGhb kbJC0yROPakmWAdBtimdWWq9V0NUttR21wMhaK7sOcSpHPLpFMbN0C+SinCvTVlMx9rJ 0+EDaUUkx6CUhrfpLvCTwJ+14U9xVNJufuwVjk7lG7G54UCYJDYccM5VIArjuETpaovs ZXFwRb6RpF1IBIkUkfsdTsSMrsTc7Rtvc0doRj67AhTbts01bN/AoOxFeYtpzkVGTRMh e3S3m/v9Qr4osChIdPfnVGeahxT+DIwwgdzwFDX4MM4mFw7kTKNTokM88khAXD2ntH3q FBCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Ih3NfUSF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si11978297plr.341.2019.02.26.04.06.49; Tue, 26 Feb 2019 04:07:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Ih3NfUSF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbfBZMG2 (ORCPT + 99 others); Tue, 26 Feb 2019 07:06:28 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:36079 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbfBZMG1 (ORCPT ); Tue, 26 Feb 2019 07:06:27 -0500 Received: by mail-it1-f196.google.com with SMTP id v83so3664453itf.1 for ; Tue, 26 Feb 2019 04:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g5Ov+RxKwl/mKZYYxN4XrdesfyZ+XBCP+/DRAcMvDBk=; b=Ih3NfUSFo3kJvGozOKt3/XFrX/Ys15EcmTGZJWiclYvBcXRkLDaOmfHljoCVRTePqr RoFq3ma1iNasuxa7/ExGCZWxVxb1AloMRBV/u4YddyATmo1anFvh6sbQpeVEOO440rpW bzZvyyVAy6qYa4sWU7B+5YFopUx8ccwhuwydQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g5Ov+RxKwl/mKZYYxN4XrdesfyZ+XBCP+/DRAcMvDBk=; b=O9On5EzgXmwi0cj5ibnQSHAuRRPLa2VpjLtf0pGiTzz2MMdSkkOHGCA9Ee+rr+UCog VcikpCiitS30JAlMHoFmNlzYmzVq2DeAqMelCvFm9+F4OdlShsTRCseJwR0son3kMdii z3C6qsEmyCDXOWlonWho2MtFPcVugxM+xYiI6E5j5RcBbMm9Qk40DsDbe1AGqs+9Tc3W wuYVTJTz8IsUtVuVqHbvJ59IPxrk75zb/euBpvOIOuTk9aNfzeDivIeA5zu+Z2RYIZYS f/r5fEV8lITIuXGYEmS2DzQApNtHfhISPj/sz6etfvXN4sNuLHqHX1k/VTgV0DnseAAF d+Uw== X-Gm-Message-State: AHQUAuY43YAe63nqOGsWH2pxYbAvhcTA6fvIRYygP64T/ZI6Hw5vfzQq NQT7vSqn5ZliDNPcEtKl+j49aEsk0YKwxpOjciy1pQ== X-Received: by 2002:a24:7412:: with SMTP id o18mr2143337itc.117.1551182786028; Tue, 26 Feb 2019 04:06:26 -0800 (PST) MIME-Version: 1.0 References: <1550953697-7288-1-git-send-email-hyun.kwon@xilinx.com> <1550953697-7288-2-git-send-email-hyun.kwon@xilinx.com> <20190226115311.GA4094@kroah.com> In-Reply-To: <20190226115311.GA4094@kroah.com> From: Daniel Vetter Date: Tue, 26 Feb 2019 13:06:13 +0100 Message-ID: Subject: Re: [PATCH RFC 1/1] uio: Add dma-buf import ioctls To: Greg Kroah-Hartman Cc: Hyun Kwon , Stefano Stabellini , Sonal Santan , Cyril Chemparathy , Jiaying Liang , dri-devel , Linux Kernel Mailing List , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Michal Simek , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 26, 2019 at 12:53 PM 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 > > --- > > 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 > > #include > > #include > > +#include > > +#include > > + > > +#include > > + > > +#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? > > 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? > > 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 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 -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch