[PATCH 1/2] media: verisilicon: av1: Find the reference buffers by timestamp

Benjamin Gaignard benjamin.gaignard at collabora.com
Tue Nov 17 07:49:52 PST 2026


Le 15/11/2026 à 09:59, Arun Iyengar via B4 Relay a écrit :
> From: Arun Iyengar <aiyengar1990 at gmail.com>
>
> frame_refs[] keeps a CAPTURE buffer pointer per reference across jobs.
> VIDIOC_REMOVE_BUFS can free that buffer, and a missing reference falls
> back to slot 0, which can hold a stale pointer.
>
> Look the buffer up by timestamp at each job, as the other Hantro codecs
> do, and use the current CAPTURE buffer and frame size when the reference
> is missing.
>
> Fixes: 727a400686a2 ("media: verisilicon: Add Rockchip AV1 decoder")
> Cc: stable at vger.kernel.org
> Signed-off-by: Arun Iyengar <aiyengar1990 at gmail.com>

I have tested the series on rock5b with fluster.

Reviewed-by: Benjamin Gaignard <benjamin.gaignard at collabora.com>

Thanks for the patch.
Benjamin

> ---
>   drivers/media/platform/verisilicon/hantro_hw.h     |  1 -
>   .../verisilicon/rockchip_vpu981_hw_av1_dec.c       | 37 ++++++++++++----------
>   2 files changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h
> index 13e573f1f19d..36df8caa077d 100644
> --- a/drivers/media/platform/verisilicon/hantro_hw.h
> +++ b/drivers/media/platform/verisilicon/hantro_hw.h
> @@ -287,7 +287,6 @@ struct hantro_av1_frame_ref {
>   	bool used;
>   	u32 order_hint;
>   	u32 order_hints[V4L2_AV1_TOTAL_REFS_PER_FRAME];
> -	struct vb2_v4l2_buffer *vb2_ref;
>   };
>   
>   /**
> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
> index 2a145433e6d1..59f2adf74850 100644
> --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
> +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
> @@ -169,7 +169,6 @@ static int rockchip_vpu981_av1_dec_frame_ref(struct hantro_ctx *ctx,
>   		av1_dec->frame_refs[i].timestamp = timestamp;
>   		av1_dec->frame_refs[i].frame_type = frame->frame_type;
>   		av1_dec->frame_refs[i].order_hint = frame->order_hint;
> -		av1_dec->frame_refs[i].vb2_ref = hantro_get_dst_buf(ctx);
>   
>   		for (j = 0; j < V4L2_AV1_TOTAL_REFS_PER_FRAME; j++)
>   			av1_dec->frame_refs[i].order_hints[j] = frame->order_hints[j];
> @@ -182,6 +181,18 @@ static int rockchip_vpu981_av1_dec_frame_ref(struct hantro_ctx *ctx,
>   	return AV1_INVALID_IDX;
>   }
>   
> +static struct vb2_buffer *rockchip_vpu981_av1_dec_ref_buf(struct hantro_ctx *ctx, int idx)
> +{
> +	struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
> +	struct vb2_queue *q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
> +	struct vb2_buffer *buf = NULL;
> +
> +	if (idx >= 0 && av1_dec->frame_refs[idx].used)
> +		buf = vb2_find_buffer(q, av1_dec->frame_refs[idx].timestamp);
> +
> +	return buf ?: &hantro_get_dst_buf(ctx)->vb2_buf;
> +}
> +
>   static void rockchip_vpu981_av1_dec_frame_unref(struct hantro_ctx *ctx, int idx)
>   {
>   	struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
> @@ -829,7 +840,7 @@ rockchip_vpu981_av1_dec_set_ref(struct hantro_ctx *ctx, int ref, int idx,
>   		pr_warn("AV1 invalid reference frame index\n");
>   	}
>   
> -	dst = vb2_to_hantro_decoded_buf(&av1_dec->frame_refs[idx].vb2_ref->vb2_buf);
> +	dst = vb2_to_hantro_decoded_buf(rockchip_vpu981_av1_dec_ref_buf(ctx, idx));
>   	luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
>   	chroma_addr = luma_addr + dst->av1.chroma_offset;
>   	mv_addr = luma_addr + dst->av1.mv_offset;
> @@ -894,7 +905,7 @@ static void rockchip_vpu981_av1_dec_set_segmentation(struct hantro_ctx *ctx)
>   			struct hantro_decoded_buffer *seg;
>   			size_t mv_offset = rockchip_vpu981_av1_dec_chroma_size(ctx);
>   
> -			seg = vb2_to_hantro_decoded_buf(&av1_dec->frame_refs[idx].vb2_ref->vb2_buf);
> +			seg = vb2_to_hantro_decoded_buf(rockchip_vpu981_av1_dec_ref_buf(ctx, idx));
>   			luma_addr = hantro_get_dec_buf_addr(ctx, &seg->base.vb.vb2_buf);
>   			mv_addr = luma_addr + mv_offset;
>   
> @@ -1983,16 +1994,13 @@ static void rockchip_vpu981_av1_dec_set_reference_frames(struct hantro_ctx *ctx)
>   
>   	for (i = V4L2_AV1_REF_LAST_FRAME; i < V4L2_AV1_TOTAL_REFS_PER_FRAME; i++) {
>   		u32 ref = i - 1;
> -		int idx = 0;
> -		int width, height;
> +		int idx = AV1_INVALID_IDX;
> +		int width = frame->frame_width_minus_1 + 1;
> +		int height = frame->frame_height_minus_1 + 1;
>   
> -		if (allow_intrabc) {
> -			idx = av1_dec->current_frame_index;
> -			width = frame->frame_width_minus_1 + 1;
> -			height = frame->frame_height_minus_1 + 1;
> -		} else {
> -			if (rockchip_vpu981_get_frame_index(ctx, ref) > 0)
> -				idx = rockchip_vpu981_get_frame_index(ctx, ref);
> +		if (!allow_intrabc)
> +			idx = rockchip_vpu981_get_frame_index(ctx, ref);
> +		if (idx >= 0) {
>   			width = av1_dec->frame_refs[idx].width;
>   			height = av1_dec->frame_refs[idx].height;
>   		}
> @@ -2185,16 +2193,13 @@ rockchip_vpu981_av1_dec_set_input_buffer(struct hantro_ctx *ctx,
>   static void
>   rockchip_vpu981_av1_dec_set_output_buffer(struct hantro_ctx *ctx)
>   {
> -	struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
>   	struct hantro_dev *vpu = ctx->dev;
>   	struct hantro_decoded_buffer *dst;
> -	struct vb2_v4l2_buffer *vb2_dst;
>   	dma_addr_t luma_addr, chroma_addr, mv_addr = 0;
>   	size_t cr_offset = rockchip_vpu981_av1_dec_luma_size(ctx);
>   	size_t mv_offset = rockchip_vpu981_av1_dec_chroma_size(ctx);
>   
> -	vb2_dst = av1_dec->frame_refs[av1_dec->current_frame_index].vb2_ref;
> -	dst = vb2_to_hantro_decoded_buf(&vb2_dst->vb2_buf);
> +	dst = vb2_to_hantro_decoded_buf(&hantro_get_dst_buf(ctx)->vb2_buf);
>   	luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
>   	chroma_addr = luma_addr + cr_offset;
>   	mv_addr = luma_addr + mv_offset;
>



More information about the Linux-rockchip mailing list