From: sashiko-bot@kernel.org
To: "Detlev Casanova" <detlev.casanova@collabora.com>
Cc: linux-trace-kernel@vger.kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3 9/9] media: hantro: Add v4l2_hw run/done traces
Date: Wed, 25 Nov 2026 19:01:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-234029@kernel.org> (raw)
In-Reply-To: <20261125-v4l2-add-ftrace-v3-9-1d1db48372ed@collabora.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] media: hantro: NULL dereference and race on ctx in
rk3588_vpu981_irq()
- [Medium] media: hantro: race and UAF in device_run() calling
trace_v4l2_hw_run()
- [Medium] media: hantro: UAF race and duplicate trace in
hantro_irq_done()
- [Low] media: hantro: stale ctx->hw_cycles reported in
trace_v4l2_hw_done()
- [Low] media: hantro: missing kernel-doc entry for hw_cycles in
hantro_ctx
--
commit e206fb95ea0a2df26a322693fa1382eb6fa7b49a
Author: Detlev Casanova <detlev.casanova@collabora.com>
media: hantro: Add v4l2_hw run/done traces
This commit adds trace_v4l2_hw_run() and trace_v4l2_hw_done() calls to
the hantro VPU driver and records the hardware cycle count from
AV1_CYCLE_COUNT on the Rockchip VPU981 core.
[Severity: Low]
In drivers/media/platform/verisilicon/hantro.h, struct hantro_ctx
(around line 256):
This isn't a bug, but struct hantro_ctx has a kernel-doc comment block
above it and the new hw_cycles field has no @hw_cycles: entry, which
triggers a W=1 kernel-doc warning.
[Severity: Medium]
In drivers/media/platform/verisilicon/hantro_drv.c, hantro_irq_done()
(around line 105):
Can calling trace_v4l2_hw_done() before cancel_delayed_work() emit a
duplicate trace event or read a freed ctx?
cancel_delayed_work(&vpu->watchdog_work) is what synchronizes
hantro_irq_done() against hantro_watchdog(). If the watchdog is already
running on another CPU when the IRQ fires, both paths emit
trace_v4l2_hw_done() for the same job. Worse, if hantro_watchdog()
finishes the job right after v4l2_m2m_get_curr_priv() returns ctx, a
concurrent close() can free ctx before hantro_irq_done() reads ctx->fh
and ctx->hw_cycles:
CPU0 (<hardirq>) CPU1 (watchdog / close)
hantro_irq_done() hantro_watchdog()
ctx = v4l2_m2m_get_curr_priv()
hantro_job_finish(ctx, ...)
...
/* clears TRANS_RUNNING */
hantro_release()
v4l2_m2m_ctx_release()
kfree(ctx)
trace_v4l2_hw_done(ctx->fh.tgid,
ctx->fh.fd,
ctx->hw_cycles) <-- use-after-free
Moving trace_v4l2_hw_done() inside the
if (cancel_delayed_work(&vpu->watchdog_work)) block avoids both the
race and the duplicate trace event.
[Severity: Low]
In drivers/media/platform/verisilicon/hantro_drv.c, hantro_watchdog()
(around line 131):
Can trace_v4l2_hw_done() in hantro_watchdog() report a stale
ctx->hw_cycles value from an earlier frame?
ctx->hw_cycles is only written in rk3588_vpu981_irq() and is never reset
before a new job starts or when a job times out. If frame N succeeds on
VPU981 and frame N+1 times out (or fails at the prepare_error path in
rockchip_vpu981_av1_dec_run()), trace_v4l2_hw_done() reports frame N's
cycle count instead of 0.
[Severity: Medium]
In drivers/media/platform/verisilicon/hantro_drv.c, device_run()
(around line 199):
Can the completion interrupt fire inside ctx->codec_ops->run(ctx) before
device_run() calls trace_v4l2_hw_run()?
The .run() callbacks start the hardware before returning, while
device_run() runs with interrupts and preemption enabled. If the job
completes immediately (or device_run() is preempted right after writing
the start register), hantro_irq_done() emits trace_v4l2_hw_done() before
trace_v4l2_hw_run() runs, and also clears TRANS_RUNNING so a concurrent
hantro_release() can kfree(ctx) before trace_v4l2_hw_run() reads
ctx->fh.tgid and ctx->fh.fd:
CPU0 CPU1
device_run()
ctx->codec_ops->run(ctx)
/* starts HW */
<hardirq>
hantro_irq_done()
trace_v4l2_hw_done(...)
hantro_job_finish(ctx, ...)
hantro_release()
v4l2_m2m_ctx_release()
kfree(ctx)
trace_v4l2_hw_run(ctx->fh.tgid,
ctx->fh.fd) <-- use-after-free
[Severity: High]
In drivers/media/platform/verisilicon/rockchip_vpu_hw.c,
rk3588_vpu981_irq() (around lines 427-438):
Can ctx be NULL or freed when rk3588_vpu981_irq() writes ctx->hw_cycles?
If hantro_watchdog() expires before the interrupt runs,
hantro_job_finish() clears m2m_dev->curr_ctx to NULL. Because
rk3588_vpu981_codec_ops has no .reset callback, the VPU981 hardware keeps
running and can still raise its interrupt afterward. Although
hantro_irq_done() checks if (ctx), rk3588_vpu981_irq() unconditionally
dereferences ctx->hw_cycles right before calling hantro_irq_done(),
causing a NULL pointer dereference in hard IRQ context.
Even when v4l2_m2m_get_curr_priv() returns a non-NULL ctx,
v4l2_m2m_get_curr_priv() drops job_spinlock before returning and
cancel_delayed_work() has not run yet, so a concurrent hantro_watchdog()
and hantro_release() can finish the job and kfree(ctx) before
ctx->hw_cycles is written.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-v4l2-add-ftrace-v3-0-1d1db48372ed@collabora.com?part=9
prev parent reply other threads:[~2026-11-25 19:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:33 [PATCH v3 0/9] v4l2: Add tracing for stateless codecs Detlev Casanova
2026-11-25 18:33 ` [PATCH v3 1/9] media: Move visl traces to v4l2-core Detlev Casanova
2026-11-25 18:58 ` sashiko-bot
2026-11-25 18:33 ` [PATCH v3 2/9] media: Map each struct field to its own trace field Detlev Casanova
2026-11-25 18:33 ` [PATCH v3 3/9] media: Add tgid and fd fields in v4l2_fh struct Detlev Casanova
2026-11-25 18:59 ` sashiko-bot
2026-11-25 18:33 ` [PATCH v3 4/9] media: Add tgid and fd to the v4l2-requests trace fields Detlev Casanova
2026-11-25 18:56 ` sashiko-bot
2026-11-25 18:33 ` [PATCH v3 5/9] media: Add missing types to v4l2_ctrl_ptr Detlev Casanova
2026-11-25 18:33 ` [PATCH v3 6/9] media: Trace the stateless controls when set in v4l2-ctrls-core.c Detlev Casanova
2026-11-25 19:00 ` sashiko-bot
2026-11-25 18:33 ` [PATCH v3 7/9] media: Add stream on/off traces and run them in the ioctl Detlev Casanova
2026-11-25 18:57 ` sashiko-bot
2026-11-25 18:33 ` [PATCH v3 8/9] media: Add HW run/done trace events Detlev Casanova
2026-11-25 18:33 ` [PATCH v3 9/9] media: hantro: Add v4l2_hw run/done traces Detlev Casanova
2026-11-25 19:01 ` sashiko-bot [this message]
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=sashiko-outbox-234029@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=detlev.casanova@collabora.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=sashiko-reviews@lists.linux.dev \
/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