[PATCH v2 0/4] media: verisilicon: Check the CAPTURE buffer size when a decode job starts

From: Arun Iyengar via B4 Relay

Date: Thu Dec 03 2026 - 00:35:26 EST


The CAPTURE format of a Hantro decoder can grow while CAPTURE buffers
are queued. Patch 1 refuses a job whose CAPTURE buffer is now too small,
patch 2 a reference that is. Patch 3 makes the G1 VP8 missing-reference
fallback use the decoder buffer, and patch 4 fails a job whose decoder
buffer could not be allocated instead of programming address 0.

AV1 reads the primary reference's segmentation map at the current
format's offset; "media: verisilicon: av1: Fix two reference reads"
fixes that [1]. HEVC (G2) references are not checked: I have no G2
hardware.

device_run() does not hold the queue lock, so S_FMT can still change the
format after the check.

Tested on an Orange Pi 5 (RK3588S) with the series ported to a 7.3-based
tree, where patches 1 and 4 check in device_run() as that tree lacks
Sascha's ->run() rework. A picture decoded into a 640x368 buffer, the
format grown to 1920x1088, then a request naming it as reference: H.264,
VP8 and MPEG-2 refuse the reference and complete the request, H.264 and
VP8 with no IOMMU fault. The zero-filled MPEG-2 test stream also hangs
VPU121 (buffer empty) in its first request, which has no reference and
does not reach the code patch 2 changes. A forced decoder buffer
allocation failure fails the job. fluster H.264, VP8 and AV1 results are
unchanged. Patch 3 is untested: no RK3588 path uses the G1 post-
processor.

[1] https://lore.kernel.org/r/20261119-b4-vpu981-av1-refs-v2-0-7c270158b20e@xxxxxxxxx

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
Changes in v2:
- New patch 2: refuse references smaller than the CAPTURE format
(Sashiko).
- Check in hantro_start_prepare_run() and use the ->run() error paths
of Sascha Hauer's series, now in media next.
- New patch 3: G1 VP8 missing references use the decoder buffer.
- New patch 4: fail the job when the decoder buffer can't be allocated.
- Shorter commit message and notes.
- Link to v1: https://patch.msgid.link/20261112-hantro-dec-size-check-v1-1-e5f1180b625f@xxxxxxxxx

---
Arun Iyengar (4):
media: verisilicon: Check the CAPTURE buffer size when a decode job starts
media: verisilicon: Don't use a reference smaller than the CAPTURE format
media: verisilicon: g1: vp8: Use the decoder buffer for missing references
media: verisilicon: Fail the job if the decoder buffer can't be allocated

drivers/media/platform/verisilicon/hantro_drv.c | 35 ++++++++++++++++++++--
.../platform/verisilicon/hantro_g1_mpeg2_dec.c | 7 ++++-
.../media/platform/verisilicon/hantro_g1_vp8_dec.c | 13 +++++---
.../media/platform/verisilicon/hantro_g2_vp9_dec.c | 5 +++-
drivers/media/platform/verisilicon/hantro_h264.c | 5 +++-
drivers/media/platform/verisilicon/hantro_hevc.c | 4 ++-
drivers/media/platform/verisilicon/hantro_hw.h | 2 +-
.../verisilicon/rockchip_vpu2_hw_mpeg2_dec.c | 7 ++++-
.../verisilicon/rockchip_vpu2_hw_vp8_dec.c | 7 ++++-
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 4 ++-
10 files changed, 75 insertions(+), 14 deletions(-)
---
base-commit: d99d0a5a82f54a169b45b81a5da8a0985008a205
change-id: 20261112-hantro-dec-size-check-f8a4b2872656

Best regards,
--
Arun Iyengar <aiyengar1990@xxxxxxxxx>