From patchwork Thu Nov 10 20:13:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 18306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp355681wru; Thu, 10 Nov 2022 12:16:59 -0800 (PST) X-Google-Smtp-Source: AMsMyM6JKg0d2B0m/uuNw7YZQ1s9Vg/3Mcm72bJfazOtutjHs4ECtkzYrsHWPLp7wLx+O6+DA6Dc X-Received: by 2002:a17:907:2d13:b0:78d:d4ca:21f7 with SMTP id gs19-20020a1709072d1300b0078dd4ca21f7mr3823070ejc.128.1668111419349; Thu, 10 Nov 2022 12:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668111419; cv=none; d=google.com; s=arc-20160816; b=DNb7a/tWse9Wknr39ZpCSQMIUgxV4LeJSuIFMDYN84a7Gmxxfz8ZDyYjzp+sy2UuYu LzWWf5t6qplnhWf+9jXYo5qjj+GOqDwe/0dBULVfzduALvk9HLCxoS1YLKRyltBzNzHy 5pOotih/HY2Ndl/Cmkow51j/CuqE2BDmc15PeVfB6CsZD+f5lO9++/ShLFkpzPxs7WXW tahJsQZN6pc65tN4N4pzVsA9+wPAlg1C9IgKUJqIizl9EGyGZeCanxogzM/Rb2m8E+nX ge8+cDCHeA/3e0EBRJr5GTKAM7uktd+QnpB9b/Mosvv3ImNcxgz1o4vOpYuihKgbhKOr OgkA== 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=ycaxoTYoP4GhyoT8zMmVSzMBy1GadJiA9aZMSS+tTxQ=; b=zoElozG0bm4jUdw9hRtr4SNvazTdV+oJpDNJxLRow76DuKHWCUpMlv+1P1R114ZvlB sz/33pfD60NLSEx6A1mGL5wfPqVYyjj/bgUqvFvG00KfeLCOEP2UEZuBYXRiMk3WByL+ A2kfCE3iWFOJOzD81YIXUJASwlDw0LDNhIw47UUAXXiQ2wixRO3XTwSElx/27VBTTbLf 3v+r4z+pelkZ3/r6qRC2alGtLaFApN2go7QObrCDbVqfzxS340C0pk94wZaFJYNI98TV ktTH48KCKHqH0SbfVtfnxA50cuo/hZcryKW32fbpVWAgR58+sEmRlQ6MgBzDbRozcyon Pe1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YvJFNfG0; 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 z10-20020a056402274a00b0044f288e02edsi662300edd.15.2022.11.10.12.16.33; Thu, 10 Nov 2022 12:16:59 -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=YvJFNfG0; 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 S231642AbiKJUPK (ORCPT + 99 others); Thu, 10 Nov 2022 15:15:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbiKJUO4 (ORCPT ); Thu, 10 Nov 2022 15:14:56 -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 62A0E50F1B; Thu, 10 Nov 2022 12:14:56 -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 69D8C6602A41; Thu, 10 Nov 2022 20:14:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668111295; bh=Y9B9YrrEmHlNO1aEObVWaFh4UvP89E0LA68VwtlK5tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YvJFNfG0veek5/GRaGa5nRrI/zKHIbyJmgP5Wf0I7nWHz14yHRQEDHx4U91zB4+XD DSZNDsmp1HtnE+QNOMSbxp9pUzx2JkuOF6lmfXmztWoOfbHEwP6SzHu/oMI5WkiuD4 oX6vaEzRzRW/siHAWBjRVqW6yjWzyJfTbPzG3MvfNQs8R1zP6AMq/0gU0aPQp1L80R yXf2zI9i9HIIVNTDlvjA7BXetRNrmgqF/RdqwW+1JMdVFVILpoEaFunwkrayKHghVS 4ZSMpbMXyeTxhUhFrD0LReNJC90DC/wylSo3H1ulvMs/kenG8FCVxr2YPwqlzXVQM0 QMcmyw/jqO+gQ== 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 3/6] udmabuf: Assert held reservation lock for dma-buf mmapping Date: Thu, 10 Nov 2022 23:13:46 +0300 Message-Id: <20221110201349.351294-4-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?1749141599550472921?= X-GMAIL-MSGID: =?utf-8?q?1749141599550472921?= When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be held. Add locking sanity check to the dma-buf mmaping callback to ensure that the locking assumption won't regress in the future. Suggested-by: Daniel Vetter Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/udmabuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 2bcdb935a3ac..283816fbd72f 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,8 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) { struct udmabuf *ubuf = buf->priv; + dma_resv_assert_held(buf->resv); + if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) return -EINVAL;