Linux-Rockchip Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Detlev Casanova <detlev.casanova@collabora.com>,
	Mauro Carvalho Chehab	 <mchehab@kernel.org>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Heiko Stuebner <heiko@sntech.de>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Jonas Karlman <jonas@kwiboo.se>
Cc: "Sven Püschel" <s.pueschel@pengutronix.de>,
	kernel@collabora.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 1/5] media: rkvdec: Keep RCB to the correct size
Date: Thu, 19 Nov 2026 12:33:37 -0500	[thread overview]
Message-ID: <33293a67f1427fdca259fd58ebfb463836c4c2c3.camel@collabora.com> (raw)
In-Reply-To: <20260810-rkvdec-multicore-v2-1-986f89d22cdc@collabora.com>


[-- Attachment #1.1: Type: text/plain, Size: 6187 bytes --]

Hi,

Le lundi 10 août 2026 à 11:22 -0400, Detlev Casanova a écrit :
> Currently, if a video changes resolution, the RCB size might be too small
> and the HW could try to write out of the allocated buffer.
> 
> To fix that, make sure that the RCB size is validated for each run and
> increase the buffer size when needed.
> 
> Fixes: e5640dbb991c ("media: rkvdec: Add RCB and SRAM support")
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
> ---
>  .../media/platform/rockchip/rkvdec/rkvdec-rcb.c    | 26 +++++++++++++++---
>  .../media/platform/rockchip/rkvdec/rkvdec-rcb.h    |  3 ++-
>  drivers/media/platform/rockchip/rkvdec/rkvdec.c    | 31 +++++++++++-----------
>  3 files changed, 40 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
> index fdcf1f177379..191f78278c01 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
> @@ -17,6 +17,8 @@
>  struct rkvdec_rcb_config {
>  	struct rkvdec_aux_buf *rcb_bufs;
>  	size_t rcb_count;
> +	u32 width;
> +	u32 height;
>  };
>  
>  static size_t rkvdec_rcb_size(const struct rcb_size_info *size_info,
> @@ -40,6 +42,21 @@ int rkvdec_rcb_buf_count(struct rkvdec_ctx *ctx)
>  	return ctx->rcb_config->rcb_count;
>  }
>  
> +bool rkvdec_rcb_buf_validate_size(struct rkvdec_ctx *ctx)
> +{
> +	struct rkvdec_rcb_config *cfg = ctx->rcb_config;
> +
> +	bool ret = cfg && cfg->height >= ctx->decoded_fmt.fmt.pix_mp.height &&
> +		   cfg->width >= ctx->decoded_fmt.fmt.pix_mp.width;
> +
> +	if (!ret && cfg) {
> +		dev_dbg(ctx->dev->dev, "RCB size %ux%u -> %ux%u\n", cfg->width, cfg->height,
> +			ctx->decoded_fmt.fmt.pix_mp.width, ctx->decoded_fmt.fmt.pix_mp.height);
> +	}

I'm not asking to respin for that, but it would be easier to review in this
form:

	struct rkvdec_rcb_config *cfg = ctx->rcb_config;

	if (!cfg)
		return false;

	if (cfg->height < ctx->decoded_fmt.fmt.pix_mp.height ||
		   cfg->width < ctx->decoded_fmt.fmt.pix_mp.width) {
		dev_dbg(ctx->dev->dev, "RCB size %ux%u -> %ux%u\n", cfg->width,
cfg->height,
			ctx->decoded_fmt.fmt.pix_mp.width, ctx-
>decoded_fmt.fmt.pix_mp.height);
		return false;
	}

	return true;

> +
> +	return ret;
> +}
> +
>  void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
>  {
>  	struct rkvdec_dev *dev = ctx->dev;
> @@ -77,14 +94,15 @@ void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
>  		devm_kfree(dev->dev, cfg->rcb_bufs);
>  
>  	devm_kfree(dev->dev, cfg);
> +
> +	ctx->rcb_config = NULL;

nit: Just conceptually, I'd do that before free, not after (no need to respin
either).

>  }
>  
> -int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
> +int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx, u32 width, u32 height,
>  			const struct rcb_size_info *size_info,
>  			size_t rcb_count)
>  {
>  	int ret, i;
> -	u32 width, height;
>  	struct rkvdec_dev *rkvdec = ctx->dev;
>  	struct rkvdec_rcb_config *cfg;
>  
> @@ -105,8 +123,8 @@ int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
>  		goto err_alloc;
>  	}
>  
> -	width = ctx->decoded_fmt.fmt.pix_mp.width;
> -	height = ctx->decoded_fmt.fmt.pix_mp.height;
> +	cfg->width = width;
> +	cfg->height = height;
>  
>  	for (i = 0; i < rcb_count; i++) {
>  		void *cpu = NULL;
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
> index 30e8002555c8..0662a4359bdf 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
> @@ -20,10 +20,11 @@ struct rcb_size_info {
>  	enum rcb_axis axis;
>  };
>  
> -int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
> +int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx, u32 width, u32 height,
>  			const struct rcb_size_info *size_info,
>  			size_t rcb_count);
>  dma_addr_t rkvdec_rcb_buf_dma_addr(struct rkvdec_ctx *ctx, int id);
>  size_t rkvdec_rcb_buf_size(struct rkvdec_ctx *ctx, int id);
>  int rkvdec_rcb_buf_count(struct rkvdec_ctx *ctx);
> +bool rkvdec_rcb_buf_validate_size(struct rkvdec_ctx *ctx);
>  void rkvdec_free_rcb(struct rkvdec_ctx *ctx);
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> index 1d1e9bfef8e9..31ddfcc58894 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> @@ -978,8 +978,7 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)
>  {
>  	struct rkvdec_ctx *ctx = vb2_get_drv_priv(q);
>  	const struct rkvdec_coded_fmt_desc *desc;
> -	const struct rkvdec_variant *variant = ctx->dev->variant;
> -	int ret;
> +	int ret = 0;
>  
>  	if (V4L2_TYPE_IS_CAPTURE(q->type))
>  		return 0;
> @@ -988,20 +987,8 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)
>  	if (WARN_ON(!desc))
>  		return -EINVAL;
>  
> -	ret = rkvdec_allocate_rcb(ctx, variant->rcb_sizes, variant->num_rcb_sizes);
> -	if (ret)
> -		return ret;
> -
> -	if (desc->ops->start) {
> +	if (desc->ops->start)
>  		ret = desc->ops->start(ctx);
> -		if (ret)
> -			goto err_ops_start;
> -	}
> -
> -	return 0;
> -
> -err_ops_start:
> -	rkvdec_free_rcb(ctx);
>  
>  	return ret;
>  }
> @@ -1174,6 +1161,20 @@ static void rkvdec_device_run(void *priv)
>  		return;
>  	}
>  
> +	if (!rkvdec_rcb_buf_validate_size(ctx)) {
> +		rkvdec_free_rcb(ctx);
> +
> +		ret = rkvdec_allocate_rcb(ctx,
> +					  ctx->decoded_fmt.fmt.pix_mp.width,
> +					  ctx->decoded_fmt.fmt.pix_mp.height,
> +					  ctx->dev->variant->rcb_sizes,
> +					  ctx->dev->variant->num_rcb_sizes);
> +		if (ret) {
> +			rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
> +			return;
> +		}
> +	}
> +
>  	ret = desc->ops->run(ctx);
>  	if (ret)
>  		rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);

So unless there is things to fix on other patches (or someone else oppose), you
can leave it like that:

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  reply	other threads:[~2026-11-19 17:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 15:22 [PATCH v2 0/5] media: rkvdec: Enable multi-core support Detlev Casanova
2026-08-10 15:22 ` [PATCH v2 1/5] media: rkvdec: Keep RCB to the correct size Detlev Casanova
2026-11-19 17:33   ` Nicolas Dufresne [this message]
2026-08-10 15:22 ` [PATCH v2 2/5] media: rkvdec: Remove unused need_reset Detlev Casanova
2026-11-19 17:35   ` Nicolas Dufresne
2026-08-10 15:22 ` [PATCH v2 3/5] v4l2: export v4l2_m2m_set_max_parallel_jobs Detlev Casanova
2026-11-19 17:36   ` Nicolas Dufresne
2026-08-10 15:22 ` [PATCH v2 4/5] media: rkvdec: Split into core and master platform drivers Detlev Casanova
2026-11-19 17:58   ` Nicolas Dufresne
2026-08-10 15:22 ` [PATCH v2 5/5] media: rkvdec: Add multicore support Detlev Casanova
2026-11-19 18:08   ` Nicolas Dufresne
2026-11-13 12:39 ` [PATCH v2 0/5] media: rkvdec: Enable multi-core support Lukas Splavec
2026-11-14  4:50 ` Arun Iyengar
2026-11-14  5:01 ` Arun Iyengar

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=33293a67f1427fdca259fd58ebfb463836c4c2c3.camel@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=detlev.casanova@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jonas@kwiboo.se \
    --cc=kernel@collabora.com \
    --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=s.pueschel@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