* [PATCH 0/4] media: Track v4l2 buffers through an allocator
@ 2026-09-16 14:25 Detlev Casanova
2026-09-16 14:25 ` [PATCH 1/4] media: Add a v4l2 memory allocations tracker Detlev Casanova
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-09-16 14:25 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip,
linux-arm-kernel, Detlev Casanova
Hello,
Currently, the only way to track buffers allocated by v4l2 from usespace
is to use the subsystem available debug information (e.g.:
/sys/kernel/debug/dma_buf/bufinfo).
But that information is generic and cannot be matched to a v4l2 driver or
to a userspace application: It is merely information about the allocation.
Other types of allocations require the developper to find where they are
exposed and how to link them to their test.
This can become hard to track when mutliple drivers are working at the
same time.
To improve that, add a small wrapper around buffer allocations to keep
track of them at the video device level so that we can add debug
information to them like a name, userspace pid/fd that did the
allocation,... and expose them to userspace via a debugfs entry.
It currently only supports DMA buffer allocations and adds support for
VB2 allocations too.
Other kind of memory tracking can be added later.
The verisilicon and rkvdec drivers have been ported to use the tracked
dma alloactions.
Note that this depends on the ftrace support patch series[1] that
provides fd/pid info in the v4l2_fh struct.
That series is a bit old, so this is based on an older linux version, but
that only changes things for the last 2 commits.
A v4l2top utility[2] has been made, to be used in parallel with the
fdinfo patch series[3], to show the list of active streams with their HW
and memory usage.
With this, debugfs looks like this when decoding a HEVC 1080p stream with
rkvdec on rk3588:
root # cat /sys/kernel/debug/v4l2/fdc38100.video-codec/mem
created-by fd pid size label
-------------------------------------------------------------------------------------
gst-launch-1.0 7 635 39184 vdpu381-hevc-priv-tbl
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-7
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-6
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-5
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-4
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-3
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-2
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-1
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-0
gst-launch-1.0 7 635 3133440 out-000000005c0230f6-1
gst-launch-1.0 7 635 3133440 out-000000005c0230f6-0
=====================================================================================
Total size: 39729424
[1]: https://lore.kernel.org/all/20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com/
[2]: https://github.com/cazou/v4l2top/tree/upstream
[3]: https://lore.kernel.org/all/20260706-v4l2-add-fdinfo-v3-0-d556568cf38e@collabora.com/
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
Detlev Casanova (4):
media: Add a v4l2 memory allocations tracker
media: Store v4l2_fh in the vb_queue
media: verisilicon: Switch to tracked dma allocations
media: rkvdec: Switch to tracked dma allocations
drivers/media/common/videobuf2/Makefile | 1 +
drivers/media/common/videobuf2/v4l2-allocator.c | 186 +++++++++++++++++++++
.../media/common/videobuf2/videobuf2-dma-contig.c | 27 ++-
.../media/platform/rockchip/rkvdec/rkvdec-h264.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-hevc.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-rcb.c | 21 ++-
.../platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-vp9.c | 33 ++--
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 4 +
drivers/media/platform/verisilicon/hantro.h | 1 +
drivers/media/platform/verisilicon/hantro_drv.c | 4 +
drivers/media/platform/verisilicon/hantro_h264.c | 7 +-
drivers/media/platform/verisilicon/hantro_hevc.c | 100 ++++++-----
drivers/media/platform/verisilicon/hantro_mpeg2.c | 16 +-
.../media/platform/verisilicon/hantro_postproc.c | 14 +-
drivers/media/platform/verisilicon/hantro_vp8.c | 25 +--
drivers/media/platform/verisilicon/hantro_vp9.c | 34 +++-
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 160 +++++++++++-------
drivers/media/v4l2-core/v4l2-device.c | 4 +-
include/media/v4l2-allocator.h | 26 +++
include/media/v4l2-device.h | 2 +
include/media/videobuf2-core.h | 3 +
25 files changed, 555 insertions(+), 197 deletions(-)
---
base-commit: 66affa37cfac0aec061cc4bcf4a065b0c52f7e19
change-id: 20260612-v4l2-add-mem-tracker-da0088c74a64
prerequisite-change-id: 20260608-v4l2-add-ftrace-aec6e7f60a6c:v2
prerequisite-patch-id: bd45b4df66799a7f9f22b49973a78d1bd3590a4a
prerequisite-patch-id: 6a5ed5615f08257cf854d441785066b5ff4d5d47
prerequisite-patch-id: 02594c869498b9e91e416d70242afbaa6b3a8d6a
prerequisite-patch-id: 9f25ec78f3b99ac1c5d42eb732f5bd9eae73fadd
prerequisite-patch-id: 4ed2c2e8c3abfa7f6328d0ea4f488ca5a3eec8fb
prerequisite-patch-id: 8787d50eb80e1a63a57a123268cade23c9e64618
prerequisite-patch-id: bfe85822378fa771f9bbc3e1e8c8ff6bce0eb7fd
prerequisite-patch-id: 784d0801da320f7b41194f4632ee422c32f1b5b8
prerequisite-patch-id: 362c8366e2efbfb5e6f1a3f71cfddbd46e8d1506
Best regards,
--
Detlev Casanova <detlev.casanova@collabora.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] media: Add a v4l2 memory allocations tracker
2026-09-16 14:25 [PATCH 0/4] media: Track v4l2 buffers through an allocator Detlev Casanova
@ 2026-09-16 14:25 ` Detlev Casanova
2026-09-16 14:25 ` [PATCH 2/4] media: Store v4l2_fh in the vb_queue Detlev Casanova
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-09-16 14:25 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip,
linux-arm-kernel, Detlev Casanova
This is a wrapper around dma allocation functions to keep track of
allocated buffers and expose the list through a per v4l2 device debugfs.
This currently doesn't support all kind of memory allocation, only
dma_alloc_attrs.
The wrapper can therefore be used by drivers, but also by the vb2
allocation functions, so that all buffers are accounted for.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/common/videobuf2/Makefile | 1 +
drivers/media/common/videobuf2/v4l2-allocator.c | 180 +++++++++++++++++++++
.../media/common/videobuf2/videobuf2-dma-contig.c | 24 ++-
drivers/media/v4l2-core/v4l2-device.c | 4 +-
include/media/v4l2-allocator.h | 26 +++
include/media/v4l2-device.h | 2 +
include/media/videobuf2-core.h | 2 +
7 files changed, 231 insertions(+), 8 deletions(-)
diff --git a/drivers/media/common/videobuf2/Makefile b/drivers/media/common/videobuf2/Makefile
index a6fe3f304685..aa2754731535 100644
--- a/drivers/media/common/videobuf2/Makefile
+++ b/drivers/media/common/videobuf2/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
videobuf2-common-objs := videobuf2-core.o
videobuf2-common-objs += frame_vector.o
+videobuf2-common-objs += v4l2-allocator.o
ifeq ($(CONFIG_TRACEPOINTS),y)
videobuf2-common-objs += vb2-trace.o
diff --git a/drivers/media/common/videobuf2/v4l2-allocator.c b/drivers/media/common/videobuf2/v4l2-allocator.c
new file mode 100644
index 000000000000..9dde9d4a342b
--- /dev/null
+++ b/drivers/media/common/videobuf2/v4l2-allocator.c
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <media/v4l2-allocator.h>
+#include <media/v4l2-device.h>
+
+#include <linux/types.h>
+#include <linux/debugfs.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/seq_file.h>
+
+#define ENTRY_NAME_LEN 64
+
+static struct dentry *v4l2_debugfs_dir;
+
+struct v4l2_allocator {
+ struct list_head list;
+ struct mutex lock;
+ struct dentry *debugfs_dir;
+ struct dentry *debugfs_entry;
+};
+
+struct v4l2_allocator_entry {
+ struct list_head list;
+ size_t size;
+ dma_addr_t dma_addr;
+ char name[ENTRY_NAME_LEN];
+ char creator[TASK_COMM_LEN];
+ pid_t tgid;
+ u16 fd;
+};
+
+static int v4l2_allocator_debugfs_show(struct seq_file *m, void *data)
+{
+ struct v4l2_device *v4l2_dev = m->private;
+ struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
+ struct v4l2_allocator_entry *entry;
+ size_t total_size = 0;
+
+ if (!allocator)
+ return 0;
+
+ seq_puts(m, "created-by fd pid size label\n");
+ seq_puts(m, "-------------------------------------------------------------------------------------\n");
+ mutex_lock(&allocator->lock);
+ list_for_each_entry(entry, &allocator->list, list) {
+ seq_printf(m, "%-32s%-16u%-16u%-16zu%s\n",
+ entry->creator,
+ entry->fd,
+ entry->tgid,
+ entry->size,
+ entry->name);
+ total_size += entry->size;
+ }
+ mutex_unlock(&allocator->lock);
+
+ seq_puts(m, "=====================================================================================\n");
+ seq_printf(m, "Total size: %zu\n", total_size);
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(v4l2_allocator_debugfs);
+
+int v4l2_allocator_init(struct v4l2_device *v4l2_dev)
+{
+ struct v4l2_allocator *allocator;
+
+ allocator = kzalloc_obj(*allocator);
+ if (!allocator)
+ return -ENOMEM;
+
+ INIT_LIST_HEAD(&allocator->list);
+ mutex_init(&allocator->lock);
+ v4l2_dev->v4l2_allocator = allocator;
+
+ if (!v4l2_debugfs_dir)
+ v4l2_debugfs_dir = debugfs_create_dir("v4l2", NULL);
+
+ allocator->debugfs_dir = debugfs_create_dir(dev_name(v4l2_dev->dev),
+ v4l2_debugfs_dir);
+ allocator->debugfs_entry = debugfs_create_file("mem", 0444,
+ allocator->debugfs_dir,
+ v4l2_dev,
+ &v4l2_allocator_debugfs_fops);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_allocator_init);
+
+void v4l2_allocator_cleanup(struct v4l2_device *v4l2_dev)
+{
+ struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
+ struct v4l2_allocator_entry *entry, *tmp;
+
+ if (allocator) {
+ debugfs_remove(allocator->debugfs_entry);
+ debugfs_remove(allocator->debugfs_dir);
+ mutex_lock(&allocator->lock);
+ list_for_each_entry_safe(entry, tmp, &allocator->list, list) {
+ list_del(&entry->list);
+ kfree(entry);
+ }
+ mutex_unlock(&allocator->lock);
+ mutex_destroy(&allocator->lock);
+ kfree(allocator);
+ v4l2_dev->v4l2_allocator = NULL;
+ }
+}
+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)
+{
+ struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
+ struct v4l2_allocator_entry *entry;
+
+ if (!allocator)
+ return -EINVAL;
+
+ entry = kzalloc_obj(*entry);
+ if (!entry)
+ return -ENOMEM;
+
+ entry->size = 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;
+
+ mutex_lock(&allocator->lock);
+ list_add(&entry->list, &allocator->list);
+ mutex_unlock(&allocator->lock);
+
+ return 0;
+}
+
+static void v4l2_allocator_remove(struct v4l2_device *v4l2_dev, size_t size, dma_addr_t dma_addr)
+{
+ struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
+ struct v4l2_allocator_entry *entry, *tmp;
+
+ if (!allocator)
+ return;
+
+ mutex_lock(&allocator->lock);
+ list_for_each_entry_safe(entry, tmp, &allocator->list, list) {
+ if (entry->size == size && entry->dma_addr == dma_addr) {
+ list_del(&entry->list);
+ mutex_unlock(&allocator->lock);
+ kfree(entry);
+ return;
+ }
+ }
+ mutex_unlock(&allocator->lock);
+}
+
+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)
+{
+ void *ret = dma_alloc_attrs(dev, size, dma_handle, flag, attrs);
+
+ if (ret && v4l2_dev)
+ v4l2_allocator_add(v4l2_dev, size, *dma_handle, name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_dma_alloc_attrs);
+
+void v4l2_dma_free_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
+ size_t size, void *cpu_addr,
+ dma_addr_t dma_handle, unsigned long attrs)
+{
+ if (v4l2_dev)
+ v4l2_allocator_remove(v4l2_dev, size, dma_handle);
+
+ dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
+}
+EXPORT_SYMBOL_GPL(v4l2_dma_free_attrs);
+
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index 9ce6284cd5f2..b6b7ddc96b9c 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -22,6 +22,7 @@
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-dma-contig.h>
#include <media/videobuf2-memops.h>
+#include <media/v4l2-allocator.h>
struct vb2_dc_buf {
struct device *dev;
@@ -43,6 +44,7 @@ struct vb2_dc_buf {
struct dma_buf_attachment *db_attach;
struct vb2_buffer *vb;
+ struct v4l2_device *v4l2_dev;
bool non_coherent_mem;
};
@@ -181,8 +183,10 @@ static void vb2_dc_put(void *buf_priv)
sg_free_table(buf->sgt_base);
kfree(buf->sgt_base);
}
- dma_free_attrs(buf->dev, buf->size, buf->cookie,
- buf->dma_addr, buf->attrs);
+
+ v4l2_dma_free_attrs(buf->v4l2_dev, buf->dev, buf->size, buf->cookie,
+ buf->dma_addr, buf->attrs);
+
}
put_device(buf->dev);
kfree(buf);
@@ -191,12 +195,17 @@ static void vb2_dc_put(void *buf_priv)
static int vb2_dc_alloc_coherent(struct vb2_dc_buf *buf)
{
struct vb2_queue *q = buf->vb->vb2_queue;
+ char name[64] = {0};
+
+ sprintf(name, "%s-%d", q->name, buf->vb->index);
- buf->cookie = dma_alloc_attrs(buf->dev,
- buf->size,
- &buf->dma_addr,
- GFP_KERNEL | q->gfp_flags,
- buf->attrs);
+ buf->cookie = v4l2_dma_alloc_attrs(buf->v4l2_dev,
+ buf->dev,
+ buf->size,
+ &buf->dma_addr,
+ GFP_KERNEL | q->gfp_flags,
+ buf->attrs,
+ name);
if (!buf->cookie)
return -ENOMEM;
@@ -246,6 +255,7 @@ static void *vb2_dc_alloc(struct vb2_buffer *vb,
buf->dma_dir = vb->vb2_queue->dma_dir;
buf->vb = vb;
buf->non_coherent_mem = vb->vb2_queue->non_coherent_mem;
+ buf->v4l2_dev = vb->vb2_queue->v4l2_dev;
buf->size = size;
/* Prevent the device from being released while the buffer is used */
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 67e3073de132..3cce2b4bc4c7 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -13,6 +13,7 @@
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
+#include <media/v4l2-allocator.h>
int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
{
@@ -38,7 +39,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
dev->driver->name, dev_name(dev));
if (!dev_get_drvdata(dev))
dev_set_drvdata(dev, v4l2_dev);
- return 0;
+ return v4l2_allocator_init(v4l2_dev);
}
EXPORT_SYMBOL_GPL(v4l2_device_register);
@@ -93,6 +94,7 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
* unregistered before. */
if (v4l2_dev == NULL || !v4l2_dev->name[0])
return;
+ v4l2_allocator_cleanup(v4l2_dev);
v4l2_device_disconnect(v4l2_dev);
/* Unregister subdevs */
diff --git a/include/media/v4l2-allocator.h b/include/media/v4l2-allocator.h
new file mode 100644
index 000000000000..f3fe0da10321
--- /dev/null
+++ b/include/media/v4l2-allocator.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * V4L2 Memory Allocator - Track memory allocations and deallocations in the v4l2 device.
+ *
+ * It provides functions to allocate and free memory while keeping
+ * track of the allocations for debugging and analysis purposes.
+ *
+ * Copyright 2026 Collabora, Ltd.
+ * Detlev Casanova <detlev.casanova@collabora.com>
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+
+#include <media/v4l2-device.h>
+
+int v4l2_allocator_init(struct v4l2_device *v4l2_dev);
+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);
+
+void v4l2_dma_free_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
+ size_t size, void *cpu_addr,
+ dma_addr_t dma_handle, unsigned long attrs);
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 25f69b1b8db0..c2b882d32012 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -14,6 +14,7 @@
#include <media/v4l2-dev.h>
struct v4l2_ctrl_handler;
+struct v4l2_allocator;
/**
* struct v4l2_device - main struct to for V4L2 device drivers
@@ -46,6 +47,7 @@ struct v4l2_device {
struct device *dev;
struct media_device *mdev;
struct list_head subdevs;
+ struct v4l2_allocator *v4l2_allocator;
spinlock_t lock;
char name[36];
void (*notify)(struct v4l2_subdev *sd,
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 4424d481d7f7..83a5aea34f3c 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -19,6 +19,7 @@
#include <linux/bitops.h>
#include <media/media-request.h>
#include <media/frame_vector.h>
+#include <media/v4l2-device.h>
#define VB2_MAX_FRAME (32)
#define VB2_MAX_PLANES (8)
@@ -602,6 +603,7 @@ struct vb2_queue {
unsigned int type;
unsigned int io_modes;
struct device *dev;
+ struct v4l2_device *v4l2_dev;
unsigned long dma_attrs;
unsigned int bidirectional:1;
unsigned int fileio_read_once:1;
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] media: Store v4l2_fh in the vb_queue
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
2026-09-16 14:25 ` [PATCH 3/4] media: verisilicon: Switch to tracked dma allocations Detlev Casanova
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-09-16 14:25 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip,
linux-arm-kernel, Detlev Casanova
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] media: verisilicon: Switch to tracked dma allocations
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 ` [PATCH 2/4] media: Store v4l2_fh in the vb_queue Detlev Casanova
@ 2026-09-16 14:25 ` 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
4 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-09-16 14:25 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip,
linux-arm-kernel, Detlev Casanova
Use the newly introduced v4l2_dma_alloc_attrs and v4l2_dma_free_attrs
functions to track all dma allocations and have them exposed to
userspace for easier debug.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/platform/verisilicon/hantro.h | 1 +
drivers/media/platform/verisilicon/hantro_drv.c | 4 +
drivers/media/platform/verisilicon/hantro_h264.c | 7 +-
drivers/media/platform/verisilicon/hantro_hevc.c | 100 +++++++------
drivers/media/platform/verisilicon/hantro_mpeg2.c | 16 +--
.../media/platform/verisilicon/hantro_postproc.c | 14 +-
drivers/media/platform/verisilicon/hantro_vp8.c | 25 ++--
drivers/media/platform/verisilicon/hantro_vp9.c | 34 +++--
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 160 ++++++++++++---------
9 files changed, 215 insertions(+), 146 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index d5cddc783688..acf5312d5ed4 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -24,6 +24,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
+#include <media/v4l2-allocator.h>
#include "hantro_hw.h"
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 32855b14e0f1..2b8aa2033d3f 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -232,6 +232,8 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->lock = &ctx->dev->vpu_mutex;
src_vq->dev = ctx->dev->v4l2_dev.dev;
+ src_vq->v4l2_dev = &ctx->dev->v4l2_dev;
+ src_vq->v4l2_fh = &ctx->fh;
src_vq->supports_requests = true;
ret = vb2_queue_init(src_vq);
@@ -258,6 +260,8 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->lock = &ctx->dev->vpu_mutex;
dst_vq->dev = ctx->dev->v4l2_dev.dev;
+ dst_vq->v4l2_dev = &ctx->dev->v4l2_dev;
+ dst_vq->v4l2_fh = &ctx->fh;
return vb2_queue_init(dst_vq);
}
diff --git a/drivers/media/platform/verisilicon/hantro_h264.c b/drivers/media/platform/verisilicon/hantro_h264.c
index 2414782f1eb6..6b6afd74f8ae 100644
--- a/drivers/media/platform/verisilicon/hantro_h264.c
+++ b/drivers/media/platform/verisilicon/hantro_h264.c
@@ -498,7 +498,7 @@ void hantro_h264_dec_exit(struct hantro_ctx *ctx)
struct hantro_h264_dec_hw_ctx *h264_dec = &ctx->h264_dec;
struct hantro_aux_buf *priv = &h264_dec->priv;
- dma_free_coherent(vpu->dev, priv->size, priv->cpu, priv->dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu, priv->dma, 0);
}
int hantro_h264_dec_init(struct hantro_ctx *ctx)
@@ -508,8 +508,9 @@ int hantro_h264_dec_init(struct hantro_ctx *ctx)
struct hantro_aux_buf *priv = &h264_dec->priv;
struct hantro_h264_dec_priv_tbl *tbl;
- priv->cpu = dma_alloc_coherent(vpu->dev, sizeof(*tbl), &priv->dma,
- GFP_KERNEL);
+ priv->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ sizeof(*tbl), &priv->dma,
+ GFP_KERNEL, 0, &ctx->fh, "h264-priv");
if (!priv->cpu)
return -ENOMEM;
diff --git a/drivers/media/platform/verisilicon/hantro_hevc.c b/drivers/media/platform/verisilicon/hantro_hevc.c
index 83cd12b0ddd6..e73498285bf7 100644
--- a/drivers/media/platform/verisilicon/hantro_hevc.c
+++ b/drivers/media/platform/verisilicon/hantro_hevc.c
@@ -7,6 +7,7 @@
#include <linux/types.h>
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "hantro.h"
#include "hantro_hw.h"
@@ -89,46 +90,52 @@ static int tile_buffer_reallocate(struct hantro_ctx *ctx)
/* Need to reallocate due to tiles passed via PPS */
if (hevc_dec->tile_filter.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+ hevc_dec->tile_filter.cpu,
+ hevc_dec->tile_filter.dma, 0);
hevc_dec->tile_filter.cpu = NULL;
}
if (hevc_dec->tile_sao.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+ hevc_dec->tile_sao.cpu,
+ hevc_dec->tile_sao.dma, 0);
hevc_dec->tile_sao.cpu = NULL;
}
if (hevc_dec->tile_bsd.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_bsd.size,
- hevc_dec->tile_bsd.cpu,
- hevc_dec->tile_bsd.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_bsd.size,
+ hevc_dec->tile_bsd.cpu,
+ hevc_dec->tile_bsd.dma, 0);
hevc_dec->tile_bsd.cpu = NULL;
}
size = (VERT_FILTER_RAM_SIZE * height64 * (num_tile_cols - 1) * ctx->bit_depth) / 8;
- hevc_dec->tile_filter.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_filter.dma,
- GFP_KERNEL);
+ hevc_dec->tile_filter.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &hevc_dec->tile_filter.dma,
+ GFP_KERNEL,
+ DMA_ATTR_NO_KERNEL_MAPPING,
+ &ctx->fh, "hevc-tile-filter");
if (!hevc_dec->tile_filter.cpu)
return -ENOMEM;
hevc_dec->tile_filter.size = size;
size = (VERT_SAO_RAM_SIZE * height64 * (num_tile_cols - 1) * ctx->bit_depth) / 8;
- hevc_dec->tile_sao.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_sao.dma,
- GFP_KERNEL);
+ hevc_dec->tile_sao.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &hevc_dec->tile_sao.dma,
+ GFP_KERNEL,
+ DMA_ATTR_NO_KERNEL_MAPPING,
+ &ctx->fh, "hevc-tile-sao");
if (!hevc_dec->tile_sao.cpu)
goto err_free_tile_buffers;
hevc_dec->tile_sao.size = size;
size = BSD_CTRL_RAM_SIZE * height64 * (num_tile_cols - 1);
- hevc_dec->tile_bsd.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_bsd.dma,
- GFP_KERNEL);
+ hevc_dec->tile_bsd.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &hevc_dec->tile_bsd.dma,
+ GFP_KERNEL,
+ DMA_ATTR_NO_KERNEL_MAPPING,
+ &ctx->fh, "hevc-tile-bsd");
if (!hevc_dec->tile_bsd.cpu)
goto err_free_sao_buffers;
hevc_dec->tile_bsd.size = size;
@@ -139,16 +146,16 @@ static int tile_buffer_reallocate(struct hantro_ctx *ctx)
err_free_sao_buffers:
if (hevc_dec->tile_sao.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+ hevc_dec->tile_sao.cpu,
+ hevc_dec->tile_sao.dma, 0);
hevc_dec->tile_sao.cpu = NULL;
err_free_tile_buffers:
if (hevc_dec->tile_filter.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+ hevc_dec->tile_filter.cpu,
+ hevc_dec->tile_filter.dma, 0);
hevc_dec->tile_filter.cpu = NULL;
return -ENOMEM;
@@ -218,33 +225,33 @@ void hantro_hevc_dec_exit(struct hantro_ctx *ctx)
struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
if (hevc_dec->tile_sizes.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sizes.size,
- hevc_dec->tile_sizes.cpu,
- hevc_dec->tile_sizes.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sizes.size,
+ hevc_dec->tile_sizes.cpu,
+ hevc_dec->tile_sizes.dma, 0);
hevc_dec->tile_sizes.cpu = NULL;
if (hevc_dec->scaling_lists.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->scaling_lists.size,
- hevc_dec->scaling_lists.cpu,
- hevc_dec->scaling_lists.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->scaling_lists.size,
+ hevc_dec->scaling_lists.cpu,
+ hevc_dec->scaling_lists.dma, 0);
hevc_dec->scaling_lists.cpu = NULL;
if (hevc_dec->tile_filter.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+ hevc_dec->tile_filter.cpu,
+ hevc_dec->tile_filter.dma, 0);
hevc_dec->tile_filter.cpu = NULL;
if (hevc_dec->tile_sao.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+ hevc_dec->tile_sao.cpu,
+ hevc_dec->tile_sao.dma, 0);
hevc_dec->tile_sao.cpu = NULL;
if (hevc_dec->tile_bsd.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_bsd.size,
- hevc_dec->tile_bsd.cpu,
- hevc_dec->tile_bsd.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_bsd.size,
+ hevc_dec->tile_bsd.cpu,
+ hevc_dec->tile_bsd.dma, 0);
hevc_dec->tile_bsd.cpu = NULL;
}
@@ -262,17 +269,20 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx)
* chunk (HW guys wanted to have this).
*/
size = round_up(MAX_TILE_COLS * MAX_TILE_ROWS * 4 * sizeof(u16) + 16, 16);
- hevc_dec->tile_sizes.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_sizes.dma,
- GFP_KERNEL);
+ hevc_dec->tile_sizes.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &hevc_dec->tile_sizes.dma,
+ GFP_KERNEL, 0,
+ &ctx->fh, "hevc-tile-sizes");
if (!hevc_dec->tile_sizes.cpu)
return -ENOMEM;
hevc_dec->tile_sizes.size = size;
- hevc_dec->scaling_lists.cpu = dma_alloc_coherent(vpu->dev, SCALING_LIST_SIZE,
- &hevc_dec->scaling_lists.dma,
- GFP_KERNEL);
+ hevc_dec->scaling_lists.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ SCALING_LIST_SIZE,
+ &hevc_dec->scaling_lists.dma,
+ GFP_KERNEL, 0,
+ &ctx->fh, "hevc-scaling-lists");
if (!hevc_dec->scaling_lists.cpu)
return -ENOMEM;
diff --git a/drivers/media/platform/verisilicon/hantro_mpeg2.c b/drivers/media/platform/verisilicon/hantro_mpeg2.c
index 04e545eb0a83..edb29204b9c2 100644
--- a/drivers/media/platform/verisilicon/hantro_mpeg2.c
+++ b/drivers/media/platform/verisilicon/hantro_mpeg2.c
@@ -41,10 +41,10 @@ int hantro_mpeg2_dec_init(struct hantro_ctx *ctx)
ctx->mpeg2_dec.qtable.size = ARRAY_SIZE(zigzag) * 4;
ctx->mpeg2_dec.qtable.cpu =
- dma_alloc_coherent(vpu->dev,
- ctx->mpeg2_dec.qtable.size,
- &ctx->mpeg2_dec.qtable.dma,
- GFP_KERNEL);
+ v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ ctx->mpeg2_dec.qtable.size,
+ &ctx->mpeg2_dec.qtable.dma,
+ GFP_KERNEL, 0, &ctx->fh, "mpeg2-qtable");
if (!ctx->mpeg2_dec.qtable.cpu)
return -ENOMEM;
return 0;
@@ -54,8 +54,8 @@ void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx)
{
struct hantro_dev *vpu = ctx->dev;
- dma_free_coherent(vpu->dev,
- ctx->mpeg2_dec.qtable.size,
- ctx->mpeg2_dec.qtable.cpu,
- ctx->mpeg2_dec.qtable.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ ctx->mpeg2_dec.qtable.size,
+ ctx->mpeg2_dec.qtable.cpu,
+ ctx->mpeg2_dec.qtable.dma, 0);
}
diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c
index e94d1ba5ef10..030db07f96e3 100644
--- a/drivers/media/platform/verisilicon/hantro_postproc.c
+++ b/drivers/media/platform/verisilicon/hantro_postproc.c
@@ -189,8 +189,8 @@ void hantro_postproc_free(struct hantro_ctx *ctx)
struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i];
if (priv->cpu) {
- dma_free_attrs(vpu->dev, priv->size, priv->cpu,
- priv->dma, priv->attrs);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu,
+ priv->dma, priv->attrs);
priv->cpu = NULL;
}
}
@@ -226,6 +226,7 @@ static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index)
struct hantro_dev *vpu = ctx->dev;
struct hantro_aux_buf *priv = &ctx->postproc.dec_q[index];
unsigned int buf_size = hantro_postproc_buffer_size(ctx);
+ char name[32];
if (!buf_size)
return -EINVAL;
@@ -235,8 +236,9 @@ static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index)
* buffers for the decoder, so no mapping is needed.
*/
priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING;
- priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma,
- GFP_KERNEL, priv->attrs);
+ snprintf(name, sizeof(name), "postproc-dec-%d", index);
+ priv->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, buf_size, &priv->dma,
+ GFP_KERNEL, priv->attrs, &ctx->fh, name);
if (!priv->cpu)
return -ENOMEM;
priv->size = buf_size;
@@ -273,8 +275,8 @@ hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index)
if (priv->size < buf_size && priv->cpu) {
/* buffer is too small, release it */
- dma_free_attrs(vpu->dev, priv->size, priv->cpu,
- priv->dma, priv->attrs);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu,
+ priv->dma, priv->attrs);
priv->cpu = NULL;
}
diff --git a/drivers/media/platform/verisilicon/hantro_vp8.c b/drivers/media/platform/verisilicon/hantro_vp8.c
index 381bc1d3bfda..c94b1692adbb 100644
--- a/drivers/media/platform/verisilicon/hantro_vp8.c
+++ b/drivers/media/platform/verisilicon/hantro_vp8.c
@@ -161,8 +161,9 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
*/
aux_buf = &ctx->vp8_dec.segment_map;
aux_buf->size = segment_map_size;
- aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
- &aux_buf->dma, GFP_KERNEL);
+ aux_buf->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ aux_buf->size, &aux_buf->dma,
+ GFP_KERNEL, 0, &ctx->fh, "vp8-segment-map");
if (!aux_buf->cpu)
return -ENOMEM;
@@ -172,8 +173,9 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
*/
aux_buf = &ctx->vp8_dec.prob_tbl;
aux_buf->size = sizeof(struct vp8_prob_tbl_packed);
- aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
- &aux_buf->dma, GFP_KERNEL);
+ aux_buf->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ aux_buf->size, &aux_buf->dma,
+ GFP_KERNEL, 0, &ctx->fh, "vp8-prob-tbl");
if (!aux_buf->cpu) {
ret = -ENOMEM;
goto err_free_seg_map;
@@ -182,9 +184,10 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
return 0;
err_free_seg_map:
- dma_free_coherent(vpu->dev, ctx->vp8_dec.segment_map.size,
- ctx->vp8_dec.segment_map.cpu,
- ctx->vp8_dec.segment_map.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ ctx->vp8_dec.segment_map.size,
+ ctx->vp8_dec.segment_map.cpu,
+ ctx->vp8_dec.segment_map.dma, 0);
return ret;
}
@@ -194,8 +197,8 @@ void hantro_vp8_dec_exit(struct hantro_ctx *ctx)
struct hantro_vp8_dec_hw_ctx *vp8_dec = &ctx->vp8_dec;
struct hantro_dev *vpu = ctx->dev;
- dma_free_coherent(vpu->dev, vp8_dec->segment_map.size,
- vp8_dec->segment_map.cpu, vp8_dec->segment_map.dma);
- dma_free_coherent(vpu->dev, vp8_dec->prob_tbl.size,
- vp8_dec->prob_tbl.cpu, vp8_dec->prob_tbl.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, vp8_dec->segment_map.size,
+ vp8_dec->segment_map.cpu, vp8_dec->segment_map.dma, 0);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, vp8_dec->prob_tbl.size,
+ vp8_dec->prob_tbl.cpu, vp8_dec->prob_tbl.dma, 0);
}
diff --git a/drivers/media/platform/verisilicon/hantro_vp9.c b/drivers/media/platform/verisilicon/hantro_vp9.c
index 566cd376c097..3933a835cc57 100644
--- a/drivers/media/platform/verisilicon/hantro_vp9.c
+++ b/drivers/media/platform/verisilicon/hantro_vp9.c
@@ -182,7 +182,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
vp9_dec->bsd_ctrl_offset = size;
size += hantro_vp9_bsd_control_size(max_height);
- tile_edge->cpu = dma_alloc_coherent(vpu->dev, size, &tile_edge->dma, GFP_KERNEL);
+ tile_edge->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ size, &tile_edge->dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vp9-tile-edge");
if (!tile_edge->cpu)
return -ENOMEM;
@@ -193,7 +196,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
vp9_dec->segment_map_size = size;
size *= 2; /* we need two areas of this size, used alternately */
- segment_map->cpu = dma_alloc_coherent(vpu->dev, size, &segment_map->dma, GFP_KERNEL);
+ segment_map->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ size, &segment_map->dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vp9-segment-map");
if (!segment_map->cpu)
goto err_segment_map;
@@ -206,7 +212,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
vp9_dec->tile_info_offset = size;
size += hantro_vp9_tile_info_size();
- misc->cpu = dma_alloc_coherent(vpu->dev, size, &misc->dma, GFP_KERNEL);
+ misc->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ size, &misc->dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vp9-misc");
if (!misc->cpu)
goto err_misc;
@@ -218,10 +227,14 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
return 0;
err_misc:
- dma_free_coherent(vpu->dev, segment_map->size, segment_map->cpu, segment_map->dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ segment_map->size, segment_map->cpu,
+ segment_map->dma, 0);
err_segment_map:
- dma_free_coherent(vpu->dev, tile_edge->size, tile_edge->cpu, tile_edge->dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ tile_edge->size, tile_edge->cpu,
+ tile_edge->dma, 0);
return -ENOMEM;
}
@@ -234,7 +247,12 @@ void hantro_vp9_dec_exit(struct hantro_ctx *ctx)
struct hantro_aux_buf *segment_map = &vp9_dec->segment_map;
struct hantro_aux_buf *misc = &vp9_dec->misc;
- dma_free_coherent(vpu->dev, misc->size, misc->cpu, misc->dma);
- dma_free_coherent(vpu->dev, segment_map->size, segment_map->cpu, segment_map->dma);
- dma_free_coherent(vpu->dev, tile_edge->size, tile_edge->cpu, tile_edge->dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ misc->size, misc->cpu, misc->dma, 0);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ segment_map->size, segment_map->cpu,
+ segment_map->dma, 0);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ tile_edge->size, tile_edge->cpu,
+ tile_edge->dma, 0);
}
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
index e4e21ad37323..f48e8dbfc880 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -232,30 +232,38 @@ static void rockchip_vpu981_av1_dec_tiles_free(struct hantro_ctx *ctx)
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
if (av1_dec->db_data_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->db_data_col.size,
- av1_dec->db_data_col.cpu,
- av1_dec->db_data_col.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->db_data_col.size,
+ av1_dec->db_data_col.cpu,
+ av1_dec->db_data_col.dma, 0);
av1_dec->db_data_col.cpu = NULL;
if (av1_dec->db_ctrl_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->db_ctrl_col.size,
- av1_dec->db_ctrl_col.cpu,
- av1_dec->db_ctrl_col.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->db_ctrl_col.size,
+ av1_dec->db_ctrl_col.cpu,
+ av1_dec->db_ctrl_col.dma, 0);
av1_dec->db_ctrl_col.cpu = NULL;
if (av1_dec->cdef_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->cdef_col.size,
- av1_dec->cdef_col.cpu, av1_dec->cdef_col.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->cdef_col.size,
+ av1_dec->cdef_col.cpu,
+ av1_dec->cdef_col.dma, 0);
av1_dec->cdef_col.cpu = NULL;
if (av1_dec->sr_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->sr_col.size,
- av1_dec->sr_col.cpu, av1_dec->sr_col.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->sr_col.size,
+ av1_dec->sr_col.cpu,
+ av1_dec->sr_col.dma, 0);
av1_dec->sr_col.cpu = NULL;
if (av1_dec->lr_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->lr_col.size,
- av1_dec->lr_col.cpu, av1_dec->lr_col.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->lr_col.size,
+ av1_dec->lr_col.cpu,
+ av1_dec->lr_col.dma, 0);
av1_dec->lr_col.cpu = NULL;
}
@@ -278,41 +286,46 @@ static int rockchip_vpu981_av1_dec_tiles_reallocate(struct hantro_ctx *ctx)
rockchip_vpu981_av1_dec_tiles_free(ctx);
size = ALIGN(height * 12 * ctx->bit_depth / 8, 128) * num_tile_cols;
- av1_dec->db_data_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->db_data_col.dma,
- GFP_KERNEL);
+ av1_dec->db_data_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &av1_dec->db_data_col.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-db-data-col");
if (!av1_dec->db_data_col.cpu)
goto buffer_allocation_error;
av1_dec->db_data_col.size = size;
size = ALIGN(height * 2 * 16 / 4, 128) * num_tile_cols;
- av1_dec->db_ctrl_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->db_ctrl_col.dma,
- GFP_KERNEL);
+ av1_dec->db_ctrl_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &av1_dec->db_ctrl_col.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-db-ctrl-col");
if (!av1_dec->db_ctrl_col.cpu)
goto buffer_allocation_error;
av1_dec->db_ctrl_col.size = size;
size = ALIGN(height_in_sb * 44 * ctx->bit_depth * 16 / 8, 128) * num_tile_cols;
- av1_dec->cdef_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->cdef_col.dma,
- GFP_KERNEL);
+ av1_dec->cdef_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &av1_dec->cdef_col.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-cdef-col");
if (!av1_dec->cdef_col.cpu)
goto buffer_allocation_error;
av1_dec->cdef_col.size = size;
size = ALIGN(height_in_sb * (3040 + 1280), 128) * num_tile_cols;
- av1_dec->sr_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->sr_col.dma,
- GFP_KERNEL);
+ av1_dec->sr_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &av1_dec->sr_col.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-sr-col");
if (!av1_dec->sr_col.cpu)
goto buffer_allocation_error;
av1_dec->sr_col.size = size;
size = ALIGN(stripe_num * 1536 * ctx->bit_depth / 8, 128) * num_tile_cols;
- av1_dec->lr_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->lr_col.dma,
- GFP_KERNEL);
+ av1_dec->lr_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+ &av1_dec->lr_col.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-lr-col");
if (!av1_dec->lr_col.cpu)
goto buffer_allocation_error;
av1_dec->lr_col.size = size;
@@ -331,37 +344,45 @@ void rockchip_vpu981_av1_dec_exit(struct hantro_ctx *ctx)
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
if (av1_dec->global_model.cpu)
- dma_free_coherent(vpu->dev, av1_dec->global_model.size,
- av1_dec->global_model.cpu,
- av1_dec->global_model.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->global_model.size,
+ av1_dec->global_model.cpu,
+ av1_dec->global_model.dma, 0);
av1_dec->global_model.cpu = NULL;
if (av1_dec->tile_info.cpu)
- dma_free_coherent(vpu->dev, av1_dec->tile_info.size,
- av1_dec->tile_info.cpu,
- av1_dec->tile_info.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->tile_info.size,
+ av1_dec->tile_info.cpu,
+ av1_dec->tile_info.dma, 0);
av1_dec->tile_info.cpu = NULL;
if (av1_dec->film_grain.cpu)
- dma_free_coherent(vpu->dev, av1_dec->film_grain.size,
- av1_dec->film_grain.cpu,
- av1_dec->film_grain.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->film_grain.size,
+ av1_dec->film_grain.cpu,
+ av1_dec->film_grain.dma, 0);
av1_dec->film_grain.cpu = NULL;
if (av1_dec->prob_tbl.cpu)
- dma_free_coherent(vpu->dev, av1_dec->prob_tbl.size,
- av1_dec->prob_tbl.cpu, av1_dec->prob_tbl.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->prob_tbl.size,
+ av1_dec->prob_tbl.cpu,
+ av1_dec->prob_tbl.dma, 0);
av1_dec->prob_tbl.cpu = NULL;
if (av1_dec->prob_tbl_out.cpu)
- dma_free_coherent(vpu->dev, av1_dec->prob_tbl_out.size,
- av1_dec->prob_tbl_out.cpu,
- av1_dec->prob_tbl_out.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->prob_tbl_out.size,
+ av1_dec->prob_tbl_out.cpu,
+ av1_dec->prob_tbl_out.dma, 0);
av1_dec->prob_tbl_out.cpu = NULL;
if (av1_dec->tile_buf.cpu)
- dma_free_coherent(vpu->dev, av1_dec->tile_buf.size,
- av1_dec->tile_buf.cpu, av1_dec->tile_buf.dma);
+ v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+ av1_dec->tile_buf.size,
+ av1_dec->tile_buf.cpu,
+ av1_dec->tile_buf.dma, 0);
av1_dec->tile_buf.cpu = NULL;
rockchip_vpu981_av1_dec_tiles_free(ctx);
@@ -374,40 +395,48 @@ int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx)
memset(av1_dec, 0, sizeof(*av1_dec));
- av1_dec->global_model.cpu = dma_alloc_coherent(vpu->dev, GLOBAL_MODEL_SIZE,
- &av1_dec->global_model.dma,
- GFP_KERNEL);
+ av1_dec->global_model.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ GLOBAL_MODEL_SIZE,
+ &av1_dec->global_model.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-global-model");
if (!av1_dec->global_model.cpu)
return -ENOMEM;
av1_dec->global_model.size = GLOBAL_MODEL_SIZE;
- av1_dec->tile_info.cpu = dma_alloc_coherent(vpu->dev, AV1_TILE_INFO_SIZE,
- &av1_dec->tile_info.dma,
- GFP_KERNEL);
+ av1_dec->tile_info.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ AV1_TILE_INFO_SIZE,
+ &av1_dec->tile_info.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-tile-info");
if (!av1_dec->tile_info.cpu)
return -ENOMEM;
av1_dec->tile_info.size = AV1_TILE_INFO_SIZE;
- av1_dec->film_grain.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct rockchip_av1_film_grain), 2048),
- &av1_dec->film_grain.dma,
- GFP_KERNEL);
+ av1_dec->film_grain.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ ALIGN(sizeof(struct rockchip_av1_film_grain),
+ 2048),
+ &av1_dec->film_grain.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-film-grain");
if (!av1_dec->film_grain.cpu)
return -ENOMEM;
av1_dec->film_grain.size = ALIGN(sizeof(struct rockchip_av1_film_grain), 2048);
- av1_dec->prob_tbl.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct av1cdfs), 2048),
- &av1_dec->prob_tbl.dma,
- GFP_KERNEL);
+ av1_dec->prob_tbl.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ ALIGN(sizeof(struct av1cdfs), 2048),
+ &av1_dec->prob_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-prob-tbl");
if (!av1_dec->prob_tbl.cpu)
return -ENOMEM;
av1_dec->prob_tbl.size = ALIGN(sizeof(struct av1cdfs), 2048);
- av1_dec->prob_tbl_out.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct av1cdfs), 2048),
- &av1_dec->prob_tbl_out.dma,
- GFP_KERNEL);
+ av1_dec->prob_tbl_out.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ ALIGN(sizeof(struct av1cdfs), 2048),
+ &av1_dec->prob_tbl_out.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-prob-tbl-out");
if (!av1_dec->prob_tbl_out.cpu)
return -ENOMEM;
av1_dec->prob_tbl_out.size = ALIGN(sizeof(struct av1cdfs), 2048);
@@ -416,10 +445,11 @@ int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx)
rockchip_av1_set_default_cdfs(av1_dec->cdfs, av1_dec->cdfs_ndvc);
- av1_dec->tile_buf.cpu = dma_alloc_coherent(vpu->dev,
- AV1_TILE_SIZE,
- &av1_dec->tile_buf.dma,
- GFP_KERNEL);
+ av1_dec->tile_buf.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+ AV1_TILE_SIZE,
+ &av1_dec->tile_buf.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "av1-tile-buf");
if (!av1_dec->tile_buf.cpu)
return -ENOMEM;
av1_dec->tile_buf.size = AV1_TILE_SIZE;
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] media: rkvdec: Switch to tracked dma allocations
2026-09-16 14:25 [PATCH 0/4] media: Track v4l2 buffers through an allocator Detlev Casanova
` (2 preceding siblings ...)
2026-09-16 14:25 ` [PATCH 3/4] media: verisilicon: Switch to tracked dma allocations Detlev Casanova
@ 2026-09-16 14:25 ` Detlev Casanova
2026-09-20 13:50 ` [PATCH 0/4] media: Track v4l2 buffers through an allocator Diederik de Haas
4 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-09-16 14:25 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip,
linux-arm-kernel, Detlev Casanova
Use the newly introduced v4l2_dma_alloc_attrs and v4l2_dma_free_attrs
functions to track all dma allocations and have them exposed to
userspace for easier debug.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
.../media/platform/rockchip/rkvdec/rkvdec-h264.c | 14 ++++++---
.../media/platform/rockchip/rkvdec/rkvdec-hevc.c | 14 ++++++---
.../media/platform/rockchip/rkvdec/rkvdec-rcb.c | 21 ++++++++------
.../platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c | 14 ++++++---
.../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 14 ++++++---
.../platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c | 14 ++++++---
.../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 14 ++++++---
.../media/platform/rockchip/rkvdec/rkvdec-vp9.c | 33 +++++++++++++++-------
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 4 +++
9 files changed, 100 insertions(+), 42 deletions(-)
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c
index d3202cecb988..5b5bc091e792 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c
@@ -11,6 +11,7 @@
#include <media/v4l2-h264.h>
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-regs.h"
@@ -379,8 +380,11 @@ static int rkvdec_h264_start(struct rkvdec_ctx *ctx)
if (!h264_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &h264_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &h264_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "h264-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -404,8 +408,10 @@ static void rkvdec_h264_stop(struct rkvdec_ctx *ctx)
struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, h264_ctx->priv_tbl.size,
- h264_ctx->priv_tbl.cpu, h264_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ h264_ctx->priv_tbl.size,
+ h264_ctx->priv_tbl.cpu,
+ h264_ctx->priv_tbl.dma, 0);
kfree(h264_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c
index ac8b825d080a..fef8bf6c7625 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c
@@ -13,6 +13,7 @@
*/
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-regs.h"
@@ -532,8 +533,11 @@ static int rkvdec_hevc_start(struct rkvdec_ctx *ctx)
if (!hevc_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &hevc_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &hevc_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "hevc-priv-tbl");
if (!priv_tbl) {
kfree(hevc_ctx);
return -ENOMEM;
@@ -553,8 +557,10 @@ static void rkvdec_hevc_stop(struct rkvdec_ctx *ctx)
struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, hevc_ctx->priv_tbl.size,
- hevc_ctx->priv_tbl.cpu, hevc_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ hevc_ctx->priv_tbl.size,
+ hevc_ctx->priv_tbl.cpu,
+ hevc_ctx->priv_tbl.dma, 0);
kfree(hevc_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
index fdcf1f177379..1d43793720c7 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
@@ -13,6 +13,7 @@
#include <linux/genalloc.h>
#include <linux/sizes.h>
#include <linux/types.h>
+#include <media/v4l2-allocator.h>
struct rkvdec_rcb_config {
struct rkvdec_aux_buf *rcb_bufs;
@@ -65,10 +66,10 @@ void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
gen_pool_free(dev->sram_pool, virt_addr, rcb_size);
break;
case RKVDEC_ALLOC_DMA:
- dma_free_coherent(dev->dev,
- rcb_size,
- cfg->rcb_bufs[i].cpu,
- cfg->rcb_bufs[i].dma);
+ v4l2_dma_free_attrs(&dev->v4l2_dev, dev->dev,
+ rcb_size,
+ cfg->rcb_bufs[i].cpu,
+ cfg->rcb_bufs[i].dma, 0);
break;
}
}
@@ -150,10 +151,14 @@ int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
ram_fallback:
/* Fallback to RAM */
if (!cpu) {
- cpu = dma_alloc_coherent(ctx->dev->dev,
- rcb_size,
- &dma,
- GFP_KERNEL);
+ char name[32];
+
+ snprintf(name, sizeof(name), "rcb-%d", i);
+ cpu = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, ctx->dev->dev,
+ rcb_size,
+ &dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ name);
alloc_type = RKVDEC_ALLOC_DMA;
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
index b961fddc8583..b0cb6963c8e0 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
@@ -8,6 +8,7 @@
#include <media/v4l2-h264.h>
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-cabac.h"
@@ -387,8 +388,11 @@ static int rkvdec_h264_start(struct rkvdec_ctx *ctx)
if (!h264_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &h264_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &h264_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vdpu381-h264-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -412,8 +416,10 @@ static void rkvdec_h264_stop(struct rkvdec_ctx *ctx)
struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, h264_ctx->priv_tbl.size,
- h264_ctx->priv_tbl.cpu, h264_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ h264_ctx->priv_tbl.size,
+ h264_ctx->priv_tbl.cpu,
+ h264_ctx->priv_tbl.dma, 0);
kfree(h264_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
index fe6414a17551..c1e16ba6f80f 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
@@ -7,6 +7,7 @@
*/
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-cabac.h"
@@ -555,8 +556,11 @@ static int rkvdec_hevc_start(struct rkvdec_ctx *ctx)
if (!hevc_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &hevc_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &hevc_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vdpu381-hevc-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -580,8 +584,10 @@ static void rkvdec_hevc_stop(struct rkvdec_ctx *ctx)
struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, hevc_ctx->priv_tbl.size,
- hevc_ctx->priv_tbl.cpu, hevc_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ hevc_ctx->priv_tbl.size,
+ hevc_ctx->priv_tbl.cpu,
+ hevc_ctx->priv_tbl.dma, 0);
kfree(hevc_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
index fb4f849d7366..3c1d3ca7cb6f 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
@@ -8,6 +8,7 @@
#include <media/v4l2-h264.h>
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include <linux/iopoll.h>
@@ -455,8 +456,11 @@ static int rkvdec_h264_start(struct rkvdec_ctx *ctx)
if (!h264_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &h264_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &h264_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vdpu383-h264-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -481,8 +485,10 @@ static void rkvdec_h264_stop(struct rkvdec_ctx *ctx)
struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, h264_ctx->priv_tbl.size,
- h264_ctx->priv_tbl.cpu, h264_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ h264_ctx->priv_tbl.size,
+ h264_ctx->priv_tbl.cpu,
+ h264_ctx->priv_tbl.dma, 0);
kfree(h264_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
index 96d938ee70b0..b0ec46f482fa 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
@@ -7,6 +7,7 @@
*/
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-cabac.h"
@@ -563,8 +564,11 @@ static int rkvdec_hevc_start(struct rkvdec_ctx *ctx)
if (!hevc_ctx)
return -ENOMEM;
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &hevc_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &hevc_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vdpu383-hevc-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -588,8 +592,10 @@ static void rkvdec_hevc_stop(struct rkvdec_ctx *ctx)
struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, hevc_ctx->priv_tbl.size,
- hevc_ctx->priv_tbl.cpu, hevc_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ hevc_ctx->priv_tbl.size,
+ hevc_ctx->priv_tbl.cpu,
+ hevc_ctx->priv_tbl.dma, 0);
kfree(hevc_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c
index 2751f5396ee8..9f41f6ca82d1 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c
@@ -20,6 +20,7 @@
#include <linux/vmalloc.h>
#include <media/v4l2-mem2mem.h>
#include <media/v4l2-vp9.h>
+#include <media/v4l2-allocator.h>
#include "rkvdec.h"
#include "rkvdec-regs.h"
@@ -979,8 +980,11 @@ static int rkvdec_vp9_start(struct rkvdec_ctx *ctx)
ctx->priv = vp9_ctx;
BUILD_BUG_ON(sizeof(priv_tbl->probs) % 16); /* ensure probs size is 128-bit aligned */
- priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
- &vp9_ctx->priv_tbl.dma, GFP_KERNEL);
+ priv_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ sizeof(*priv_tbl),
+ &vp9_ctx->priv_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vp9-priv-tbl");
if (!priv_tbl) {
ret = -ENOMEM;
goto err_free_ctx;
@@ -989,8 +993,11 @@ static int rkvdec_vp9_start(struct rkvdec_ctx *ctx)
vp9_ctx->priv_tbl.size = sizeof(*priv_tbl);
vp9_ctx->priv_tbl.cpu = priv_tbl;
- count_tbl = dma_alloc_coherent(rkvdec->dev, RKVDEC_VP9_COUNT_SIZE,
- &vp9_ctx->count_tbl.dma, GFP_KERNEL);
+ count_tbl = v4l2_dma_alloc_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ RKVDEC_VP9_COUNT_SIZE,
+ &vp9_ctx->count_tbl.dma,
+ GFP_KERNEL, 0, &ctx->fh,
+ "vp9-count-tbl");
if (!count_tbl) {
ret = -ENOMEM;
goto err_free_priv_tbl;
@@ -1003,8 +1010,10 @@ static int rkvdec_vp9_start(struct rkvdec_ctx *ctx)
return 0;
err_free_priv_tbl:
- dma_free_coherent(rkvdec->dev, vp9_ctx->priv_tbl.size,
- vp9_ctx->priv_tbl.cpu, vp9_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ vp9_ctx->priv_tbl.size,
+ vp9_ctx->priv_tbl.cpu,
+ vp9_ctx->priv_tbl.dma, 0);
err_free_ctx:
kfree(vp9_ctx);
@@ -1016,10 +1025,14 @@ static void rkvdec_vp9_stop(struct rkvdec_ctx *ctx)
struct rkvdec_vp9_ctx *vp9_ctx = ctx->priv;
struct rkvdec_dev *rkvdec = ctx->dev;
- dma_free_coherent(rkvdec->dev, vp9_ctx->count_tbl.size,
- vp9_ctx->count_tbl.cpu, vp9_ctx->count_tbl.dma);
- dma_free_coherent(rkvdec->dev, vp9_ctx->priv_tbl.size,
- vp9_ctx->priv_tbl.cpu, vp9_ctx->priv_tbl.dma);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ vp9_ctx->count_tbl.size,
+ vp9_ctx->count_tbl.cpu,
+ vp9_ctx->count_tbl.dma, 0);
+ v4l2_dma_free_attrs(&rkvdec->v4l2_dev, rkvdec->dev,
+ vp9_ctx->priv_tbl.size,
+ vp9_ctx->priv_tbl.cpu,
+ vp9_ctx->priv_tbl.dma, 0);
kfree(vp9_ctx);
}
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 1d1e9bfef8e9..8770fdb5c919 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -1208,6 +1208,8 @@ static int rkvdec_queue_init(void *priv,
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->lock = &rkvdec->vdev_lock;
src_vq->dev = rkvdec->v4l2_dev.dev;
+ src_vq->v4l2_dev = &rkvdec->v4l2_dev;
+ src_vq->v4l2_fh = &ctx->fh;
src_vq->supports_requests = true;
src_vq->requires_requests = true;
@@ -1227,6 +1229,8 @@ static int rkvdec_queue_init(void *priv,
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->lock = &rkvdec->vdev_lock;
dst_vq->dev = rkvdec->v4l2_dev.dev;
+ dst_vq->v4l2_dev = &rkvdec->v4l2_dev;
+ dst_vq->v4l2_fh = &ctx->fh;
return vb2_queue_init(dst_vq);
}
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] media: Track v4l2 buffers through an allocator
2026-09-16 14:25 [PATCH 0/4] media: Track v4l2 buffers through an allocator Detlev Casanova
` (3 preceding siblings ...)
2026-09-16 14:25 ` [PATCH 4/4] media: rkvdec: " Detlev Casanova
@ 2026-09-20 13:50 ` Diederik de Haas
4 siblings, 0 replies; 6+ messages in thread
From: Diederik de Haas @ 2026-09-20 13:50 UTC (permalink / raw)
To: Detlev Casanova, Tomasz Figa, Marek Szyprowski,
Mauro Carvalho Chehab, Nicolas Dufresne, Benjamin Gaignard,
Philipp Zabel, Heiko Stuebner, Ezequiel Garcia
Cc: kernel, linux-kernel, linux-media, linux-rockchip, linux-arm-kernel
Hi Detlev,
On Wed Sep 16, 2026 at 4:25 PM CEST, Detlev Casanova wrote:
> Hello,
>
> Currently, the only way to track buffers allocated by v4l2 from usespace
> is to use the subsystem available debug information (e.g.:
> /sys/kernel/debug/dma_buf/bufinfo).
> But that information is generic and cannot be matched to a v4l2 driver or
> to a userspace application: It is merely information about the allocation.
>
> Other types of allocations require the developper to find where they are
> exposed and how to link them to their test.
>
> This can become hard to track when mutliple drivers are working at the
> same time.
>
> To improve that, add a small wrapper around buffer allocations to keep
> track of them at the video device level so that we can add debug
> information to them like a name, userspace pid/fd that did the
> allocation,... and expose them to userspace via a debugfs entry.
>
> It currently only supports DMA buffer allocations and adds support for
> VB2 allocations too.
> Other kind of memory tracking can be added later.
> The verisilicon and rkvdec drivers have been ported to use the tracked
> dma alloactions.
>
> Note that this depends on the ftrace support patch series[1] that
> provides fd/pid info in the v4l2_fh struct.
> That series is a bit old, so this is based on an older linux version, but
> that only changes things for the last 2 commits.
>
> A v4l2top utility[2] has been made, to be used in parallel with the
> fdinfo patch series[3], to show the list of active streams with their HW
> and memory usage.
>
> With this, debugfs looks like this when decoding a HEVC 1080p stream with
> rkvdec on rk3588:
>
> root # cat /sys/kernel/debug/v4l2/fdc38100.video-codec/mem
> created-by fd pid size label
> -------------------------------------------------------------------------------------
> gst-launch-1.0 7 635 39184 vdpu381-hevc-priv-tbl
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-7
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-6
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-5
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-4
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-3
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-2
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-1
> gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-0
> gst-launch-1.0 7 635 3133440 out-000000005c0230f6-1
> gst-launch-1.0 7 635 3133440 out-000000005c0230f6-0
> =====================================================================================
> Total size: 39729424
I build a kernel with your 3 patch series and I also build the v4l2top utility.
Cool tool :-D
Especially after I found out I should build the 'upstream' branch ;-)
There were a couple of things I noticed:
1) With 'plain' kernel 7.3-rc3 but also with all my patches included, but
excluding the patches from this series, I see this:
```
root@nanopc-t6-plus:~# ls -lh /sys/kernel/debug/v4l2/
total 0
drwxr-xr-x 3 root root 0 Sep 20 15:10 fdee0000.hdmi_receiver
```
Which is presumably the reason that with a kernel which also includes this
patch series, I get the following kernel error:
``[ 10.849405] debugfs: 'v4l2' already exists in '/'``
I don't think this should generate an error/warning/info message at all,
but just silently dealt with.
Checking v4l2 debug dir again results in this:
```
root@nanopc-t6-plus:~# ls -lh /sys/kernel/debug/v4l2/
total 0
drwxr-xr-x 2 root root 0 Sep 20 15:13 fdb60000.rga
drwxr-xr-x 2 root root 0 Sep 20 15:13 fdb80000.rga
drwxr-xr-x 2 root root 0 Sep 20 15:13 fdc38000.video-codec
drwxr-xr-x 2 root root 0 Sep 20 15:13 fdee0000.hdmi_receiver
```
I noticed my video-codec address was slightly different from yours.
Playing a 1080p BBB x264 video with a patched ffmpeg+mpv, results in this:
```
root@nanopc-t6-plus:~# cat /sys/kernel/debug/v4l2/fdc38000.video-codec/mem
created-by fd pid size label
-------------------------------------------------------------------------------------
mpv 26 2027 4177920 cap-00000000205a3b3a-10
mpv 26 2027 4177920 cap-00000000205a3b3a-9
mpv 26 2027 4177920 cap-00000000205a3b3a-8
mpv 26 2027 16736 vdpu381-h264-priv-tbl
mpv 26 2027 3133440 out-0000000079002cb1-3
mpv 26 2027 3133440 out-0000000079002cb1-2
mpv 26 2027 3133440 out-0000000079002cb1-1
mpv 26 2027 3133440 out-0000000079002cb1-0
mpv 26 2027 4177920 cap-00000000205a3b3a-7
mpv 26 2027 4177920 cap-00000000205a3b3a-6
mpv 26 2027 4177920 cap-00000000205a3b3a-5
mpv 26 2027 4177920 cap-00000000205a3b3a-4
mpv 26 2027 4177920 cap-00000000205a3b3a-3
mpv 26 2027 4177920 cap-00000000205a3b3a-2
mpv 26 2027 4177920 cap-00000000205a3b3a-1
mpv 26 2027 4177920 cap-00000000205a3b3a-0
=====================================================================================
Total size: 58507616
```
And looking at the v4l2top utility, I noticed the following:
1. I see differing indications of the load while it's playing :-D
2. The ``Clock rate`` is always 750.0MHz (or 786431991Hz) (expected I think?)
3. The ``Total Memory`` is always 0B and the ``Memory usage details`` column
is always empty. That's also the case when I press one of the arrow keys
which seems to select the entry. Am I missing sth or doing sth wrong?
Cheers,
Diederik
> [1]: https://lore.kernel.org/all/20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com/
> [2]: https://github.com/cazou/v4l2top/tree/upstream
> [3]: https://lore.kernel.org/all/20260706-v4l2-add-fdinfo-v3-0-d556568cf38e@collabora.com/
>
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
> ---
> Detlev Casanova (4):
> media: Add a v4l2 memory allocations tracker
> media: Store v4l2_fh in the vb_queue
> media: verisilicon: Switch to tracked dma allocations
> media: rkvdec: Switch to tracked dma allocations
>
> drivers/media/common/videobuf2/Makefile | 1 +
> drivers/media/common/videobuf2/v4l2-allocator.c | 186 +++++++++++++++++++++
> .../media/common/videobuf2/videobuf2-dma-contig.c | 27 ++-
> .../media/platform/rockchip/rkvdec/rkvdec-h264.c | 14 +-
> .../media/platform/rockchip/rkvdec/rkvdec-hevc.c | 14 +-
> .../media/platform/rockchip/rkvdec/rkvdec-rcb.c | 21 ++-
> .../platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c | 14 +-
> .../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 14 +-
> .../platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c | 14 +-
> .../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 14 +-
> .../media/platform/rockchip/rkvdec/rkvdec-vp9.c | 33 ++--
> drivers/media/platform/rockchip/rkvdec/rkvdec.c | 4 +
> drivers/media/platform/verisilicon/hantro.h | 1 +
> drivers/media/platform/verisilicon/hantro_drv.c | 4 +
> drivers/media/platform/verisilicon/hantro_h264.c | 7 +-
> drivers/media/platform/verisilicon/hantro_hevc.c | 100 ++++++-----
> drivers/media/platform/verisilicon/hantro_mpeg2.c | 16 +-
> .../media/platform/verisilicon/hantro_postproc.c | 14 +-
> drivers/media/platform/verisilicon/hantro_vp8.c | 25 +--
> drivers/media/platform/verisilicon/hantro_vp9.c | 34 +++-
> .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 160 +++++++++++-------
> drivers/media/v4l2-core/v4l2-device.c | 4 +-
> include/media/v4l2-allocator.h | 26 +++
> include/media/v4l2-device.h | 2 +
> include/media/videobuf2-core.h | 3 +
> 25 files changed, 555 insertions(+), 197 deletions(-)
> ---
> base-commit: 66affa37cfac0aec061cc4bcf4a065b0c52f7e19
> change-id: 20260612-v4l2-add-mem-tracker-da0088c74a64
> prerequisite-change-id: 20260608-v4l2-add-ftrace-aec6e7f60a6c:v2
> prerequisite-patch-id: bd45b4df66799a7f9f22b49973a78d1bd3590a4a
> prerequisite-patch-id: 6a5ed5615f08257cf854d441785066b5ff4d5d47
> prerequisite-patch-id: 02594c869498b9e91e416d70242afbaa6b3a8d6a
> prerequisite-patch-id: 9f25ec78f3b99ac1c5d42eb732f5bd9eae73fadd
> prerequisite-patch-id: 4ed2c2e8c3abfa7f6328d0ea4f488ca5a3eec8fb
> prerequisite-patch-id: 8787d50eb80e1a63a57a123268cade23c9e64618
> prerequisite-patch-id: bfe85822378fa771f9bbc3e1e8c8ff6bce0eb7fd
> prerequisite-patch-id: 784d0801da320f7b41194f4632ee422c32f1b5b8
> prerequisite-patch-id: 362c8366e2efbfb5e6f1a3f71cfddbd46e8d1506
>
> Best regards,
> --
> Detlev Casanova <detlev.casanova@collabora.com>
>
>
> _______________________________________________
> Linux-rockchip mailing list
> Linux-rockchip@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-20 13:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/4] media: Store v4l2_fh in the vb_queue Detlev Casanova
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
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®