From patchwork Wed Jul 18 10:47:41 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: 10532051 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 0FDB9600F4 for ; Wed, 18 Jul 2018 10:47:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1053D28D7D for ; Wed, 18 Jul 2018 10:47:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04B9628DEB; Wed, 18 Jul 2018 10:47:51 +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 B052028D7D for ; Wed, 18 Jul 2018 10:47:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF6AC6EAB9; Wed, 18 Jul 2018 10:47:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 734766EAB7 for ; Wed, 18 Jul 2018 10:47:46 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id f21-v6so2302880wmc.5 for ; Wed, 18 Jul 2018 03:47:46 -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=LwilhxN3RHSGMbF0CH0O4qtgZHyJLw84LhpRGR0fdJg=; b=QUWZMpUNS6rpctJPIoyRps/9d7YYn0dUPBcY+GmCSgSDck0LL5Ky2QBr7VX5JVRiqh VelfOGyYoC1UG+fNAKUfRDi1FuBuDumJbEWu11woFRobCq/mW0m7hcusXdLluUv6xibQ KiftpJM7SS9xLuIpjmttACB0GVI8fDUU6ilcY6g/Wg3RBcYUNiuS9TxQfBxuwrokBLVn ZEwfmYJOjkCLf0wnCtDA/k/rMknBShLA0/OzIKx76E3KPXk1sxXmKtzkZTxc7nZo4xX/ ixSyQcgIuxUkzpFM7W6eVqdPmX8fUKDAj7dv6Pn1xbsZijMw5nwksLCleO/sap3uiEvk 9MIw== X-Gm-Message-State: AOUpUlEAfHFLIIesADRpqAIlUA+4X6s1uhJwQc/SsjLmgTSnP81FzWHL /CBdHAD0HkSkaCEy8+gatEY+8g== X-Google-Smtp-Source: AAOMgpcrqDAYmoInlTvC0x58xeqOjZSA2NrYSPI5I1/fIIFy/RVI3acgrqghi4En7571MvAaGMebfQ== X-Received: by 2002:a1c:1183:: with SMTP id 125-v6mr1245074wmr.138.1531910864926; Wed, 18 Jul 2018 03:47:44 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:909a:c6d2:3325:2b02]) by smtp.gmail.com with ESMTPSA id d7-v6sm5793364wro.92.2018.07.18.03.47.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 03:47:44 -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: Wed, 18 Jul 2018 12:47:41 +0200 Message-Id: <20180718104741.2524-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180718104741.2524-1-christian.koenig@amd.com> References: <20180718104741.2524-1-christian.koenig@amd.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 4/4] dma-buf: lock the reservation object during (un)map_dma_buf v3 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 First step towards unpinned DMA buf operation. I've checked the DRM drivers to potential locking of the reservation object, but essentially we need to audit all implementations of the dma_buf _ops for this to work. v2: reordered v3: rebased on sgt caching Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 15 ++++++--------- include/linux/dma-buf.h | 6 ++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index e68322c953a9..21608306349d 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -686,10 +686,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); + reservation_object_lock(attach->dmabuf->resv, NULL); + sg_table = dma_buf_map_attachment_locked(attach, direction); + reservation_object_unlock(attach->dmabuf->resv); if (!sg_table) sg_table = ERR_PTR(-ENOMEM); @@ -742,11 +741,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); + reservation_object_lock(attach->dmabuf->resv, NULL); + dma_buf_unmap_attachment_locked(attach, sg_table, direction); + reservation_object_unlock(attach->dmabuf->resv); } EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index a40f8f586a95..e964077a7e7e 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -128,6 +128,9 @@ struct dma_buf_ops { * any other kind of sharing that the exporter might wish to make * available to buffer-users. * + * This is always called with the dmabuf->resv object locked when + * no_sgt_cache is true. + * * Returns: * * A &sg_table scatter list of or the backing storage of the DMA buffer, @@ -148,6 +151,9 @@ struct dma_buf_ops { * It should also unpin the backing storage if this is the last mapping * of the DMA buffer, it the exporter supports backing storage * migration. + * + * This is always called with the dmabuf->resv object locked when + * no_sgt_cache is true. */ void (*unmap_dma_buf)(struct dma_buf_attachment *, struct sg_table *,