Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp426415rwe; Wed, 24 Aug 2022 03:32:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR6WXFd2UginMncXYyf0A+DuobPEvgEvBKn9w8fLnZ52/GmDWkDj4iuHLHlsbY294GhOqlE/ X-Received: by 2002:a17:907:7354:b0:73c:d528:94ae with SMTP id dq20-20020a170907735400b0073cd52894aemr2502207ejc.274.1661337125572; Wed, 24 Aug 2022 03:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661337125; cv=none; d=google.com; s=arc-20160816; b=zl4d8bYp317WrL/UsdhEly8Dv9zsjxZ4Ri7yFvJFLqVpb/SvXEpvj3tAKKb5mGT0Ew aV+AkKlBfVq1Zn1NTaT6mT/O7qRwbfZQeIxMnRGhpFS9CL1G6ByX3D17hqIK/dJK4nD1 KQFT6qXnDrK+lqonYoHqSXftabBkQcR4t1B1Mn3Kz5TTs3+6W9w3tSJ+dSzoowanNWED LF7ICm+JYmD2iMCXlND1dvBxiG0uW+3Ldh10KrmFEK+gWbapzhKf1bxfl4wsaMyw5/1V 9Pqs1Lm/TfRdnYuk57Mkr0UtxkwwdJw1iDp1ZgKEPmaXZ5AtdnoZT1Vk0F7q5WB5dIFP KP3Q== 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=bX0hgQCt6+hUh7pMgPiblE7p5YrQ4oolqXVW2iXR4yM=; b=e5JZXeTbjK0tB2pLXZ+7iWlWpZezxVv6DbX4dyrsbwNns1j3GWKliAmcGftNM7rkcb MCRCzY5OoYurY6/Zk0bnt2bPd8gqDuy/f7Raz+O84YI8D+94SI+Bttyry6WDNKsbVuub SEBbpacBvLIVboRQzE+oI4FXXL3o6Xe5tO+D0Fi3xU2NugkwB/evr25FHP0f6RlSUrWa QSzCu5jSM0DordMrMxYhslnMS0yfVaFQseCgXJ3rwtJRg8uQFxFdi7jSHDop67zpzQ7d 4RZrBFZqu0tqasGBF2ZoSK54YK9Dx9TiuuJ5aDaov5zsqFxjHNqsiE4x7aIr/YLrfsBr /EIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JIhKt4lz; 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 m18-20020a50d7d2000000b0044662581a68si3719916edj.442.2022.08.24.03.31.39; Wed, 24 Aug 2022 03:32:05 -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=JIhKt4lz; 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 S236868AbiHXKYS (ORCPT + 99 others); Wed, 24 Aug 2022 06:24:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236887AbiHXKYE (ORCPT ); Wed, 24 Aug 2022 06:24:04 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62C777969E; Wed, 24 Aug 2022 03:23:52 -0700 (PDT) Received: from dimapc.. (109-252-119-13.nat.spd-mgts.ru [109.252.119.13]) (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 A9AE36601E7F; Wed, 24 Aug 2022 11:23:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1661336631; bh=bBPiDsDV8VShdB9ZtsiGZVkPLMJ84keUgctgg0zrhSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JIhKt4lzNSoUC/gVVAg+P2BZTIZZfWC4j8cmZ96m9spViCUOHP9dhSzL9/TwHMFqo MTL1a+pEkZHqam6VPg/TGjdRI6cjmTtHT3J2wR/VgKIz1/2FTiyCqnedrxarpJbRon PjDbcSi39vlbNnMuWe4Xxek0HqedxV/W1+HbMYb8btuuknX9qbhxejZCbKsfYzxDeg oM/OFKz9xE1rWQ9VV5hB49pv1q49DazwU2I1XPcrSlkRqNX99vp8QPqLCv1IrBjHRv b7CBEceUTBLBPfRqP6/JOvxFvZEKyEqAOxXJiaUh6K3gSid1+JBtb4oOBcyMThzL6I BS7ztXgJe5vKQ== 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 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, lima@lists.freedesktop.org Subject: [PATCH v3 5/9] dma-buf: Move dma_buf_mmap_unlocked() to dynamic locking specification Date: Wed, 24 Aug 2022 13:22:44 +0300 Message-Id: <20220824102248.91964-6-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824102248.91964-1-dmitry.osipenko@collabora.com> References: <20220824102248.91964-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 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,URIBL_BLOCKED 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 Move dma_buf_mmap_unlocked() function to the dynamic locking specification by taking the reservation lock. Neither of the today's drivers take the reservation lock within the mmap() callback, hence it's safe to enforce the locking. Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/dma-buf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index f358af401360..4556a12bd741 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1348,6 +1348,8 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_end_cpu_access, DMA_BUF); int dma_buf_mmap_unlocked(struct dma_buf *dmabuf, struct vm_area_struct *vma, unsigned long pgoff) { + int ret; + if (WARN_ON(!dmabuf || !vma)) return -EINVAL; @@ -1368,7 +1370,11 @@ int dma_buf_mmap_unlocked(struct dma_buf *dmabuf, struct vm_area_struct *vma, vma_set_file(vma, dmabuf->file); vma->vm_pgoff = pgoff; - return dmabuf->ops->mmap(dmabuf, vma); + dma_resv_lock(dmabuf->resv, NULL); + ret = dmabuf->ops->mmap(dmabuf, vma); + dma_resv_unlock(dmabuf->resv); + + return ret; } EXPORT_SYMBOL_NS_GPL(dma_buf_mmap_unlocked, DMA_BUF); -- 2.37.2