Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4237789imm; Wed, 30 May 2018 01:34:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKjrT5lSdd4RP38ZRPpJNR++XcbCdsyXyIRBZpz2yhwlSCvKE4hrtrjmXzePHTEP/AHjkQd X-Received: by 2002:a17:902:3281:: with SMTP id z1-v6mr1921994plb.226.1527669277656; Wed, 30 May 2018 01:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527669277; cv=none; d=google.com; s=arc-20160816; b=WrSQBSkLEo9phDd0j2Vba3q9DxiI+Elb0uAWP6gkPhUwrWrIYLD9KWhIy8UctauBhj 1GqswYF1+SkDLNVdCU1onK9l69Bt5bdMV3gb1NOTZYCSOdtOSXLVwlAb8EgJMkBuIvCP oN/aHrGGy4O9eQVQfLAoZRRSveGLaez49aaPwQ8W/vfQnKS7cuB64TujhvIym7XoA55B V//PM+8h6eeuXMqr1YreFlivIab9P+NAN4zu91oLoZMys6sjUwZh5DfwwDQzCEjTZsPg 5M78woD2L04oY6+SqCWOa3mHYn4TyV2BJBCCsvvPF+ZlSSIMbqxJ5HhhFAyzAabcN8/D k+HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=DaS4XNEVEKphCW41ow7QgbYYkv7X0bucOAIPEanghog=; b=GsTeYqy4QmG9gccunbSONdqJamaIeowFqrcbyy1x7pjQpsJeQVj/RFthHrpxpd8T2N sfsguem86KuVT1EH1MVFBQjjO83CE+Dfi/AnHE4nIPrOL/i5PVzAT73bMR9cbW6s4lG4 g0MvD4I0HPPG4z+N+Hxda5VCaDk3Ti1xJoSvh8YpBLlFDRVSsyZJrI2F1KQ8XFX1hp13 CSTgUpFPTI9qfKLCIDxogJbQ2PYsmXwYz9m3LWKAci5+uRQi2svhB5jojqo9ep9OZT49 UkooDaZUXZqosQL1bAChxcFcHxCyTDxiIqNxHvqTSH0q2h6PqEmDak2yZfK3GDkO3xxQ To6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZZUjUV+H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o89-v6si9202772pfi.165.2018.05.30.01.34.23; Wed, 30 May 2018 01:34:37 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=ZZUjUV+H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937338AbeE3Ice (ORCPT + 99 others); Wed, 30 May 2018 04:32:34 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:42888 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935879AbeE3IcD (ORCPT ); Wed, 30 May 2018 04:32:03 -0400 Received: by mail-lf0-f65.google.com with SMTP id v135-v6so2948451lfa.9; Wed, 30 May 2018 01:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=DaS4XNEVEKphCW41ow7QgbYYkv7X0bucOAIPEanghog=; b=ZZUjUV+HvzR8XMvr8+G0KEmpYYwN+wXGPUciY7eIM9vaWlehKCraKR6fjc8zAHRqQN MDIubNx/rZh66w7J6wztbTRFNyjoXaG/5zu9olHMe5tF9TswwQvzcz6RCVr8lvGwm9aM ja0CCiLricBktr4O1IWEZRRdpee5uVA1uNCENqBBF0xNdc9U2biYnxyha4Lf/SXtCRD5 BcoBqj+JdGnab0xWWlJWyG6XqlMcokYpJRd+C/P4TC32VYE8hNc13Xwdk+J5CDpSzUEk 9YK83MckHMfFzhu8n/F4xscHyruaYBQLik03ZAUqdObYGwt9h/ahOEbOvVf3ReVk83A4 frrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=DaS4XNEVEKphCW41ow7QgbYYkv7X0bucOAIPEanghog=; b=DD6LnRRmKk7gv5T1fqI+HprHkWy8xz++WxAoJP2L4If6+mCfSeGEcIdwUahpB3VLGP N3EZ/IfpODhYN1PuJGw7Jzwe5lFs7OAfB62i4jb8kOiuCw/OtxunhSXNhG1tP5KlAdk5 5L/dBcRruv4nx/pQMxEkn/VaTNargX0uT3cWAsDg8rhVcmEU/ZhXAqQ22Y8YolXuU2tY XRQislC1essHyBZs+nr/HxEFcdzeYzIYvsE4h3MJB8SvkQZaUFxryb6mh2okKKue6SPQ UtCKpA1Q9guaBjL9SVdq+ZMalGIXW3t5PgfWRv5xqSQ2v0oQCjH7N6NVXrMxxJlDC1a/ iVQw== X-Gm-Message-State: ALKqPwcybVwIBzW228gmaAovb5oxVCufY+py8LXbrPhJ4vwIPl6O7utc 2czzEz1wGBKVSQ54TFHSlrQ= X-Received: by 2002:a2e:3e0c:: with SMTP id l12-v6mr1418151lja.23.1527669121960; Wed, 30 May 2018 01:32:01 -0700 (PDT) Received: from [10.17.182.9] (ll-55.209.223.85.sovam.net.ua. [85.223.209.55]) by smtp.gmail.com with ESMTPSA id k23-v6sm4563752ljh.27.2018.05.30.01.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 01:32:01 -0700 (PDT) Subject: Re: [PATCH 8/8] xen/gntdev: Expose gntdev's dma-buf API for in-kernel use To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: daniel.vetter@intel.com, dongwon.kim@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko References: <20180525153331.31188-1-andr2000@gmail.com> <20180525153331.31188-9-andr2000@gmail.com> From: Oleksandr Andrushchenko Message-ID: <94c6bc22-da2e-6543-0f13-7c6c1752533d@gmail.com> Date: Wed, 30 May 2018 11:32:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180525153331.31188-9-andr2000@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/25/2018 06:33 PM, Oleksandr Andrushchenko wrote: > From: Oleksandr Andrushchenko > > 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. > > Signed-off-by: Oleksandr Andrushchenko > --- > 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 > > diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c > index d8b6168f2cd9..912056f3e909 100644 > --- a/drivers/xen/gntdev.c > +++ b/drivers/xen/gntdev.c > @@ -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); I will convert EXPORT_SYMBOL to EXPORT_SYMBOL_GPL here and below > + > +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 > > diff --git a/include/xen/grant_dev.h b/include/xen/grant_dev.h > new file mode 100644 > index 000000000000..faccc9170174 > --- /dev/null > +++ b/include/xen/grant_dev.h > @@ -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 > + */ > + > +#ifndef _GRANT_DEV_H > +#define _GRANT_DEV_H > + > +#include > + > +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