From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: "Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
"Liam Mark" <lmark@codeaurora.org>,
"Brian Starkey" <Brian.Starkey@arm.com>,
"John Stultz" <jstultz@google.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tvrtko.ursulin@linux.intel.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Tomi Valkeinen" <tomba@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Tomasz Figa" <tfiga@chromium.org>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
"Amol Maheshwari" <amahesh@qti.qualcomm.com>
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 5/6] media: videobuf2: Assert held reservation lock for dma-buf mmapping
Date: Thu, 10 Nov 2022 23:13:48 +0300 [thread overview]
Message-ID: <20221110201349.351294-6-dmitry.osipenko@collabora.com> (raw)
In-Reply-To: <20221110201349.351294-1-dmitry.osipenko@collabora.com>
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 <daniel@ffwll.ch>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
drivers/media/common/videobuf2/videobuf2-dma-sg.c | 3 +++
drivers/media/common/videobuf2/videobuf2-vmalloc.c | 3 +++
3 files changed, 9 insertions(+)
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index 555bd40fa472..7f45a62969f2 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -11,6 +11,7 @@
*/
#include <linux/dma-buf.h>
+#include <linux/dma-resv.h>
#include <linux/module.h>
#include <linux/refcount.h>
#include <linux/scatterlist.h>
@@ -455,6 +456,8 @@ static int vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf, struct iosys_map *map)
static int vb2_dc_dmabuf_ops_mmap(struct dma_buf *dbuf,
struct vm_area_struct *vma)
{
+ dma_resv_assert_held(dbuf->resv);
+
return vb2_dc_mmap(dbuf->priv, vma);
}
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index 36981a5b5c53..b7f39ee49ed8 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -10,6 +10,7 @@
* the Free Software Foundation.
*/
+#include <linux/dma-resv.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/refcount.h>
@@ -495,6 +496,8 @@ static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
struct vm_area_struct *vma)
{
+ dma_resv_assert_held(dbuf->resv);
+
return vb2_dma_sg_mmap(dbuf->priv, vma);
}
diff --git a/drivers/media/common/videobuf2/videobuf2-vmalloc.c b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
index 41db707e43a4..f9b665366365 100644
--- a/drivers/media/common/videobuf2/videobuf2-vmalloc.c
+++ b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
@@ -10,6 +10,7 @@
* the Free Software Foundation.
*/
+#include <linux/dma-resv.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/mm.h>
@@ -316,6 +317,8 @@ static int vb2_vmalloc_dmabuf_ops_vmap(struct dma_buf *dbuf,
static int vb2_vmalloc_dmabuf_ops_mmap(struct dma_buf *dbuf,
struct vm_area_struct *vma)
{
+ dma_resv_assert_held(dbuf->resv);
+
return vb2_vmalloc_mmap(dbuf->priv, vma);
}
--
2.37.3
next prev parent reply other threads:[~2022-11-10 20:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 20:13 [PATCH v1 0/6] Move dma_buf_mmap_internal() to dynamic locking specification Dmitry Osipenko
2022-11-10 20:13 ` [PATCH v1 1/6] dma-buf: " Dmitry Osipenko
2022-11-11 12:47 ` Christian König
2022-11-10 20:13 ` [PATCH v1 2/6] drm: Assert held reservation lock for dma-buf mmapping Dmitry Osipenko
2022-11-10 20:13 ` [PATCH v1 3/6] udmabuf: " Dmitry Osipenko
2022-11-10 20:13 ` [PATCH v1 4/6] dma-buf/heaps: " Dmitry Osipenko
2022-11-10 20:13 ` Dmitry Osipenko [this message]
2022-11-11 3:39 ` [PATCH v1 5/6] media: videobuf2: " Tomasz Figa
2022-11-10 20:13 ` [PATCH v1 6/6] fastrpc: " Dmitry Osipenko
2022-11-11 20:59 ` [PATCH v1 0/6] Move dma_buf_mmap_internal() to dynamic locking specification Dmitry Osipenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221110201349.351294-6-dmitry.osipenko@collabora.com \
--to=dmitry.osipenko@collabora.com \
--cc=Brian.Starkey@arm.com \
--cc=amahesh@qti.qualcomm.com \
--cc=benjamin.gaignard@collabora.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=jstultz@google.com \
--cc=kernel@collabora.com \
--cc=kraxel@redhat.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=lmark@codeaurora.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=sumit.semwal@linaro.org \
--cc=tfiga@chromium.org \
--cc=thierry.reding@gmail.com \
--cc=tomba@kernel.org \
--cc=tvrtko.ursulin@linux.intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox