From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795527627; b=5OSfL2pCRL1gaDnZQ52zmXQjwrbZpB7UMNzfA3oCuqJdz6tZaiBzYeKz4faFCSPlo1s9 kPL4R2QwUYIydy8MMqksdByUxGmZNtdJBsc5H5oIwk9z/3WEAdSK/FMO/tKWgRsuZI0mT afsClkw25Nfb0M7t/TR2mahceByXOLjIfLWBx+gSKJBvHhToHgIhz4ZvsnSlfo9zy2nld 0UyZdv0cV3NPkWXMsndrjHGsm/MWiSlL8+bBwG8ijIUxKOrYOoWNR9yIzYEIx+QqZt8gu J+Jy4SQesVLKsR2bBOgmFchjcT7YQWu2IwktuNH2//l9XUtz4t95wJhYQLo/WAlbHxw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795527627; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=JhX6GJToIPCSWTgKM33kXD6qd9kkvSZE3MFHQwmpZfQ=; b=YlFYXPIV1DiWDlYbFIWwI74tLNiSnIkuO8hHXBWfDUxWOyaeXo17IdpTv6Iou2pi6UFf XozEcGzUoMh/eWxnbJELkdQoqVmTaLWM3FEKvkTS96EuzOd8KuTC7M3iZDbP8is+UmIpb Bbm5LDVjauIliMSUSF/igt7Rp6XlYt4YaLzIEzDgCpiNNFahJAQAmPpIHX/lu1eVIFmbO 5uuSJ4uFhZQSk/IF697C49HCkQdxfym7aqsrV6p7Y5EYQbN6iofX+DH3G5HKiISdyKOis O+676+uYl6u8/8IaC7eKg802LEB2Ey2sikr1UjKIUD0E049Kt1Js05tbmRn9j57pxww== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lRSOelAP; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23ECD606A31E; Tue, 24 Nov 2026 13:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lRSOelAP Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795527626; b=IKwLydFBd7+Kj9nc6xiATlMRJrZCdG01xvBYZCV4eFlxGCJ8Uj4A1NORVTrzfE8NBVE6 6f12hBXGX82pTRAmDx89ZNy/dT1PwXZcIzTVq6kdrKjxBijwbPuOccrtzt4D+5jj67K4l ed2pkDTaAIS+XG+YoRERXa89HvBKqK/Njuiz4TLYLZgr9BhBgRkC7R1+AZe0a71pwMrjr yCrUaaIWvvRJ7k6dfnPsiTBmeVAW2GtGnc2cr/SxYEgyZwqk9mtLYGAs12giQzzZbusrj SCYCvFoCM0jpGBfGnsIUoDMdxhi83n/ebSJFZNqBXhy2vT9WUCeB+9TZC9I+nQFVayg== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795527626; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=JhX6GJToIPCSWTgKM33kXD6qd9kkvSZE3MFHQwmpZfQ=; b=Ghu9iPaA7s7D5t2xbwuTpiXrH2Fqu1VGyTV5sgzAAH+DXHD+Ht+xc/Emi0OkXQyjB8to q3eTcRJIp2eYvLEhLcmhI32GqjzL55fg3SpnR3y1lDiM4m3lf3FG5n0wuLivQmVejtmqP foDfA3e0jsHClAjJuOi8hIhMAnhoeS4hrgXrfXEvR1ZdBhd+cTQtoPhRzN2TbJoS9aPCh kcocjavUZwvldnAHlDJK0xyC/bI+WmtG+XTb10ThIrfxjjT5Z7UcRP3oclYKNnKOInoR4 iFWx6H+tsqE/E0r/0NU4qD7rfrqO6KtS9YhHiXynz8a78eXKOir+xF96ZMC8o+r1SUw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id A76581F000C0; Tue, 24 Nov 2026 13:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795527626; bh=JhX6GJToIPCSWTgKM33kXD6qd9kkvSZE3MFHQwmpZfQ=; h=From:Subject:Date:To:Cc:Reply-To; b=lRSOelAPN1fpJMrE92QGIFiQwGPIaaPyds/gGKQYpQhUqKatfXGEcPXwrlnMURK5M 8cuy89KILRT9cUvgPHMTux8oRcgPmaKoPbhLAaz8w4M8MIyAeGc8c9ta13DBy7P85X l0gQtBAKxAnKkgO9n0tKKqsfy4aacLPQT2ZO4VMCKz8ABK4QOAySCiDqWLcmvAbKla UayrDaxVvpcgtj6IHE4vtyY2PuwZpSysXv0Y8UEnF7dx5ELk/gk0zHOTiiY6Zcctl/ hcUEUugtHzIx76OLM267L+mSFoqtD1kDHBethUjWaHYymuZ+BDCdT8iWeqhqKB/b+1 noGPwSFcLlo4Q== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 3861A4CA5B; Tue, 24 Nov 2026 13:40:21 +0000 (UTC) From: Sergei Khomenkov via B4 Relay Subject: [PATCH v3 0/3] media: verisilicon: fix JPEG encoder writes past the CAPTURE buffer Date: Tue, 24 Nov 2026 16:40:16 +0300 Message-Id: <20261124-hantro-buflimit-v3-0-780903970ca0@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/2WNwQqDMBAFf0VybsomYjQ99T9KDxo3uqCmJDa0i P/eKBQEj/Ng5i0soCcM7JYtzGOkQG5KkF8yZvp66pBTm5hJkEoIUDyNs3e8eduBRpo5FAVWIHW DMmfJenm09NmLj2finsLs/Hc/iGJb/y19akXBgVtoKmVQCVTq3o01DVfjRra1ojz4As6+3Hxbl hpatNqao7+u6w/R2YDI7gAAAA== X-Change-ID: 20261106-hantro-buflimit-055e8029be23 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@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Sergei Khomenkov X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795527620; l=3845; i=shomenkow@gmail.com; s=20261104; h=from:subject:message-id; bh=CS9Hh2KOnLAmmovBFtvM/OChuActMNOyzEIbmU8KbTc=; b=y17AVohcoo/KohpGkVwr+Ely6dXWd6I4yYSnnuzNlvSkAMEJvfHGiBx1esxZ7X04A3R7vSKwQ 3i8ptxwqT4MAbW5cmI5aHdACqvfkRQ5iPFh1yaZPPIAp6l2S+5UkOJs X-Developer-Key: i=shomenkow@gmail.com; a=ed25519; pk=FwuHDVe7aiISDMLmQEcMC+RflEIJ6kEp/ekwznWXmI8= X-Endpoint-Received: by B4 Relay for shomenkow@gmail.com/20261104 with auth_id=1409 X-Original-From: Sergei Khomenkov Reply-To: shomenkow@gmail.com 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