From patchwork Fri Jul 6 14:42:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10511873 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 C348E60325 for ; Fri, 6 Jul 2018 14:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B33FA26255 for ; Fri, 6 Jul 2018 14:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A75B3285F7; Fri, 6 Jul 2018 14:42:27 +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=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 5EB6726255 for ; Fri, 6 Jul 2018 14:42:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DFF806F059; Fri, 6 Jul 2018 14:42:24 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8C606F054 for ; Fri, 6 Jul 2018 14:42:21 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id j33-v6so4440767wrj.5 for ; Fri, 06 Jul 2018 07:42:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xmnIXWgaQ5QMk+onN05bqOPiKs2PsnAB1wGiYo9Xguk=; b=T5hCU8GZjula38GmToenjLlu7yclJ/d1E7zrbxRcdbMwcTcrM6j4Wlc6GwRmltI6Cu 5zV+/nutgE9QKq3Hn1PCTvdusWMyaPAnyFLCPSKPec1n7rkcohDuSkQPCkxpF+6AwLLl p7vzQ0ZtWaocn/S9hUGWymF6DMDMdus8DqOVhwY0fVHmiMBx64TXBNOIktZhgFoH8MZ1 +N2b1aU/AVHpBQE0nPi4AXkrT+lTmmOqO9/8LpuYZVkPaLWdCZDgcRC0MahJJtRG/qH7 1hJm2RvAVkOCnM1y76No0oQIYq4sc+oIgED2XKoKcj2B+eIJXOXDStsNzMiOoZ4V/S6+ mOmw== X-Gm-Message-State: APt69E0hjrhRHN3vJY3omE2GHQ3dZh10a+osr9fUZSCibdkfNAMVaSkx vk0KFF7EyhXIqHlBdYg7zdireQ== X-Google-Smtp-Source: AAOMgpfpilSxpLpuWFcc5Uzg3T2LAVROPKeV5+sDdM1n53/arZfPVDhH5iC4NU03/TuJ63mhT6tOKQ== X-Received: by 2002:adf:ea87:: with SMTP id s7-v6mr7271844wrm.150.1530888140323; Fri, 06 Jul 2018 07:42:20 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:dce0:19d0:7b51:c8f5]) by smtp.gmail.com with ESMTPSA id w24-v6sm6886055wmc.15.2018.07.06.07.42.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 07:42:19 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org Date: Fri, 6 Jul 2018 16:42:11 +0200 Message-Id: <20180706144216.14731-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180706144216.14731-1-christian.koenig@amd.com> References: <20180706144216.14731-1-christian.koenig@amd.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/6] dma-buf: add caching of sg_table X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP To allow a smooth transition from pinning buffer objects to dynamic invalidation we first start to cache the sg_table for an attachment unless the driver explicitly says to not do so. Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 24 ++++++++++++++++++++++++ include/linux/dma-buf.h | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 13884474d158..0bea5eecf554 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -574,6 +574,20 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, list_add(&attach->node, &dmabuf->attachments); mutex_unlock(&dmabuf->lock); + + if (!dmabuf->ops->no_sgt_cache) { + struct sg_table *sgt; + + sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL); + if (!sgt) + sgt = ERR_PTR(-ENOMEM); + if (IS_ERR(sgt)) { + dma_buf_detach(dmabuf, attach); + return ERR_CAST(sgt); + } + attach->sgt = sgt; + } + return attach; err_attach: @@ -596,6 +610,10 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) if (WARN_ON(!dmabuf || !attach)) return; + if (attach->sgt) + dmabuf->ops->unmap_dma_buf(attach, attach->sgt, + DMA_BIDIRECTIONAL); + mutex_lock(&dmabuf->lock); list_del(&attach->node); if (dmabuf->ops->detach) @@ -631,6 +649,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, if (WARN_ON(!attach || !attach->dmabuf)) return ERR_PTR(-EINVAL); + if (attach->sgt) + return attach->sgt; + sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); if (!sg_table) sg_table = ERR_PTR(-ENOMEM); @@ -658,6 +679,9 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) return; + if (attach->sgt == sg_table) + return; + attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); } diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 58725f890b5b..6534a6769e17 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -51,6 +51,16 @@ struct dma_buf_attachment; * @vunmap: [optional] unmaps a vmap from the buffer */ struct dma_buf_ops { + /** + * @no_sgt_cache: + * + * Flag controlling the caching of the sg_table in the DMA-buf helpers. + * If not set the sg_table is created during device attaching, if set + * the sg_table is created dynamically when dma_buf_map_attachment() is + * called. + */ + bool no_sgt_cache; + /** * @attach: * @@ -323,6 +333,7 @@ struct dma_buf_attachment { struct device *dev; struct list_head node; void *priv; + struct sg_table *sgt; }; /**