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 v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group
Date: Fri, 04 Dec 2026 07:03:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-249286@kernel.org> (raw)
In-Reply-To: <20261204-rocket-fixes-v2-3-e9f9bb6f1304@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] accel/rocket: rocket_reset() restarts scheduler during
  rocket_job_fini()
--

commit 6fe140dbccf88903c67a0f0dcdcf14ada0be91e3
Author: Arun Iyengar <aiyengar1990@gmail.com>

accel/rocket: Stop the scheduler before releasing the IOMMU group

This commit moves rocket_job_fini() before runtime PM teardown and
iommu_group_put() in rocket_core_fini().

> diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
> index d4c06ad4ba957..e51b64845a8b6 100644
> --- a/drivers/accel/rocket/rocket_core.c
> +++ b/drivers/accel/rocket/rocket_core.c
> @@ -100,11 +100,11 @@ int rocket_core_init(struct rocket_core *core)
>  
>  void rocket_core_fini(struct rocket_core *core)
>  {
> +	rocket_job_fini(core);
>  	pm_runtime_dont_use_autosuspend(core->dev);
>  	pm_runtime_disable(core->dev);
>  	iommu_group_put(core->iommu_group);
>  	core->iommu_group = NULL;
> -	rocket_job_fini(core);
>  }

[Severity: Medium]
Can a concurrent job timeout restart the scheduler during rocket_job_fini()
and cause a use-after-free on core->reset.wq?

CPU0                                CPU1
rocket_core_fini()
  rocket_job_fini()
    drm_sched_fini()
      drm_sched_wqueue_stop()
        pause_submit = true
      cancel_delayed_work_sync(
        &sched->work_tdr) [waits]
                                    drm_sched_job_timedout()
                                      rocket_job_timedout()
                                        rocket_reset()
                                          drm_sched_start()
                                            pause_submit = false
                                            queue work_run_job
      destroy_workqueue(submit_wq)
        drm_sched_run_job_work()
          drm_sched_job_begin()
            mod_delayed_work(
              work_tdr on reset.wq)
          rocket_job_run() [succeeds]
    cancel_work_sync(&reset.work)
    destroy_workqueue(reset.wq)
                                    delayed_work_timer_fn()
                                      <-- use-after-free on reset.wq

Because runtime PM and core->iommu_group stay active during rocket_job_fini(),
rocket_reset() completes and calls drm_sched_start() unconditionally, clearing
pause_submit and queueing work_run_job.

When destroy_workqueue(sched->submit_wq) drains work_run_job after
cancel_delayed_work_sync(&sched->work_tdr) returns, rocket_job_run() starts a
new job on hardware and re-arms sched->work_tdr on core->reset.wq.

rocket_job_fini() then destroys core->reset.wq without canceling work_tdr,
leaving the armed timer pointing at a freed workqueue.  That live job can also
hit a NULL pointer dereference in rocket_job_handle_irq() once
rocket_core_fini() clears core->iommu_group.

Note that commit "accel/rocket: Reset the core at unbind" does not close this
completely because rocket_reset() still calls drm_sched_start() and
drm_sched_get_finished_job() uses non-sync cancel_delayed_work(), which can
still leave work_tdr running against a freed sched->submit_wq.

Skipping drm_sched_start() in rocket_reset() once teardown begins would
prevent the scheduler from restarting during unbind.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-rocket-fixes-v2-0-e9f9bb6f1304@gmail.com?part=3

  reply	other threads:[~2026-12-04  7:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
2026-12-04  6:35 ` Arun Iyengar via B4 Relay
2026-12-04  6:35 ` Arun Iyengar
2026-12-04  6:35 ` [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar
2026-12-04  7:05   ` sashiko-bot
2026-12-04  6:35 ` [PATCH v2 2/4] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar
2026-12-04  6:35 ` [PATCH v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar
2026-12-04  7:03   ` sashiko-bot [this message]
2026-12-04  6:35 ` [PATCH v2 4/4] accel/rocket: Reset the core at unbind Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar via B4 Relay
2026-12-04  6:35   ` Arun Iyengar
2026-12-04  7:02   ` sashiko-bot

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-249286@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.