From patchwork Tue Dec 19 19:29:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kim, Dongwon" X-Patchwork-Id: 10124027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E56496019C for ; Tue, 19 Dec 2017 19:36:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D729429230 for ; Tue, 19 Dec 2017 19:36:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC15C2951E; Tue, 19 Dec 2017 19:36:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49BAB29553 for ; Tue, 19 Dec 2017 19:36:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3BAA56E333; Tue, 19 Dec 2017 19:36:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id CEDF96E329 for ; Tue, 19 Dec 2017 19:36:26 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 11:36:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018463" Received: from downor-z87x-ud5h.fm.intel.com ([10.1.122.11]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2017 11:36:24 -0800 From: Dongwon Kim To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 03/60] hyper_dmabuf: re-use dma_buf previously exported if exist Date: Tue, 19 Dec 2017 11:29:19 -0800 Message-Id: <1513711816-2618-3-git-send-email-dongwon.kim@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> References: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> MIME-Version: 1.0 Cc: xen-devel@lists.xenproject.org, mateuszx.potrola@intel.com, dri-devel@lists.freedesktop.org, dongwon.kim@intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now we re-use dma_buf instead of exporting it via normal process (including new mappings). For this, hyper_dmabuf list entries can be searched with "struct dma_buf*". Also, ioctl (export_remote) is modified to just return hyper_dmabuf_id if the specific dmabuf has already been exported to the target domain. This patch also Includes changes in printk calles for debugging. Signed-off-by: Dongwon Kim --- drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c | 28 +++++++++++++-------------- drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 17 ++++++++-------- drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c | 4 ++-- drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c index faa5c1b..7cb5c35 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c @@ -532,7 +532,7 @@ static int hyper_dmabuf_ops_attach(struct dma_buf* dmabuf, struct device* dev, HYPER_DMABUF_OPS_ATTACH); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return ret; @@ -552,7 +552,7 @@ static void hyper_dmabuf_ops_detach(struct dma_buf* dmabuf, struct dma_buf_attac HYPER_DMABUF_OPS_DETACH); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } @@ -586,7 +586,7 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme HYPER_DMABUF_OPS_MAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return st; @@ -618,7 +618,7 @@ static void hyper_dmabuf_ops_unmap(struct dma_buf_attachment *attachment, HYPER_DMABUF_OPS_UNMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } @@ -636,7 +636,7 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dmabuf) HYPER_DMABUF_OPS_RELEASE); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } @@ -653,7 +653,7 @@ static int hyper_dmabuf_ops_begin_cpu_access(struct dma_buf *dmabuf, enum dma_da ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return ret; @@ -672,7 +672,7 @@ static int hyper_dmabuf_ops_end_cpu_access(struct dma_buf *dmabuf, enum dma_data ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_END_CPU_ACCESS); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return 0; @@ -691,7 +691,7 @@ static void *hyper_dmabuf_ops_kmap_atomic(struct dma_buf *dmabuf, unsigned long ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_KMAP_ATOMIC); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return NULL; /* for now NULL.. need to return the address of mapped region */ @@ -710,7 +710,7 @@ static void hyper_dmabuf_ops_kunmap_atomic(struct dma_buf *dmabuf, unsigned long ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_KUNMAP_ATOMIC); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } @@ -727,7 +727,7 @@ static void *hyper_dmabuf_ops_kmap(struct dma_buf *dmabuf, unsigned long pgnum) ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_KMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return NULL; /* for now NULL.. need to return the address of mapped region */ @@ -746,7 +746,7 @@ static void hyper_dmabuf_ops_kunmap(struct dma_buf *dmabuf, unsigned long pgnum, ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_KUNMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } @@ -763,7 +763,7 @@ static int hyper_dmabuf_ops_mmap(struct dma_buf *dmabuf, struct vm_area_struct * ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_MMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return ret; @@ -782,7 +782,7 @@ static void *hyper_dmabuf_ops_vmap(struct dma_buf *dmabuf) ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_VMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } return NULL; @@ -801,7 +801,7 @@ static void hyper_dmabuf_ops_vunmap(struct dma_buf *dmabuf, void *vaddr) ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id), HYPER_DMABUF_OPS_VUNMAP); if (ret < 0) { - printk("send dmabuf sync request failed\n"); + printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__); } } diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c index 5e50908..665cada 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c @@ -86,27 +86,28 @@ static int hyper_dmabuf_export_remote(void *data) export_remote_attr = (struct ioctl_hyper_dmabuf_export_remote *)data; dma_buf = dma_buf_get(export_remote_attr->dmabuf_fd); + if (!dma_buf) { printk("Cannot get dma buf\n"); return -1; } - attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device); - if (!attachment) { - printk("Cannot get attachment\n"); - return -1; - } - /* we check if this specific attachment was already exported * to the same domain and if yes, it returns hyper_dmabuf_id * of pre-exported sgt */ - ret = hyper_dmabuf_find_id(attachment, export_remote_attr->remote_domain); + ret = hyper_dmabuf_find_id(dma_buf, export_remote_attr->remote_domain); if (ret != -1) { - dma_buf_detach(dma_buf, attachment); dma_buf_put(dma_buf); export_remote_attr->hyper_dmabuf_id = ret; return 0; } + + attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device); + if (!attachment) { + printk("Cannot get attachment\n"); + return -1; + } + /* Clear ret, as that will cause whole ioctl to return failure to userspace, which is not true */ ret = 0; diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c index 77a7e65..ad2109c 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c @@ -65,13 +65,13 @@ struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id) } /* search for pre-exported sgt and return id of it if it exist */ -int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid) +int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid) { struct hyper_dmabuf_info_entry_exported *info_entry; int bkt; hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node) - if(info_entry->info->attachment == attach && + if(info_entry->info->attachment->dmabuf == dmabuf && info_entry->info->hyper_dmabuf_rdomain == domid) return info_entry->info->hyper_dmabuf_id; diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h index 869cd9a..463a6da 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h @@ -25,7 +25,7 @@ int hyper_dmabuf_table_destroy(void); int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info); /* search for pre-exported sgt and return id of it if it exist */ -int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid); +int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid); int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);