From patchwork Fri Jun 1 12:00:19 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: 10443187 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 26C13604D4 for ; Fri, 1 Jun 2018 12:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1715128E1D for ; Fri, 1 Jun 2018 12:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BAE828E35; Fri, 1 Jun 2018 12:00:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 762A128E23 for ; Fri, 1 Jun 2018 12:00:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751599AbeFAMAb (ORCPT ); Fri, 1 Jun 2018 08:00:31 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:37747 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751378AbeFAMA0 (ORCPT ); Fri, 1 Jun 2018 08:00:26 -0400 Received: by mail-wr0-f194.google.com with SMTP id d8-v6so4900141wro.4 for ; Fri, 01 Jun 2018 05:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5njr4+axUHvp+VGMaKQrxDXaMv7oUa7uRUiw+9QTucY=; b=GfhhWqmKzq4nPcHbum/y74Jq8NDHf3Dl4Ykjhg7DkhSSC+11ZXGi8WGrRb6ung4ib2 4g0K8PgxNdYk7nTwLXslS21fU6cCJiW2UJ3To17BrFCEsVvcftyZVAwLt6M1tAFvEJb4 7U4vrBntKYMJJRadv+McE/JZMRCdaKEx7BqB8V/EKtuwC1jR1Vynzj9rN/7ZgzIHbWz9 WceNYkDCn/9sG6AAu5r7gpV8xlGgQccqL6Co9D9l97uuDJwRYteLt+YWGocxemBNvgsK FuD0DNVh9l1uAai/WLTrOtldVU0c+tWnRKsIBA1pazYejeVTTj6ZXoZmDaZIhTGIGLa0 TMXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5njr4+axUHvp+VGMaKQrxDXaMv7oUa7uRUiw+9QTucY=; b=CEVhFvhoXp0pnJy2S+j0CnHqRDtkdzOaBfkSzRY8gySI77sQJ7hWFPWkBk26+vd3IY oBmvNIUmMkwlZodktzGeiuKAXtEhKvwlyJ3HzRgfHt0KqeJuq/P/LK5nOs/aHIjZh9Ry GhsX6vtM4U0U/QN4jiCx1mVdwGnzicXikNQ9Ld8yBXwtd9aPYkWTcOTcXXShVkHSE3Wi bwjRbxqn5ZXCzXXLvEYOhWCDj8Uc0mAztcO/bda14o/dJgsbgl5crivI+zoVCH40G7iK 28tZnYsjppBBF1OwlI8pUCsA0Cz6G5Whta1rh2UrUmdLQg4J0dirz8KAhYK5RagoGD6B nASA== X-Gm-Message-State: ALKqPwdIvlKPItih2YqnVSK5IU+UKIFgRaeMaSsJI6gEq6LP0oQvexq3 1L/ceWYGuoXAqa00AhOQ/kV+Wg== X-Google-Smtp-Source: ADUXVKJZo7Z+g53mWWh9mRFBsDxA2FkXFBI8Fq6FLxZLf/qrcx07nPfz1End9UpQM71fDRof6t3kbQ== X-Received: by 2002:adf:c08a:: with SMTP id d10-v6mr8022615wrf.268.1527854425192; Fri, 01 Jun 2018 05:00:25 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:59ea:b342:b14d:9f05]) by smtp.gmail.com with ESMTPSA id g205-v6sm2984242wmg.43.2018.06.01.05.00.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 05:00:24 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: sumit.semwal@linaro.org Subject: [PATCH 4/5] dma-buf: add dma_buf_(un)map_attachment_locked variants Date: Fri, 1 Jun 2018 14:00:19 +0200 Message-Id: <20180601120020.11520-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180601120020.11520-1-christian.koenig@amd.com> References: <20180601120020.11520-1-christian.koenig@amd.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add function variants which can be called with the reservation lock already held. Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 60 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/dma-buf.h | 5 ++++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 4f0708cb58a7..3371509b468e 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -606,6 +606,38 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) } EXPORT_SYMBOL_GPL(dma_buf_detach); +/** + * dma_buf_map_attachment_locked - Maps the buffer into _device_ address space + * with the reservation lock held. Is a wrapper for map_dma_buf() of the + * + * Returns the scatterlist table of the attachment; + * dma_buf_ops. + * @attach: [in] attachment whose scatterlist is to be returned + * @direction: [in] direction of DMA transfer + * + * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR + * on error. May return -EINTR if it is interrupted by a signal. + * + * A mapping must be unmapped by using dma_buf_unmap_attachment(). Note that + * the underlying backing storage is pinned for as long as a mapping exists, + * therefore users/importers should not hold onto a mapping for undue amounts of + * time. + */ +struct sg_table * +dma_buf_map_attachment_locked(struct dma_buf_attachment *attach, + enum dma_data_direction direction) +{ + struct sg_table *sg_table; + + might_sleep(); + sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); + if (!sg_table) + sg_table = ERR_PTR(-ENOMEM); + + return sg_table; +} +EXPORT_SYMBOL_GPL(dma_buf_map_attachment_locked); + /** * dma_buf_map_attachment - Returns the scatterlist table of the attachment; * mapped into _device_ address space. Is a wrapper for map_dma_buf() of the @@ -626,13 +658,12 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, { struct sg_table *sg_table; - might_sleep(); if (WARN_ON(!attach || !attach->dmabuf)) return ERR_PTR(-EINVAL); reservation_object_lock(attach->dmabuf->resv, NULL); - sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); + sg_table = dma_buf_map_attachment_locked(attach, direction); reservation_object_unlock(attach->dmabuf->resv); if (!sg_table) sg_table = ERR_PTR(-ENOMEM); @@ -641,6 +672,26 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, } EXPORT_SYMBOL_GPL(dma_buf_map_attachment); +/** + * dma_buf_unmap_attachment_locked - unmaps the buffer with reservation lock + * held, should deallocate the associated scatterlist. Is a wrapper for + * unmap_dma_buf() of dma_buf_ops. + * @attach: [in] attachment to unmap buffer from + * @sg_table: [in] scatterlist info of the buffer to unmap + * @direction: [in] direction of DMA transfer + * + * This unmaps a DMA mapping for @attached obtained by dma_buf_map_attachment(). + */ +void dma_buf_unmap_attachment_locked(struct dma_buf_attachment *attach, + struct sg_table *sg_table, + enum dma_data_direction direction) +{ + might_sleep(); + attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, + direction); +} +EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment_locked); + /** * dma_buf_unmap_attachment - unmaps and decreases usecount of the buffer;might * deallocate the scatterlist associated. Is a wrapper for unmap_dma_buf() of @@ -655,14 +706,11 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, struct sg_table *sg_table, enum dma_data_direction direction) { - might_sleep(); - if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) return; reservation_object_lock(attach->dmabuf->resv, NULL); - attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, - direction); + 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 d2ba7a027a78..968777e8c662 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -388,8 +388,13 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags); struct dma_buf *dma_buf_get(int fd); void dma_buf_put(struct dma_buf *dmabuf); +struct sg_table *dma_buf_map_attachment_locked(struct dma_buf_attachment *, + enum dma_data_direction); struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *, enum dma_data_direction); +void dma_buf_unmap_attachment_locked(struct dma_buf_attachment *, + struct sg_table *, + enum dma_data_direction); void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *, enum dma_data_direction); int dma_buf_begin_cpu_access(struct dma_buf *dma_buf,