From patchwork Tue Dec 19 19:30:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kim, Dongwon" X-Patchwork-Id: 10124189 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 BFA0F6019C for ; Tue, 19 Dec 2017 19:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B04D0293F6 for ; Tue, 19 Dec 2017 19:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5503294E3; Tue, 19 Dec 2017 19:41:50 +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=unavailable 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 513A2293F6 for ; Tue, 19 Dec 2017 19:41:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C115089EB8; Tue, 19 Dec 2017 19:37:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id B34CF6E365 for ; Tue, 19 Dec 2017 19:37:07 +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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 11:37:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018675" Received: from downor-z87x-ud5h.fm.intel.com ([10.1.122.11]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2017 11:37:06 -0800 From: Dongwon Kim To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 53/60] hyper_dmabuf: define fastpath_export for exporting existing buffer Date: Tue, 19 Dec 2017 11:30:09 -0800 Message-Id: <1513711816-2618-53-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 To make hyper_dmabuf_export_remote_ioctl more compact and readable, a new function call, 'fastpath_export' is created to replace a routine in hyper_dmabuf_export_remote_ioctl for the case requested buffer for exporting is already in the LIST (exported previously). Signed-off-by: Dongwon Kim --- drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 153 +++++++++++++++----------- 1 file changed, 87 insertions(+), 66 deletions(-) diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c index b40cf89..d11f609 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c @@ -122,6 +122,82 @@ static int send_export_msg(struct exported_sgt_info *exported, return ret; } +/* Fast path exporting routine in case same buffer is already exported. + * In this function, we skip normal exporting process and just update + * private data on both VMs (importer and exporter) + * + * return '1' if reexport is needed, return '0' if succeeds, return + * Kernel error code if something goes wrong + */ +static int fastpath_export(hyper_dmabuf_id_t hid, int sz_priv, char *priv) +{ + int reexport = 1; + int ret = 0; + struct exported_sgt_info *exported; + + exported = hyper_dmabuf_find_exported(hid); + + if (!exported) + return reexport; + + if (exported->valid == false) + return reexport; + + /* + * Check if unexport is already scheduled for that buffer, + * if so try to cancel it. If that will fail, buffer needs + * to be reexport once again. + */ + if (exported->unexport_sched) { + if (!cancel_delayed_work_sync(&exported->unexport)) + return reexport; + + exported->unexport_sched = false; + } + + /* if there's any change in size of private data. + * we reallocate space for private data with new size + */ + if (sz_priv != exported->sz_priv) { + kfree(exported->priv); + + /* truncating size */ + if (sz_priv > MAX_SIZE_PRIV_DATA) + exported->sz_priv = MAX_SIZE_PRIV_DATA; + else + exported->sz_priv = sz_priv; + + exported->priv = kcalloc(1, exported->sz_priv, + GFP_KERNEL); + + if (!exported->priv) { + hyper_dmabuf_remove_exported(exported->hid); + hyper_dmabuf_cleanup_sgt_info(exported, true); + kfree(exported); + return -ENOMEM; + } + } + + /* update private data in sgt_info with new ones */ + ret = copy_from_user(exported->priv, priv, exported->sz_priv); + if (ret) { + dev_err(hy_drv_priv->dev, + "Failed to load a new private data\n"); + ret = -EINVAL; + } else { + /* send an export msg for updating priv in importer */ + ret = send_export_msg(exported, NULL); + + if (ret < 0) { + dev_err(hy_drv_priv->dev, + "Failed to send a new private data\n"); + ret = -EBUSY; + } + } + + return ret; +} + static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) { struct ioctl_hyper_dmabuf_export_remote *export_remote_attr = @@ -153,79 +229,24 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) */ hid = hyper_dmabuf_find_hid_exported(dma_buf, export_remote_attr->remote_domain); - if (hid.id != -1) { - exported = hyper_dmabuf_find_exported(hid); - if (!exported) - goto reexport; - - if (exported->valid == false) - goto reexport; + if (hid.id != -1) { + ret = fastpath_export(hid, export_remote_attr->sz_priv, + export_remote_attr->priv); - /* - * Check if unexport is already scheduled for that buffer, - * if so try to cancel it. If that will fail, buffer needs - * to be reexport once again. + /* return if fastpath_export succeeds or + * gets some fatal error */ - if (exported->unexport_sched) { - if (!cancel_delayed_work_sync(&exported->unexport)) { - dma_buf_put(dma_buf); - goto reexport; - } - exported->unexport_sched = false; + if (ret <= 0) { + dma_buf_put(dma_buf); + export_remote_attr->hid = hid; + return ret; } - - /* if there's any change in size of private data. - * we reallocate space for private data with new size - */ - if (export_remote_attr->sz_priv != exported->sz_priv) { - kfree(exported->priv); - - /* truncating size */ - if (export_remote_attr->sz_priv > MAX_SIZE_PRIV_DATA) - exported->sz_priv = MAX_SIZE_PRIV_DATA; - else - exported->sz_priv = export_remote_attr->sz_priv; - - exported->priv = kcalloc(1, exported->sz_priv, - GFP_KERNEL); - - if (!exported->priv) { - hyper_dmabuf_remove_exported(exported->hid); - hyper_dmabuf_cleanup_sgt_info(exported, true); - kfree(exported); - dma_buf_put(dma_buf); - return -ENOMEM; - } - } - - /* update private data in sgt_info with new ones */ - ret = copy_from_user(exported->priv, export_remote_attr->priv, - exported->sz_priv); - if (ret) { - dev_err(hy_drv_priv->dev, - "Failed to load a new private data\n"); - ret = -EINVAL; - } else { - /* send an export msg for updating priv in importer */ - ret = send_export_msg(exported, NULL); - - if (ret < 0) { - dev_err(hy_drv_priv->dev, - "Failed to send a new private data\n"); - ret = -EBUSY; - } - } - - dma_buf_put(dma_buf); - export_remote_attr->hid = hid; - return ret; } -reexport: attachment = dma_buf_attach(dma_buf, hy_drv_priv->dev); if (IS_ERR(attachment)) { - dev_err(hy_drv_priv->dev, "Cannot get attachment\n"); + dev_err(hy_drv_priv->dev, "cannot get attachment\n"); ret = PTR_ERR(attachment); goto fail_attach; } @@ -233,7 +254,7 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL); if (IS_ERR(sgt)) { - dev_err(hy_drv_priv->dev, "Cannot map attachment\n"); + dev_err(hy_drv_priv->dev, "cannot map attachment\n"); ret = PTR_ERR(sgt); goto fail_map_attachment; }