From patchwork Fri Jul 6 14:42:14 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: 10511877 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 BE5B7600CA for ; Fri, 6 Jul 2018 14:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFC7126255 for ; Fri, 6 Jul 2018 14:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A431A285F7; Fri, 6 Jul 2018 14:42:29 +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 41F3426255 for ; Fri, 6 Jul 2018 14:42:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C9FF6F061; Fri, 6 Jul 2018 14:42:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D4B46F053 for ; Fri, 6 Jul 2018 14:42:23 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id v3-v6so11128561wmh.0 for ; Fri, 06 Jul 2018 07:42:23 -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=iKS69kgkE9o75AzUUA7poHrhyfgEnZwKQ9aKg2D3Nu+lD5eQXBDIFKzxJmd95gqLui 8ZO0bWLOdFYlSoAAr9jTOEr2rOZ4mXDMjQ/g58B7fsJjzJd9k3Tfuk6Zya5RKxeXsHvQ Se6t4bxhm8dk9WbGhx+0XpJ+dbRFimDspSAk/O6mjuBfFjzjBunnlltpTKQjnavU/EeJ ETydtKq2PToghmdThabfkSBySzQqJ9GiKmpbW7gq6wS1Zgw8zc+0y4ahMB/J7cpu708N 5N/s73dOHscmRXUnq/zax2dMAFr/p4bMo0JwqSNL23hoSUX/jqjLGxcoL+vF/f6gKKJz q+jg== X-Gm-Message-State: APt69E02UleK+piHXrwiJCIVVn4vhN2TLHUT4neB4B4hxPKU8TH/Eo0z MQl4DgZqgwfPKG8qdOFt8DJIeQ== X-Google-Smtp-Source: AAOMgpfWA38UaUZ1Fc5zo2SqMASZBMjOSPFP9E7ConZSnJHwOTEGSRkjanTzF2IWnEi/iFrBxWbxug== X-Received: by 2002:a1c:ec1:: with SMTP id 184-v6mr7328779wmo.84.1530888142285; Fri, 06 Jul 2018 07:42:22 -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.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 07:42:21 -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:14 +0200 Message-Id: <20180706144216.14731-5-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 4/6] 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 *,