Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4771124rwi; Mon, 17 Oct 2022 10:26:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7R0T5jHcdsEKWth1QFHoF9Tl8n/ejWv1xxZCBg/PT26fJlC7yq9adeEe0c4xvMiD3K9w1a X-Received: by 2002:a63:c4e:0:b0:45f:795:c20a with SMTP id 14-20020a630c4e000000b0045f0795c20amr11713147pgm.559.1666027602292; Mon, 17 Oct 2022 10:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666027602; cv=none; d=google.com; s=arc-20160816; b=Dykjgyyk8SV8PEWGi4020O72LwzdQvIxQw+NtZ3rGOgFGdpK6L9cVRsGD60F3MBpGg s9wqFYU8kwuLgeqt2t7bETW6ExuaR8r6AxWiiCdzP1rqlysmWmNOLS959rv4dn/UpVkl sUef0IzJa76dODcTShqXquJ1rGqGMUPWrZOEy9V2BVpDHxj9ddJY0UmpJTpPQEZrebaO X3ltjV0yejIO/fOgEkZ/D13Yp338QifOECHLgBnhya7UlkW+CQfJubHMssb79a4lIsPD 8uKtowR4OlaVgw3o/XHX4ERdGf2Yd8EGXHNsQ92PRcukNZSaD+sM5pCua3uuv8Iy2IIn YbmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Iwt2ng2dL99BIM9okC1GUL4jHHMinksBSY616vA78gY=; b=mX2z3PuQwyUobivHRsZhZM+JG6kDrjI1jXNL6UBupmCzyVNz9UDKa6AjyyvXugBGig bGuqZtwMVlhu2Bcex/Ej6Rci3J21cUxjeyrp7yS5sYPBU4nAu5f7VuaycklKWwibnslh i9sQqttgId+UkKWVqanuQV7kL2wVoucasyQ57gKrWd+NHxZXIZtkR6Ux7WrNCLtXQu1c D9f/yPD+Uzg8rD5d1U4tK/PGsey43Dqkxu/922gzDrpXhqBOkp4dKhCkNWnr72Aj/Ghj qpe4g9vIPrHXAttCZE1bC1D1g1qZMWt5wTVka6InbXJa4Ps3ZTLy23yX7RDC/vNDmN+y lnTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D14SQhLa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a63e213000000b0043ce8a884desi12131759pgh.856.2022.10.17.10.26.27; Mon, 17 Oct 2022 10:26:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D14SQhLa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbiJQRYf (ORCPT + 99 others); Mon, 17 Oct 2022 13:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbiJQRY2 (ORCPT ); Mon, 17 Oct 2022 13:24:28 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5CB726A1; Mon, 17 Oct 2022 10:24:17 -0700 (PDT) Received: from dimapc.. (109-252-119-114.nat.spd-mgts.ru [109.252.119.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2F9B2660232A; Mon, 17 Oct 2022 18:24:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1666027456; bh=Ex3AyquhNB6SUyXxM39A6LQM86DSUXI6d8WILYiNDB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D14SQhLaDc3wymEhfQ7kLOLaTxtKSAiqblynz43C7tbL9D87TBKj9qtbPtRFBl5Ic kvkmX9iLBEezccTFptMYfIZsAxP7NV4mdV6qTt+Lf3Ckfx6h1kPMZGVHErAzDSPl5F P1D6fEHo10EcXP/Bipt6/vA++Ef96gT5IAOt6Aj40ir/ztZO4RQYBUBkohSMkXIFbx WLQ5L+mUh9KjBkUe0zWKlm27XCOHUx7l+LZ6Pu0jBhzR1UzXVlzAEmfsnxx8Grpzmd +KBvqdSOy6UATlaRldthV2/8tkSd2Qa2P/DOAMyCHnepVWOFc+PuG0157aUl6S2IIY kEb5ReGRHuzpw== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Qiang Yu , Srinivas Kandagatla , Amol Maheshwari , Jason Gunthorpe , Leon Romanovsky , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Tomi Valkeinen , Russell King , Lucas Stach , Christian Gmeiner , Ruhl Michael J Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com, virtualization@lists.linux-foundation.org, linux-rdma@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v7 01/21] dma-buf: Add unlocked variant of vmapping functions Date: Mon, 17 Oct 2022 20:22:09 +0300 Message-Id: <20221017172229.42269-2-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017172229.42269-1-dmitry.osipenko@collabora.com> References: <20221017172229.42269-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add unlocked variant of dma_buf_vmap/vunmap() that will be utilized by drivers that don't take the reservation lock explicitly. Acked-by: Sumit Semwal Acked-by: Christian König Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/dma-buf.c | 43 +++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index efb4990b29e1..e95fc8dc3aed 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1425,6 +1425,33 @@ int dma_buf_vmap(struct dma_buf *dmabuf, struct iosys_map *map) } EXPORT_SYMBOL_NS_GPL(dma_buf_vmap, DMA_BUF); +/** + * dma_buf_vmap_unlocked - Create virtual mapping for the buffer object into kernel + * address space. Same restrictions as for vmap and friends apply. + * @dmabuf: [in] buffer to vmap + * @map: [out] returns the vmap pointer + * + * Unlocked version of dma_buf_vmap() + * + * Returns 0 on success, or a negative errno code otherwise. + */ +int dma_buf_vmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map) +{ + int ret; + + iosys_map_clear(map); + + if (WARN_ON(!dmabuf)) + return -EINVAL; + + dma_resv_lock(dmabuf->resv, NULL); + ret = dma_buf_vmap(dmabuf, map); + dma_resv_unlock(dmabuf->resv); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(dma_buf_vmap_unlocked, DMA_BUF); + /** * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap. * @dmabuf: [in] buffer to vunmap @@ -1449,6 +1476,22 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map) } EXPORT_SYMBOL_NS_GPL(dma_buf_vunmap, DMA_BUF); +/** + * dma_buf_vunmap_unlocked - Unmap a vmap obtained by dma_buf_vmap. + * @dmabuf: [in] buffer to vunmap + * @map: [in] vmap pointer to vunmap + */ +void dma_buf_vunmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map) +{ + if (WARN_ON(!dmabuf)) + return; + + dma_resv_lock(dmabuf->resv, NULL); + dma_buf_vunmap(dmabuf, map); + dma_resv_unlock(dmabuf->resv); +} +EXPORT_SYMBOL_NS_GPL(dma_buf_vunmap_unlocked, DMA_BUF); + #ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show(struct seq_file *s, void *unused) { diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 71731796c8c3..8daa054dd7fe 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -632,4 +632,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long); int dma_buf_vmap(struct dma_buf *dmabuf, struct iosys_map *map); void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map); +int dma_buf_vmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map); +void dma_buf_vunmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map); #endif /* __DMA_BUF_H__ */ -- 2.37.3