All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arun Iyengar" <aiyengar1990@gmail.com>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org
Subject: Re: [PATCH v4 5/7] accel/rocket: Reset the core at unbind
Date: Sun, 06 Dec 2026 07:41:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-252255@kernel.org> (raw)
In-Reply-To: <20261206-rocket-fixes-v4-5-75a6279bce98@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] accel/rocket: rocket_job_fini() calls rocket_core_reset()
  without RPM ref
- [Medium] accel/rocket: rocket_job_timedout() NO_HANG races with
  drm_sched_fini()
--

commit 370f6efb177fdda3477d63fbe322d2349ae0184c
Author: Arun Iyengar <aiyengar1990@gmail.com>

accel/rocket: Reset the core at unbind

This commit marks the core as removing during rocket_job_fini(), runs
rocket_reset_work() before calling drm_sched_fini(), rejects new jobs in
rocket_job_run(), and returns DRM_GPU_SCHED_STAT_NO_HANG from
rocket_job_timedout() once removal has started.

> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index d83306eaeb864..b44101800f854 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c

[ ... ]

> @@ -453,6 +456,10 @@ static enum drm_gpu_sched_stat rocket_job_timedout(struct drm_sched_job *sched_j
>  	struct rocket_device *rdev = job->rdev;
>  	struct rocket_core *core = sched_to_core(rdev, sched_job->sched);
>  
> +	/* The reset work queued by rocket_job_fini() resets the core */
> +	if (READ_ONCE(core->removing))
> +		return DRM_GPU_SCHED_STAT_NO_HANG;
> +
>  	dev_err(core->dev, "NPU job timed out");
>  
>  	atomic_set(&core->reset.pending, 1);

[Severity: Medium]
Can returning DRM_GPU_SCHED_STAT_NO_HANG here race with drm_sched_fini()
and leave sched->work_tdr armed on core->reset.wq after it is destroyed?

rocket_job_fini() runs rocket_reset_work(), which calls drm_sched_start().
That restarts submit_wq and re-arms work_tdr while jobs remain on
pending_list.

If work_tdr fires before work_free_job drains pending_list,
drm_sched_job_timedout() calls drm_sched_run_free_queue(), whose
pause_submit check is not serialized with drm_sched_wqueue_stop():

CPU0 (reset.wq / work_tdr)         CPU1 (rocket_job_fini)
drm_sched_job_timedout()
  rocket_job_timedout()
    -> DRM_GPU_SCHED_STAT_NO_HANG
  drm_sched_run_free_queue()
    !drm_sched_is_stopped()
                                   drm_sched_fini()
                                     drm_sched_wqueue_stop()
                                       pause_submit = true
                                       cancel_work_sync(work_free_job)
    queue_work(..., work_free_job)
                                     cancel_delayed_work_sync(work_tdr)
                                     destroy_workqueue(submit_wq)
                                       drm_sched_free_job_work()
                                         drm_sched_start_timeout()
                                   destroy_workqueue(core->reset.wq)
delayed_work_timer_fn()
  queue_work(core->reset.wq, ...)  <-- use-after-free

When drm_sched_wqueue_start() queues work_run_job before work_free_job
while credit_count is 0, a second job can be on pending_list, so the
stray work_free_job re-arms work_tdr after cancel_delayed_work_sync() has
already returned.  When the timer later fires, it accesses the destroyed
core->reset.wq.

With .cancel_job added in commit "accel/rocket: Free the jobs left at
scheduler teardown", drm_sched_cancel_remaining_jobs() also races with
the stray work_free_job and double frees the rocket_job.

Skipping drm_sched_start() in rocket_reset() when core->removing is set
avoids restarting submit_wq and work_tdr during unbind.

[ ... ]

> @@ -553,6 +562,14 @@ int rocket_job_init(struct rocket_core *core)
>  
>  void rocket_job_fini(struct rocket_core *core)
>  {
> +	/*
> +	 * drm_sched_fini() leaves the job on the NPU. Reset the core on the
> +	 * timeout queue, after any running timeout; that cancels pending jobs.
> +	 */
> +	WRITE_ONCE(core->removing, true);
> +	queue_work(core->reset.wq, &core->reset.work);
> +	flush_work(&core->reset.work);
> +
>  	drm_sched_fini(&core->sched);
>  
>  	cancel_work_sync(&core->reset.work);

[Severity: Medium]
Does flushing rocket_reset_work() here call rocket_core_reset() without
holding a runtime PM reference?

In rocket_reset(), pm_runtime_get_if_active() is dropped right after
clearing interrupts rather than held across rocket_core_reset(), and
rocket_core_reset() still runs when pm_runtime_get_if_active() returns 0
and no job is in flight.

On an idle unbind, __device_release_driver() calls pm_runtime_put_sync()
before device_remove(), so core->dev is already runtime-suspended or has
its autosuspend timer armed when rocket_job_fini() runs.

rocket_core_reset() then toggles the AXI/AHB soft resets while the clocks
and power domain are off, or concurrently with rockchip_pd_power()
running rockchip_pmu_set_idle_request(), risking a PMU idle handshake
timeout or power-domain power-off failure.

This breaks the runtime PM invariant from commit 36161ff0c00f
("accel/rocket: let the core suspend after a reset").  Holding the
pm_runtime_get_if_active() reference across rocket_core_reset() and
skipping the reset when already suspended would avoid both.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-rocket-fixes-v4-0-75a6279bce98@gmail.com?part=5

  reply	other threads:[~2026-12-06  7:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  7:17 [PATCH v4 0/7] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar
2026-12-06  7:17 ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 1/7] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 2/7] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 3/7] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 4/7] accel/rocket: Serialise core probe and removal Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 5/7] accel/rocket: Reset the core at unbind Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:41   ` sashiko-bot [this message]
2026-12-06  7:17 ` [PATCH v4 6/7] accel/rocket: Free the jobs left at scheduler teardown Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17 ` [PATCH v4 7/7] accel/rocket: Move open files off a core at unbind Arun Iyengar
2026-12-06  7:17   ` Arun Iyengar via B4 Relay
2026-12-06  7:17   ` Arun Iyengar via B4 Relay

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-252255@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=media-ci@linuxtv.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.