Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1239182rwb; Thu, 10 Nov 2022 13:14:33 -0800 (PST) X-Google-Smtp-Source: AMsMyM5/CoVJfZVebmEd/IZfkISuTqYLmfaHDw7pgU3ZCKd6x7cfPeBKhiLQ/Yi6hujSnh9pnB9K X-Received: by 2002:a05:6402:4d5:b0:459:2b41:3922 with SMTP id n21-20020a05640204d500b004592b413922mr3397243edw.160.1668114873386; Thu, 10 Nov 2022 13:14:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668114873; cv=none; d=google.com; s=arc-20160816; b=oKsZDceXDfVORRHyzFf8lo5nQEUmKnuQLdZ8yZqLB0VCZAavKbbb6Cp/BMNetA2j2s r1ktXG3/VnGyOGxfCr8lH0sNyGCdOtXFV2eHrKDQxUPzKTrZCpP56aMl1OiHkzNata8R PTZlLSTl1RvpWf+7NurijMFxqihGxzcN50J/h3EkGqeqlDOSWC/WNqDiu95gTvePoGR7 1hzXmx+QhKDH1wYceUZREAJbGzbzg96Cpxu/3aEIFSQBPpjWfz/AK6AjO/NtFxd+7zCD aiYaacjrNj8JMAnJIGSKgyOpSG1VnFKmD1HX2lkK9PVLeEcYXTwV9kkytO7zE0nLXxfJ Gh9Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a056402271000b0045be16903d0si701039edd.310.2022.11.10.13.14.10; Thu, 10 Nov 2022 13:14:33 -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 + 92 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=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 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 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 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; -- 2.37.3