dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rob Herring (Arm)" <robh@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 02/31] accel: ethosu: Ensure suspended on removal
Date: Thu, 29 Oct 2026 14:02:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-189463@kernel.org> (raw)
In-Reply-To: <20261029-ethosu-fixes-v4-2-4aa25e22578e@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] accel: ethosu: double ethosu_device_suspend() call in ethosu_remove()
--

commit 8f693e6f09e933d0b127a2a725128f9cb43526dc
Author: Rob Herring (Arm) <robh@kernel.org>

accel: ethosu: Ensure suspended on removal

This commit adds a runtime PM barrier and a direct call to
ethosu_device_suspend() in ethosu_remove() when the device is not runtime
suspended, aiming to ensure clocks are disabled on device removal.

> diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
> index 38af57807cee7..ae7ebf29cb2f6 100644
> --- a/drivers/accel/ethosu/ethosu_drv.c
> +++ b/drivers/accel/ethosu/ethosu_drv.c
> @@ -387,6 +387,11 @@ static void ethosu_remove(struct platform_device *pdev)
>  
>  	drm_dev_unregister(&ethosudev->base);
>  	ethosu_job_fini(ethosudev);
> +
> +	pm_runtime_barrier(&pdev->dev);
> +	if (!pm_runtime_status_suspended(&pdev->dev))
> +		ethosu_device_suspend(&pdev->dev);

[Severity: High]
Can calling ethosu_device_suspend() directly here while runtime PM is still
enabled and runtime_status is RPM_ACTIVE cause ethosu_device_suspend() to be
invoked a second time during devres teardown, underflowing the clock enable
and prepare counts?

In ethosu_init() in drivers/accel/ethosu/ethosu_drv.c, runtime PM is
configured with autosuspend and devres:

	pm_runtime_set_autosuspend_delay(ethosudev->base.dev, 50);
	pm_runtime_use_autosuspend(ethosudev->base.dev);
	ret = devm_pm_runtime_set_active_enabled(ethosudev->base.dev);

During driver unbind or device removal under CONFIG_PM=y with
power/control=auto, __device_release_driver() calls pm_runtime_get_sync() and
pm_runtime_put_sync() before invoking ethosu_remove(), which leaves the
device in RPM_ACTIVE with usage_count == 0 and the autosuspend timer armed.

In ethosu_remove(), pm_runtime_barrier() cancels the autosuspend timer, and
ethosu_device_suspend() then runs:

	clk_bulk_disable_unprepare(ethosudev->num_clks, ethosudev->clks);

However, runtime PM remains enabled (disable_depth == 0) and runtime_status
remains RPM_ACTIVE. Immediately after ethosu_remove() returns,
__device_release_driver() -> device_unbind_cleanup() -> devres_release_all()
runs pm_runtime_disable_action() in drivers/base/power/runtime.c:

static void pm_runtime_disable_action(void *data)
{
	pm_runtime_dont_use_autosuspend(data);
	pm_runtime_disable(data);
}

Because pm_runtime_dont_use_autosuspend() runs before pm_runtime_disable(),
it calls __pm_runtime_use_autosuspend(dev, false) -> update_autosuspend() ->
rpm_idle(dev, RPM_AUTO) -> rpm_suspend(dev, RPM_AUTO). Since disable_depth is
0, usage_count is 0, use_autosuspend is now false, and runtime_status is
still RPM_ACTIVE, rpm_suspend() synchronously invokes ethosu_device_suspend()
a second time, calling clk_bulk_disable_unprepare() on clocks that were
already disabled and unprepared.

Also, while runtime_status remains RPM_ACTIVE after ethosu_device_suspend()
has disabled the clocks, could an open DRM file descriptor closing or issuing
an ioctl concurrently (such as ethosu_postclose() ->
ethosu_perfmon_close_file() -> ethosu_perfmon_stop_locked() checking
pm_runtime_get_if_active(), or ethosu_ioctl_perfmon_get_values() calling
pm_runtime_resume_and_get()) see RPM_ACTIVE and access ethosu->pmu_regs with
the NPU clocks disabled?

Would calling pm_runtime_dont_use_autosuspend(&pdev->dev) and
pm_runtime_disable(&pdev->dev) before checking pm_runtime_status_suspended()
(and calling pm_runtime_set_suspended(&pdev->dev) after
ethosu_device_suspend()) avoid both issues?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261029-ethosu-fixes-v4-0-4aa25e22578e@kernel.org?part=2

  reply	other threads:[~2026-10-29 14:03 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 13:35 [PATCH v4 00/31] accel: ethosu: Another batch of fixes Rob Herring (Arm)
2026-10-29 13:35 ` [PATCH v4 01/31] accel: ethosu: Suspend after initialization Rob Herring (Arm)
2026-10-29 15:42   ` Frank Li
2026-10-29 13:35 ` [PATCH v4 02/31] accel: ethosu: Ensure suspended on removal Rob Herring (Arm)
2026-10-29 14:02   ` sashiko-bot [this message]
2026-10-29 13:35 ` [PATCH v4 03/31] accel: ethosu: Fix probe error cleanup Rob Herring (Arm)
2026-10-29 15:52   ` Frank Li
2026-10-29 16:00     ` Rob Herring
2026-10-29 16:20       ` Frank Li
2026-10-29 13:35 ` [PATCH v4 04/31] accel: ethosu: Disable clocks on PM setup failure Rob Herring (Arm)
2026-10-29 14:01   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 05/31] accel: ethosu: Quiesce jobs before scheduler teardown Rob Herring (Arm)
2026-10-29 14:07   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 06/31] accel: ethosu: Fix runtime PM get error handling Rob Herring (Arm)
2026-10-29 16:03   ` Frank Li
2026-10-29 16:38   ` Frank Li
2026-10-29 13:35 ` [PATCH v4 07/31] accel: ethosu: Limit perfmon counters to UAPI Rob Herring (Arm)
2026-10-29 13:35 ` [PATCH v4 08/31] accel: ethosu: Serialize job completion Rob Herring (Arm)
2026-10-29 14:25   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 09/31] accel: ethosu: Guard operations after unplug Rob Herring (Arm)
2026-10-29 14:26   ` sashiko-bot
2026-10-29 19:01     ` Rob Herring
2026-10-29 13:35 ` [PATCH v4 10/31] accel: ethosu: Keep scheduler " Rob Herring (Arm)
2026-10-29 14:29   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 11/31] accel: ethosu: Clear SRAM before submission Rob Herring (Arm)
2026-10-29 14:36   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 12/31] accel: ethosu: Validate timeout command offset Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 13/31] accel: ethosu: Prevent command stream export Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 14/31] accel: ethosu: Move DMA mode to src/dst struct Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 15/31] accel: ethosu: Track command stream register setup Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 16/31] accel: ethosu: Factor buffer bounds checks Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 17/31] accel: ethosu: Fix NHCWB16 bounds calculation Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 18/31] accel: ethosu: Validate secondary streams Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 19/31] accel: ethosu: Reject unsupported commands and params Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 20/31] accel: ethosu: Validate all feature map tiles Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 21/31] accel: ethosu: Account for feature map element size Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 22/31] accel: ethosu: Validate convolution parameter Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 23/31] accel: ethosu: Account for kernel dilation in IFM size Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 24/31] accel: ethosu: Validate accumulator input Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 25/31] accel: ethosu: Restrict dynamic IFM2 weights Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 26/31] accel: ethosu: Split U65 and U85 DMA length validation Rob Herring (Arm)
2026-10-29 15:32   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 27/31] accel: ethosu: Validate OFM transpose Rob Herring (Arm)
2026-10-29 15:03   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 28/31] accel: ethosu: Validate resize operations Rob Herring (Arm)
2026-10-29 15:14   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 29/31] accel: ethosu: Ensure cmd stream is multiple of 4 bytes Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 30/31] accel: ethosu: Require active weight streams setup Rob Herring (Arm)
2026-10-29 15:18   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 31/31] accel: ethosu: Support U85 IFM upscaling Rob Herring (Arm)

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-189463@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.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