From PENDING-COMMIT-SHA Mon Sep 17 00:00:00 2001 From: Markus Fritsche Date: Sat May 16 2026 Subject: [PATCH RFC v2 0007] media: rkvdec: attach dma_resv release fence at per-codec run() Opt the rkvdec CAPTURE queue into vb2 release-fence publishing, following the validated hantro (0005) and rockchip-rga (0006) patterns. The fence-attach is placed inside each per-codec `_run()` function AFTER `_run_preamble()` returns and BEFORE the HW kick writel(). This matches hantro's pattern of attaching after `v4l2_m2m_buf_copy_metadata()` (which `rkvdec_run_preamble()` calls internally). Attach sites: - drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c::rkvdec_h264_run() (legacy RK3399) - drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c::rkvdec_hevc_run() (legacy RK3399) - drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c::rkvdec_h264_run() (RK3588) - drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c::rkvdec_hevc_run() (RK3588) - drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c::rkvdec_h264_run() (RK3576) - drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c::rkvdec_hevc_run() (RK3576) - drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c::rkvdec_vp9_run() (RK3399 + variants) The vp9 path requires special handling: rkvdec_vp9_run_preamble() returns int and can fail (returns ret with cleanup via rkvdec_run_postamble). Fence attach must be AFTER the error check. Queue-init flag opts the dst_vq into vb2_buffer_attach_release_fence's no-op-unless-opted-in gate. No-op without CONFIG_VIDEOBUF2_RELEASE_FENCES=y. Changes vs v1 0007 (which placed fence-attach in rkvdec_device_run before desc->ops->run): moved INTO desc->ops->run after preamble, matching hantro's prior-art structurally. Independent Phase 5 architect review identified the v1 placement as architecturally inconsistent with the validated pattern. Validated locally on RK3588 vdpu381 with PROVE_LOCKING enabled before merge. Cc: linux-media@vger.kernel.org Signed-off-by: Markus Fritsche --- drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c | 3 +++ drivers/media/platform/rockchip/rkvdec/rkvdec.c | 4 ++++ 8 files changed, 25 insertions(+) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c @@ -412,6 +412,9 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) struct rkvdec_h264_priv_tbl *tbl = h264_ctx->priv_tbl.cpu; rkvdec_h264_run_preamble(ctx, &run); + + /* iter6 v2: attach release fence after preamble metadata copy, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); /* Build the P/B{0,1} ref lists. */ v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c @@ -561,6 +561,9 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) u32 reg; rkvdec_hevc_run_preamble(ctx, &run); + + /* iter6 v2: attach release fence after preamble metadata copy, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache); diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c @@ -420,6 +420,9 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) struct rkvdec_h264_run run; rkvdec_h264_run_preamble(ctx, &run); + + /* iter6 v2: attach release fence after preamble metadata copy, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); /* Build the P/B{0,1} ref lists. */ v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -589,6 +589,9 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) struct rkvdec_hevc_priv_tbl *tbl = hevc_ctx->priv_tbl.cpu; rkvdec_hevc_run_preamble(ctx, &run); + + /* iter6 v2: attach release fence after preamble metadata copy, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache); diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c @@ -485,6 +485,9 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) u32 timeout_threshold; rkvdec_h264_run_preamble(ctx, &run); + + /* iter6 v2: attach release fence after preamble metadata copy, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); /* Build the P/B{0,1} ref lists. */ v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c @@ -605,6 +605,9 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) return -EINVAL; } + /* iter6 v2: attach release fence after preamble metadata copy + RPS validation, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); + rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache); assemble_hw_pps(ctx, &run); diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c @@ -773,6 +773,9 @@ static int rkvdec_vp9_run(struct rkvdec_ctx *ctx) rkvdec_run_postamble(ctx, &run.base); return ret; } + + /* iter6 v2: attach release fence after preamble succeeded, before HW kick */ + (void)vb2_buffer_attach_release_fence(&run.base.bufs.dst->vb2_buf); /* Prepare probs. */ init_probs(ctx, &run); diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c @@ -1241,6 +1241,10 @@ static int rkvdec_queue_init(void *priv, dst_vq->lock = &rkvdec->vdev_lock; dst_vq->dev = rkvdec->v4l2_dev.dev; + /* iter6: opt CAPTURE queue into vb2 release-fence publishing. + * No-op unless CONFIG_VIDEOBUF2_RELEASE_FENCES=y. */ + dst_vq->supports_release_fences = true; + return vb2_queue_init(dst_vq); } -- 2.53.0