mirror of
https://github.com/openwrt/openwrt.git
synced 2026-11-27 14:41:12 +04:00
rockchip: fix rkvdec HEVC reference picture set handling
The rkvdec HEVC code reads the reference picture set controls before it applies the request and beyond the elements userspace passed, lets sets derived by prediction outgrow their arrays, and rebuilds the short-term set table only when the first set changes. The VDPU381 back end, which the RK356x VDPU346 shares, starts the decoder without the sets, which resets an RK3568, and the VDPU383 back end leaves the request of a refused job incomplete. Add the seven fixes of a series pending upstream, the last of which checks the scratch allocation of the short-term set table. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
1 parent
41c8c0fbde
commit
b951b4fcde
7 files changed
+521
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
From f60a2fe6ea602bb1eb91c19ba802fd6ddf1eef94 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: hevc: apply request controls first
|
||||
|
||||
rkvdec_hevc_run_preamble() takes the control pointers and the slice
|
||||
count before rkvdec_run_preamble() applies the request. When a request
|
||||
carries more elements of a dynamic array control than the control has
|
||||
held so far, v4l2_ctrl_request_setup() reallocates the array and frees
|
||||
the old one, which leaves run->slices_params, run->ext_sps_st_rps or
|
||||
run->ext_sps_lt_rps pointing to freed memory, and run->num_slices holds
|
||||
the element count of the previous request. The EXT SPS RPS controls are
|
||||
also looked up depending on has_sps_st_rps and has_sps_lt_rps before
|
||||
the request's own controls could set them.
|
||||
|
||||
A userspace V4L2 client that can open the RKVDEC m2m decoder can submit
|
||||
a request that grows one of these dynamic array controls and reach the
|
||||
freed array through the stale pointer.
|
||||
|
||||
Apply the request first, as rkvdec_vp9_run_preamble() does.
|
||||
|
||||
Fixes: 3595375c2301 ("media: rkvdec: Add HEVC backend")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
@@ -429,6 +429,8 @@ void rkvdec_hevc_run_preamble(struct rkv
|
||||
{
|
||||
struct v4l2_ctrl *ctrl;
|
||||
|
||||
+ rkvdec_run_preamble(ctx, &run->base);
|
||||
+
|
||||
ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl,
|
||||
V4L2_CID_STATELESS_HEVC_DECODE_PARAMS);
|
||||
run->decode_params = ctrl ? ctrl->p_cur.p : NULL;
|
||||
@@ -460,6 +462,4 @@ void rkvdec_hevc_run_preamble(struct rkv
|
||||
} else {
|
||||
run->ext_sps_lt_rps = NULL;
|
||||
}
|
||||
-
|
||||
- rkvdec_run_preamble(ctx, &run->base);
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
From 44dff8ef55da3d03c513f216f487c4c05737ef48 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: vdpu383: complete refused HEVC requests
|
||||
|
||||
rkvdec_hevc_run() returns -EINVAL when the RPS controls are missing,
|
||||
after rkvdec_hevc_run_preamble() applied the request's controls but
|
||||
without completing them. rkvdec_device_run() then returns the buffers
|
||||
with VB2_BUF_STATE_ERROR, which unbinds the source buffer from the
|
||||
request, while the request's control handler object stays incomplete.
|
||||
The request never reaches MEDIA_REQUEST_STATE_COMPLETE: poll() on its
|
||||
file descriptor never reports it, and MEDIA_REQUEST_IOC_REINIT fails
|
||||
with -EBUSY.
|
||||
|
||||
Complete the request's controls before returning the error, as
|
||||
rkvdec_vp9_run() does.
|
||||
|
||||
Fixes: e3b5b77e3689 ("media: rkvdec: Add HEVC support for the VDPU383 variant")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
@@ -553,6 +553,7 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
(!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n");
|
||||
+ rkvdec_run_postamble(ctx, &run.base);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
From 9d75ec1126feb21198f9cce305493af70161677a Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: hevc: bound the RPS reads by the control size
|
||||
|
||||
The RPS helpers read num_short_term_ref_pic_sets elements of the
|
||||
EXT_SPS_ST_RPS control and num_long_term_ref_pics_sps elements of the
|
||||
EXT_SPS_LT_RPS control, however many elements userspace passed. Beyond
|
||||
the passed elements they read stale entries of the control's array,
|
||||
and past its allocation once the SPS counts more sets than the control
|
||||
has ever held, as the control framework sizes a dynamic array for the
|
||||
largest element count it has seen. The short-term sets read from there
|
||||
are unchecked, and a num_negative_pics or num_positive_pics above 16
|
||||
overflows the calculated sets, the stack arrays of
|
||||
st_ref_pic_set_prediction() and the hardware RPS table.
|
||||
|
||||
A userspace V4L2 client that can open the RKVDEC m2m decoder can set an
|
||||
SPS whose counts exceed the number of elements it passed in these
|
||||
controls, so the reads run past the allocation.
|
||||
|
||||
Use the controls only when they hold at least as many elements as the
|
||||
SPS counts, and treat them as not set otherwise in both back ends.
|
||||
|
||||
Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
.../platform/rockchip/rkvdec/rkvdec-hevc-common.c | 12 ++++++------
|
||||
.../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 4 ++--
|
||||
.../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 4 ++--
|
||||
3 files changed, 10 insertions(+), 10 deletions(-)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
@@ -448,18 +448,18 @@ void rkvdec_hevc_run_preamble(struct rkv
|
||||
V4L2_CID_STATELESS_HEVC_SCALING_MATRIX);
|
||||
run->scaling_matrix = ctrl ? ctrl->p_cur.p : NULL;
|
||||
|
||||
+ run->ext_sps_st_rps = NULL;
|
||||
if (ctx->has_sps_st_rps) {
|
||||
ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl,
|
||||
V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS);
|
||||
- run->ext_sps_st_rps = ctrl ? ctrl->p_cur.p : NULL;
|
||||
- } else {
|
||||
- run->ext_sps_st_rps = NULL;
|
||||
+ if (ctrl && ctrl->elems >= run->sps->num_short_term_ref_pic_sets)
|
||||
+ run->ext_sps_st_rps = ctrl->p_cur.p;
|
||||
}
|
||||
+ run->ext_sps_lt_rps = NULL;
|
||||
if (ctx->has_sps_lt_rps) {
|
||||
ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl,
|
||||
V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS);
|
||||
- run->ext_sps_lt_rps = ctrl ? ctrl->p_cur.p : NULL;
|
||||
- } else {
|
||||
- run->ext_sps_lt_rps = NULL;
|
||||
+ if (ctrl && ctrl->elems >= run->sps->num_long_term_ref_pics_sps)
|
||||
+ run->ext_sps_lt_rps = ctrl->p_cur.p;
|
||||
}
|
||||
}
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
@@ -604,8 +604,8 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
* On vdpu381, not setting the long and short term ref sets will just output wrong frames.
|
||||
* Let's just warn about it and let the decoder run anyway.
|
||||
*/
|
||||
- if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
- (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
+ if ((!run.ext_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
+ (!run.ext_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
dev_warn_ratelimited(rkvdec->dev, "Long and short term RPS not set\n");
|
||||
} else {
|
||||
rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
@@ -550,8 +550,8 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
* To be on the safe side for this new v4l2 control, write an error in the log and mark
|
||||
* the buffer as failed by returning an error here.
|
||||
*/
|
||||
- if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
- (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
+ if ((!run.ext_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
+ (!run.ext_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n");
|
||||
rkvdec_run_postamble(ctx, &run.base);
|
||||
return -EINVAL;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
From 303f94e2dd498a482ab5c15584d225ea0d2f976e Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: hevc: bound predicted short-term RPS sets
|
||||
|
||||
st_ref_pic_set_prediction() copies the use_delta_flag and
|
||||
used_by_curr_pic bits of entries 0 to num_delta_pocs of the reference
|
||||
set into two 16-entry stack arrays, and a predicted set can hold one
|
||||
entry more than its reference set. The control validation accepts 16
|
||||
entries in an explicit set, so the copy writes one byte past each stack
|
||||
array and the predicted set its 17th entry past its 16-entry arrays,
|
||||
and a chain of predicted sets writes further past the stack arrays and
|
||||
the calculated sets. ITU-T H.265 7.4.8 bounds a set by
|
||||
sps_max_dec_pic_buffering_minus1, at most 15 entries, and the hardware
|
||||
table holds 15 entries per set.
|
||||
|
||||
A userspace V4L2 client that can open the RKVDEC m2m decoder can submit
|
||||
an EXT_SPS_ST_RPS control whose predicted sets overflow these arrays.
|
||||
|
||||
Skip a predicted set whose reference set holds more than 15 entries,
|
||||
as is done for a reference index out of range.
|
||||
|
||||
Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
@@ -223,6 +223,8 @@ static void st_ref_pic_set_prediction(st
|
||||
(rps_data->abs_delta_rps_minus1 + 1); /* 7-60 */
|
||||
|
||||
ref_rps = &calculated_rps_st_sets[ref_rps_idx];
|
||||
+ if (ref_rps->num_delta_pocs >= ARRAY_SIZE(use_delta_flag))
|
||||
+ return;
|
||||
|
||||
for (j = 0; j <= ref_rps->num_delta_pocs; j++) {
|
||||
used_by_curr_pic_flag[j] = !!(rps_data->used_by_curr_pic & (1 << j));
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
From 57582ceef513693a1417341c9a5b3dc84720e7d3 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: vdpu381: refuse HEVC jobs without RPS sets
|
||||
|
||||
When the SPS uses short-term or long-term reference picture sets and
|
||||
the matching EXT_SPS_ST_RPS or EXT_SPS_LT_RPS control was never set or
|
||||
holds fewer sets than the SPS counts, rkvdec_hevc_run() logs a warning
|
||||
and starts the decoder with an RPS table that does not belong to the
|
||||
stream, which at best gives wrong pictures. On the VDPU346 of the
|
||||
RK3568, which uses this back end, such decodes also raise error
|
||||
interrupts and time out, the IOMMU force reset fails, and the system
|
||||
stops responding until the hardware watchdog resets it.
|
||||
|
||||
Refuse the job as the VDPU383 back end does: log an error and return
|
||||
-EINVAL before any table is assembled, so that rkvdec_device_run()
|
||||
returns the buffers with VB2_BUF_STATE_ERROR and the hardware is not
|
||||
started. The request's controls are completed first, as
|
||||
rkvdec_vp9_run() does, so that the request is signalled as complete.
|
||||
|
||||
Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
.../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 19 ++++++++-----------
|
||||
1 file changed, 8 insertions(+), 11 deletions(-)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
@@ -596,21 +596,18 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
|
||||
rkvdec_hevc_run_preamble(ctx, &run);
|
||||
|
||||
- rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
|
||||
- &hevc_ctx->scaling_matrix_cache);
|
||||
- assemble_hw_pps(ctx, &run);
|
||||
-
|
||||
- /*
|
||||
- * On vdpu381, not setting the long and short term ref sets will just output wrong frames.
|
||||
- * Let's just warn about it and let the decoder run anyway.
|
||||
- */
|
||||
if ((!run.ext_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) ||
|
||||
(!run.ext_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) {
|
||||
- dev_warn_ratelimited(rkvdec->dev, "Long and short term RPS not set\n");
|
||||
- } else {
|
||||
- rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+ dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n");
|
||||
+ rkvdec_run_postamble(ctx, &run.base);
|
||||
+ return -EINVAL;
|
||||
}
|
||||
|
||||
+ rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
|
||||
+ &hevc_ctx->scaling_matrix_cache);
|
||||
+ assemble_hw_pps(ctx, &run);
|
||||
+ rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+
|
||||
config_registers(ctx, &run);
|
||||
|
||||
rkvdec_run_postamble(ctx, &run.base);
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
From c060e6a24db6124fb0a7dc54bbb5f6d8902f2cad Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: hevc: cache every short-term RPS set
|
||||
|
||||
rkvdec_hevc_prepare_hw_st_rps() skips building the short-term RPS
|
||||
table when the first element of the EXT_SPS_ST_RPS control equals its
|
||||
cache, which holds a single element and starts zeroed. When the first
|
||||
element is all zero, e.g. for an empty first set, the table entries of
|
||||
the remaining sets are never built, and an SPS that differs from the
|
||||
previous one only after its first set, or only in
|
||||
num_short_term_ref_pic_sets, keeps the previous table. Inter pictures
|
||||
are then decoded with wrong references: JCT-VC DELTAQP_A_BRCM_4 decodes
|
||||
its intra pictures correctly and its inter pictures wrongly on an
|
||||
RK3568, whose VDPU346 uses the VDPU381 back end.
|
||||
|
||||
Cache all sets the SPS uses together with their number, for both the
|
||||
VDPU381 and the VDPU383 back end. The SPS control validation bounds
|
||||
num_short_term_ref_pic_sets to 64, the size of the cache.
|
||||
|
||||
Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant")
|
||||
Cc: stable@vger.kernel.org
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
.../platform/rockchip/rkvdec/rkvdec-hevc-common.c | 12 ++++++++----
|
||||
.../platform/rockchip/rkvdec/rkvdec-hevc-common.h | 9 ++++++++-
|
||||
.../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 +-
|
||||
.../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 2 +-
|
||||
4 files changed, 18 insertions(+), 7 deletions(-)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
@@ -330,14 +330,17 @@ static void st_ref_pic_set_calculate(str
|
||||
}
|
||||
|
||||
static void rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct v4l2_ctrl_hevc_ext_sps_st_rps *cache)
|
||||
+ struct rkvdec_hevc_st_rps_cache *cache)
|
||||
{
|
||||
+ u8 num_sets = run->sps->num_short_term_ref_pic_sets;
|
||||
+ size_t size;
|
||||
int idx;
|
||||
|
||||
if (!run->ext_sps_st_rps)
|
||||
return;
|
||||
|
||||
- if (!memcmp(cache, run->ext_sps_st_rps, sizeof(struct v4l2_ctrl_hevc_ext_sps_st_rps)))
|
||||
+ size = num_sets * sizeof(*cache->sets);
|
||||
+ if (cache->num_sets == num_sets && !memcmp(cache->sets, run->ext_sps_st_rps, size))
|
||||
return;
|
||||
|
||||
struct calculated_rps_st_set *calculated_rps_st_sets =
|
||||
@@ -357,11 +360,12 @@ static void rkvdec_hevc_prepare_hw_st_rp
|
||||
|
||||
kfree(calculated_rps_st_sets);
|
||||
|
||||
- memcpy(cache, run->ext_sps_st_rps, sizeof(struct v4l2_ctrl_hevc_ext_sps_st_rps));
|
||||
+ memcpy(cache->sets, run->ext_sps_st_rps, size);
|
||||
+ cache->num_sets = num_sets;
|
||||
}
|
||||
|
||||
void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache)
|
||||
+ struct rkvdec_hevc_st_rps_cache *st_cache)
|
||||
{
|
||||
rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache);
|
||||
rkvdec_hevc_assemble_hw_lt_rps(run, rps);
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
|
||||
@@ -35,10 +35,17 @@
|
||||
|
||||
#define RKVDEC_RPS_HEVC_SIZE ALIGN(1032 + 64 * 384, 128)
|
||||
|
||||
+#define RKVDEC_HEVC_MAX_SHORT_TERM_REF_PIC_SETS 64
|
||||
+
|
||||
struct rkvdec_rps {
|
||||
u32 info[RKVDEC_RPS_HEVC_SIZE / 8 / 4];
|
||||
} __packed;
|
||||
|
||||
+struct rkvdec_hevc_st_rps_cache {
|
||||
+ struct v4l2_ctrl_hevc_ext_sps_st_rps sets[RKVDEC_HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
|
||||
+ u8 num_sets;
|
||||
+};
|
||||
+
|
||||
struct rkvdec_hevc_run {
|
||||
struct rkvdec_run base;
|
||||
const struct v4l2_ctrl_hevc_slice_params *slices_params;
|
||||
@@ -65,7 +72,7 @@ void compute_tiles_non_uniform(struct rk
|
||||
u16 width, u16 height, s32 pic_in_cts_width,
|
||||
s32 pic_in_cts_height, u16 *column_width, u16 *row_height);
|
||||
void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache);
|
||||
+ struct rkvdec_hevc_st_rps_cache *st_cache);
|
||||
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
|
||||
struct rkvdec_hevc_run *run,
|
||||
struct scaling_factor *scaling_factor,
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
@@ -117,7 +117,7 @@ struct rkvdec_hevc_priv_tbl {
|
||||
struct rkvdec_hevc_ctx {
|
||||
struct rkvdec_aux_buf priv_tbl;
|
||||
struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache;
|
||||
- struct v4l2_ctrl_hevc_ext_sps_st_rps st_cache;
|
||||
+ struct rkvdec_hevc_st_rps_cache st_cache;
|
||||
struct rkvdec_vdpu381_regs_hevc regs;
|
||||
};
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
@@ -124,7 +124,7 @@ struct rkvdec_hevc_priv_tbl {
|
||||
struct rkvdec_hevc_ctx {
|
||||
struct rkvdec_aux_buf priv_tbl;
|
||||
struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache;
|
||||
- struct v4l2_ctrl_hevc_ext_sps_st_rps st_cache;
|
||||
+ struct rkvdec_hevc_st_rps_cache st_cache;
|
||||
struct vdpu383_regs_h26x regs;
|
||||
};
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
From 4c7a0e820e483a0c91a833c8a29c71b6b17adf61 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Golle <daniel@makrotopia.org>
|
||||
Date: Fri, 13 Nov 2026 22:04:58 +0000
|
||||
Subject: [PATCH] media: rkvdec: hevc: check the RPS scratch allocation
|
||||
|
||||
rkvdec_hevc_prepare_hw_st_rps() uses the array returned by kzalloc()
|
||||
without checking it, so a failed allocation while a decode job is
|
||||
prepared dereferences a NULL pointer. Return -ENOMEM through
|
||||
rkvdec_hevc_assemble_hw_rps() and let both back ends refuse the job
|
||||
after completing the request's controls.
|
||||
|
||||
Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant")
|
||||
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
||||
---
|
||||
.../rockchip/rkvdec/rkvdec-hevc-common.c | 26 ++++++++++++++-----
|
||||
.../rockchip/rkvdec/rkvdec-hevc-common.h | 4 +--
|
||||
.../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 7 ++++-
|
||||
.../rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 7 ++++-
|
||||
4 files changed, 33 insertions(+), 11 deletions(-)
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
|
||||
@@ -329,24 +329,27 @@ static void st_ref_pic_set_calculate(str
|
||||
st_rps->num_delta_pocs = st_rps->num_positive_pics + st_rps->num_negative_pics;
|
||||
}
|
||||
|
||||
-static void rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct rkvdec_hevc_st_rps_cache *cache)
|
||||
+static int rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
+ struct rkvdec_hevc_st_rps_cache *cache)
|
||||
{
|
||||
u8 num_sets = run->sps->num_short_term_ref_pic_sets;
|
||||
size_t size;
|
||||
int idx;
|
||||
|
||||
if (!run->ext_sps_st_rps)
|
||||
- return;
|
||||
+ return 0;
|
||||
|
||||
size = num_sets * sizeof(*cache->sets);
|
||||
if (cache->num_sets == num_sets && !memcmp(cache->sets, run->ext_sps_st_rps, size))
|
||||
- return;
|
||||
+ return 0;
|
||||
|
||||
struct calculated_rps_st_set *calculated_rps_st_sets =
|
||||
kzalloc(sizeof(struct calculated_rps_st_set) *
|
||||
run->sps->num_short_term_ref_pic_sets, GFP_KERNEL);
|
||||
|
||||
+ if (!calculated_rps_st_sets)
|
||||
+ return -ENOMEM;
|
||||
+
|
||||
for (idx = 0; idx < run->sps->num_short_term_ref_pic_sets; idx++) {
|
||||
const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx];
|
||||
|
||||
@@ -362,13 +365,22 @@ static void rkvdec_hevc_prepare_hw_st_rp
|
||||
|
||||
memcpy(cache->sets, run->ext_sps_st_rps, size);
|
||||
cache->num_sets = num_sets;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
-void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct rkvdec_hevc_st_rps_cache *st_cache)
|
||||
+int rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
+ struct rkvdec_hevc_st_rps_cache *st_cache)
|
||||
{
|
||||
- rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache);
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
rkvdec_hevc_assemble_hw_lt_rps(run, rps);
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
struct vb2_buffer *
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
|
||||
@@ -71,8 +71,8 @@ void compute_tiles_uniform(struct rkvdec
|
||||
void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size,
|
||||
u16 width, u16 height, s32 pic_in_cts_width,
|
||||
s32 pic_in_cts_height, u16 *column_width, u16 *row_height);
|
||||
-void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
- struct rkvdec_hevc_st_rps_cache *st_cache);
|
||||
+int rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
|
||||
+ struct rkvdec_hevc_st_rps_cache *st_cache);
|
||||
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
|
||||
struct rkvdec_hevc_run *run,
|
||||
struct scaling_factor *scaling_factor,
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
|
||||
@@ -593,6 +593,7 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
struct rkvdec_hevc_run run;
|
||||
struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv;
|
||||
struct rkvdec_hevc_priv_tbl *tbl = hevc_ctx->priv_tbl.cpu;
|
||||
+ int ret;
|
||||
|
||||
rkvdec_hevc_run_preamble(ctx, &run);
|
||||
|
||||
@@ -606,7 +607,11 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
|
||||
&hevc_ctx->scaling_matrix_cache);
|
||||
assemble_hw_pps(ctx, &run);
|
||||
- rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+ ret = rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+ if (ret) {
|
||||
+ rkvdec_run_postamble(ctx, &run.base);
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
config_registers(ctx, &run);
|
||||
|
||||
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
|
||||
@@ -542,6 +542,7 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv;
|
||||
struct rkvdec_hevc_priv_tbl *tbl = hevc_ctx->priv_tbl.cpu;
|
||||
u32 timeout_threshold;
|
||||
+ int ret;
|
||||
|
||||
rkvdec_hevc_run_preamble(ctx, &run);
|
||||
|
||||
@@ -560,7 +561,11 @@ static int rkvdec_hevc_run(struct rkvdec
|
||||
rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
|
||||
&hevc_ctx->scaling_matrix_cache);
|
||||
assemble_hw_pps(ctx, &run);
|
||||
- rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+ ret = rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache);
|
||||
+ if (ret) {
|
||||
+ rkvdec_run_postamble(ctx, &run.base);
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
config_registers(ctx, &run);
|
||||
|
||||
Reference in new issue
Block a user