Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Charvi Mehta" <charvi.mehta@arm.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls
Date: Thu, 19 Nov 2026 15:55:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-223441@kernel.org> (raw)
In-Reply-To: <20261119153758.1426673-8-charvi.mehta@arm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] media: mali-vpu: missing CAPTURE busy check in
  mali_vpu_s_fmt() on OUTPUT
- [Medium] media: mali-vpu: CAPTURE colorimetry lost in mali_vpu_s_fmt()
  and try_fmt
- [Medium] media: mali-vpu: incomplete field check in
  mali_vpu_try_format_common()
- [Medium] media: mali-vpu: early return on bad pixfmt in
  mali_vpu_try_format_common()
--

commit 5a51818e198650b05f2b6b84f5fbe1b7fdc55bf4
Author: Charvi Mehta <charvi.mehta@arm.com>

media: mali-vpu: implement TRY_FMT and S_FMT ioctls

This commit implements the VIDIOC_TRY_FMT and VIDIOC_S_FMT ioctls for the
decoder OUTPUT and CAPTURE queues and moves format lookup and buffer sizing
into shared helpers.

> diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
> index b993255b8c817..dd142527a1a0c 100644
> --- a/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
> +++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
[ ... ]
> @@ -168,32 +169,119 @@ static int mali_vpu_g_fmt(struct file *filp, void *fh, struct v4l2_format *fmt)
>  	return ret;
>  }
>  
> -static const struct mali_vpu_format_desc *mali_vpu_find_format(struct mali_vpu_session *sess,
> -							       u32 pixfmt, u32 type)
> +static int mali_vpu_try_format_common(struct mali_vpu_session *sess, struct v4l2_format *fmt)
>  {
> -	const struct mali_vpu_format_desc *fmt_list;
> -	u32 num_fmts;
> -	u32 i;
> +	const struct mali_vpu_framesize_caps *fmsz = &sess->vpu_dev->variant->frmsz_caps;
> +	struct v4l2_pix_format_mplane *pix_mp = &fmt->fmt.pix_mp;
> +	const struct mali_vpu_format_desc *vpu_fmt;
> +	const struct v4l2_format *port_fmt, *port_fmt_dec;
> +	struct vb2_queue *src_q;
> +	u32 w, h;
> +	int ret = 0;
>  
> -	switch (type) {
> -	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
> -		fmt_list = sess->port_src.supported_fmts.fmts;
> -		num_fmts = sess->port_src.supported_fmts.num_fmts;
> -		break;
> -	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
> -		fmt_list = sess->port_dst.supported_fmts.fmts;
> -		num_fmts = sess->port_dst.supported_fmts.num_fmts;
> -		break;
> -	default:
> -		return NULL;
> +	vpu_fmt = mali_vpu_find_format(sess, pix_mp->pixelformat, fmt->type);
> +	if (!vpu_fmt) {
> +		port_fmt = mali_vpu_get_port_fmt(sess, fmt->type);
> +		if (!port_fmt)
> +			return -EINVAL;
> +
> +		*pix_mp = port_fmt->fmt.pix_mp;
> +		return 0;
> +	}

[Severity: Medium]
When pix_mp->pixelformat is unrecognized, should mali_vpu_try_format_common()
fall back to a supported format descriptor and continue validating the rest
of pix_mp instead of overwriting *pix_mp with port_fmt->fmt.pix_mp and
returning early?

Returning here discards the caller's requested width, height, and OUTPUT
colorimetry and skips v4l2_apply_frmsize_constraints() as well as the
streaming CAPTURE geometry lock.

> +
> +	/* Requested format found, validate other fields */
> +	w = pix_mp->width ? pix_mp->width : fmsz->width_default;
> +	h = pix_mp->height ? pix_mp->height : fmsz->height_default;
> +
> +	v4l2_apply_frmsize_constraints(&w, &h, &fmsz->stepwise);
> +
> +	/* Decode CAPTURE queue: lock geometry to input if streaming */
> +	if (sess->role == MALI_VPU_DECODER && fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
> +		src_q = v4l2_m2m_get_src_vq(sess->m2m_ctx);
> +		if (vb2_is_streaming(src_q)) {
> +			port_fmt_dec = &sess->port_src.curr_fmt;
> +			w = port_fmt_dec->fmt.pix_mp.width;
> +			h = port_fmt_dec->fmt.pix_mp.height;
> +		}
> +	}
> +
> +	ret = mali_vpu_fill_pixmp_fmt(vpu_fmt, w, h, pix_mp);
> +	if (ret)
> +		return ret;
> +
> +	if (pix_mp->field == V4L2_FIELD_ANY)
> +		pix_mp->field = V4L2_FIELD_NONE;

[Severity: Medium]
Should pix_mp->field be set unconditionally to V4L2_FIELD_NONE?  Because the
driver only supports progressive frames, checking only for V4L2_FIELD_ANY
leaves any other field value (such as V4L2_FIELD_INTERLACED or an invalid
value from userspace) intact in fmt and port->curr_fmt.

> +
> +	return 0;
> +}
> +
> +static int mali_vpu_try_fmt(struct file *filp, void *fh, struct v4l2_format *fmt)
> +{
> +	struct mali_vpu_session *sess = mali_vpu_get_session(filp);
> +	int ret;
> +
> +	mutex_lock(&sess->vq_lock);
> +
> +	ret = mali_vpu_try_format_common(sess, fmt);
> +
> +	mutex_unlock(&sess->vq_lock);
> +	return ret;
> +}
> +
> +static int mali_vpu_s_fmt(struct file *filp, void *fh, struct v4l2_format *fmt)
> +{
> +	struct mali_vpu_session *sess = mali_vpu_get_session(filp);
> +	struct vb2_queue *vq;
> +	struct v4l2_pix_format_mplane *pixmp_src = &sess->port_src.curr_fmt.fmt.pix_mp;
> +	struct v4l2_pix_format_mplane *pixmp_dst = &sess->port_dst.curr_fmt.fmt.pix_mp;
> +	int ret = 0;
> +
> +	mutex_lock(&sess->vq_lock);
> +
> +	vq = v4l2_m2m_get_vq(sess->m2m_ctx, fmt->type);
> +	if (vb2_is_busy(vq)) {
> +		ret = -EBUSY;
> +		goto mutex_unlock_return;
> +	}
> +
> +	ret = mali_vpu_try_format_common(sess, fmt);
> +	if (ret)
> +		goto mutex_unlock_return;
> +
> +	/* OUTPUT provides initial CAPTURE geometry */
> +	if (V4L2_TYPE_IS_OUTPUT(fmt->type)) {
> +		const struct mali_vpu_format_desc *cap_fmt;
> +		struct v4l2_pix_format_mplane *cap;
> +		struct v4l2_pix_format_mplane *fmt_mp = &fmt->fmt.pix_mp;
> +
> +		cap = &sess->port_dst.curr_fmt.fmt.pix_mp;
> +		cap_fmt = mali_vpu_find_format(sess, cap->pixelformat,
> +					       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> +		if (!cap_fmt) {
> +			ret = -EINVAL;
> +			goto mutex_unlock_return;
> +		}
> +
> +		ret = mali_vpu_fill_pixmp_fmt(cap_fmt, fmt_mp->width, fmt_mp->height, cap);
> +		if (ret)
> +			goto mutex_unlock_return;
> +	}

[Severity: Medium]
Can VIDIOC_S_FMT on the OUTPUT queue overwrite sess->port_dst.curr_fmt while
CAPTURE buffers are already allocated?

Only the queue for fmt->type is checked with vb2_is_busy(vq).  If userspace
allocates CAPTURE buffers and then calls VIDIOC_S_FMT on OUTPUT with a new
resolution, sess->port_dst.curr_fmt.fmt.pix_mp is updated in place without
checking whether the destination queue is busy, which violates the V4L2
stateful decoder specification and causes later VIDIOC_PREPARE_BUF or
VIDIOC_QBUF calls on existing CAPTURE buffers to fail size validation in
mali_vpu_vb2_buffer_prepare().

> +
> +	if (V4L2_TYPE_IS_OUTPUT(fmt->type))
> +		sess->port_src.curr_fmt = *fmt;
> +	else
> +		sess->port_dst.curr_fmt = *fmt;
> +
> +	/* Keep peer queue colorimetry aligned with input */
> +	if (V4L2_TYPE_IS_OUTPUT(fmt->type)) {
> +		pixmp_dst->colorspace	= pixmp_src->colorspace;
> +		pixmp_dst->ycbcr_enc	= pixmp_src->ycbcr_enc;
> +		pixmp_dst->quantization = pixmp_src->quantization;
> +		pixmp_dst->xfer_func	= pixmp_src->xfer_func;
> +	}

[Severity: Medium]
Does calling VIDIOC_TRY_FMT or VIDIOC_S_FMT on the CAPTURE queue lose the
OUTPUT colorimetry?

mali_vpu_try_format_common() does not copy colorspace, ycbcr_enc,
quantization, and xfer_func from sess->port_src.curr_fmt.fmt.pix_mp when
fmt->type is V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE.  As a result,
VIDIOC_TRY_FMT on CAPTURE returns the caller's unaligned colorimetry, and
VIDIOC_S_FMT on CAPTURE overwrites sess->port_dst.curr_fmt with *fmt,
clobbering the colorimetry propagated during VIDIOC_S_FMT on OUTPUT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119153758.1426673-1-charvi.mehta@arm.com?part=7

  reply	other threads:[~2026-11-19 15:55 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 15:37 [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 01/28] dt-bindings: media: add Arm Mali-V76 VPU Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 02/28] media: mali-vpu: add Mali VPU platform driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 03/28] media: mali-vpu: register V4L2 decoder device and add querycap ioctl Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 05/28] media: mali-vpu: add V4L2 mem2mem and VB2 queue support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 06/28] media: mali-vpu: implement format query ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls Charvi Mehta
2026-11-19 15:55   ` sashiko-bot [this message]
2026-11-19 15:37 ` [RFC PATCH 08/28] media: mali-vpu: register V76 decoder controls and introduce UAPI controls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 09/28] media: mali-vpu: add MMU software page table manager Charvi Mehta
2026-11-19 15:59   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 10/28] media: mali-vpu: add firmware cache infrastructure Charvi Mehta
2026-11-19 15:50   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 11/28] media: mali-vpu: load firmware for decoder sessions Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space Charvi Mehta
2026-11-19 15:57   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 13/28] media: mali-vpu: add firmware message transport Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 14/28] media: mali-vpu: route decoder controls to firmware Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 15/28] media: mali-vpu: handle firmware RPC requests Charvi Mehta
2026-11-19 15:51   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 16/28] media: mali-vpu: add LSID hardware support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 17/28] media: mali-vpu: add single session scheduler Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 18/28] media: mali-vpu: handle firmware interrupts Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 19/28] media: mali-vpu: start decoder firmware through LSID scheduling Charvi Mehta
2026-11-19 16:03   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 20/28] media: mali-vpu: implement vb2 buffer queue handling Charvi Mehta
2026-11-19 16:06   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 21/28] media: mali-vpu: handle firmware buffer exchange Charvi Mehta
2026-11-19 15:58   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 22/28] media: mali-vpu: handle fatal firmware error Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 23/28] media: mali-vpu: propagate buffer metadata Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 24/28] media: mali-vpu: add decoder EOS and DRC handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 25/28] media: mali-vpu: handle firmware buffer parameters Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 26/28] media: mali-vpu: handle firmware event responses Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 27/28] media: mali-vpu: add stateful decoder state machine Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta

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=sashiko-outbox-223441@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=charvi.mehta@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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