Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp489729imm; Fri, 1 Jun 2018 04:44:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKobfN2DiOheTtpVCJ0WT/ntgFVauWhXWElUuVWyJup/QodPHNlwkDRf9v0WaDPG3k7ubXS X-Received: by 2002:a17:902:d882:: with SMTP id b2-v6mr10473333plz.220.1527853466683; Fri, 01 Jun 2018 04:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527853466; cv=none; d=google.com; s=arc-20160816; b=aNjVkx6MkrFBIqA0y0HZkWyMSsJLSbiDzJlKYa4Olnmv77eTGspVFVhYfeu68NEeyg B1GqARycdf1ZUnju1gNNAhXgARuXg46IvZ/fio+W3GzDCdNk5zv2yiMD81XXyJPsajfj O7oo0YY3GLgHxJH/S7G5fZGq+Q8IO3D+emqhXCKoPNdlibedxkkrIN8UXrMEki0BuQbr /RBk00NdWmzX3zuILwTd9QHqJHGUABS/+c/dFkCfjy4v9IeYnw/AcWbYWTxEIeIvnHox rA3aKeVOPoOWXCd57oBTp2AKUiYMBi18TxP7gjYgzN7a0NNF3WrUyAEfcFysHP6ZnsnS s09w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Objklaokw+WcBMhZ8XsIcNrFSir3IIx2T8m3vRHk5ww=; b=NU/fx3/665t4XcDtFR6ClVtxd89Hle5i73kxy5hQNXporpMX8/RfwdcYX/LH8pG2q3 S+v8B68Ii+01VrUREi6cCyogyOhmFiSgmJPKgVggXqAOZ/IUa6W6FNMRZcQWHZap966S usuClkrUI2m8hBJwd5wyH4hfKV+sRsx+lvEMgfZ4hJJOZHQZ3XXrxMMGcvxLfgXnK7zR JEb/VZuJrchsyBk+wMs9rHH94NyWTWw3M+1ltK3oYYZ3FJs79g9KxRdKTSpA2JYNdOzy +2X87Z56c1L4fUDVlcMqPCyExZ4QqC38i7WJpMbanTIM86pUMhJVpywwU5ICyUShafFM naMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kzE+okL8; 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 l1-v6si39414004pld.493.2018.06.01.04.44.12; Fri, 01 Jun 2018 04:44:26 -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=kzE+okL8; 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 S1752027AbeFALmT (ORCPT + 99 others); Fri, 1 Jun 2018 07:42:19 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:43578 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751938AbeFALlz (ORCPT ); Fri, 1 Jun 2018 07:41:55 -0400 Received: by mail-lf0-f68.google.com with SMTP id n18-v6so14357450lfh.10; Fri, 01 Jun 2018 04:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Objklaokw+WcBMhZ8XsIcNrFSir3IIx2T8m3vRHk5ww=; b=kzE+okL8Nem0rKnJnJOIHS1il7UQKvROO2ItmRQoiUKRDbjStSCh/WrSW6LCxvUjl8 oD2JzksdBJ+Gggagg/JY6gReTTVww9xAf95ab1HvwfcQkV0ayF7aUIwfddea+edqdZ0O Jmgmy32gq1c1hfSJRgt60i99a8P8OXaAoUDQSTSKcGl+w/4fZyaBN0ERi2eG9NG9iRCa q1L0KQ0bfnnwTskz7USSFoO0c/ERuUb4tewGhFoLLmSLVHm3LOY384XM3kJfX2lEfv+s cjTB0h3sL7+nPp/Rp6qWT/HqrHshaHXeyQaqyU+sINOy5451jnuyidaOZs1SW751qH9i stNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Objklaokw+WcBMhZ8XsIcNrFSir3IIx2T8m3vRHk5ww=; b=mvGFKpPUeoRYyoB626idey9lOEBchAe7vIzEYr6RszFhp4fdoZBzyOCpY1cmIJQrau WvMtyqk1pFtthSnaykoNx4bY7TfZOYygQWacXhsieLP3ZAOsOcnfNZTBT7SvBBL8pMKt C6Lw+JZRk8ugmE0kPDL4nqR5EjzQVdiKwxcIUtnHu365ok8jEdIkWN/1Dd49IwtDsP4G W9xYTfw8z1dLxSKOAjFHEW24k9NJBLBflc1lH+YeRPR5YapJhyVhZsRfxKHvArFARTLr 6uJj87Ewr9FaREgsu/YVLR6UxBISZu/DmbRVyVlg3iqbvwcMKhDKLn/iq9AwcmhLW6cR dzKQ== X-Gm-Message-State: ALKqPwc9/nVSWbtAptKDx1VYqipb+O160jDY1A34WFhiPywU9lOcxcWZ 4iD2TFBzwCR/TZ4VW2Op2SJu/A== X-Received: by 2002:a2e:911a:: with SMTP id m26-v6mr7842688ljg.73.1527853313450; Fri, 01 Jun 2018 04:41:53 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-51.209.223.85.sovam.net.ua. [85.223.209.51]) by smtp.gmail.com with ESMTPSA id c6-v6sm8066280lja.22.2018.06.01.04.41.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Jun 2018 04:41:52 -0700 (PDT) From: Oleksandr Andrushchenko 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, andr2000@gmail.com, dongwon.kim@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko Subject: [PATCH v2 9/9] xen/gntdev: Expose gntdev's dma-buf API for in-kernel use Date: Fri, 1 Jun 2018 14:41:32 +0300 Message-Id: <20180601114132.22596-10-andr2000@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601114132.22596-1-andr2000@gmail.com> References: <20180601114132.22596-1-andr2000@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-dmabuf.c | 6 +++ drivers/xen/gntdev.c | 92 +++++++++++++++++++++++-------------- include/xen/grant_dev.h | 37 +++++++++++++++ 3 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 include/xen/grant_dev.h diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index b5569a220f03..3890ac9dfab6 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -196,6 +196,7 @@ int gntdev_dmabuf_exp_wait_released(struct gntdev_dmabuf_priv *priv, int fd, dmabuf_exp_wait_obj_free(priv, obj); return ret; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_exp_wait_released); /* ------------------------------------------------------------------ */ /* DMA buffer export support. */ @@ -621,6 +622,7 @@ gntdev_dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev, dma_buf_put(dma_buf); return ret; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_imp_to_refs); u32 *gntdev_dmabuf_imp_get_refs(struct gntdev_dmabuf *gntdev_dmabuf) { @@ -629,6 +631,7 @@ u32 *gntdev_dmabuf_imp_get_refs(struct gntdev_dmabuf *gntdev_dmabuf) return NULL; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_imp_get_refs); /* * Find the hyper dma-buf by its file descriptor and remove @@ -678,6 +681,7 @@ int gntdev_dmabuf_imp_release(struct gntdev_dmabuf_priv *priv, u32 fd) dmabuf_imp_free_storage(gntdev_dmabuf); return 0; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_imp_release); struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void) { @@ -694,8 +698,10 @@ struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void) return priv; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_init); void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv) { kfree(priv); } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_fini); diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index cf255d45f20f..63902f5298c9 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -621,14 +621,37 @@ 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); + +#ifdef CONFIG_XEN_GNTDEV_DMABUF + gntdev_dmabuf_fini(priv->dmabuf_priv); +#endif + + kfree(priv); +} +EXPORT_SYMBOL_GPL(gntdev_free_context); + +struct gntdev_priv *gntdev_alloc_context(struct device *dev) { struct gntdev_priv *priv; - int ret = 0; priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) - return -ENOMEM; + return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&priv->maps); INIT_LIST_HEAD(&priv->freeable_maps); @@ -637,12 +660,40 @@ static int gntdev_open(struct inode *inode, struct file *flip) #ifdef CONFIG_XEN_GNTDEV_DMABUF priv->dmabuf_priv = gntdev_dmabuf_init(); if (IS_ERR(priv->dmabuf_priv)) { - ret = PTR_ERR(priv->dmabuf_priv); + struct gntdev_priv *ret; + + ret = ERR_CAST(priv->dmabuf_priv); kfree(priv); return ret; } #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_GPL(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) { @@ -655,23 +706,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; } @@ -679,27 +718,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); - -#ifdef CONFIG_XEN_GNTDEV_DMABUF - gntdev_dmabuf_fini(priv->dmabuf_priv); -#endif if (use_ptemod) mmu_notifier_unregister(&priv->mn, priv->mm); - kfree(priv); + gntdev_free_context(priv); return 0; } @@ -1156,6 +1179,7 @@ int gntdev_dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags, gntdev_remove_map(priv, map); return ret; } +EXPORT_SYMBOL_GPL(gntdev_dmabuf_exp_from_refs); /* ------------------------------------------------------------------ */ /* DMA buffer IOCTL support. */ diff --git a/include/xen/grant_dev.h b/include/xen/grant_dev.h new file mode 100644 index 000000000000..b7d0abd1ab16 --- /dev/null +++ b/include/xen/grant_dev.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * 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 -- 2.17.0