The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] media: cedrus: allocation failure and capture payload fixes
@ 2026-11-19 16:34 Arun Iyengar via B4 Relay
  2026-11-19 16:34 ` [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM Arun Iyengar via B4 Relay
  2026-11-19 16:34 ` [PATCH 2/2] media: cedrus: report only the picture as capture payload Arun Iyengar via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:34 UTC (permalink / raw)
  To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hans Verkuil
  Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
	linux-kernel, Arun Iyengar

Two cedrus fixes, found on an Orange Pi Zero2 (H616) and reproduced on
media-committers next. Patch 2 concerns the private plane of Jernej
Skrabec's 10-bit HEVC support.

Tested on H616 only: 17 x 64 MiB REQBUFS gives 12 buffers and no OOM
kill (next: five processes killed); 10-bit H.265 bytesused 12441600
(next: 15552000); v4l2-compliance 49/49; MPEG-2, H.264 and H.265
bit-exact.

Developed with Claude (Anthropic) as a coding assistant, which wrote
the code and the commit messages. I reviewed and tested them.

---
Arun Iyengar (2):
      media: cedrus: fail buffer allocations that do not fit with -ENOMEM
      media: cedrus: report only the picture as capture payload

 drivers/staging/media/sunxi/cedrus/cedrus_video.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
base-commit: aa0f4c41d4870a18e65772a1817af16427200371
change-id: 20261114-b4-cedrus-generic-fixes-8ce71c2dafd5

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM
  2026-11-19 16:34 [PATCH 0/2] media: cedrus: allocation failure and capture payload fixes Arun Iyengar via B4 Relay
@ 2026-11-19 16:34 ` Arun Iyengar via B4 Relay
  2026-11-26 17:21   ` Jernej Škrabec
  2026-11-19 16:34 ` [PATCH 2/2] media: cedrus: report only the picture as capture payload Arun Iyengar via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:34 UTC (permalink / raw)
  To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hans Verkuil
  Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
	linux-kernel, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

vb2-dma-contig allocates with GFP_KERNEL, so a buffer pool that does
not fit in memory invokes the OOM killer. Set __GFP_RETRY_MAYFAIL on
both queues: the request returns fewer buffers or -ENOMEM instead.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/staging/media/sunxi/cedrus/cedrus_video.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index ad4ec3490775..9b2d24e77fdb 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -602,6 +602,7 @@ int cedrus_queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->dev = ctx->dev->dev;
 	src_vq->supports_requests = true;
 	src_vq->requires_requests = true;
+	src_vq->gfp_flags = __GFP_RETRY_MAYFAIL;
 
 	ret = vb2_queue_init(src_vq);
 	if (ret)
@@ -616,6 +617,7 @@ int cedrus_queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->dev->dev_mutex;
 	dst_vq->dev = ctx->dev->dev;
+	dst_vq->gfp_flags = __GFP_RETRY_MAYFAIL;
 
 	return vb2_queue_init(dst_vq);
 }

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] media: cedrus: report only the picture as capture payload
  2026-11-19 16:34 [PATCH 0/2] media: cedrus: allocation failure and capture payload fixes Arun Iyengar via B4 Relay
  2026-11-19 16:34 ` [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM Arun Iyengar via B4 Relay
@ 2026-11-19 16:34 ` Arun Iyengar via B4 Relay
  2026-11-26 17:22   ` Jernej Škrabec
  1 sibling, 1 reply; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:34 UTC (permalink / raw)
  To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hans Verkuil
  Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
	linux-kernel, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

For 10-bit H.265 the driver appends the low 2 bits of every sample to
the capture buffer and counts them in sizeimage (extra_cap_size).
buf_prepare reports the whole sizeimage as bytesused, so userspace that
copies the payload gets the private plane as part of the picture.

Report only the picture; sizeimage stays the allocation size.

Fixes: 65429ba82572 ("media: cedrus: h265: Support decoding 10-bit frames")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/staging/media/sunxi/cedrus/cedrus_video.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index 9b2d24e77fdb..b7e0cbe548e6 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -511,8 +511,15 @@ static int cedrus_buf_prepare(struct vb2_buffer *vb)
 	 * (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets
 	 * it to buffer length).
 	 */
-	if (V4L2_TYPE_IS_CAPTURE(vq->type))
-		vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage);
+	if (V4L2_TYPE_IS_CAPTURE(vq->type)) {
+		unsigned int payload = pix_fmt->sizeimage;
+
+		if (ctx->current_codec->extra_cap_size)
+			payload -= ctx->current_codec->extra_cap_size(ctx,
+								     pix_fmt);
+
+		vb2_set_plane_payload(vb, 0, payload);
+	}
 
 	return 0;
 }

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM
  2026-11-19 16:34 ` [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM Arun Iyengar via B4 Relay
@ 2026-11-26 17:21   ` Jernej Škrabec
  0 siblings, 0 replies; 5+ messages in thread
From: Jernej Škrabec @ 2026-11-26 17:21 UTC (permalink / raw)
  To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Chen-Yu Tsai, Samuel Holland, Hans Verkuil,
	aiyengar1990
  Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
	linux-kernel, Arun Iyengar

Dne četrtek, 19. november 2026 ob 17:34:47 Srednjeevropski standardni čas je Arun Iyengar via B4 Relay napisal(a):
> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> vb2-dma-contig allocates with GFP_KERNEL, so a buffer pool that does
> not fit in memory invokes the OOM killer. Set __GFP_RETRY_MAYFAIL on
> both queues: the request returns fewer buffers or -ENOMEM instead.

This is correct only for IOMMU allocation. CMA fails directly.

Please update commit message.

Best regards,
Jernej

> 
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_video.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> index ad4ec3490775..9b2d24e77fdb 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> @@ -602,6 +602,7 @@ int cedrus_queue_init(void *priv, struct vb2_queue *src_vq,
>  	src_vq->dev = ctx->dev->dev;
>  	src_vq->supports_requests = true;
>  	src_vq->requires_requests = true;
> +	src_vq->gfp_flags = __GFP_RETRY_MAYFAIL;
>  
>  	ret = vb2_queue_init(src_vq);
>  	if (ret)
> @@ -616,6 +617,7 @@ int cedrus_queue_init(void *priv, struct vb2_queue *src_vq,
>  	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
>  	dst_vq->lock = &ctx->dev->dev_mutex;
>  	dst_vq->dev = ctx->dev->dev;
> +	dst_vq->gfp_flags = __GFP_RETRY_MAYFAIL;
>  
>  	return vb2_queue_init(dst_vq);
>  }
> 
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] media: cedrus: report only the picture as capture payload
  2026-11-19 16:34 ` [PATCH 2/2] media: cedrus: report only the picture as capture payload Arun Iyengar via B4 Relay
@ 2026-11-26 17:22   ` Jernej Škrabec
  0 siblings, 0 replies; 5+ messages in thread
From: Jernej Škrabec @ 2026-11-26 17:22 UTC (permalink / raw)
  To: Maxime Ripard, Paul Kocialkowski, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Chen-Yu Tsai, Samuel Holland, Hans Verkuil,
	aiyengar1990
  Cc: linux-media, linux-staging, linux-arm-kernel, linux-sunxi,
	linux-kernel, Arun Iyengar

Dne četrtek, 19. november 2026 ob 17:34:48 Srednjeevropski standardni čas je Arun Iyengar via B4 Relay napisal(a):
> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> For 10-bit H.265 the driver appends the low 2 bits of every sample to
> the capture buffer and counts them in sizeimage (extra_cap_size).
> buf_prepare reports the whole sizeimage as bytesused, so userspace that
> copies the payload gets the private plane as part of the picture.
> 
> Report only the picture; sizeimage stays the allocation size.
> 
> Fixes: 65429ba82572 ("media: cedrus: h265: Support decoding 10-bit frames")
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej

> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_video.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> index 9b2d24e77fdb..b7e0cbe548e6 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> @@ -511,8 +511,15 @@ static int cedrus_buf_prepare(struct vb2_buffer *vb)
>  	 * (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets
>  	 * it to buffer length).
>  	 */
> -	if (V4L2_TYPE_IS_CAPTURE(vq->type))
> -		vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage);
> +	if (V4L2_TYPE_IS_CAPTURE(vq->type)) {
> +		unsigned int payload = pix_fmt->sizeimage;
> +
> +		if (ctx->current_codec->extra_cap_size)
> +			payload -= ctx->current_codec->extra_cap_size(ctx,
> +								     pix_fmt);
> +
> +		vb2_set_plane_payload(vb, 0, payload);
> +	}
>  
>  	return 0;
>  }
> 
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 17:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:34 [PATCH 0/2] media: cedrus: allocation failure and capture payload fixes Arun Iyengar via B4 Relay
2026-11-19 16:34 ` [PATCH 1/2] media: cedrus: fail buffer allocations that do not fit with -ENOMEM Arun Iyengar via B4 Relay
2026-11-26 17:21   ` Jernej Škrabec
2026-11-19 16:34 ` [PATCH 2/2] media: cedrus: report only the picture as capture payload Arun Iyengar via B4 Relay
2026-11-26 17:22   ` Jernej Škrabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox