All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anthony McGivern" <anthony.mcgivern@arm.com>,
	devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver
Date: Tue, 24 Nov 2026 17:39:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-231725@kernel.org> (raw)
In-Reply-To: <20261124-b4-initial-upstream-candidate-v1-13-0cb9bde1bd30@arm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] media: mali-c720: reuse_buffer descriptor lost across runtime
  PM reset
- [Medium] media: mali-c720: premature upstream disable in fr_pipe
  disable_streams()
- [Medium] media: mali-c720: unbalanced power off on probe error in
  mali_c720_probe()
- [Medium] media: mali-c720: race on capture format in
  mali_c720_s_fmt_vid_cap_mplane()
- [Low] media: mali-c720: legacy PM ops macros and missing pm_ptr() in
  mali-c720-core
--

commit 673cd59feb7192d4abbadb5d84db3f82e14b2c89
Author: Anthony McGivern <Anthony.McGivern@arm.com>

media: mali-c720: Add Mali-C720 ISP driver

This commit integrates the hardware identification, capability discovery,
context management, V4L2 subdevices, power management, media graph
registration, frame scheduling, and build configuration for the Mali-C720
ISP driver.

> diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-capture.c b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
> index 78e9f5aba97d5..ef69901730b4e 100644
> --- a/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
> +++ b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
> @@ -289,6 +294,7 @@ static int mali_c720_vb2_start_streaming(struct vb2_queue *q, unsigned int count
>  	struct mali_c720_cap_dev *cap_dev = q->drv_priv;
>  	struct mali_c720 *mali_c720 = cap_dev->mali_c720;
>  	struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
> +	struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
>  	int ret;
>  
>  	guard(mutex)(&mali_c720->device_lock);
> @@ -328,8 +334,30 @@ static int mali_c720_vb2_start_streaming(struct vb2_queue *q, unsigned int count
>  		goto err_release_buffer_pool;
>  	}
>  
> +	/*
> +	 * All ISP source pads use the same start process, so the HV pad can
> +	 * represent the ISP when starting the pipeline.
> +	 */
> +	ret = mali_c720_pipeline_ready(mali_c720);
> +	if (ret && ret != -EAGAIN)
> +		goto err_disable_src;
> +
> +	if (!ret) {
> +		ret = v4l2_subdev_enable_streams(isp_sd,
> +						 MALI_C720_ISP_PAD_SOURCE_HV,
> +						 BIT(0));
> +		if (ret) {
> +			dev_err(mali_c720->dev, "%s failed to start ISP subdevice\n",
> +				cap_dev->vdev.name);
> +			goto err_disable_src;
> +		}
> +	}
> +
>  	return 0;
>  
> +err_disable_src:
> +	v4l2_subdev_disable_streams(cap_dev->src_sd, cap_dev->src_pad,
> +				    BIT(0));
>  err_release_buffer_pool:
>  	mali_c720_cap_dev_release_buffer_pool(cap_dev);

[Severity: Medium]
Can a concurrent VIDIOC_S_FMT on one capture device race with
VIDIOC_STREAMON on the other capture device in the pipeline and bypass link
validation?

Each capture node has its own cap_dev->lock (used for vdev->lock and
vb2q->lock). When both FR0_RGB and FR0_YUV links are enabled:

CPU0 (cap_devs[0] VIDIOC_STREAMON)    CPU1 (cap_devs[1] VIDIOC_S_FMT)
lock(&cap_devs[0].lock)               lock(&cap_devs[1].lock)
mali_c720_vb2_start_streaming()       mali_c720_s_fmt_vid_cap_mplane()
  lock(&mali_c720->device_lock)         media_entity_is_streaming() -> false
  video_device_pipeline_start()
    __media_pipeline_start()
      mali_c720_link_validate()
        reads cap_devs[1].format        mali_c720_set_format()
      cap_devs[1].pad.pipe = pipe         writes cap_devs[1].format  <-- race

When VIDIOC_STREAMON is subsequently called on cap_devs[1],
__media_pipeline_start() sees pipe->start_count > 0 and skips link
validation, so the buffer pool is configured with an unvalidated
cap_devs[1].format that may not match the upstream FR pipe pad format.
Taking mali_c720->device_lock in mali_c720_s_fmt_vid_cap_mplane() would
serialize format updates against video_device_pipeline_start().

[Severity: Medium]
When both FR0_RGB and FR0_YUV links on the FR pipe are enabled, does
disabling one source pad stream here (or in mali_c720_vb2_stop_streaming())
prematurely disable the upstream vision_pipe subdevice while the other FR
pipe source pad is still active?

When the second capture device starts streaming,
mali_c720_fr_pipe_enable_streams() calls v4l2_subdev_enable_streams() on
pipe->remote_src (which returns -EALREADY without incrementing the upstream
stream count) and sets the second pad bit in pipe->enabled_crops. However,
mali_c720_fr_pipe_disable_streams() disables pipe->remote_src
unconditionally:

drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c:mali_c720_fr_pipe_disable_streams() {
	if (pipe->remote_src) {
		src_sd = media_entity_to_v4l2_subdev(pipe->remote_src->entity);
		v4l2_subdev_disable_streams(src_sd, pipe->remote_src->index,
					    BIT(0));
	}
	pipe->remote_src = NULL;

	guard(spinlock)(&pipe->resizer_lock);
	pipe->enabled_crops &= ~BIT(pad);
}

If starting the second capture device fails and jumps to err_disable_src,
or if one of the two capture devices stops streaming first, the upstream
vision_pipe subdevice is disabled and pipe->remote_src is cleared while the
remaining FR pipe pad is still enabled.

> diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-core.c b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
> new file mode 100644
> index 0000000000000..2a46e7b348910
> --- /dev/null
> +++ b/drivers/media/platform/arm/mali-c720/mali-c720-core.c

[ ... ]

> +static int mali_c720_power_on(struct mali_c720 *mali_c720)
> +{
> +	int ret;
> +
> +	ret = clk_prepare_enable(mali_c720->clk);
> +	if (ret) {
> +		dev_err(mali_c720->dev, "failed to enable clocks\n");
> +		return ret;
> +	}
> +
> +	ret = reset_control_deassert(mali_c720->reset);
> +	if (ret) {
> +		dev_err(mali_c720->dev, "failed to deassert resets\n");
> +		goto err_disable_clk;
> +	}
> +
> +	return 0;
> +
> +err_disable_clk:
> +	clk_disable_unprepare(mali_c720->clk);
> +	return ret;
> +}
> +
> +static void mali_c720_power_off(struct mali_c720 *mali_c720)
> +{
> +	reset_control_assert(mali_c720->reset);
> +	clk_disable_unprepare(mali_c720->clk);
> +}
> +
> +static int __maybe_unused mali_c720_runtime_resume(struct device *dev)
> +{
> +	struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
> +
> +	return mali_c720_power_on(mali_c720);
> +}
> +
> +static int __maybe_unused mali_c720_runtime_suspend(struct device *dev)
> +{
> +	struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
> +
> +	mali_c720_power_off(mali_c720);
> +	return 0;
> +}

[Severity: High]
Does asserting mali_c720->reset in mali_c720_power_off() wipe the
ctx_mgr->reuse_buffer descriptor registers that were only programmed during
probe?

In mali_c720_probe(), mali_c720_init_ctx_mgr() calls
mali_c720_ctx_mgr_init_reuse_buffer() once to program the hardware raw
buffer descriptor at index ctx_mgr->reuse_buffer (including setting
buffer->nonsecure to 1) before calling pm_runtime_idle(&pdev->dev):

drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c:mali_c720_ctx_mgr_init_reuse_buffer() {
    ...
	buffer_addr = mali_c720_group_base(&buffer->raw_group, ctx_mgr->reuse_buffer);
	mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
					 MALI_C720_BUFFER_STATE_SW_EMPTY);
	mali_c720_group_write(mali_c720, buffer_addr,
			      &buffer->nonsecure, 1);
    ...
}

When the ISP enters runtime suspend (or system suspend),
mali_c720_power_off() asserts mali_c720->reset and disables mali_c720->clk,
resetting the MMIO registers. On runtime resume, mali_c720_power_on() does
not re-initialize ctx_mgr->reuse_buffer, so when streaming later stops,
mali_c720_ctx_mgr_stop_input_port() enables the input port with an
unconfigured reuse_buffer descriptor (nonsecure = 0), breaking the
r0p0/r0p1 input cleanup workaround and timing out waiting for the input
port to stop.

> +
> +static int __maybe_unused mali_c720_suspend(struct device *dev)
> +{
> +	struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
> +
> +	guard(mutex)(&mali_c720->device_lock);
> +
> +	/* Active pipelines cannot survive the hardware reset during suspend. */
> +	if (media_entity_is_streaming(&mali_c720->isp.mdev.sd.entity))
> +		return -EBUSY;
> +
> +	return pm_runtime_force_suspend(dev);
> +}
> +
> +static const struct dev_pm_ops mali_c720_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(mali_c720_suspend,
> +				pm_runtime_force_resume)
> +	SET_RUNTIME_PM_OPS(mali_c720_runtime_suspend, mali_c720_runtime_resume,
> +			   NULL)
> +};

[ ... ]

> +	pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
> +	pm_runtime_use_autosuspend(&pdev->dev);
> +	pm_runtime_set_active(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);
> +
> +	ret = platform_get_irq_byname(pdev, "isp");
> +	if (ret < 0) {
> +		dev_err(dev, "Failed to get interrupt\n");
> +		goto err_pm_runtime_disable;
> +	}
> +	irq = (unsigned int)ret;
> +
> +	spin_lock_init(&mali_c720->irq_lock);
> +	INIT_KFIFO(mali_c720->irq_fifo);
> +	ret = devm_request_threaded_irq(&pdev->dev, irq,
> +					mali_c720_isr_top, mali_c720_isr,
> +					0,
> +					dev_driver_string(&pdev->dev),
> +					&pdev->dev);
> +	if (ret) {
> +		dev_err(dev, "Failed to request threaded IRQ\n");
> +		goto err_pm_runtime_disable;
> +	}
> +	mali_c720->irq = irq;
> +
> +	mali_c720->media_dev.dev = dev;
> +	mali_c720->media_dev.ops = &mali_c720_media_device_ops;
> +	ret = mali_c720_media_frameworks_init(mali_c720);
> +	if (ret)
> +		goto err_free_irq;
> +
> +	pm_runtime_idle(&pdev->dev);
> +
> +	dev_info(&pdev->dev, "Media frameworks and entities registered successfully\n");
> +
> +	return 0;
> +
> +err_free_irq:
> +	devm_free_irq(dev, mali_c720->irq, dev);
> +err_pm_runtime_disable:
> +	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_set_suspended(&pdev->dev);
> +err_power_off:
> +	mali_c720_power_off(mali_c720);

[Severity: Medium]
Can the err_pm_runtime_disable error path call mali_c720_power_off() a
second time if the device has already runtime-suspended after
pm_runtime_enable()?

Runtime PM is enabled with usage_count == 0 before IRQ request and
mali_c720_media_frameworks_init(). If the device runtime-suspends during
that window and a later step fails, err_pm_runtime_disable falls through to
err_power_off without checking !pm_runtime_status_suspended(&pdev->dev) the
way mali_c720_remove() does, causing an unbalanced clk_disable_unprepare().
Also, neither err_pm_runtime_disable nor mali_c720_remove() calls
pm_runtime_dont_use_autosuspend(&pdev->dev) to pair with
pm_runtime_use_autosuspend(&pdev->dev).

[ ... ]

> +static struct platform_driver mali_c720_driver = {
> +	.driver		= {
> +		.name		= "mali-c720",
> +		.of_match_table	= mali_c720_of_match,
> +		.pm = &mali_c720_pm_ops,
> +	},
> +	.probe		= mali_c720_probe,
> +	.remove		= mali_c720_remove,
> +};

[Severity: Low]
This isn't a bug, but using SYSTEM_SLEEP_PM_OPS() and RUNTIME_PM_OPS() in
mali_c720_pm_ops along with .pm = pm_ptr(&mali_c720_pm_ops) here would let
the compiler drop the PM callbacks and drop the __maybe_unused annotations
when CONFIG_PM or CONFIG_PM_SLEEP is disabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-initial-upstream-candidate-v1-0-0cb9bde1bd30@arm.com?part=13

  reply	other threads:[~2026-11-24 17:39 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
2026-11-24 17:18   ` sashiko-bot
2026-11-25  8:51   ` Krzysztof Kozlowski
2026-11-26 14:55     ` Anthony McGivern
2026-11-26 15:12       ` Krzysztof Kozlowski
2026-11-27 12:32         ` Anthony McGivern
2026-11-27 12:49           ` Laurent Pinchart
2026-11-27 14:25             ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP Anthony McGivern
2026-11-24 17:07 ` [PATCH 04/24] media: mali-c720: Add register access helpers Anthony McGivern
2026-11-24 17:07 ` [PATCH 05/24] media: mali-c720: Add hardware identification Anthony McGivern
2026-11-25  8:52   ` Krzysztof Kozlowski
2026-11-26 15:00     ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 06/24] media: mali-c720: Add format handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 07/24] media: mali-c720: Add hardware discovery support Anthony McGivern
2026-11-24 17:07 ` [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 09/24] media: mali-c720: Add input frontend subdevice Anthony McGivern
2026-11-24 17:07 ` [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices Anthony McGivern
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
2026-11-24 17:21   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 12/24] media: mali-c720: Add video capture nodes Anthony McGivern
2026-11-24 17:35   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver Anthony McGivern
2026-11-24 17:39   ` sashiko-bot [this message]
2026-11-25  8:55   ` Krzysztof Kozlowski
2026-11-26 15:53     ` Anthony McGivern
2026-12-01 18:40       ` Linus Walleij
2026-12-01 22:10         ` Laurent Pinchart
2026-12-01 22:20           ` Linus Walleij
2026-11-24 17:07 ` [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices Anthony McGivern
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
2026-11-24 17:20   ` sashiko-bot
2026-11-28  0:43   ` kernel test robot
2026-11-24 17:07 ` [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:26   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 18/24] media: mali-c720: Add 3A statistics video node Anthony McGivern
2026-11-24 17:31   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture Anthony McGivern
2026-11-24 17:25   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:33   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 22/24] media: mali-c720: Add parameters video node Anthony McGivern
2026-11-24 17:45   ` sashiko-bot
2026-11-24 17:07 ` [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings Anthony McGivern
2026-11-24 17:07 ` [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver Anthony McGivern

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-231725@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anthony.mcgivern@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.