* [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup
@ 2026-12-01 15:26 Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:26 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
Cedrus sets up each slice with its bit reader in device_run(), with
req_queue_mutex held when called from the request queue ioctl:
- patch 1: the H.264 bit skip can wait forever, hanging every close();
- patches 2-3: userspace bit offsets past the slice can lock up the SoC;
- patches 4-5: H.265 and VP8 ignore bit reader timeouts. Patch 4 is
Dmitry Osipenko's 2022 v1 [1], rebased.
Tested on an Orange Pi Zero 2 (H616), 7.3 based kernel, with the bit
reader stalled by holding the VE's IOMMU masters in reset. Before: the
H.264 skip spun until a VE reset, H.265 offsets past the slice locked
up the board in 2 of 3 tries, VP8 decoded until the watchdog. After:
-EINVAL or one -ETIMEDOUT within 30 ms, no lockup in 9 tries, and 42
conformance decodes run afterwards match the control. On this base:
build only.
Developed with Claude (Anthropic) as a coding assistant; I reviewed and
tested it.
[1] https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@collabora.com/
---
Arun Iyengar (5):
media: staging: cedrus: h264: bound the wait for the bit skip
media: staging: cedrus: h264: reject a slice header larger than the slice
media: staging: cedrus: h265: reject a slice data offset past the slice
media: staging: cedrus: h265: fail the job when the bit reader times out
media: staging: cedrus: vp8: fail the job on a bit reader timeout
drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 31 +++--
drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 40 ++++--
drivers/staging/media/sunxi/cedrus/cedrus_vp8.c | 159 +++++++++++++----------
3 files changed, 143 insertions(+), 87 deletions(-)
---
base-commit: 95c189b26efb07257888ccf9d873a5c366aafbc6
change-id: 20261128-b4-cedrus-bitreader-49a8ddfb794e
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
@ 2026-12-01 15:26 ` Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice Arun Iyengar via B4 Relay
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:26 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
cedrus_skip_bits() polls the VLD busy bit without a limit. If the
bitstream engine does not go idle, device_run() spins forever with
req_queue_mutex held. Use cedrus_wait_for() as the H.265 code does and
fail the job on a timeout.
Fixes: 61ad123318c2 ("media: cedrus: Fix decoding for some H264 videos")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 28 +++++++++++++++---------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
index e7a3bfbc3531..c683f1261da7 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
@@ -6,7 +6,6 @@
* Copyright (c) 2018 Bootlin
*/
-#include <linux/delay.h>
#include <linux/types.h>
#include <media/videobuf2-dma-contig.h>
@@ -346,7 +345,7 @@ static void cedrus_write_pred_weight_table(struct cedrus_ctx *ctx,
* rare cases frame is not decoded correctly. However, setting offset to 0 and
* skipping appropriate amount of bits with flush bits trigger always works.
*/
-static void cedrus_skip_bits(struct cedrus_dev *dev, int num)
+static int cedrus_skip_bits(struct cedrus_dev *dev, int num)
{
int count = 0;
@@ -356,15 +355,21 @@ static void cedrus_skip_bits(struct cedrus_dev *dev, int num)
cedrus_write(dev, VE_H264_TRIGGER_TYPE,
VE_H264_TRIGGER_TYPE_FLUSH_BITS |
VE_H264_TRIGGER_TYPE_N_BITS(tmp));
- while (cedrus_read(dev, VE_H264_STATUS) & VE_H264_STATUS_VLD_BUSY)
- udelay(1);
+ if (cedrus_wait_for(dev, VE_H264_STATUS,
+ VE_H264_STATUS_VLD_BUSY)) {
+ dev_err_ratelimited(dev->dev,
+ "timed out waiting to skip bits\n");
+ return -ETIMEDOUT;
+ }
count += tmp;
}
+
+ return 0;
}
-static void cedrus_set_params(struct cedrus_ctx *ctx,
- struct cedrus_run *run)
+static int cedrus_set_params(struct cedrus_ctx *ctx,
+ struct cedrus_run *run)
{
const struct v4l2_ctrl_h264_decode_params *decode = run->h264.decode_params;
const struct v4l2_ctrl_h264_slice_params *slice = run->h264.slice_params;
@@ -377,6 +382,7 @@ static void cedrus_set_params(struct cedrus_ctx *ctx,
unsigned int pic_width_in_mbs;
bool mbaff_pic;
u32 reg;
+ int ret;
cedrus_write(dev, VE_H264_VLD_LEN, slice_bytes * 8);
cedrus_write(dev, VE_H264_VLD_OFFSET, 0);
@@ -411,7 +417,9 @@ static void cedrus_set_params(struct cedrus_ctx *ctx,
cedrus_write(dev, VE_H264_TRIGGER_TYPE,
VE_H264_TRIGGER_TYPE_INIT_SWDEC);
- cedrus_skip_bits(dev, slice->header_bit_size);
+ ret = cedrus_skip_bits(dev, slice->header_bit_size);
+ if (ret)
+ return ret;
if (V4L2_H264_CTRL_PRED_WEIGHTS_REQUIRED(pps, slice))
cedrus_write_pred_weight_table(ctx, run);
@@ -503,6 +511,8 @@ static void cedrus_set_params(struct cedrus_ctx *ctx,
VE_H264_CTRL_SLICE_DECODE_INT |
VE_H264_CTRL_DECODE_ERR_INT |
VE_H264_CTRL_VLD_DATA_REQ_INT);
+
+ return 0;
}
static enum cedrus_irq_status
@@ -562,9 +572,7 @@ static int cedrus_h264_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
if (ret)
return ret;
- cedrus_set_params(ctx, run);
-
- return 0;
+ return cedrus_set_params(ctx, run);
}
static int cedrus_h264_start(struct cedrus_ctx *ctx)
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
@ 2026-12-01 15:26 ` Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past " Arun Iyengar via B4 Relay
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:26 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
header_bit_size comes from userspace and is not checked; skipping up to
2^31 bits takes seconds. Fail the job when it is larger than the slice.
Fixes: 61ad123318c2 ("media: cedrus: Fix decoding for some H264 videos")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
index c683f1261da7..5ff13fea9f55 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
@@ -384,6 +384,9 @@ static int cedrus_set_params(struct cedrus_ctx *ctx,
u32 reg;
int ret;
+ if (slice->header_bit_size > slice_bytes * 8)
+ return -EINVAL;
+
cedrus_write(dev, VE_H264_VLD_LEN, slice_bytes * 8);
cedrus_write(dev, VE_H264_VLD_OFFSET, 0);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past the slice
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice Arun Iyengar via B4 Relay
@ 2026-12-01 15:26 ` Arun Iyengar via B4 Relay
2026-12-01 15:27 ` [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out Arun Iyengar via B4 Relay
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:26 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
data_byte_offset comes from userspace and is only checked against 0; an
offset past the slice locked up the SoC. Fail the job in that case.
Fixes: 7678c5462680 ("media: cedrus: Fix decoding for some HEVC videos")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
index f10178106ba6..44539936b550 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
@@ -457,6 +457,9 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
num_entry_point_offsets != run->h265.entry_points_count)
return -ERANGE;
+ if (slice_params->data_byte_offset > slice_bytes)
+ return -EINVAL;
+
log2_max_luma_coding_block_size =
sps->log2_min_luma_coding_block_size_minus3 + 3 +
sps->log2_diff_max_min_luma_coding_block_size;
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
` (2 preceding siblings ...)
2026-12-01 15:26 ` [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past " Arun Iyengar via B4 Relay
@ 2026-12-01 15:27 ` Arun Iyengar via B4 Relay
2026-12-01 15:27 ` [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout Arun Iyengar via B4 Relay
2026-12-01 16:07 ` [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Jernej Škrabec
5 siblings, 0 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:27 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
From Dmitry Osipenko's v1 [1], as Jernej asked [2].
cedrus_h265_skip_bits() logs a timeout and goes on, and
cedrus_h265_show_bits() ignores it, so the slice is set up from a wrong
position. Return -ETIMEDOUT from both and fail the job.
Fixes: 91db7a3fc7fe ("media: cedrus: Fix endless loop in cedrus_h265_skip_bits()")
Fixes: e9120e76a6f7 ("media: cedrus: hevc: Fix offset adjustments")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@collabora.com/ [1]
Link: https://lore.kernel.org/all/1733932.VLH7GnMWUR@kista/ [2]
Suggested-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Co-developed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 37 ++++++++++++++++++------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
index 44539936b550..a00d7bc705c3 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
@@ -237,7 +237,7 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev,
}
}
-static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
+static int cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
{
int count = 0;
@@ -248,23 +248,32 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
VE_DEC_H265_TRIGGER_FLUSH_BITS |
VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp));
- if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY))
+ if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) {
dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n");
+ return -ETIMEDOUT;
+ }
count += tmp;
}
+
+ return 0;
}
-static u32 cedrus_h265_show_bits(struct cedrus_dev *dev, int num)
+static int cedrus_h265_show_bits(struct cedrus_dev *dev, int num, u32 *val)
{
cedrus_write(dev, VE_DEC_H265_TRIGGER,
VE_DEC_H265_TRIGGER_SHOW_BITS |
VE_DEC_H265_TRIGGER_TYPE_N_BITS(num));
- cedrus_wait_for(dev, VE_DEC_H265_STATUS,
- VE_DEC_H265_STATUS_VLD_BUSY);
+ if (cedrus_wait_for(dev, VE_DEC_H265_STATUS,
+ VE_DEC_H265_STATUS_VLD_BUSY)) {
+ dev_err_ratelimited(dev->dev, "timed out waiting to show bits\n");
+ return -ETIMEDOUT;
+ }
- return cedrus_read(dev, VE_DEC_H265_BITS_READ);
+ *val = cedrus_read(dev, VE_DEC_H265_BITS_READ);
+
+ return 0;
}
static void cedrus_h265_write_scaling_list(struct cedrus_ctx *ctx,
@@ -433,8 +442,10 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
u32 pic_order_cnt[2];
size_t slice_bytes;
u8 padding;
+ u32 bits;
int count;
u32 reg;
+ int ret;
sps = run->h265.sps;
pps = run->h265.pps;
@@ -546,9 +557,15 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
if (slice_params->data_byte_offset == 0)
return -EOPNOTSUPP;
- cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8);
+ ret = cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8);
+ if (ret)
+ return ret;
+
+ ret = cedrus_h265_show_bits(dev, 8, &bits);
+ if (ret)
+ return ret;
- padding = cedrus_h265_show_bits(dev, 8);
+ padding = bits;
/* at least one bit must be set in that byte */
if (padding == 0)
@@ -561,7 +578,9 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
/* Include the one bit. */
count++;
- cedrus_h265_skip_bits(dev, 8 - count);
+ ret = cedrus_h265_skip_bits(dev, 8 - count);
+ if (ret)
+ return ret;
/* Bitstream parameters. */
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
` (3 preceding siblings ...)
2026-12-01 15:27 ` [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out Arun Iyengar via B4 Relay
@ 2026-12-01 15:27 ` Arun Iyengar via B4 Relay
2026-12-01 16:07 ` [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Jernej Škrabec
5 siblings, 0 replies; 7+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:27 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Hans Verkuil
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
The VP8 header parser ignores bit reader timeouts and decodes the frame
from a wrong position. Stop reading after the first timeout and fail
the job.
Fixes: 3c39a16d30d8 ("media: cedrus: Add support for VP8 decoding")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_vp8.c | 159 ++++++++++++++----------
1 file changed, 91 insertions(+), 68 deletions(-)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
index bb32232d37ff..b5ae9a2f9d96 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
@@ -433,87 +433,101 @@ static const u8 k_mv_entropy_update_probs[2][V4L2_VP8_MV_PROB_CNT] = {
254, 254, 254, 254, 254, 251, 251, 254, 254, 254 }
};
-static uint8_t read_bits(struct cedrus_dev *dev, unsigned int bits_count,
+struct cedrus_vp8_bits {
+ struct cedrus_dev *dev;
+ int error;
+};
+
+static uint8_t read_bits(struct cedrus_vp8_bits *b, unsigned int bits_count,
unsigned int probability)
{
+ struct cedrus_dev *dev = b->dev;
+
+ if (b->error)
+ return 0;
+
cedrus_write(dev, VE_H264_TRIGGER_TYPE,
VE_H264_TRIGGER_TYPE_VP8_GET_BITS |
VE_H264_TRIGGER_TYPE_BIN_LENS(bits_count) |
VE_H264_TRIGGER_TYPE_PROBABILITY(probability));
- cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VLD_BUSY);
+ if (cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VLD_BUSY)) {
+ dev_err_ratelimited(dev->dev, "timed out waiting to read bits\n");
+ b->error = -ETIMEDOUT;
+ return 0;
+ }
return cedrus_read(dev, VE_H264_BASIC_BITS);
}
-static void get_delta_q(struct cedrus_dev *dev)
+static void get_delta_q(struct cedrus_vp8_bits *b)
{
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 4, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 4, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
-static void process_segmentation_info(struct cedrus_dev *dev)
+static void process_segmentation_info(struct cedrus_vp8_bits *b)
{
int update, i;
- update = read_bits(dev, 1, VP8_PROB_HALF);
+ update = read_bits(b, 1, VP8_PROB_HALF);
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 1, VP8_PROB_HALF);
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 7, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 7, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
if (update)
for (i = 0; i < 3; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF))
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF))
+ read_bits(b, 8, VP8_PROB_HALF);
}
-static void process_ref_lf_delta_info(struct cedrus_dev *dev)
+static void process_ref_lf_delta_info(struct cedrus_vp8_bits *b)
{
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
int i;
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
}
-static void process_ref_frame_info(struct cedrus_dev *dev)
+static void process_ref_frame_info(struct cedrus_vp8_bits *b)
{
- u8 refresh_golden_frame = read_bits(dev, 1, VP8_PROB_HALF);
- u8 refresh_alt_ref_frame = read_bits(dev, 1, VP8_PROB_HALF);
+ u8 refresh_golden_frame = read_bits(b, 1, VP8_PROB_HALF);
+ u8 refresh_alt_ref_frame = read_bits(b, 1, VP8_PROB_HALF);
if (!refresh_golden_frame)
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(b, 2, VP8_PROB_HALF);
if (!refresh_alt_ref_frame)
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(b, 2, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
static void cedrus_irq_clear(struct cedrus_dev *dev)
@@ -522,73 +536,79 @@ static void cedrus_irq_clear(struct cedrus_dev *dev)
VE_H264_STATUS_INT_MASK);
}
-static void cedrus_read_header(struct cedrus_dev *dev,
- const struct v4l2_ctrl_vp8_frame *slice)
+static int cedrus_read_header(struct cedrus_dev *dev,
+ const struct v4l2_ctrl_vp8_frame *slice)
{
+ struct cedrus_vp8_bits b = { .dev = dev };
int i, j;
if (V4L2_VP8_FRAME_IS_KEY_FRAME(slice)) {
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
}
- if (read_bits(dev, 1, VP8_PROB_HALF))
- process_segmentation_info(dev);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ process_segmentation_info(&b);
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 3, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+ read_bits(&b, 6, VP8_PROB_HALF);
+ read_bits(&b, 3, VP8_PROB_HALF);
- if (read_bits(dev, 1, VP8_PROB_HALF))
- process_ref_lf_delta_info(dev);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ process_ref_lf_delta_info(&b);
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(&b, 2, VP8_PROB_HALF);
/* y_ac_qi */
- read_bits(dev, 7, VP8_PROB_HALF);
+ read_bits(&b, 7, VP8_PROB_HALF);
/* Parses y_dc_delta, y2_dc_delta, etc. */
for (i = 0; i < QUANT_DELTA_COUNT; i++)
- get_delta_q(dev);
+ get_delta_q(&b);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice))
- process_ref_frame_info(dev);
+ process_ref_frame_info(&b);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice))
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+
+ if (b.error)
+ return b.error;
cedrus_write(dev, VE_H264_TRIGGER_TYPE, VE_H264_TRIGGER_TYPE_VP8_UPDATE_COEF);
cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VP8_UPPROB_BUSY);
cedrus_irq_clear(dev);
- if (read_bits(dev, 1, VP8_PROB_HALF))
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ read_bits(&b, 8, VP8_PROB_HALF);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
-
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+
+ if (read_bits(&b, 1, VP8_PROB_HALF)) {
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
}
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(&b, 1, VP8_PROB_HALF)) {
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
}
for (i = 0; i < 2; i++)
for (j = 0; j < V4L2_VP8_MV_PROB_CNT; j++)
- if (read_bits(dev, 1, k_mv_entropy_update_probs[i][j]))
- read_bits(dev, 7, VP8_PROB_HALF);
+ if (read_bits(&b, 1, k_mv_entropy_update_probs[i][j]))
+ read_bits(&b, 7, VP8_PROB_HALF);
}
+
+ return b.error;
}
static void cedrus_vp8_update_probs(const struct v4l2_ctrl_vp8_frame *slice,
@@ -659,6 +679,7 @@ static int cedrus_vp8_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
struct cedrus_dev *dev = ctx->dev;
dma_addr_t luma_addr, chroma_addr;
dma_addr_t src_buf_addr;
+ int ret;
int header_size;
u32 reg;
@@ -766,7 +787,9 @@ static int cedrus_vp8_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
reg |= VE_VP8_PPS_PIC_TYPE_P_FRAME;
cedrus_write(dev, VE_VP8_PPS, reg);
- cedrus_read_header(dev, slice);
+ ret = cedrus_read_header(dev, slice);
+ if (ret)
+ return ret;
/* reset registers changed by HW */
cedrus_write(dev, VE_H264_CUR_MB_NUM, 0);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
` (4 preceding siblings ...)
2026-12-01 15:27 ` [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout Arun Iyengar via B4 Relay
@ 2026-12-01 16:07 ` Jernej Škrabec
5 siblings, 0 replies; 7+ messages in thread
From: Jernej Škrabec @ 2026-12-01 16:07 UTC (permalink / raw)
To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
Greg Kroah-Hartman, Chen-Yu Tsai, Samuel Holland, Hans Verkuil,
aiyengar1990
Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
linux-kernel, Emmanuel Gil Peyrot, Ezequiel Garcia,
Dmitry Osipenko, Nicolas Dufresne, stable, Arun Iyengar
Dne torek, 1. december 2026 ob 16:26:56 Srednjeevropski standardni čas je Arun Iyengar via B4 Relay napisal(a):
> Cedrus sets up each slice with its bit reader in device_run(), with
> req_queue_mutex held when called from the request queue ioctl:
>
> - patch 1: the H.264 bit skip can wait forever, hanging every close();
> - patches 2-3: userspace bit offsets past the slice can lock up the SoC;
> - patches 4-5: H.265 and VP8 ignore bit reader timeouts. Patch 4 is
> Dmitry Osipenko's 2022 v1 [1], rebased.
>
> Tested on an Orange Pi Zero 2 (H616), 7.3 based kernel, with the bit
> reader stalled by holding the VE's IOMMU masters in reset. Before: the
> H.264 skip spun until a VE reset, H.265 offsets past the slice locked
> up the board in 2 of 3 tries, VP8 decoded until the watchdog. After:
> -EINVAL or one -ETIMEDOUT within 30 ms, no lockup in 9 tries, and 42
> conformance decodes run afterwards match the control. On this base:
> build only.
>
> Developed with Claude (Anthropic) as a coding assistant; I reviewed and
> tested it.
Which part of stop sending patch series you didn't understand?
Nothing of this will land in v7.4.
Jernej
>
> [1] https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@collabora.com/
>
> ---
> Arun Iyengar (5):
> media: staging: cedrus: h264: bound the wait for the bit skip
> media: staging: cedrus: h264: reject a slice header larger than the slice
> media: staging: cedrus: h265: reject a slice data offset past the slice
> media: staging: cedrus: h265: fail the job when the bit reader times out
> media: staging: cedrus: vp8: fail the job on a bit reader timeout
>
> drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 31 +++--
> drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 40 ++++--
> drivers/staging/media/sunxi/cedrus/cedrus_vp8.c | 159 +++++++++++++----------
> 3 files changed, 143 insertions(+), 87 deletions(-)
> ---
> base-commit: 95c189b26efb07257888ccf9d873a5c366aafbc6
> change-id: 20261128-b4-cedrus-bitreader-49a8ddfb794e
>
> Best regards,
> --
> Arun Iyengar <aiyengar1990@gmail.com>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-01 16:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past " Arun Iyengar via B4 Relay
2026-12-01 15:27 ` [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out Arun Iyengar via B4 Relay
2026-12-01 15:27 ` [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout Arun Iyengar via B4 Relay
2026-12-01 16:07 ` [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Jernej Škrabec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox