From patchwork Mon Oct 17 17:22:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 3641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1562510wrs; Mon, 17 Oct 2022 10:28:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nzLsvpMQrN/nFKfh08CtjwKi1lo5RURhUcMeH9az+JT9FV9mJBn+Yk95odJaHOHeGTkM3 X-Received: by 2002:a17:90a:f3c6:b0:20b:3ae:4c40 with SMTP id ha6-20020a17090af3c600b0020b03ae4c40mr14552342pjb.20.1666027721228; Mon, 17 Oct 2022 10:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666027721; cv=none; d=google.com; s=arc-20160816; b=cesAujzAa2oAkB5aFQZ3bl2sKPh1xNuB422tVkRpN8R+gGU8oTgmxV0rARE8Y6bw3S w8flZ8cWN3nxkLM6Sqdss9jPtMFBK+S3yZk1aJczmPxkttKDp7PVguhLPedbF/TlByK6 GY0RE99OxVBuLTY/QKjEZEWIq0GbsvYTli9FUsL9IAEBK5R5ui3oHf0q3cEuzX2zvy+n XHhmWA31cKaGVBtmiU3ePeBNMXR+E2G7VO67YJ/4q2wU/nMiRaJdzQuTaimREUxXl2fd 0Bp8IqoHBxHOx3yL2vT364YUKGtTSTyFWrMpD1wkeHbS+/N0h7DEHUosXwQTyWmf+zbk NcPA== 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=k5K0Weso97DjqFOC7P5IvOxGcqYVZEYIKWQhJaF0bJw=; b=RS3KishkhyWFfKfhWp46rVsRFDPXPthQ8qRNr/SFp6ke7ePPKuusrS4MPmc/4cpXII DIJ+9qVGATL2BRLuCABvfRMyOWZ8sa4H1KiXjiHOAsMib/DV8KhyopGHnGcyWBs9eU8D 69BkERZpmjxb9q/ExSKoQTmJiFFc2f/1M7vzt9NIP7o92u8PaiLkug7c4lvQRGXKH1ix 3y/eNjTgjdPK+opWYZ/mbH6OOGmjvnNUJb86/po2NZAb3Z7RnhPgrKW8g5oC1rs7eyV/ xXW02ER4wk8TTnFHdGNEa+7ppkVvBeappyuxt9gOIt/bufDCcEA8SiwlkHh0dkv+e30l SP2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hOccsgza; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a056a00158a00b005583001558dsi12894876pfk.150.2022.10.17.10.28.28; Mon, 17 Oct 2022 10:28:41 -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=hOccsgza; 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 S230440AbiJQR1I (ORCPT + 99 others); Mon, 17 Oct 2022 13:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbiJQR0d (ORCPT ); Mon, 17 Oct 2022 13:26:33 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9246561D97; Mon, 17 Oct 2022 10:25:49 -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 ED1536602389; Mon, 17 Oct 2022 18:25:17 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1666027522; bh=slRsrx8jd5qqbp6acBFvPPDjrd/mCjdHRIup7TQFD18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOccsgzaEh3rdMESZPZR5rULMUeDBpxVACSlIxLMhXR05HQ8dwANMcFtVPSldPRYV jsKZ1H4HrLIjpNsMEt0DjMUD6YR7GPUj2UMWLxwE95EtuuwT1PXiZhuEHhctsq0jEQ hLDsnwmeCK5PaKpDaTl7VtDHd6oPep12PHvf1n7XRu2hYU+YqqE6TNHfdiy9ybHQlK zpavElnB/hMtNPMd/6dDXWDf3kWjLDf9D5f3F8bz9xai+TxkNrILVWXMq8JLmihYMm QGjMcBx5l1kkJdhpQGzIV+zRpK3oHs60xRnu8yH6nMdkFVcNHd1TkJn//9GGCACbEr 9Lnr6dcjrvw3Q== 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_K=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_Hellstr?= =?utf-8?q?=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 18/21] dma-buf: Move dma_buf_mmap() to dynamic locking specification Date: Mon, 17 Oct 2022 20:22:26 +0300 Message-Id: <20221017172229.42269-19-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746956683852524736?= X-GMAIL-MSGID: =?utf-8?q?1746956683852524736?= Move dma_buf_mmap() 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. Acked-by: Sumit Semwal Acked-by: Christian König 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 f54c649f922a..f149b384f4dd 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1390,6 +1390,8 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_end_cpu_access, DMA_BUF); int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, unsigned long pgoff) { + int ret; + if (WARN_ON(!dmabuf || !vma)) return -EINVAL; @@ -1410,7 +1412,11 @@ int dma_buf_mmap(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, DMA_BUF);