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>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] media: verisilicon: hevc: Find the reference buffers by timestamp
Date: Tue, 1 Dec 2026 12:07:41 +0100 [thread overview]
Message-ID: <be388952-9b80-4699-85d1-e5a4076c08d3@collabora.com> (raw)
In-Reply-To: <20261129-hantro-hevc-ref-ts-v1-1-e0ef7325d3f3@gmail.com>
Le 29/11/2026 à 20:32, Arun Iyengar via B4 Relay a écrit :
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> The G2 HEVC decoder keeps a table of CAPTURE buffer addresses keyed
> by POC. Entries that left the DPB stay in the table and still match a
> POC, so a DPB entry can get the address of a buffer that was requeued
> or removed with VIDIOC_REMOVE_BUFS, and the hardware then reads freed
> memory.
>
> Look the references up by their DPB timestamp instead, like the other
> codecs do, and drop the table.
>
> Fixes: cb5dd5a0fa51 ("media: hantro: Introduce G2/HEVC decoder")
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
I have tested it one imx8mq.
Reviewed-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> ---
> Found by code reading. The G2 HEVC decoder (i.MX8MQ, i.MX8MM, i.MX8MP)
> can reach this through the DPB controls: an entry whose picture was
> not decoded through the table matches a stale slot. RFC because it is compile-tested only (arm64
> allmodconfig, W=1); I have no i.MX8M board.
>
> Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.
> ---
> .../platform/verisilicon/hantro_g2_hevc_dec.c | 8 +---
> drivers/media/platform/verisilicon/hantro_hevc.c | 44 ----------------------
> drivers/media/platform/verisilicon/hantro_hw.h | 11 ------
> 3 files changed, 1 insertion(+), 62 deletions(-)
>
> diff --git a/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c b/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c
> index e7a7c7a42467..c988dd579b2f 100644
> --- a/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c
> +++ b/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c
> @@ -448,14 +448,11 @@ static int set_ref(struct hantro_ctx *ctx)
>
> set_ref_pic_list(ctx);
>
> - /* We will only keep the reference pictures that are still used */
> - hantro_hevc_ref_init(ctx);
> -
> /* Set up addresses of DPB buffers */
> dpb_longterm_e = 0;
> for (i = 0; i < decode_params->num_active_dpb_entries &&
> i < (V4L2_HEVC_DPB_ENTRIES_NUM_MAX - 1); i++) {
> - luma_addr = hantro_hevc_get_ref_buf(ctx, dpb[i].pic_order_cnt_val);
> + luma_addr = hantro_get_ref(ctx, dpb[i].timestamp);
> if (!luma_addr)
> return -ENOMEM;
>
> @@ -480,9 +477,6 @@ static int set_ref(struct hantro_ctx *ctx)
> if (!luma_addr)
> return -ENOMEM;
>
> - if (hantro_hevc_add_ref_buf(ctx, decode_params->pic_order_cnt_val, luma_addr))
> - return -EINVAL;
> -
> chroma_addr = luma_addr + cr_offset;
> mv_addr = luma_addr + mv_offset;
> compress_luma_addr = luma_addr + compress_luma_offset;
> diff --git a/drivers/media/platform/verisilicon/hantro_hevc.c b/drivers/media/platform/verisilicon/hantro_hevc.c
> index 83cd12b0ddd6..7a38012cbb32 100644
> --- a/drivers/media/platform/verisilicon/hantro_hevc.c
> +++ b/drivers/media/platform/verisilicon/hantro_hevc.c
> @@ -30,48 +30,6 @@ module_param_named(hevc_use_compression, hevc_use_compression, bool, 0644);
> MODULE_PARM_DESC(hevc_use_compression,
> "Use reference frame compression for HEVC");
>
> -void hantro_hevc_ref_init(struct hantro_ctx *ctx)
> -{
> - struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
> -
> - hevc_dec->ref_bufs_used = 0;
> -}
> -
> -dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx,
> - s32 poc)
> -{
> - struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
> - int i;
> -
> - /* Find the reference buffer in already known ones */
> - for (i = 0; i < NUM_REF_PICTURES; i++) {
> - if (hevc_dec->ref_bufs_poc[i] == poc) {
> - hevc_dec->ref_bufs_used |= 1 << i;
> - return hevc_dec->ref_bufs[i].dma;
> - }
> - }
> -
> - return 0;
> -}
> -
> -int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr)
> -{
> - struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
> - int i;
> -
> - /* Add a new reference buffer */
> - for (i = 0; i < NUM_REF_PICTURES; i++) {
> - if (!(hevc_dec->ref_bufs_used & 1 << i)) {
> - hevc_dec->ref_bufs_used |= 1 << i;
> - hevc_dec->ref_bufs_poc[i] = poc;
> - hevc_dec->ref_bufs[i].dma = addr;
> - return 0;
> - }
> - }
> -
> - return -EINVAL;
> -}
> -
> static int tile_buffer_reallocate(struct hantro_ctx *ctx)
> {
> struct hantro_dev *vpu = ctx->dev;
> @@ -278,8 +236,6 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx)
>
> hevc_dec->scaling_lists.size = SCALING_LIST_SIZE;
>
> - hantro_hevc_ref_init(ctx);
> -
> hevc_dec->use_compression =
> hevc_use_compression & hantro_needs_postproc(ctx, ctx->vpu_dst_fmt);
>
> diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h
> index 13e573f1f19d..87f0eaf31869 100644
> --- a/drivers/media/platform/verisilicon/hantro_hw.h
> +++ b/drivers/media/platform/verisilicon/hantro_hw.h
> @@ -36,8 +36,6 @@
> #define FMT_4K_WIDTH 4096
> #define FMT_4K_HEIGHT 2304
>
> -#define NUM_REF_PICTURES (V4L2_HEVC_DPB_ENTRIES_NUM_MAX + 1)
> -
> #define AV1_MAX_FRAME_BUF_COUNT (V4L2_AV1_TOTAL_REFS_PER_FRAME + 1)
>
> #define MAX_POSTPROC_BUFFERS 64
> @@ -145,10 +143,7 @@ struct hantro_hevc_dec_ctrls {
> * @tile_filter: Tile vertical filter buffer
> * @tile_sao: Tile SAO buffer
> * @tile_bsd: Tile BSD control buffer
> - * @ref_bufs: Internal reference buffers
> * @scaling_lists: Scaling lists buffer
> - * @ref_bufs_poc: Internal reference buffers picture order count
> - * @ref_bufs_used: Bitfield of used reference buffers
> * @ctrls: V4L2 controls attached to a run
> * @num_tile_cols_allocated: number of allocated tiles
> * @use_compression: use reference buffer compression
> @@ -158,10 +153,7 @@ struct hantro_hevc_dec_hw_ctx {
> struct hantro_aux_buf tile_filter;
> struct hantro_aux_buf tile_sao;
> struct hantro_aux_buf tile_bsd;
> - struct hantro_aux_buf ref_bufs[NUM_REF_PICTURES];
> struct hantro_aux_buf scaling_lists;
> - s32 ref_bufs_poc[NUM_REF_PICTURES];
> - u32 ref_bufs_used;
> struct hantro_hevc_dec_ctrls ctrls;
> unsigned int num_tile_cols_allocated;
> bool use_compression;
> @@ -454,9 +446,6 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx);
> void hantro_hevc_dec_exit(struct hantro_ctx *ctx);
> int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx);
> int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);
> -void hantro_hevc_ref_init(struct hantro_ctx *ctx);
> -dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, s32 poc);
> -int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr);
>
> int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx);
> void rockchip_vpu981_av1_dec_exit(struct hantro_ctx *ctx);
>
> ---
> base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747
> change-id: 20261129-hantro-hevc-ref-ts-71638230c181
>
> Best regards,
> --
> Arun Iyengar <aiyengar1990@gmail.com>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
prev parent reply other threads:[~2026-12-01 11:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 19:32 [PATCH RFC] media: verisilicon: hevc: Find the reference buffers by timestamp Arun Iyengar via B4 Relay
2026-12-01 11:07 ` Benjamin Gaignard [this message]
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=be388952-9b80-4699-85d1-e5a4076c08d3@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=aiyengar1990@gmail.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=hverkuil@kernel.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 \
/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