From: sashiko-bot@kernel.org
To: "Rob Herring (Arm)" <robh@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 10/31] accel: ethosu: Keep scheduler after unplug
Date: Thu, 29 Oct 2026 14:29:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-189517@kernel.org> (raw)
In-Reply-To: <20261029-ethosu-fixes-v4-10-4aa25e22578e@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] accel: ethosu: race with work_tdr and pending_list leak in ethosu_job_stop()
- [High] accel: ethosu: double clock disable and RPM imbalance in ethosu_remove()
- [Medium] accel: ethosu: premature entity kill on file close in ethosu_job_close()
--
commit b4de18ee902b7d8141192389e4617bb0996bcadc
Author: Rob Herring (Arm) <robh@kernel.org>
accel: ethosu: Keep scheduler after unplug
This commit defers scheduler teardown until the final DRM device reference is
released and tracks open scheduling entities so device removal can stop each
entity and cancel the in-flight job while leaving the scheduler alive for
postclose handling.
> diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
> index 91b2c2ab0a03e..ee50e7db36ad1 100644
> --- a/drivers/accel/ethosu/ethosu_drv.c
> +++ b/drivers/accel/ethosu/ethosu_drv.c
[ ... ]
> @@ -389,20 +389,18 @@ static int ethosu_probe(struct platform_device *pdev)
[ ... ]
> static void ethosu_remove(struct platform_device *pdev)
> {
> struct ethosu_device *ethosudev = dev_get_drvdata(&pdev->dev);
> + bool clocks_disabled;
>
> drm_dev_unplug(ðosudev->base);
> - ethosu_job_fini(ethosudev);
> -
> pm_runtime_barrier(&pdev->dev);
> - if (!pm_runtime_status_suspended(&pdev->dev))
> + clocks_disabled = ethosu_job_stop(ethosudev);
> + if (!clocks_disabled && !pm_runtime_status_suspended(&pdev->dev))
> ethosu_device_suspend(&pdev->dev);
[Severity: High]
Can calling ethosu_device_suspend() directly here (or inside ethosu_job_stop()
when ethosu_device_reset() fails) cause clk_bulk_disable_unprepare() to run a
second time during devres teardown?
In ethosu_init(), the driver enables autosuspend and registers runtime PM
cleanup via devm_pm_runtime_set_active_enabled().
In ethosu_remove(), pm_runtime_barrier() is called before ethosu_job_stop().
Inside ethosu_job_stop(), ethosu_perfmon_stop_locked() calls pm_runtime_put(),
and flushing work_free_job runs ethosu_job_cleanup() ->
pm_runtime_put_autosuspend(), which drops usage_count and arms the autosuspend
timer while runtime_status remains RPM_ACTIVE.
When ethosu_device_suspend() is then called directly, it disables and
unprepares the clocks without updating runtime_status to RPM_SUSPENDED or
disabling runtime PM. When ethosu_remove() returns and devres_release_all()
runs pm_runtime_disable_action() -> pm_runtime_dont_use_autosuspend() ->
rpm_idle() -> rpm_suspend() (or if the autosuspend timer fires first),
runtime PM invokes ethosu_device_suspend() again on already-disabled clocks.
In addition, for queued entity jobs killed via drm_sched_entity_kill() in
ethosu_job_stop(), cleanup runs asynchronously via
drm_sched_entity_kill_jobs_work(). Because ethosu_job_stop() does not wait for
those killed jobs (such as jobs waiting on external dependencies kept alive via
keep_device), won't they retain their pm_runtime_resume_and_get() usage_count
references across ethosu_remove() and later call pm_runtime_put_autosuspend()
in ethosu_job_cleanup() after the device has been unbound?
> diff --git a/drivers/accel/ethosu/ethosu_job.c b/drivers/accel/ethosu/ethosu_job.c
> index 8ffdc83d06f98..ef95a8abd61e2 100644
> --- a/drivers/accel/ethosu/ethosu_job.c
> +++ b/drivers/accel/ethosu/ethosu_job.c
[ ... ]
> @@ -388,45 +421,76 @@ int ethosu_job_init(struct ethosu_device *edev)
[ ... ]
> -void ethosu_job_fini(struct ethosu_device *dev)
> +bool ethosu_job_stop(struct ethosu_device *dev)
> {
> + struct ethosu_file_priv *priv;
> + struct ethosu_job *job;
> + bool clocks_disabled = false;
> +
> + guard(mutex)(&dev->sched_lock);
> drm_sched_wqueue_stop(&dev->sched);
> + disable_irq(dev->irq);
> cancel_delayed_work_sync(&dev->sched.work_tdr);
>
> - if (READ_ONCE(dev->in_flight_job)) {
> - WRITE_ONCE(dev->in_flight_job, NULL);
> - ethosu_device_reset(dev);
> + scoped_guard(mutex, &dev->perfmon_state.lock)
> + ethosu_perfmon_stop_locked(dev, dev->perfmon_state.active, false);
> +
> + list_for_each_entry(priv, &dev->sched_entities, sched_entity_list)
> + drm_sched_entity_kill(&priv->sched_entity);
> +
> + job = ethosu_job_clear_in_flight(dev);
> + if (job && ethosu_device_reset(dev)) {
> + ethosu_device_suspend(dev->base.dev);
> + clocks_disabled = true;
> }
>
> - synchronize_irq(dev->irq);
> - drm_sched_fini(&dev->sched);
> + if (job)
> + ethosu_job_cancel(&job->base);
> +
> + /* Let drm-sched release the cancelled in-flight job. */
> + drm_sched_wqueue_start(&dev->sched);
> + flush_work(&dev->sched.work_free_job);
> + drm_sched_wqueue_stop(&dev->sched);
> +
> + return clocks_disabled;
> }
[Severity: High]
What happens in ethosu_job_stop() if work_tdr (drm_sched_job_timedout() ->
ethosu_job_timedout()) is already running or has previously failed recovery?
First, drm_sched_wqueue_stop() and disable_irq() are called before
cancel_delayed_work_sync(&dev->sched.work_tdr) and before killing entities with
drm_sched_entity_kill(). Since ethosu_job_timedout() does not take
dev->sched_lock:
drivers/accel/ethosu/ethosu_job.c:ethosu_job_timedout() {
...
drm_sched_stop(&dev->sched, bad);
ethosu_job_clear_in_flight(dev);
/* Proceed with reset now. */
ret = pm_runtime_force_suspend(dev->base.dev);
if (!ret)
ret = pm_runtime_force_resume(dev->base.dev);
if (ret) {
dev_err(dev->base.dev, "Failed to recover NPU: %d\n", ret);
return DRM_GPU_SCHED_STAT_ENODEV;
}
/* Drain a pending completion IRQ before a replacement job can run. */
synchronize_irq(dev->irq);
/* Restart the scheduler */
drm_sched_start(&dev->sched, 0);
...
}
an in-progress ethosu_job_timedout() can finish recovery while
ethosu_job_stop() is waiting in cancel_delayed_work_sync(&dev->sched.work_tdr)
and call drm_sched_start() -> drm_sched_wqueue_start() (as well as
drm_sched_start_timeout_unlocked() in drm_sched_job_timedout()). When
cancel_delayed_work_sync() returns, sched->pause_submit is false and
work_run_job is queued while dev->sched_entities are not yet killed. Can
drm_sched_run_job_work() then pop a job from an entity before
drm_sched_entity_kill() reaches it, submit it to hardware via ethosu_job_run()
with IRQs already disabled, and re-arm work_tdr after
cancel_delayed_work_sync() has completed?
Second, if a prior timeout recovery in ethosu_job_timedout() failed at
pm_runtime_force_suspend() or pm_runtime_force_resume() and returned
DRM_GPU_SCHED_STAT_ENODEV, drm_sched_stop() has already placed the timed-out
job back onto dev->sched.pending_list and detached its parent fence callback,
while ethosu_job_clear_in_flight() cleared dev->in_flight_job to NULL.
Because ethosu_job_push() now takes a drm_dev_get() and try_module_get()
reference on every pushed job until ethosu_job_cleanup(), and drm_sched_fini()
(which calls drm_sched_cancel_remaining_jobs()) is deferred to the drmm action
ethosu_job_fini(), ethosu_job_stop() sees ethosu_job_clear_in_flight(dev) ==
NULL and never cancels the job left on dev->sched.pending_list. Doesn't this
create a reference cycle where the unsignaled job on pending_list (and any
entity jobs chained to entity->last_scheduled in drm_sched_entity_kill()) is
never freed, leaking the drm_device, THIS_MODULE, GEM objects, and runtime PM
references?
>
> int ethosu_job_open(struct ethosu_file_priv *ethosu_priv)
> {
> struct ethosu_device *dev = ethosu_priv->edev;
> struct drm_gpu_scheduler *sched = &dev->sched;
> + int ret;
>
> - return drm_sched_entity_init(ðosu_priv->sched_entity,
> - DRM_SCHED_PRIORITY_NORMAL,
> - &sched, 1, NULL);
> + guard(mutex)(&dev->sched_lock);
> + ret = drm_sched_entity_init(ðosu_priv->sched_entity,
> + DRM_SCHED_PRIORITY_NORMAL,
> + &sched, 1, NULL);
> + if (!ret)
> + list_add(ðosu_priv->sched_entity_list, &dev->sched_entities);
> +
> + return ret;
> }
>
> void ethosu_job_close(struct ethosu_file_priv *ethosu_priv)
> {
> + struct ethosu_device *dev = ethosu_priv->edev;
> struct drm_sched_entity *entity = ðosu_priv->sched_entity;
>
> + scoped_guard(mutex, &dev->sched_lock) {
> + drm_sched_entity_kill(entity);
> + list_del(ðosu_priv->sched_entity_list);
> + }
> drm_sched_entity_destroy(entity);
> }
[Severity: Medium]
Should ethosu_job_close() call drm_sched_entity_kill() unconditionally before
drm_sched_entity_destroy()?
During normal operation when the device has not been unplugged,
drm_sched_entity_destroy() calls drm_sched_entity_flush() to allow queued jobs
in entity->job_queue to be scheduled before drm_sched_entity_fini() kills the
entity.
Because the scheduler has credit_limit = 1, if userspace submits multiple jobs
or a job waiting on dependencies and then closes the DRM file descriptor,
calling drm_sched_entity_kill() first immediately sets entity->stopped = true
and aborts all unscheduled jobs in entity->job_queue with -ESRCH instead of
flushing them in drm_sched_entity_destroy().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261029-ethosu-fixes-v4-0-4aa25e22578e@kernel.org?part=10
next prev parent reply other threads:[~2026-10-29 14:29 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
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 [this message]
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-189517@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 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.