From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796123293; b=q6i10Xx35U+9p1Ox+KqwqcvT8imoC4B+/2PSoDKvd+yila09r6TuKb9uD/bqBHG+l3e6 HC3WcfbJqRrKa+mQmHeoMFs6BVNlBZcqAvXqhhqdXWlxo989wwy3V0wcHMz/ZfZPRFbqP xo4x5Ola7BiCJY+dmA5r/st3BFG9gTQ0bNKcvX6ucMEZiB7Vx4ReDG/rNehFViUQTJV7W i2qzd3c8J1rwJoRKg2ahIVn0lEfLyxrU308O5iiTlk8UHldVQl2Di+X6zQsd1oKCfctC1 srLpcjDEwzTlJ5pfNMljqqCkd9/GVwwCVbcNE5oyKqxT1o/UY1pmn4jGydAylhBXsMw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123293; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=74WH9Hrl8ocIeI/orsDeWe4KRewFxtDoeUNuRMOWU4s=; b=Mwb9lf4NbtIT0gUy8tzePI9eOjSJjM0BPn99SdFN2bTuGo69xGNXxfWn1BW3PNY2Sx7I AecxXN/8FWxNE7Xv62ZPmCcgKLvPWIxe2bpgPFfHW/Pu0b5kWXL71FG634VJjc2tHU7pL xJX80aR7BY8FVB8BehmB0dc7JXxMNz5eLuUFPEoAterLp+7UX4yM20Df8Yes1NBUNJpPn hu3fm5oKSvzXsDBRJoMI7hwtJYUY34lKrhBQgqf6I5rjVGYWL6p07RO2aTC83ynqzFW3c EzxIUrG0oDba9IquVIEOlwZRaUKvtwlvNfmOnd06CJRK3funlFy+P9008GD/yWMX1OA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b="T+pz5q/Q"; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 Received: from sender6-op-o11.zoho.com (sender6-op-o11.zoho.com [165.173.180.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CFA3606A320; Tue, 1 Dec 2026 11:08:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CFA3606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=T+pz5q/Q ARC-Seal: i=1; a=rsa-sha256; t=1796123268; cv=none; d=zohomail.com; s=zohoarc; b=TNNljoOYYy79WX50psCUIN8xh1SOCnYtmhoLO8+EQyAF9UDGqmwlaxt/riPfcquXvvBkg83Gh9vkJnMEuvDDNQITQnPxKqRk/ncX5mkekOAwHbockU7ny91qjR3b+Soh/eYNX11YBCJAhsEv6CI4FlfFul5XsoXvekf5F5H757M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796123268; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=74WH9Hrl8ocIeI/orsDeWe4KRewFxtDoeUNuRMOWU4s=; b=Myw/OJVFF0BbNAqc3tRg5c06zkjm5BP4BN/V2jQAGJ9w5O3SXOpxw9cpIjRIHQa1Rei+gXwIoTw54ZhB0c02Y/XdfGaPIMwgbmDGJU/Zc+tkxpZRaYFGfoRzJYaR60YXHiBE5aOBYZz1mCh2dennlsA4dT5yqtFcgZpcvXIXn3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=benjamin.gaignard@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=T+pz5q/QpNoyQBs8hDg5R56QXUi+DLYO48Oxua8ru/Fhp797wy9ExklOm6AjD/Uu+g2muoCHlHGpilvosUSYlAKzEtqqHe2x3rrv05uzDCtGDwO82qfiP550se5YZVCG4VcKG0AkneK/YvzEBM9nAuoFto2C6YUGQKk95+r4+Nk=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=74WH9Hrl8ocIeI/orsDeWe4KRewFxtDoeUNuRMOWU4s=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 17961232657241010.2349951619155; Tue, 1 Dec 2026 03:07:45 -0800 (PST) Message-ID: Date: Tue, 1 Dec 2026 12:07:41 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC] media: verisilicon: hevc: Find the reference buffers by timestamp To: aiyengar1990@gmail.com, Nicolas Dufresne , Philipp Zabel , Mauro Carvalho Chehab , Ezequiel Garcia , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org References: <20261129-hantro-hevc-ref-ts-v1-1-e0ef7325d3f3@gmail.com> Content-Language: en-US From: Benjamin Gaignard In-Reply-To: <20261129-hantro-hevc-ref-ts-v1-1-e0ef7325d3f3@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 29/11/2026 à 20:32, Arun Iyengar via B4 Relay a écrit : > From: Arun Iyengar > > 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 I have tested it one imx8mq. Reviewed-by: Benjamin Gaignard > --- > 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