From patchwork Fri Jun 22 14:11:01 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: 10482205 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 272F2602CB for ; Fri, 22 Jun 2018 14:11:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B6EF28F47 for ; Fri, 22 Jun 2018 14:11:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE3528F4D; Fri, 22 Jun 2018 14:11:16 +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 BF1C328F47 for ; Fri, 22 Jun 2018 14:11:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BC3A6EB14; Fri, 22 Jun 2018 14:11:11 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id A77666EACB; Fri, 22 Jun 2018 14:11:09 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id e18-v6so6867582wrs.5; Fri, 22 Jun 2018 07:11:09 -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=klabc6uipzDkpTpi+VB8rX34MXOJPl60jqeIIm54UcM=; b=cgIGQIqBBxc3ggbzmINA7m0Hs6VDON+F2n9CdXnQz0KQ6mSpOobadf5dPgnESiy7I/ bYR+iwxeWO+POTUqLtLuAcjD3V0FnIEbMK7MFj3tdGjGhLnelHJAzfGcSnHDBREE1IIk eh96yPkTly43pjBEfAvNWpoN1d4DElk67KXzxN7lPm7/MZVGHX1PScQgvNxUfal/s093 ke2ar8lwV1li1GUj7ie97dypU9GL0C5e2EKxspM2YK2MeOZdDCcdav0ivWoU/6SW7k27 HJtdmDGIj+uEJ5gLHNtkVOrxxgA9KrFS30Yf1cji4I51qJJB5IA752kI+FSNVA0ecPat JyFQ== X-Gm-Message-State: APt69E3rxZ/tzGOM+NaybKMTSk9Dk/mcUt/h8HDeya7Rh77RrYmVIxDC EftB13dSnVpl34BKXbGBq6xZUQ== X-Google-Smtp-Source: AAOMgpet87pMgLReC+Iu8Ez4Hf/ARVHcHboDCzZoCiAOflzsTWorC77MsLrLnxKkYri0s+zkSOGs8g== X-Received: by 2002:adf:e4cd:: with SMTP id v13-v6mr1752503wrm.238.1529676668301; Fri, 22 Jun 2018 07:11:08 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:a936:32f2:b68b:559]) by smtp.gmail.com with ESMTPSA id b186-v6sm2026020wmh.4.2018.06.22.07.11.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 07:11:07 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, intel-gfx@lists.freedesktop.org Date: Fri, 22 Jun 2018 16:11:01 +0200 Message-Id: <20180622141103.1787-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180622141103.1787-1-christian.koenig@amd.com> References: <20180622141103.1787-1-christian.koenig@amd.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/4] dma-buf: lock the reservation object during (un)map_dma_buf v2 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 Signed-off-by: Christian König Reviewed-by: Daniel Vetter Reviewed-by: Junwei Zhang --- drivers/dma-buf/dma-buf.c | 9 ++++++--- include/linux/dma-buf.h | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index dc94e76e2e2a..49f23b791eb8 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -665,7 +665,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, if (WARN_ON(!attach || !attach->dmabuf)) return ERR_PTR(-EINVAL); - 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); @@ -715,8 +717,9 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, if (WARN_ON(!attach || !attach->dmabuf || !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 a25e754ae2f7..024658d1f22e 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -118,6 +118,8 @@ struct dma_buf_ops { * any other kind of sharing that the exporter might wish to make * available to buffer-users. * + * This is called with the dmabuf->resv object locked. + * * Returns: * * A &sg_table scatter list of or the backing storage of the DMA buffer, @@ -138,6 +140,8 @@ 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 called with the dmabuf->resv object locked. */ void (*unmap_dma_buf)(struct dma_buf_attachment *, struct sg_table *,