From: Detlev Casanova <detlev.casanova@collabora.com>
To: Tomasz Figa <tfiga@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Heiko Stuebner <heiko@sntech.de>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: kernel@collabora.com, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH 2/4] media: Store v4l2_fh in the vb_queue
Date: Wed, 16 Sep 2026 10:25:27 -0400 [thread overview]
Message-ID: <20260916-v4l2-add-mem-tracker-v1-2-900fa45e3e6a@collabora.com> (raw)
In-Reply-To: <20260916-v4l2-add-mem-tracker-v1-0-900fa45e3e6a@collabora.com>
To be able to show the fd in the debug fs, add the v4l2_fh pointer to the
queue so that vb2 allocations can retrieve it.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/common/videobuf2/v4l2-allocator.c | 16 +++++++++++-----
drivers/media/common/videobuf2/videobuf2-dma-contig.c | 1 +
include/media/v4l2-allocator.h | 2 +-
include/media/videobuf2-core.h | 1 +
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/media/common/videobuf2/v4l2-allocator.c b/drivers/media/common/videobuf2/v4l2-allocator.c
index 9dde9d4a342b..935fbbacd667 100644
--- a/drivers/media/common/videobuf2/v4l2-allocator.c
+++ b/drivers/media/common/videobuf2/v4l2-allocator.c
@@ -108,8 +108,8 @@ void v4l2_allocator_cleanup(struct v4l2_device *v4l2_dev)
}
EXPORT_SYMBOL_GPL(v4l2_allocator_cleanup);
-static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size,
- dma_addr_t dma_addr, const char *name)
+static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size, dma_addr_t dma_addr,
+ struct v4l2_fh *fh, const char *name)
{
struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
struct v4l2_allocator_entry *entry;
@@ -125,7 +125,13 @@ static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size,
entry->dma_addr = dma_addr;
strscpy(entry->name, name, sizeof(entry->name));
get_task_comm(entry->creator, current->group_leader);
- entry->tgid = current->tgid;
+ if (fh) {
+ entry->fd = fh->fd;
+ entry->tgid = fh->tgid;
+ } else {
+ entry->fd = 0;
+ entry->tgid = current->tgid;
+ }
mutex_lock(&allocator->lock);
list_add(&entry->list, &allocator->list);
@@ -156,12 +162,12 @@ static void v4l2_allocator_remove(struct v4l2_device *v4l2_dev, size_t size, dma
void *v4l2_dma_alloc_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, dma_addr_t *dma_handle,
- gfp_t flag, unsigned long attrs, const char *name)
+ gfp_t flag, unsigned long attrs, struct v4l2_fh *fh, const char *name)
{
void *ret = dma_alloc_attrs(dev, size, dma_handle, flag, attrs);
if (ret && v4l2_dev)
- v4l2_allocator_add(v4l2_dev, size, *dma_handle, name);
+ v4l2_allocator_add(v4l2_dev, size, *dma_handle, fh, name);
return ret;
}
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index b6b7ddc96b9c..30e136dd02b7 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -205,6 +205,7 @@ static int vb2_dc_alloc_coherent(struct vb2_dc_buf *buf)
&buf->dma_addr,
GFP_KERNEL | q->gfp_flags,
buf->attrs,
+ q->v4l2_fh,
name);
if (!buf->cookie)
return -ENOMEM;
diff --git a/include/media/v4l2-allocator.h b/include/media/v4l2-allocator.h
index f3fe0da10321..cdf0569bea0a 100644
--- a/include/media/v4l2-allocator.h
+++ b/include/media/v4l2-allocator.h
@@ -19,7 +19,7 @@ void v4l2_allocator_cleanup(struct v4l2_device *v4l2_dev);
void *v4l2_dma_alloc_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, dma_addr_t *dma_handle,
- gfp_t flag, unsigned long attrs, const char *name);
+ gfp_t flag, unsigned long attrs, struct v4l2_fh *fh, const char *name);
void v4l2_dma_free_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, void *cpu_addr,
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 83a5aea34f3c..aa47f1c7c9d1 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -604,6 +604,7 @@ struct vb2_queue {
unsigned int io_modes;
struct device *dev;
struct v4l2_device *v4l2_dev;
+ struct v4l2_fh *v4l2_fh;
unsigned long dma_attrs;
unsigned int bidirectional:1;
unsigned int fileio_read_once:1;
--
2.55.0
next prev parent reply other threads:[~2026-09-16 14:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 14:25 [PATCH 0/4] media: Track v4l2 buffers through an allocator Detlev Casanova
2026-09-16 14:25 ` [PATCH 1/4] media: Add a v4l2 memory allocations tracker Detlev Casanova
2026-09-16 14:25 ` Detlev Casanova [this message]
2026-09-16 14:25 ` [PATCH 3/4] media: verisilicon: Switch to tracked dma allocations Detlev Casanova
2026-09-16 14:25 ` [PATCH 4/4] media: rkvdec: " Detlev Casanova
2026-09-20 13:50 ` [PATCH 0/4] media: Track v4l2 buffers through an allocator Diederik de Haas
2026-09-24 12:36 ` Detlev Casanova
2026-09-24 13:51 ` Diederik de Haas
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=20260916-v4l2-add-mem-tracker-v1-2-900fa45e3e6a@collabora.com \
--to=detlev.casanova@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=heiko@sntech.de \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=tfiga@chromium.org \
/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
all inboxes | Powered by JetHome®