* [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer
@ 2026-11-24 13:40 Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 1/3] media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame Sergei Khomenkov via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sergei Khomenkov via B4 Relay @ 2026-11-24 13:40 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable, Sergei Khomenkov
The H1 and VEPU2 JPEG encoders are given their stream buffer limit in
bytes, but the register counts 64-bit words, so a stream that does not
fit the CAPTURE buffer is written past its end, up to eight times the
buffer size. A quality 100 frame of noise does not fit the default
sizeimage, and userspace can also set a smaller one.
Patch 1 stops the encoder in the VEPU1 interrupt handler after a
buffer-full interrupt, which leaves it paused. Patch 2 programs the
limit in 64-bit words, rounded down to whole 64-byte bursts, on the H1
and on the VEPU2. Patch 3 makes the smallest CAPTURE sizeimage of the
JPEG encoders the 624-byte header plus one burst, set in the variant
format data.
Testing, on an RK3026 (its H1 is Rockchip's VEPU1) only: without the
series the encoder wrote 230 KB past a default-sized 640x480 buffer and
1.6 MB past a 1920x1088 one. With it, 17 overflowing frames, four of
them queued back to back, stopped at the programmed limit without
writing past the plane and came back with the ERROR flag, one interrupt
each and no timeout; the jobs after them completed, and frames that fit
are byte for byte the same as before. A sizeimage of 1 or 600 now reads
back 688. v4l2-compliance 1.30.1 on the encoder node shows no new
failures.
I cannot test the VEPU2 or the STM32MP25 VENC. The VEPU2 gets patches 2
and 3, but its interrupt handler is unchanged; Nicolas offered to test
the VEPU2 part of patch 2. The STM32MP25 VENC runs the H1 code of patch
2 and gets patch 3, but not the stop of patch 1.
The bugs were found and the patches drafted with an LLM coding
assistant while porting mainline Linux to an RK3026 board.
---
Changes in v3:
- Move the LLM and test notes below the --- line and add an
Assisted-by: tag (Nicolas).
- 1/3: add Nicolas's Reviewed-by.
- 2/3: program the VEPU2 JPEG encoder's limit in 64-bit words as well;
Nicolas offered to test it. Subject says "JPEG encoder", not "H1".
- 3/3: move the header + 64 floor out of hantro_try_fmt() into a new
min_size field of struct hantro_fmt, set in the JPEG encoder formats
of the Rockchip and STM32MP25 variants (Nicolas).
- Rebase on media next aa0f4c41d487.
- Link to v2: https://lore.kernel.org/all/20261110-hantro-buflimit-v2-0-ff7790def9fc@gmail.com/
Changes in v2:
- Trim the commit messages and code comments (Nicolas).
- 1/3: clear only the enable bit of H1_REG_ENC_CTRL instead of writing
0 to the register, and add a rate-limited warning per fault bit, as
hantro_g2_irq() does; add the H1_REG_INTERRUPT_* fault bits (Nicolas).
- 3/3: keep max(): it is a floor of header + one burst, the 64-byte
rounding is on the stream limit in 2/3 (Nicolas).
- Move the test numbers from the commit messages to this cover letter.
- Link to v1: https://lore.kernel.org/r/20261109-hantro-buflimit-v1-0-f0b86ce61e66@gmail.com
---
Sergei Khomenkov (3):
media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame
media: verisilicon: program the JPEG encoder stream limit in 64-bit words
media: verisilicon: leave room for the JPEG header and one stream burst
drivers/media/platform/verisilicon/hantro.h | 2 ++
.../media/platform/verisilicon/hantro_h1_jpeg_enc.c | 4 +++-
drivers/media/platform/verisilicon/hantro_h1_regs.h | 4 ++++
drivers/media/platform/verisilicon/hantro_v4l2.c | 3 +++
.../platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c | 4 +++-
drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 19 +++++++++++++++++++
drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c | 1 +
7 files changed, 35 insertions(+), 2 deletions(-)
---
base-commit: aa0f4c41d4870a18e65772a1817af16427200371
change-id: 20261106-hantro-buflimit-055e8029be23
Best regards,
--
Sergei Khomenkov <shomenkow@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/3] media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame
2026-11-24 13:40 [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Sergei Khomenkov via B4 Relay
@ 2026-11-24 13:40 ` Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 2/3] media: verisilicon: program the JPEG encoder stream limit in 64-bit words Sergei Khomenkov via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Sergei Khomenkov via B4 Relay @ 2026-11-24 13:40 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable, Sergei Khomenkov
From: Sergei Khomenkov <shomenkow@gmail.com>
When the JPEG stream reaches the stream buffer limit, the H1 raises a
buffer-full interrupt and pauses with the enable bit of H1_REG_ENC_CTRL
still set. rockchip_vpu1_vepu_irq() does not stop it, so the next job is
programmed into the paused encoder and times out.
Clear only the enable bit when an interrupt does not report a finished
frame, and warn (rate limited) about each fault bit that is set, as
hantro_g2_irq() does.
Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Cc: stable@vger.kernel.org
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sergei Khomenkov <shomenkow@gmail.com>
---
Found with an LLM coding assistant while porting mainline Linux to a
Rockchip RK3026 board; the assistant also drafted this change. Tested
on that board, with the next patch applied: a frame that does not fit
now ends with the ERROR flag and one interrupt, and the following jobs
complete. Not tested on other SoCs.
---
drivers/media/platform/verisilicon/hantro_h1_regs.h | 4 ++++
drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro_h1_regs.h b/drivers/media/platform/verisilicon/hantro_h1_regs.h
index 8650cc489392..a7f18683dac1 100644
--- a/drivers/media/platform/verisilicon/hantro_h1_regs.h
+++ b/drivers/media/platform/verisilicon/hantro_h1_regs.h
@@ -11,6 +11,10 @@
/* Encoder registers. */
#define H1_REG_INTERRUPT 0x004
+#define H1_REG_INTERRUPT_TIMEOUT BIT(6)
+#define H1_REG_INTERRUPT_BUFFER_FULL BIT(5)
+#define H1_REG_INTERRUPT_RESET BIT(4)
+#define H1_REG_INTERRUPT_BUS_ERROR BIT(3)
#define H1_REG_INTERRUPT_FRAME_RDY BIT(2)
#define H1_REG_INTERRUPT_DIS_BIT BIT(1)
#define H1_REG_INTERRUPT_BIT BIT(0)
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
index 02673be9878e..d201b058e5e8 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
@@ -376,6 +376,24 @@ static irqreturn_t rockchip_vpu1_vepu_irq(int irq, void *dev_id)
state = (status & H1_REG_INTERRUPT_FRAME_RDY) ?
VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+ if (status & H1_REG_INTERRUPT_BUFFER_FULL)
+ dev_warn_ratelimited(vpu->dev, "stream buffer full\n");
+ if (status & H1_REG_INTERRUPT_BUS_ERROR)
+ dev_warn_ratelimited(vpu->dev, "bus error detected\n");
+ if (status & H1_REG_INTERRUPT_TIMEOUT)
+ dev_warn_ratelimited(vpu->dev, "frame encode timed out\n");
+ if (status & H1_REG_INTERRUPT_RESET)
+ dev_warn_ratelimited(vpu->dev, "encoder reset\n");
+
+ /* After a buffer full the encoder pauses, still enabled: stop it. */
+ if (!(status & H1_REG_INTERRUPT_FRAME_RDY)) {
+ u32 ctrl = vepu_read(vpu, H1_REG_ENC_CTRL);
+
+ if (ctrl & H1_REG_ENC_CTRL_EN_BIT)
+ vepu_write(vpu, ctrl & ~H1_REG_ENC_CTRL_EN_BIT,
+ H1_REG_ENC_CTRL);
+ }
+
vepu_write(vpu, 0, H1_REG_INTERRUPT);
vepu_write(vpu, 0, H1_REG_AXI_CTRL);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/3] media: verisilicon: program the JPEG encoder stream limit in 64-bit words
2026-11-24 13:40 [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 1/3] media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame Sergei Khomenkov via B4 Relay
@ 2026-11-24 13:40 ` Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst Sergei Khomenkov via B4 Relay
2026-11-24 15:56 ` [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Nicolas Dufresne
3 siblings, 0 replies; 6+ messages in thread
From: Sergei Khomenkov via B4 Relay @ 2026-11-24 13:40 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable, Sergei Khomenkov
From: Sergei Khomenkov <shomenkow@gmail.com>
H1_REG_STR_BUF_LIMIT counts 64-bit words, but the driver writes the room
left in the CAPTURE plane in bytes. A stream that does not fit, such as
a quality 100 frame of noise in a default-sized buffer, is then written
past the end of the plane, up to eight times its size.
Write the limit in 64-bit words, rounded down to whole 64-byte bursts:
the encoder finishes a burst it has started, so an unrounded limit lets
it write up to 56 bytes past it. rockchip_vpu2_jpeg_enc_set_buffers()
has the same bug with VEPU_REG_STR_BUF_LIMIT, which
rockchip_vpu2_jpeg_enc_done() reads back as a bit count; give the VEPU2
the same limit.
Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sergei Khomenkov <shomenkow@gmail.com>
---
Found with an LLM coding assistant while porting mainline Linux to a
Rockchip RK3026 board; the assistant also drafted this change. Tested
on that board (its H1 is Rockchip's VEPU1): overflowing frames now
stop at the programmed limit without writing past the plane (a canary
after the plane stays intact), and frames that fit are byte for byte
the same as before. Not tested on other SoCs, including the STM32MP25,
which shares the H1 code. The VEPU2 change is not tested: there is no
VEPU2 on the RK3026.
Rockchip's MPP programs VEPU_REG_STR_BUF_LIMIT the same way ("limit >>=
3; limit &= ~7" in hal_h264e_vepu2_v2.c). Patch 1 stops the encoder
only in the VEPU1 interrupt handler; the VEPU2 and STM32MP25 handlers do
not: if those encoders pause on a full buffer as the RK3026 H1 does, the
next job may time out.
---
drivers/media/platform/verisilicon/hantro_h1_jpeg_enc.c | 4 +++-
drivers/media/platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_h1_jpeg_enc.c b/drivers/media/platform/verisilicon/hantro_h1_jpeg_enc.c
index 86cc1a07026f..cbf0e3d034f6 100644
--- a/drivers/media/platform/verisilicon/hantro_h1_jpeg_enc.c
+++ b/drivers/media/platform/verisilicon/hantro_h1_jpeg_enc.c
@@ -55,7 +55,9 @@ static void hantro_h1_jpeg_enc_set_buffers(struct hantro_dev *vpu,
vepu_write_relaxed(vpu, vb2_dma_contig_plane_dma_addr(dst_buf, 0) +
ctx->vpu_dst_fmt->header_size,
H1_REG_ADDR_OUTPUT_STREAM);
- vepu_write_relaxed(vpu, size_left, H1_REG_STR_BUF_LIMIT);
+ /* In 64-bit words; the encoder finishes a started 64-byte burst. */
+ vepu_write_relaxed(vpu, round_down(size_left, 64) / 8,
+ H1_REG_STR_BUF_LIMIT);
if (pix_fmt->num_planes == 1) {
src[0] = vb2_dma_contig_plane_dma_addr(src_buf, 0);
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c b/drivers/media/platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c
index 61621b1be8a2..ab976c762239 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c
@@ -82,7 +82,9 @@ static void rockchip_vpu2_jpeg_enc_set_buffers(struct hantro_dev *vpu,
vepu_write_relaxed(vpu, vb2_dma_contig_plane_dma_addr(dst_buf, 0) +
ctx->vpu_dst_fmt->header_size,
VEPU_REG_ADDR_OUTPUT_STREAM);
- vepu_write_relaxed(vpu, size_left, VEPU_REG_STR_BUF_LIMIT);
+ /* In 64-bit words, in whole 64-byte bursts as on the H1. */
+ vepu_write_relaxed(vpu, round_down(size_left, 64) / 8,
+ VEPU_REG_STR_BUF_LIMIT);
if (pix_fmt->num_planes == 1) {
src[0] = vb2_dma_contig_plane_dma_addr(src_buf, 0);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst
2026-11-24 13:40 [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 1/3] media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 2/3] media: verisilicon: program the JPEG encoder stream limit in 64-bit words Sergei Khomenkov via B4 Relay
@ 2026-11-24 13:40 ` Sergei Khomenkov via B4 Relay
2026-11-24 17:24 ` Nicolas Dufresne
2026-11-24 15:56 ` [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Nicolas Dufresne
3 siblings, 1 reply; 6+ messages in thread
From: Sergei Khomenkov via B4 Relay @ 2026-11-24 13:40 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable, Sergei Khomenkov
From: Sergei Khomenkov <shomenkow@gmail.com>
hantro_try_fmt() keeps any non-zero CAPTURE sizeimage of the JPEG
encoder, however small. The CPU writes the 624-byte header into the
plane, and on the RK3026 the H1 then writes at least one 64-byte burst
even with a stream limit of 0, so a smaller plane is written past its
end. A plane smaller than the header also makes the WARN_ON() in
hantro_h1_jpeg_enc_set_buffers() fire on every job.
Add a minimum plane size to struct hantro_fmt, set it to header_size +
64 in the JPEG encoder formats of the Rockchip and STM32MP25 variants,
and raise a smaller coded sizeimage to it in hantro_try_fmt().
Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sergei Khomenkov <shomenkow@gmail.com>
---
Found with an LLM coding assistant while porting mainline Linux to a
Rockchip RK3026 board; the assistant also drafted this change. Tested
on that board: a sizeimage of 1 or 600 now reads back 688, and frames
that do not fit a 688-byte plane stop exactly at its end. Not tested on
other SoCs.
---
drivers/media/platform/verisilicon/hantro.h | 2 ++
drivers/media/platform/verisilicon/hantro_v4l2.c | 3 +++
drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 1 +
drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c | 1 +
4 files changed, 7 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 0353de154a1e..f51beae79f1f 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -286,6 +286,7 @@ struct hantro_ctx {
* @codec_mode: Codec mode related to this format. See
* enum hantro_codec_mode.
* @header_size: Optional header size. Currently used by JPEG encoder.
+ * @min_size: Optional minimum sizeimage, for bitstream formats.
* @max_depth: Maximum depth, for bitstream formats
* @enc_fmt: Format identifier for encoder registers.
* @frmsize: Supported range of frame sizes (only for bitstream formats).
@@ -297,6 +298,7 @@ struct hantro_fmt {
u32 fourcc;
enum hantro_codec_mode codec_mode;
int header_size;
+ u32 min_size;
int max_depth;
enum hantro_enc_fmt enc_fmt;
struct v4l2_frmsize_stepwise frmsize;
diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index 83af9fa1ce94..b3dbc0629d25 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -394,6 +394,9 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
*/
pix_mp->plane_fmt[0].sizeimage = fmt->header_size +
pix_mp->width * pix_mp->height * fmt->max_depth;
+ } else {
+ pix_mp->plane_fmt[0].sizeimage =
+ max(pix_mp->plane_fmt[0].sizeimage, fmt->min_size);
}
return 0;
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
index d201b058e5e8..ab5abe2c78ad 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
@@ -50,6 +50,7 @@ static const struct hantro_fmt rockchip_vpu_enc_fmts[] = {
.codec_mode = HANTRO_MODE_JPEG_ENC,
.max_depth = 2,
.header_size = JPEG_HEADER_SIZE,
+ .min_size = JPEG_HEADER_SIZE + 64, /* header + one burst */
.frmsize = {
.min_width = 96,
.max_width = 8192,
diff --git a/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c b/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
index 833821120b20..3f337554e936 100644
--- a/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
+++ b/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
@@ -83,6 +83,7 @@ static const struct hantro_fmt stm32mp25_venc_fmts[] = {
.codec_mode = HANTRO_MODE_JPEG_ENC,
.max_depth = 2,
.header_size = JPEG_HEADER_SIZE,
+ .min_size = JPEG_HEADER_SIZE + 64, /* header + one burst */
.frmsize = {
.min_width = 96,
.max_width = FMT_4K_WIDTH,
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer
2026-11-24 13:40 [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Sergei Khomenkov via B4 Relay
` (2 preceding siblings ...)
2026-11-24 13:40 ` [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst Sergei Khomenkov via B4 Relay
@ 2026-11-24 15:56 ` Nicolas Dufresne
3 siblings, 0 replies; 6+ messages in thread
From: Nicolas Dufresne @ 2026-11-24 15:56 UTC (permalink / raw)
To: shomenkow, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable
[-- Attachment #1: Type: text/plain, Size: 4382 bytes --]
Le mardi 24 novembre 2026 à 16:40 +0300, Sergei Khomenkov via B4 Relay a écrit :
> The H1 and VEPU2 JPEG encoders are given their stream buffer limit in
> bytes, but the register counts 64-bit words, so a stream that does not
> fit the CAPTURE buffer is written past its end, up to eight times the
> buffer size. A quality 100 frame of noise does not fit the default
> sizeimage, and userspace can also set a smaller one.
>
> Patch 1 stops the encoder in the VEPU1 interrupt handler after a
> buffer-full interrupt, which leaves it paused. Patch 2 programs the
> limit in 64-bit words, rounded down to whole 64-byte bursts, on the H1
> and on the VEPU2. Patch 3 makes the smallest CAPTURE sizeimage of the
> JPEG encoders the 624-byte header plus one burst, set in the variant
> format data.
>
> Testing, on an RK3026 (its H1 is Rockchip's VEPU1) only: without the
> series the encoder wrote 230 KB past a default-sized 640x480 buffer and
> 1.6 MB past a 1920x1088 one. With it, 17 overflowing frames, four of
> them queued back to back, stopped at the programmed limit without
> writing past the plane and came back with the ERROR flag, one interrupt
> each and no timeout; the jobs after them completed, and frames that fit
> are byte for byte the same as before. A sizeimage of 1 or 600 now reads
> back 688. v4l2-compliance 1.30.1 on the encoder node shows no new
> failures.
>
> I cannot test the VEPU2 or the STM32MP25 VENC. The VEPU2 gets patches 2
> and 3, but its interrupt handler is unchanged; Nicolas offered to test
> the VEPU2 part of patch 2. The STM32MP25 VENC runs the H1 code of patch
> 2 and gets patch 3, but not the stop of patch 1.
>
> The bugs were found and the patches drafted with an LLM coding
> assistant while porting mainline Linux to an RK3026 board.
>
> ---
> Changes in v3:
> - Move the LLM and test notes below the --- line and add an
> Assisted-by: tag (Nicolas).
I've just learned today that we just don't do tagging anymore for this. So
**if** you have to make a new version later on, just remove them.
commit 1e035297ffdadf2184c3c773b8c098e372324aaf
Author: Sasha Levin <sashal@kernel.org>
Date: Tue Oct 13 08:15:01 2026 -0400
docs: remove Assisted-by references
> - 1/3: add Nicolas's Reviewed-by.
> - 2/3: program the VEPU2 JPEG encoder's limit in 64-bit words as well;
> Nicolas offered to test it. Subject says "JPEG encoder", not "H1".
Yep, thanks, I'll do.
> - 3/3: move the header + 64 floor out of hantro_try_fmt() into a new
> min_size field of struct hantro_fmt, set in the JPEG encoder formats
> of the Rockchip and STM32MP25 variants (Nicolas).
> - Rebase on media next aa0f4c41d487.
> - Link to v2: https://lore.kernel.org/all/20261110-hantro-buflimit-v2-0-ff7790def9fc@gmail.com/
>
> Changes in v2:
> - Trim the commit messages and code comments (Nicolas).
> - 1/3: clear only the enable bit of H1_REG_ENC_CTRL instead of writing
> 0 to the register, and add a rate-limited warning per fault bit, as
> hantro_g2_irq() does; add the H1_REG_INTERRUPT_* fault bits (Nicolas).
> - 3/3: keep max(): it is a floor of header + one burst, the 64-byte
> rounding is on the stream limit in 2/3 (Nicolas).
> - Move the test numbers from the commit messages to this cover letter.
> - Link to v1: https://lore.kernel.org/r/20261109-hantro-buflimit-v1-0-f0b86ce61e66@gmail.com
>
> ---
> Sergei Khomenkov (3):
> media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame
> media: verisilicon: program the JPEG encoder stream limit in 64-bit words
> media: verisilicon: leave room for the JPEG header and one stream burst
>
> drivers/media/platform/verisilicon/hantro.h | 2 ++
> .../media/platform/verisilicon/hantro_h1_jpeg_enc.c | 4 +++-
> drivers/media/platform/verisilicon/hantro_h1_regs.h | 4 ++++
> drivers/media/platform/verisilicon/hantro_v4l2.c | 3 +++
> .../platform/verisilicon/rockchip_vpu2_hw_jpeg_enc.c | 4 +++-
> drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 19 +++++++++++++++++++
> drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c | 1 +
> 7 files changed, 35 insertions(+), 2 deletions(-)
> ---
> base-commit: aa0f4c41d4870a18e65772a1817af16427200371
> change-id: 20261106-hantro-buflimit-055e8029be23
>
> Best regards,
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst
2026-11-24 13:40 ` [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst Sergei Khomenkov via B4 Relay
@ 2026-11-24 17:24 ` Nicolas Dufresne
0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Dufresne @ 2026-11-24 17:24 UTC (permalink / raw)
To: shomenkow, Benjamin Gaignard, Philipp Zabel
Cc: Mauro Carvalho Chehab, Hans Verkuil, Heiko Stuebner,
Ezequiel Garcia, Chen-Yu Tsai, Hugues Fruchet, Maxime Coquelin,
Alexandre Torgue, linux-media, linux-rockchip, linux-arm-kernel,
linux-stm32, linux-kernel, stable
[-- Attachment #1: Type: text/plain, Size: 4488 bytes --]
Le mardi 24 novembre 2026 à 16:40 +0300, Sergei Khomenkov via B4 Relay a écrit :
> From: Sergei Khomenkov <shomenkow@gmail.com>
>
> hantro_try_fmt() keeps any non-zero CAPTURE sizeimage of the JPEG
> encoder, however small. The CPU writes the 624-byte header into the
> plane, and on the RK3026 the H1 then writes at least one 64-byte burst
> even with a stream limit of 0, so a smaller plane is written past its
> end. A plane smaller than the header also makes the WARN_ON() in
> hantro_h1_jpeg_enc_set_buffers() fire on every job.
>
> Add a minimum plane size to struct hantro_fmt, set it to header_size +
> 64 in the JPEG encoder formats of the Rockchip and STM32MP25 variants,
> and raise a smaller coded sizeimage to it in hantro_try_fmt().
>
> Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5-5
Drop if v4 needed.
> Signed-off-by: Sergei Khomenkov <shomenkow@gmail.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> ---
> Found with an LLM coding assistant while porting mainline Linux to a
> Rockchip RK3026 board; the assistant also drafted this change. Tested
> on that board: a sizeimage of 1 or 600 now reads back 688, and frames
> that do not fit a 688-byte plane stop exactly at its end. Not tested on
> other SoCs.
> ---
> drivers/media/platform/verisilicon/hantro.h | 2 ++
> drivers/media/platform/verisilicon/hantro_v4l2.c | 3 +++
> drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 1 +
> drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c | 1 +
> 4 files changed, 7 insertions(+)
>
> diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
> index 0353de154a1e..f51beae79f1f 100644
> --- a/drivers/media/platform/verisilicon/hantro.h
> +++ b/drivers/media/platform/verisilicon/hantro.h
> @@ -286,6 +286,7 @@ struct hantro_ctx {
> * @codec_mode: Codec mode related to this format. See
> * enum hantro_codec_mode.
> * @header_size: Optional header size. Currently used by JPEG encoder.
> + * @min_size: Optional minimum sizeimage, for bitstream formats.
> * @max_depth: Maximum depth, for bitstream formats
> * @enc_fmt: Format identifier for encoder registers.
> * @frmsize: Supported range of frame sizes (only for bitstream formats).
> @@ -297,6 +298,7 @@ struct hantro_fmt {
> u32 fourcc;
> enum hantro_codec_mode codec_mode;
> int header_size;
> + u32 min_size;
> int max_depth;
> enum hantro_enc_fmt enc_fmt;
> struct v4l2_frmsize_stepwise frmsize;
> diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
> index 83af9fa1ce94..b3dbc0629d25 100644
> --- a/drivers/media/platform/verisilicon/hantro_v4l2.c
> +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
> @@ -394,6 +394,9 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
> */
> pix_mp->plane_fmt[0].sizeimage = fmt->header_size +
> pix_mp->width * pix_mp->height * fmt->max_depth;
> + } else {
> + pix_mp->plane_fmt[0].sizeimage =
> + max(pix_mp->plane_fmt[0].sizeimage, fmt->min_size);
> }
>
> return 0;
> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> index d201b058e5e8..ab5abe2c78ad 100644
> --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> @@ -50,6 +50,7 @@ static const struct hantro_fmt rockchip_vpu_enc_fmts[] = {
> .codec_mode = HANTRO_MODE_JPEG_ENC,
> .max_depth = 2,
> .header_size = JPEG_HEADER_SIZE,
> + .min_size = JPEG_HEADER_SIZE + 64, /* header + one burst */
> .frmsize = {
> .min_width = 96,
> .max_width = 8192,
> diff --git a/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c b/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
> index 833821120b20..3f337554e936 100644
> --- a/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
> +++ b/drivers/media/platform/verisilicon/stm32mp25_vpu_hw.c
> @@ -83,6 +83,7 @@ static const struct hantro_fmt stm32mp25_venc_fmts[] = {
> .codec_mode = HANTRO_MODE_JPEG_ENC,
> .max_depth = 2,
> .header_size = JPEG_HEADER_SIZE,
> + .min_size = JPEG_HEADER_SIZE + 64, /* header + one burst */
> .frmsize = {
> .min_width = 96,
> .max_width = FMT_4K_WIDTH,
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-24 17:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 13:40 [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 1/3] media: verisilicon: stop the VEPU1 JPEG encoder after an unfinished frame Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 2/3] media: verisilicon: program the JPEG encoder stream limit in 64-bit words Sergei Khomenkov via B4 Relay
2026-11-24 13:40 ` [PATCH v3 3/3] media: verisilicon: leave room for the JPEG header and one stream burst Sergei Khomenkov via B4 Relay
2026-11-24 17:24 ` Nicolas Dufresne
2026-11-24 15:56 ` [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Nicolas Dufresne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox