Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7023005rwn; Tue, 13 Sep 2022 12:31:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR6TKKIwXn2WyvJPOpkwX9qi1/lZKmmqpcXjY4Yoe2NgPm4jcnA9Z4Qgv1OggmTlksI/JbyF X-Received: by 2002:a17:906:1e08:b0:73d:c724:4876 with SMTP id g8-20020a1709061e0800b0073dc7244876mr22536783ejj.62.1663097474758; Tue, 13 Sep 2022 12:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663097474; cv=none; d=google.com; s=arc-20160816; b=u3F/s6lHGuoZ/BJZSgcLnS0kQ6MV9dT6Uh3XwgGGX+lXlwodINeztimxf9ApE0BYai xPLK7pRo6wdMVf92/MM3p+JHZwmudJngFTB1nfFyc6i8oFzumSZWLFR6vsFbwHSQO7GB qFQTcpDMTU2jgYRvyd5tbB6OP2YHCJrUfYndBseQ1lqlE1UR30JhF9Ej13S0X64TR0XH R5ThCMN0d2gKrov79ziRfgJWww5iKe1yKiRZyomjFrv5U+9lhl16EYWFcqQy4egY4ywQ ZO8AMzy2BXQeNd1jAqy4sQL/DRRvhj43xvym+hEWN5V8HiXsAR3FRctyDDQywqkAtzAx kqlw== 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=BBpIBYqpFgw7WWnRSfO/Pi6nTDVjB9dE1qxZZdPLqJ0=; b=UoFpx5AyKiO8BUi3HiZUZsHbA1hHrHWsyZQtepIDs8Pk+OpZAMeJCyi/tTr9DXQGxG b0JCGsmCEk+knBp9i1gHGrfTYozL+osMCCdrcTMSQIiL8dGc1YOtumz0cSObA2NxNIpU Pwb1mmLtBjCEwsq32ALM/THBJhvniHrtH6g7yCBP9xbY325U1x/295f9Ys84ojWbXBH6 c/3Zb12l5VEx54QQmxKxxx4v9U9FjNYdlCQgTWAW2ypZFNLLL4A1ljd8QzHlfyJv6D1V IjHkdcUWcg439rFzLQnscUff68ICucQDE855XTcbu4DfysLorZE7dpnw/02KA7iFxMlN pIeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bljcR8ER; 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 fj4-20020a1709069c8400b0073d8e4e8c77si10007866ejc.1005.2022.09.13.12.30.48; Tue, 13 Sep 2022 12:31:14 -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=bljcR8ER; 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 S229560AbiIMT2a (ORCPT + 99 others); Tue, 13 Sep 2022 15:28:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbiIMT20 (ORCPT ); Tue, 13 Sep 2022 15:28:26 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 568337392C; Tue, 13 Sep 2022 12:28:25 -0700 (PDT) Received: from dimapc.. (109-252-122-187.nat.spd-mgts.ru [109.252.122.187]) (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 1C6BD6601FF3; Tue, 13 Sep 2022 20:28:19 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663097304; bh=mnsF4itAcjxMZ7Y+ou+YAYmIw6q3Jf/Et803MK4hUaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bljcR8ER8uIpURFnLb/Q4fLc9IK946F+5y8WQoLmBd3mZs5Z4akxI3pnk1vX55Vw3 66R/vRjhcmC8M87UzZUf1jGCJ9aZFRXFc6Wdl6aO35cGRDGopYeJUBEIjBDy84soLH j96a6t+v0jfMAJnl7yHMTtWH8AlPmGfVJ2Bh1qQzmvbmpqRs4RP6cvDtkhq8M45XV9 lB3/FZu3DMYSd5a9spzFVJSTwWe0FwkrHjZM1RRp19NI8Wxeg4ptweG9GbrXwVXKs+ KJNaOp8zEL1Mpi5BQTQy4unKOQ9edCQG9Ju5uGietckpBfJj1vMHUcixHdtXNJuipg ipWo3p+avUh/w== 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 v5 01/21] dma-buf: Add unlocked variant of vmapping functions Date: Tue, 13 Sep 2022 22:27:37 +0300 Message-Id: <20220913192757.37727-2-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913192757.37727-1-dmitry.osipenko@collabora.com> References: <20220913192757.37727-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, T_SCC_BODY_TEXT_LINE 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: Christian König Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/dma-buf.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index dd0f83ee505b..07880a34e367 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1425,6 +1425,28 @@ 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; + + 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 +1471,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