From patchwork Thu Nov 10 20:13:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 18305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp355654wru; Thu, 10 Nov 2022 12:16:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM7DPEfkqqDfE43GpPAYjXyuOh6CsshhqHYYMapLvfe61TjIz8fH8skToQKta8vq5cyTZPbp X-Received: by 2002:a17:902:64c1:b0:186:827e:a0da with SMTP id y1-20020a17090264c100b00186827ea0damr66285063pli.94.1668111414559; Thu, 10 Nov 2022 12:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668111414; cv=none; d=google.com; s=arc-20160816; b=T5xqw+ZsGwbhFCq9uhVTf8LDevKwon2VOa3BqbJFHIVYoq2TddlQU8/kxoNYLqUGQW ejeXvpej+kP6WAQneiGlrbMlCFJAgBGu2QPuyUYaOD+2uolRrvYT+AyuTZ+vBEvWmPsd 2ILf8ltQ0IDO2qRuqvbHnFz6NIRhIZDFU87DxHHS4bruKqy/P+HShKPRpDCB9Z00lphV B7Szdob1Xs+oFpNrR2d7DyvSVEL4HtvREOzmt0mACaf23rGU1fP/ExFaNjkWhVbLyyl6 owvtVti8Q8SZVVdvGT6qVHnZYVmVxiNIEbJ2nz7WyLuUdqQxKmFcFp2qcclr+bjc460+ N2RQ== 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 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.16.35; Thu, 10 Nov 2022 12:16:54 -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 + 99 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_K=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 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?1749141594688903387?= X-GMAIL-MSGID: =?utf-8?q?1749141594688903387?= 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);