From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: aiyengar1990@gmail.com,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] media: verisilicon: av1: Find the reference buffers by timestamp
Date: Tue, 17 Nov 2026 16:49:52 +0100 [thread overview]
Message-ID: <1adbb937-9da6-4b40-9fff-48af38327f11@collabora.com> (raw)
In-Reply-To: <20261115-b4-vpu981-av1-refs-v1-1-c65769715db9@gmail.com>
Le 15/11/2026 à 09:59, Arun Iyengar via B4 Relay a écrit :
> From: Arun Iyengar <aiyengar1990@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@vger.kernel.org
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
I have tested the series on rock5b with fluster.
Reviewed-by: Benjamin Gaignard <benjamin.gaignard@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;
>
next prev parent reply other threads:[~2026-11-17 15:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 8:59 [PATCH 0/2] media: verisilicon: av1: Fix two reference reads Arun Iyengar via B4 Relay
2026-11-15 8:59 ` [PATCH 1/2] media: verisilicon: av1: Find the reference buffers by timestamp Arun Iyengar via B4 Relay
2026-11-17 15:49 ` Benjamin Gaignard [this message]
2026-11-15 8:59 ` [PATCH 2/2] media: verisilicon: av1: Read the segmentation map at the reference's offset Arun Iyengar via B4 Relay
2026-11-17 15:50 ` Benjamin Gaignard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1adbb937-9da6-4b40-9fff-48af38327f11@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=aiyengar1990@gmail.com \
--cc=heiko@sntech.de \
--cc=hverkuil@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox