Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1179161rwb; Thu, 10 Nov 2022 12:17:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM6kLU0SDVKkgTS1p00g8tD7M8izTIEHwp6MNM9HRBiZ8ylhPJfoLrL6EFh/I7LG7XuXQYc0 X-Received: by 2002:a17:902:d145:b0:177:faf5:58c5 with SMTP id t5-20020a170902d14500b00177faf558c5mr1971084plt.166.1668111458977; Thu, 10 Nov 2022 12:17:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668111458; cv=none; d=google.com; s=arc-20160816; b=Qe6HOwCCTYPDfeqYaY+xKUTBJ3HyrRrEcMNFkUPkkwT9WCY4RfTNqmiUs/fyKwzw2o 0CrEuZhya3yoVttWW2Ybwv/EE3lXww5myFIBU+beo7czDvP/k/tTFi92ooQZNoS4T2BY yETreP21MRoc4N0BWIqmwPfTFf5GGXRlW2eBV98MiqSwNXcO7xu7e10YGzWRdO4tnVz9 sM2v5aJqyDbQ+XilKwqE7tsOdkIxtP+xl9viN0e+K1upIU1+Sl2ai1lCan4AGsvbYVIL bBqAOqauGNOI/CaB4wgqtJFxh7oviGsmtJ3tmpZncm25taQt7I9Mh3MmDi3yxy8135Z2 RHwQ== 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=17WiOdpySr82i2wVykeug+lkJAo2Bv+AVe8X5fIsWLw=; b=J0Kq5L5bcsGinzFSmHfKhoPp1ZUacWLb8O4uOKs/F01E+aK4+mCouSsnU2ttmft//W PxEFjv3bNSpb9h/dIY4LZ/rw2w13awbc0WQEVEGGpHdZkg3QwLCsT4TzdtFLcAGuGDX9 0Xfj5miXOQItXNbsmrTnOVu3/B4UXHgHt+pzZScWGmaQjM1a0VI4DekvB0E5wLF4vlbi OtWYUxeYyYT49Yu21H4VJtVcnPKkGTVOogJ0FT57++o5fG0A8t9EO0CA1WCBiD4xn7bt iSD+6cP7pW2dMvEG9SxyrBLyC2bFsyE4kBSB4KA2ADrWkdXs0Xx7ggOaBLnX19sTkxCv YTIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WiW5lCgR; 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 a12-20020a63cd4c000000b00442e77a852dsi90524pgj.509.2022.11.10.12.17.25; Thu, 10 Nov 2022 12:17:38 -0800 (PST) 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=WiW5lCgR; 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 S231610AbiKJUPO (ORCPT + 93 others); Thu, 10 Nov 2022 15:15:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiKJUPB (ORCPT ); Thu, 10 Nov 2022 15:15:01 -0500 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 703E04E431; Thu, 10 Nov 2022 12:14:58 -0800 (PST) Received: from dimapc.. (unknown [109.252.117.140]) (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 76FB16602A52; Thu, 10 Nov 2022 20:14:55 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668111297; bh=tFGVSeUWIaYJ9Ib1/vtuoKFGinbIYhiNCk2JIU4TCAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WiW5lCgRnkdkfo5vaoZTlj8VvywC0gJ5C4YLWKTp1ofjQ0BBj8f7uw5QjMBvlfkHw U6uiK9b4Eb3XC+zN7suX+FGdXFSRwZSf8FgLNCyB/F4QyMkABTGlj+mA975iKDaHfO 7QamiY70dGTRMjl2ygQNU3faI4aoycDXfRrLeyuRtV6KdJddWr17/u6yA3PQIE0r3w BixEZwWJq95W2JJM7jSHqPgCZc4dw6s1eFBd3ltOhk53gqgRa2fBwVWDy/XhH/Yuvl Xu/PbO9SEaWlFQa8cDg2uwSa2nXQzk1T8MYDscwlF4w/kGa25X3PWjFooAZUrY7lIj 7VRaF9B1tqf4A== From: Dmitry Osipenko To: Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Benjamin Gaignard , Liam Mark , Brian Starkey , John Stultz , Gerd Hoffmann , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Thomas Zimmermann , Tomi Valkeinen , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Srinivas Kandagatla , Amol Maheshwari Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 4/6] dma-buf/heaps: Assert held reservation lock for dma-buf mmapping Date: Thu, 10 Nov 2022 23:13:47 +0300 Message-Id: <20221110201349.351294-5-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221110201349.351294-1-dmitry.osipenko@collabora.com> References: <20221110201349.351294-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 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 When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be held. Add locking sanity checks to the dma-buf mmaping callbacks to ensure that the locking assumptions won't regress in the future. Suggested-by: Daniel Vetter Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/heaps/cma_heap.c | 3 +++ drivers/dma-buf/heaps/system_heap.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 28fb04eccdd0..1131fb943992 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,8 @@ static int cma_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) { struct cma_heap_buffer *buffer = dmabuf->priv; + dma_resv_assert_held(dmabuf->resv); + if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) return -EINVAL; diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index fcf836ba9c1f..e8bd10e60998 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -201,6 +202,8 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) struct sg_page_iter piter; int ret; + dma_resv_assert_held(dmabuf->resv); + for_each_sgtable_page(table, &piter, vma->vm_pgoff) { struct page *page = sg_page_iter_page(&piter); -- 2.37.3