mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder
@ 2026-11-15  8:39 Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 1/4] media: verisilicon: Size the VP8 segment map for the largest frame Arun Iyengar via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-15  8:39 UTC (permalink / raw)
  To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, Andrzej Pietrasiewicz, Hans Verkuil,
	Jernej Skrabec, Ezequiel Garcia
  Cc: linux-media, linux-rockchip, linux-kernel, stable, Arun Iyengar

Fixes for cases where the decoder writes past the CAPTURE format or an
auxiliary buffer, found by Sashiko on hantro-dec-size-check v1 [1].

Tested on an Orange Pi 5 (RK3588S) with AV1: the CAPTURE format is right
after film grain is turned off and for 10-bit streams; VP8 and AV1
fluster show no new failures. The overrun in patch 1 was not reproduced.
HEVC and VP9 are untested (the RK3588 has no G2 core).

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

[1] https://lore.kernel.org/r/20261112-hantro-dec-size-check-v1-1-e5f1180b625f@gmail.com

---
Changes in v2:
- 3/4: also replace a native format when post-processing; second Fixes tag (Sashiko)
- 4/4: check the control returned by v4l2_ctrl_new_custom() (Sashiko)
- Shorter commit messages, fewer code comments
- Link to v1: https://patch.msgid.link/20261114-hantro-fixes-v1-0-abb78264801e@gmail.com

---
Arun Iyengar (4):
      media: verisilicon: Size the VP8 segment map for the largest frame
      media: verisilicon: Set need_postproc before resetting the CAPTURE format
      media: verisilicon: Keep the CAPTURE format at the stream's bit depth
      media: verisilicon: Set the bit depth again when its control is rewritten

 drivers/media/platform/verisilicon/hantro_drv.c  | 12 ++++++++++--
 drivers/media/platform/verisilicon/hantro_v4l2.c | 20 +++++++++++++++++---
 drivers/media/platform/verisilicon/hantro_vp8.c  |  4 ++--
 3 files changed, 29 insertions(+), 7 deletions(-)
---
base-commit: ad6549a46748d00818483b535e5cd2a704685c98
change-id: 20261113-hantro-fixes-aace04d5268b

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/4] media: verisilicon: Size the VP8 segment map for the largest frame
  2026-11-15  8:39 [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder Arun Iyengar via B4 Relay
@ 2026-11-15  8:39 ` Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 2/4] media: verisilicon: Set need_postproc before resetting the CAPTURE format Arun Iyengar via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-15  8:39 UTC (permalink / raw)
  To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, Andrzej Pietrasiewicz, Hans Verkuil,
	Jernej Skrabec, Ezequiel Garcia
  Cc: linux-media, linux-rockchip, linux-kernel, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

The segment map is sized at STREAMON, but the CAPTURE format can grow
while streaming and overrun it. Size it for the largest frame, as VP9
does.

Fixes: bbd267daf4fc ("media: verisilicon: vp9: Allow to change resolution while streaming")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/media/platform/verisilicon/hantro_vp8.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/verisilicon/hantro_vp8.c b/drivers/media/platform/verisilicon/hantro_vp8.c
index 381bc1d3bfda..98ad86269bc3 100644
--- a/drivers/media/platform/verisilicon/hantro_vp8.c
+++ b/drivers/media/platform/verisilicon/hantro_vp8.c
@@ -151,8 +151,8 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
 	int ret;
 
 	/* segment map table size calculation */
-	mb_width = DIV_ROUND_UP(ctx->dst_fmt.width, 16);
-	mb_height = DIV_ROUND_UP(ctx->dst_fmt.height, 16);
+	mb_width = DIV_ROUND_UP(ctx->vpu_src_fmt->frmsize.max_width, 16);
+	mb_height = DIV_ROUND_UP(ctx->vpu_src_fmt->frmsize.max_height, 16);
 	segment_map_size = round_up(DIV_ROUND_UP(mb_width * mb_height, 4), 64);
 
 	/*

-- 
2.55.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] media: verisilicon: Set need_postproc before resetting the CAPTURE format
  2026-11-15  8:39 [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 1/4] media: verisilicon: Size the VP8 segment map for the largest frame Arun Iyengar via B4 Relay
@ 2026-11-15  8:39 ` Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 3/4] media: verisilicon: Keep the CAPTURE format at the stream's bit depth Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 4/4] media: verisilicon: Set the bit depth again when its control is rewritten Arun Iyengar via B4 Relay
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-15  8:39 UTC (permalink / raw)
  To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, Andrzej Pietrasiewicz, Hans Verkuil,
	Jernej Skrabec, Ezequiel Garcia
  Cc: linux-media, linux-rockchip, linux-kernel, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

hantro_reset_raw_fmt() sets bit_depth and need_postproc only after
hantro_set_fmt_cap(), so hantro_try_fmt() sizes the format with the old
values: after AV1 film grain is turned off, the CAPTURE buffers lack the
motion vector area. Set them first and restore them on error.

Fixes: 80c7373a456e ("media: verisilicon: Conditionally ignore native formats")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/media/platform/verisilicon/hantro_v4l2.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index 83af9fa1ce94..5939fffc350d 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -449,6 +449,8 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)
 {
 	const struct hantro_fmt *raw_vpu_fmt;
 	struct v4l2_pix_format_mplane raw_fmt, *encoded_fmt;
+	bool old_need_postproc = ctx->need_postproc;
+	int old_bit_depth = ctx->bit_depth;
 	int ret;
 
 	raw_vpu_fmt = hantro_get_default_fmt(ctx, false, bit_depth, need_postproc);
@@ -465,14 +467,17 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)
 	hantro_reset_fmt(&raw_fmt, raw_vpu_fmt);
 	raw_fmt.width = encoded_fmt->width;
 	raw_fmt.height = encoded_fmt->height;
+
+	ctx->bit_depth = bit_depth;
+	ctx->need_postproc = need_postproc;
 	if (ctx->is_encoder)
 		ret = hantro_set_fmt_out(ctx, &raw_fmt, need_postproc);
 	else
 		ret = hantro_set_fmt_cap(ctx, &raw_fmt);
 
-	if (!ret) {
-		ctx->bit_depth = bit_depth;
-		ctx->need_postproc = need_postproc;
+	if (ret) {
+		ctx->bit_depth = old_bit_depth;
+		ctx->need_postproc = old_need_postproc;
 	}
 
 	return ret;

-- 
2.55.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] media: verisilicon: Keep the CAPTURE format at the stream's bit depth
  2026-11-15  8:39 [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 1/4] media: verisilicon: Size the VP8 segment map for the largest frame Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 2/4] media: verisilicon: Set need_postproc before resetting the CAPTURE format Arun Iyengar via B4 Relay
@ 2026-11-15  8:39 ` Arun Iyengar via B4 Relay
  2026-11-15  8:39 ` [PATCH v2 4/4] media: verisilicon: Set the bit depth again when its control is rewritten Arun Iyengar via B4 Relay
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-15  8:39 UTC (permalink / raw)
  To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, Andrzej Pietrasiewicz, Hans Verkuil,
	Jernej Skrabec, Ezequiel Garcia
  Cc: linux-media, linux-rockchip, linux-kernel, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

S_FMT and TRY_FMT on the decoder CAPTURE queue accept formats ENUM_FMT
hides: an 8-bit format for a 10-bit stream, which the decoder overruns,
or a native format while the post-processor is needed. Replace such a
format with the stream's default one.

Fixes: 8d03c2ab881b ("media: hantro: Support format filtering by depth")
Fixes: 80c7373a456e ("media: verisilicon: Conditionally ignore native formats")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/media/platform/verisilicon/hantro_v4l2.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index 5939fffc350d..450775664742 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -342,6 +342,15 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
 		pix_mp->pixelformat = fmt->fourcc;
 	}
 
+	if (!coded && !ctx->is_encoder &&
+	    (!hantro_check_depth_match(fmt, ctx->bit_depth) ||
+	     (ctx->need_postproc && !fmt->postprocessed))) {
+		fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth, ctx->need_postproc);
+		if (!fmt)
+			return -EINVAL;
+		pix_mp->pixelformat = fmt->fourcc;
+	}
+
 	if (coded) {
 		pix_mp->num_planes = 1;
 		vpu_fmt = fmt;

-- 
2.55.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] media: verisilicon: Set the bit depth again when its control is rewritten
  2026-11-15  8:39 [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder Arun Iyengar via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-15  8:39 ` [PATCH v2 3/4] media: verisilicon: Keep the CAPTURE format at the stream's bit depth Arun Iyengar via B4 Relay
@ 2026-11-15  8:39 ` Arun Iyengar via B4 Relay
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-15  8:39 UTC (permalink / raw)
  To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, Andrzej Pietrasiewicz, Hans Verkuil,
	Jernej Skrabec, Ezequiel Garcia
  Cc: linux-media, linux-rockchip, linux-kernel, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

S_FMT on OUTPUT resets the CAPTURE format to 8 bits, but rewriting an
unchanged 10-bit HEVC SPS, VP9 frame or AV1 sequence control skips
s_ctrl, so the format stays 8-bit. Mark these controls EXECUTE_ON_WRITE;
every write of them then also sends a V4L2_EVENT_CTRL value change.

Fixes: 3c32d94c9c52 ("media: verisilicon: Do not change context bit depth before validating the format")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/media/platform/verisilicon/hantro_drv.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 26e5d5547466..248fb0e23a29 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -534,6 +534,7 @@ static const struct hantro_ctrl controls[] = {
 		.cfg = {
 			.id = V4L2_CID_STATELESS_HEVC_SPS,
 			.ops = &hantro_hevc_ctrl_ops,
+			.flags = V4L2_CTRL_FLAG_EXECUTE_ON_WRITE,
 		},
 	}, {
 		.codec = HANTRO_HEVC_DECODER,
@@ -555,6 +556,7 @@ static const struct hantro_ctrl controls[] = {
 		.cfg = {
 			.id = V4L2_CID_STATELESS_VP9_FRAME,
 			.ops = &hantro_vp9_ctrl_ops,
+			.flags = V4L2_CTRL_FLAG_EXECUTE_ON_WRITE,
 		},
 	}, {
 		.codec = HANTRO_VP9_DECODER,
@@ -577,6 +579,7 @@ static const struct hantro_ctrl controls[] = {
 		.cfg = {
 			.id = V4L2_CID_STATELESS_AV1_SEQUENCE,
 			.ops = &hantro_av1_ctrl_ops,
+			.flags = V4L2_CTRL_FLAG_EXECUTE_ON_WRITE,
 		},
 	}, {
 		.codec = HANTRO_AV1_DECODER,
@@ -591,6 +594,7 @@ static int hantro_ctrls_setup(struct hantro_dev *vpu,
 			      int allowed_codecs)
 {
 	int i, num_ctrls = ARRAY_SIZE(controls);
+	struct v4l2_ctrl *ctrl;
 
 	v4l2_ctrl_handler_init(&ctx->ctrl_handler, num_ctrls);
 
@@ -598,8 +602,8 @@ static int hantro_ctrls_setup(struct hantro_dev *vpu,
 		if (!(allowed_codecs & controls[i].codec))
 			continue;
 
-		v4l2_ctrl_new_custom(&ctx->ctrl_handler,
-				     &controls[i].cfg, NULL);
+		ctrl = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
+					    &controls[i].cfg, NULL);
 		if (ctx->ctrl_handler.error) {
 			vpu_err("Adding control (%d) failed %d\n",
 				controls[i].cfg.id,
@@ -607,6 +611,10 @@ static int hantro_ctrls_setup(struct hantro_dev *vpu,
 			v4l2_ctrl_handler_free(&ctx->ctrl_handler);
 			return ctx->ctrl_handler.error;
 		}
+
+		/* v4l2_ctrl_new_custom() drops cfg.flags of standard controls. */
+		if (ctrl)
+			ctrl->flags |= controls[i].cfg.flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
 	}
 	return v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
 }

-- 
2.55.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-15  8:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15  8:39 [PATCH v2 0/4] media: verisilicon: Keep the CAPTURE format in line with the decoder Arun Iyengar via B4 Relay
2026-11-15  8:39 ` [PATCH v2 1/4] media: verisilicon: Size the VP8 segment map for the largest frame Arun Iyengar via B4 Relay
2026-11-15  8:39 ` [PATCH v2 2/4] media: verisilicon: Set need_postproc before resetting the CAPTURE format Arun Iyengar via B4 Relay
2026-11-15  8:39 ` [PATCH v2 3/4] media: verisilicon: Keep the CAPTURE format at the stream's bit depth Arun Iyengar via B4 Relay
2026-11-15  8:39 ` [PATCH v2 4/4] media: verisilicon: Set the bit depth again when its control is rewritten Arun Iyengar via B4 Relay

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®