All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/7] accel/rocket: Fix teardown with a job on the NPU
@ 2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

Fixes for teardown with a job on the NPU: at file close, in the
timeout reset and at core unbind.

1: wait for the file's jobs before its BOs are released.
2: reset the core before detaching its IOMMU (same change as Midgy
   Balon's RK3568 RFC, linked in the patch).
3: stop the scheduler before releasing the IOMMU group.
4: serialise core probe, removal and open (the slot part overlaps
   Igor Paunovic's pending patch, linked in the patch).
5: reset the core at unbind, which also cancels the job on the NPU.
6: free the jobs left at scheduler teardown.
7: move open files off a core at unbind, and back onto it at bind.

Tested on an Orange Pi 5 (RK3588), 7.3, KASAN, unbinding the second of
the three cores. Before: SIGKILL during inference timed out 12 times in
10 kills, faulting jobs gave IOMMU stall timeouts, an unbind during a
timeout oopsed in iommu_detach_group(), close hung on a hung job, and an
unbind with queued jobs hit a use-after-free. After: none of these in 70
kills, 10 faulting jobs and 3-5 runs of each unbind case; on v4 also an
open during a core's probe, SIGKILL of the unbinding task and close of a
killed file after the last unbind (all three reproduced on v3, the last
a use-after-free oops). No KASAN or lockdep report; inference unchanged
after rebinds. The NULL detach from the interrupt handler in patch 5
follows from the code; I could not trigger it.

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Changes in v4:
- Patch 4: hold the lock across open, so a file never gets a core whose
  probe is still running; READ_ONCE()/WRITE_ONCE() on the core's .dev
  (Sashiko).
- Patch 7: close waits until the file's jobs are freed, as killed jobs
  are freed later and use the core (Sashiko).
- Patch 7: only entities on the unbound core are rebuilt; the others,
  and all at bind, get the new core list. No wait for other files' jobs,
  and a signal to the unbinding task no longer kills them (Sashiko).
- Link to v3: https://patch.msgid.link/20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com

Changes in v3:
- Patch 1: wait for the last job that reached the NPU, set in
  rocket_job_run(), not the last one pushed: close no longer waits for
  killed jobs or their fences (Sashiko).
- New patch 4: serialise core probe and removal, take a free slot.
- Patch 5: timeouts during unbind leave the core to the unbind reset and
  do not restart the scheduler (Sashiko).
- Patch 5: the reset work sets reset.pending itself, so a concurrent
  timeout cannot skip the unbind reset (Sashiko).
- New patch 6: .cancel_job, so drm_sched_fini() frees the jobs left
  pending (Sashiko).
- New patch 7: move open files off a core at unbind (was "Not fixed"),
  and back at bind.
- Link to v2: https://patch.msgid.link/20261204-rocket-fixes-v2-0-e9f9bb6f1304@gmail.com

Changes in v2:
- New patch 3: stop the scheduler before releasing the IOMMU group
  (Sashiko).
- New patch 4: reset the core at unbind.
- Patch 1: drop a comment that repeated the commit message.
- Patch 2 unchanged.
- Link to v1: https://patch.msgid.link/20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com

---
Arun Iyengar (7):
      accel/rocket: Wait for in-flight jobs before releasing the file's BOs
      accel/rocket: Reset the core before detaching its IOMMU
      accel/rocket: Stop the scheduler before releasing the IOMMU group
      accel/rocket: Serialise core probe and removal
      accel/rocket: Reset the core at unbind
      accel/rocket: Free the jobs left at scheduler teardown
      accel/rocket: Move open files off a core at unbind

 drivers/accel/rocket/rocket_core.c   |   4 +-
 drivers/accel/rocket/rocket_core.h   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.c    |  79 ++++++++++++---
 drivers/accel/rocket/rocket_drv.h    |  10 ++
 drivers/accel/rocket/rocket_job.c    | 189 +++++++++++++++++++++++++++++++----
 drivers/accel/rocket/rocket_job.h    |   3 +
 8 files changed, 256 insertions(+), 40 deletions(-)
---
base-commit: 502ea48d0d8fa5dd0c31dc449efb3d82deef8efe
change-id: 20261130-rocket-fixes-e1438ca23bee

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v4 0/7] accel/rocket: Fix teardown with a job on the NPU
@ 2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

Fixes for teardown with a job on the NPU: at file close, in the
timeout reset and at core unbind.

1: wait for the file's jobs before its BOs are released.
2: reset the core before detaching its IOMMU (same change as Midgy
   Balon's RK3568 RFC, linked in the patch).
3: stop the scheduler before releasing the IOMMU group.
4: serialise core probe, removal and open (the slot part overlaps
   Igor Paunovic's pending patch, linked in the patch).
5: reset the core at unbind, which also cancels the job on the NPU.
6: free the jobs left at scheduler teardown.
7: move open files off a core at unbind, and back onto it at bind.

Tested on an Orange Pi 5 (RK3588), 7.3, KASAN, unbinding the second of
the three cores. Before: SIGKILL during inference timed out 12 times in
10 kills, faulting jobs gave IOMMU stall timeouts, an unbind during a
timeout oopsed in iommu_detach_group(), close hung on a hung job, and an
unbind with queued jobs hit a use-after-free. After: none of these in 70
kills, 10 faulting jobs and 3-5 runs of each unbind case; on v4 also an
open during a core's probe, SIGKILL of the unbinding task and close of a
killed file after the last unbind (all three reproduced on v3, the last
a use-after-free oops). No KASAN or lockdep report; inference unchanged
after rebinds. The NULL detach from the interrupt handler in patch 5
follows from the code; I could not trigger it.

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Changes in v4:
- Patch 4: hold the lock across open, so a file never gets a core whose
  probe is still running; READ_ONCE()/WRITE_ONCE() on the core's .dev
  (Sashiko).
- Patch 7: close waits until the file's jobs are freed, as killed jobs
  are freed later and use the core (Sashiko).
- Patch 7: only entities on the unbound core are rebuilt; the others,
  and all at bind, get the new core list. No wait for other files' jobs,
  and a signal to the unbinding task no longer kills them (Sashiko).
- Link to v3: https://patch.msgid.link/20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com

Changes in v3:
- Patch 1: wait for the last job that reached the NPU, set in
  rocket_job_run(), not the last one pushed: close no longer waits for
  killed jobs or their fences (Sashiko).
- New patch 4: serialise core probe and removal, take a free slot.
- Patch 5: timeouts during unbind leave the core to the unbind reset and
  do not restart the scheduler (Sashiko).
- Patch 5: the reset work sets reset.pending itself, so a concurrent
  timeout cannot skip the unbind reset (Sashiko).
- New patch 6: .cancel_job, so drm_sched_fini() frees the jobs left
  pending (Sashiko).
- New patch 7: move open files off a core at unbind (was "Not fixed"),
  and back at bind.
- Link to v2: https://patch.msgid.link/20261204-rocket-fixes-v2-0-e9f9bb6f1304@gmail.com

Changes in v2:
- New patch 3: stop the scheduler before releasing the IOMMU group
  (Sashiko).
- New patch 4: reset the core at unbind.
- Patch 1: drop a comment that repeated the commit message.
- Patch 2 unchanged.
- Link to v1: https://patch.msgid.link/20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com

---
Arun Iyengar (7):
      accel/rocket: Wait for in-flight jobs before releasing the file's BOs
      accel/rocket: Reset the core before detaching its IOMMU
      accel/rocket: Stop the scheduler before releasing the IOMMU group
      accel/rocket: Serialise core probe and removal
      accel/rocket: Reset the core at unbind
      accel/rocket: Free the jobs left at scheduler teardown
      accel/rocket: Move open files off a core at unbind

 drivers/accel/rocket/rocket_core.c   |   4 +-
 drivers/accel/rocket/rocket_core.h   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.c    |  79 ++++++++++++---
 drivers/accel/rocket/rocket_drv.h    |  10 ++
 drivers/accel/rocket/rocket_job.c    | 189 +++++++++++++++++++++++++++++++----
 drivers/accel/rocket/rocket_job.h    |   3 +
 8 files changed, 256 insertions(+), 40 deletions(-)
---
base-commit: 502ea48d0d8fa5dd0c31dc449efb3d82deef8efe
change-id: 20261130-rocket-fixes-e1438ca23bee

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v4 0/7] accel/rocket: Fix teardown with a job on the NPU
@ 2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

Fixes for teardown with a job on the NPU: at file close, in the
timeout reset and at core unbind.

1: wait for the file's jobs before its BOs are released.
2: reset the core before detaching its IOMMU (same change as Midgy
   Balon's RK3568 RFC, linked in the patch).
3: stop the scheduler before releasing the IOMMU group.
4: serialise core probe, removal and open (the slot part overlaps
   Igor Paunovic's pending patch, linked in the patch).
5: reset the core at unbind, which also cancels the job on the NPU.
6: free the jobs left at scheduler teardown.
7: move open files off a core at unbind, and back onto it at bind.

Tested on an Orange Pi 5 (RK3588), 7.3, KASAN, unbinding the second of
the three cores. Before: SIGKILL during inference timed out 12 times in
10 kills, faulting jobs gave IOMMU stall timeouts, an unbind during a
timeout oopsed in iommu_detach_group(), close hung on a hung job, and an
unbind with queued jobs hit a use-after-free. After: none of these in 70
kills, 10 faulting jobs and 3-5 runs of each unbind case; on v4 also an
open during a core's probe, SIGKILL of the unbinding task and close of a
killed file after the last unbind (all three reproduced on v3, the last
a use-after-free oops). No KASAN or lockdep report; inference unchanged
after rebinds. The NULL detach from the interrupt handler in patch 5
follows from the code; I could not trigger it.

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Changes in v4:
- Patch 4: hold the lock across open, so a file never gets a core whose
  probe is still running; READ_ONCE()/WRITE_ONCE() on the core's .dev
  (Sashiko).
- Patch 7: close waits until the file's jobs are freed, as killed jobs
  are freed later and use the core (Sashiko).
- Patch 7: only entities on the unbound core are rebuilt; the others,
  and all at bind, get the new core list. No wait for other files' jobs,
  and a signal to the unbinding task no longer kills them (Sashiko).
- Link to v3: https://patch.msgid.link/20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com

Changes in v3:
- Patch 1: wait for the last job that reached the NPU, set in
  rocket_job_run(), not the last one pushed: close no longer waits for
  killed jobs or their fences (Sashiko).
- New patch 4: serialise core probe and removal, take a free slot.
- Patch 5: timeouts during unbind leave the core to the unbind reset and
  do not restart the scheduler (Sashiko).
- Patch 5: the reset work sets reset.pending itself, so a concurrent
  timeout cannot skip the unbind reset (Sashiko).
- New patch 6: .cancel_job, so drm_sched_fini() frees the jobs left
  pending (Sashiko).
- New patch 7: move open files off a core at unbind (was "Not fixed"),
  and back at bind.
- Link to v2: https://patch.msgid.link/20261204-rocket-fixes-v2-0-e9f9bb6f1304@gmail.com

Changes in v2:
- New patch 3: stop the scheduler before releasing the IOMMU group
  (Sashiko).
- New patch 4: reset the core at unbind.
- Patch 1: drop a comment that repeated the commit message.
- Patch 2 unchanged.
- Link to v1: https://patch.msgid.link/20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com

---
Arun Iyengar (7):
      accel/rocket: Wait for in-flight jobs before releasing the file's BOs
      accel/rocket: Reset the core before detaching its IOMMU
      accel/rocket: Stop the scheduler before releasing the IOMMU group
      accel/rocket: Serialise core probe and removal
      accel/rocket: Reset the core at unbind
      accel/rocket: Free the jobs left at scheduler teardown
      accel/rocket: Move open files off a core at unbind

 drivers/accel/rocket/rocket_core.c   |   4 +-
 drivers/accel/rocket/rocket_core.h   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.c    |  79 ++++++++++++---
 drivers/accel/rocket/rocket_drv.h    |  10 ++
 drivers/accel/rocket/rocket_job.c    | 189 +++++++++++++++++++++++++++++++----
 drivers/accel/rocket/rocket_job.h    |   3 +
 8 files changed, 256 insertions(+), 40 deletions(-)
---
base-commit: 502ea48d0d8fa5dd0c31dc449efb3d82deef8efe
change-id: 20261130-rocket-fixes-e1438ca23bee

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v4 1/7] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

drm_release() drops the GEM handles before calling postclose, where the
scheduler entity is torn down. Jobs already on the NPU can use any BO of
the file by address, not only the ones they list, so a killed process
gets its BOs unmapped under a running job. The job then times out.

Tear the entity down from the release fop instead, and wait there for
the last job of the file that reached the NPU.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 24 ++++++++++++++++++++++--
 drivers/accel/rocket/rocket_drv.h |  2 ++
 drivers/accel/rocket/rocket_job.c | 10 ++++++++++
 drivers/accel/rocket/rocket_job.h |  3 +++
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e62a20edeca7..e45b3c22b31e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -3,6 +3,7 @@
 
 #include <drm/drm_accel.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_ioctl.h>
 #include <drm/rocket_accel.h>
@@ -122,7 +123,6 @@ rocket_postclose(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_file_priv *rocket_priv = file->driver_priv;
 
-	rocket_job_close(rocket_priv);
 	rocket_vm_put(rocket_priv->vm);
 	kfree(rocket_priv);
 	module_put(THIS_MODULE);
@@ -138,7 +138,27 @@ static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = {
 	ROCKET_IOCTL(FINI_BO, fini_bo),
 };
 
-DEFINE_DRM_ACCEL_FOPS(rocket_accel_driver_fops);
+static int rocket_release(struct inode *inode, struct file *filp)
+{
+	struct drm_file *file = filp->private_data;
+
+	rocket_job_close(file->driver_priv);
+
+	return drm_release(inode, filp);
+}
+
+static const struct file_operations rocket_accel_driver_fops = {
+	.owner		= THIS_MODULE,
+	.open		= accel_open,
+	.release	= rocket_release,
+	.unlocked_ioctl	= drm_ioctl,
+	.compat_ioctl	= drm_compat_ioctl,
+	.poll		= drm_poll,
+	.read		= drm_read,
+	.llseek		= noop_llseek,
+	.mmap		= drm_gem_mmap,
+	.fop_flags	= FOP_UNSIGNED_OFFSET,
+};
 
 /*
  * Rocket driver version:
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index 7069ececffc4..f7a77ea98467 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -26,6 +26,8 @@ struct rocket_file_priv {
 
 	struct drm_gpu_scheduler **scheds;
 	struct drm_sched_entity sched_entity;
+
+	struct dma_fence *last_job_fence;
 };
 
 struct rocket_vm *rocket_vm_get(struct rocket_file_priv *rocket_priv);
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 454d465a39e3..3fcf1d4ee85f 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -358,6 +358,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 		rocket_job_hw_submit(core, job);
 	}
 
+	dma_fence_put(job->file_priv->last_job_fence);
+	job->file_priv->last_job_fence = dma_fence_get(job->inference_done_fence);
+
 	return fence;
 
 err_put_pm:
@@ -585,6 +588,12 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
 	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
 
 	drm_sched_entity_destroy(entity);
+
+	if (rocket_priv->last_job_fence) {
+		dma_fence_wait(rocket_priv->last_job_fence, false);
+		dma_fence_put(rocket_priv->last_job_fence);
+	}
+
 	kfree(rocket_priv->scheds);
 }
 
@@ -615,6 +624,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 	kref_init(&rjob->refcount);
 
 	rjob->rdev = rdev;
+	rjob->file_priv = file_priv;
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 9373c3d0273b..27db6f861250 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,6 +20,9 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
+	/* Not valid after rocket_job_close() */
+	struct rocket_file_priv *file_priv;
+
 	struct drm_gem_object **in_bos;
 	struct drm_gem_object **out_bos;
 

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 1/7] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_release() drops the GEM handles before calling postclose, where the
scheduler entity is torn down. Jobs already on the NPU can use any BO of
the file by address, not only the ones they list, so a killed process
gets its BOs unmapped under a running job. The job then times out.

Tear the entity down from the release fop instead, and wait there for
the last job of the file that reached the NPU.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 24 ++++++++++++++++++++++--
 drivers/accel/rocket/rocket_drv.h |  2 ++
 drivers/accel/rocket/rocket_job.c | 10 ++++++++++
 drivers/accel/rocket/rocket_job.h |  3 +++
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e62a20edeca7..e45b3c22b31e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -3,6 +3,7 @@
 
 #include <drm/drm_accel.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_ioctl.h>
 #include <drm/rocket_accel.h>
@@ -122,7 +123,6 @@ rocket_postclose(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_file_priv *rocket_priv = file->driver_priv;
 
-	rocket_job_close(rocket_priv);
 	rocket_vm_put(rocket_priv->vm);
 	kfree(rocket_priv);
 	module_put(THIS_MODULE);
@@ -138,7 +138,27 @@ static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = {
 	ROCKET_IOCTL(FINI_BO, fini_bo),
 };
 
-DEFINE_DRM_ACCEL_FOPS(rocket_accel_driver_fops);
+static int rocket_release(struct inode *inode, struct file *filp)
+{
+	struct drm_file *file = filp->private_data;
+
+	rocket_job_close(file->driver_priv);
+
+	return drm_release(inode, filp);
+}
+
+static const struct file_operations rocket_accel_driver_fops = {
+	.owner		= THIS_MODULE,
+	.open		= accel_open,
+	.release	= rocket_release,
+	.unlocked_ioctl	= drm_ioctl,
+	.compat_ioctl	= drm_compat_ioctl,
+	.poll		= drm_poll,
+	.read		= drm_read,
+	.llseek		= noop_llseek,
+	.mmap		= drm_gem_mmap,
+	.fop_flags	= FOP_UNSIGNED_OFFSET,
+};
 
 /*
  * Rocket driver version:
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index 7069ececffc4..f7a77ea98467 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -26,6 +26,8 @@ struct rocket_file_priv {
 
 	struct drm_gpu_scheduler **scheds;
 	struct drm_sched_entity sched_entity;
+
+	struct dma_fence *last_job_fence;
 };
 
 struct rocket_vm *rocket_vm_get(struct rocket_file_priv *rocket_priv);
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 454d465a39e3..3fcf1d4ee85f 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -358,6 +358,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 		rocket_job_hw_submit(core, job);
 	}
 
+	dma_fence_put(job->file_priv->last_job_fence);
+	job->file_priv->last_job_fence = dma_fence_get(job->inference_done_fence);
+
 	return fence;
 
 err_put_pm:
@@ -585,6 +588,12 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
 	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
 
 	drm_sched_entity_destroy(entity);
+
+	if (rocket_priv->last_job_fence) {
+		dma_fence_wait(rocket_priv->last_job_fence, false);
+		dma_fence_put(rocket_priv->last_job_fence);
+	}
+
 	kfree(rocket_priv->scheds);
 }
 
@@ -615,6 +624,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 	kref_init(&rjob->refcount);
 
 	rjob->rdev = rdev;
+	rjob->file_priv = file_priv;
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 9373c3d0273b..27db6f861250 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,6 +20,9 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
+	/* Not valid after rocket_job_close() */
+	struct rocket_file_priv *file_priv;
+
 	struct drm_gem_object **in_bos;
 	struct drm_gem_object **out_bos;
 

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 1/7] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_release() drops the GEM handles before calling postclose, where the
scheduler entity is torn down. Jobs already on the NPU can use any BO of
the file by address, not only the ones they list, so a killed process
gets its BOs unmapped under a running job. The job then times out.

Tear the entity down from the release fop instead, and wait there for
the last job of the file that reached the NPU.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 24 ++++++++++++++++++++++--
 drivers/accel/rocket/rocket_drv.h |  2 ++
 drivers/accel/rocket/rocket_job.c | 10 ++++++++++
 drivers/accel/rocket/rocket_job.h |  3 +++
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e62a20edeca7..e45b3c22b31e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -3,6 +3,7 @@
 
 #include <drm/drm_accel.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_ioctl.h>
 #include <drm/rocket_accel.h>
@@ -122,7 +123,6 @@ rocket_postclose(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_file_priv *rocket_priv = file->driver_priv;
 
-	rocket_job_close(rocket_priv);
 	rocket_vm_put(rocket_priv->vm);
 	kfree(rocket_priv);
 	module_put(THIS_MODULE);
@@ -138,7 +138,27 @@ static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = {
 	ROCKET_IOCTL(FINI_BO, fini_bo),
 };
 
-DEFINE_DRM_ACCEL_FOPS(rocket_accel_driver_fops);
+static int rocket_release(struct inode *inode, struct file *filp)
+{
+	struct drm_file *file = filp->private_data;
+
+	rocket_job_close(file->driver_priv);
+
+	return drm_release(inode, filp);
+}
+
+static const struct file_operations rocket_accel_driver_fops = {
+	.owner		= THIS_MODULE,
+	.open		= accel_open,
+	.release	= rocket_release,
+	.unlocked_ioctl	= drm_ioctl,
+	.compat_ioctl	= drm_compat_ioctl,
+	.poll		= drm_poll,
+	.read		= drm_read,
+	.llseek		= noop_llseek,
+	.mmap		= drm_gem_mmap,
+	.fop_flags	= FOP_UNSIGNED_OFFSET,
+};
 
 /*
  * Rocket driver version:
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index 7069ececffc4..f7a77ea98467 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -26,6 +26,8 @@ struct rocket_file_priv {
 
 	struct drm_gpu_scheduler **scheds;
 	struct drm_sched_entity sched_entity;
+
+	struct dma_fence *last_job_fence;
 };
 
 struct rocket_vm *rocket_vm_get(struct rocket_file_priv *rocket_priv);
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 454d465a39e3..3fcf1d4ee85f 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -358,6 +358,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 		rocket_job_hw_submit(core, job);
 	}
 
+	dma_fence_put(job->file_priv->last_job_fence);
+	job->file_priv->last_job_fence = dma_fence_get(job->inference_done_fence);
+
 	return fence;
 
 err_put_pm:
@@ -585,6 +588,12 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
 	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
 
 	drm_sched_entity_destroy(entity);
+
+	if (rocket_priv->last_job_fence) {
+		dma_fence_wait(rocket_priv->last_job_fence, false);
+		dma_fence_put(rocket_priv->last_job_fence);
+	}
+
 	kfree(rocket_priv->scheds);
 }
 
@@ -615,6 +624,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 	kref_init(&rjob->refcount);
 
 	rjob->rdev = rdev;
+	rjob->file_priv = file_priv;
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 9373c3d0273b..27db6f861250 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,6 +20,9 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
+	/* Not valid after rocket_job_close() */
+	struct rocket_file_priv *file_priv;
+
 	struct drm_gem_object **in_bos;
 	struct drm_gem_object **out_bos;
 

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 2/7] accel/rocket: Reset the core before detaching its IOMMU
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

Midgy Balon posted the same change in an RK3568 RFC series [1].

A timed-out job leaves the NPU master hung on the bus. The IOMMU then
cannot enter stall mode, the detach fails and the IOMMU core warns:

  rk_iommu fdab9000.iommu: Enable stall request timed out, status: 0x0001cb
  WARNING: drivers/iommu/iommu.c:157 at __iommu_group_set_core_domain+0x5c/0x98

Reset the core first, as the vendor driver does.

Link: https://lore.kernel.org/r/20260613070116.438906-5-midgy971@gmail.com [1]
Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Cc: Midgy BALON <midgy971@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 3fcf1d4ee85f..d83306eaeb86 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -426,15 +426,17 @@ rocket_reset(struct rocket_core *core, struct drm_sched_job *bad)
 	 */
 	scoped_guard(mutex, &core->job_lock) {
 		put_job_ref = core->in_flight_job;
-
-		iommu_detach_group(NULL, core->iommu_group);
-
 		core->in_flight_job = NULL;
 	}
 
-	/* Proceed with reset now. */
+	/*
+	 * Reset before detaching: the IOMMU cannot stall while a hung job
+	 * keeps the bus busy, and then the detach fails.
+	 */
 	rocket_core_reset(core);
 
+	iommu_detach_group(NULL, core->iommu_group);
+
 	if (put_job_ref)
 		pm_runtime_put_autosuspend(core->dev);
 

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 2/7] accel/rocket: Reset the core before detaching its IOMMU
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

Midgy Balon posted the same change in an RK3568 RFC series [1].

A timed-out job leaves the NPU master hung on the bus. The IOMMU then
cannot enter stall mode, the detach fails and the IOMMU core warns:

  rk_iommu fdab9000.iommu: Enable stall request timed out, status: 0x0001cb
  WARNING: drivers/iommu/iommu.c:157 at __iommu_group_set_core_domain+0x5c/0x98

Reset the core first, as the vendor driver does.

Link: https://lore.kernel.org/r/20260613070116.438906-5-midgy971@gmail.com [1]
Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Cc: Midgy BALON <midgy971@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 3fcf1d4ee85f..d83306eaeb86 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -426,15 +426,17 @@ rocket_reset(struct rocket_core *core, struct drm_sched_job *bad)
 	 */
 	scoped_guard(mutex, &core->job_lock) {
 		put_job_ref = core->in_flight_job;
-
-		iommu_detach_group(NULL, core->iommu_group);
-
 		core->in_flight_job = NULL;
 	}
 
-	/* Proceed with reset now. */
+	/*
+	 * Reset before detaching: the IOMMU cannot stall while a hung job
+	 * keeps the bus busy, and then the detach fails.
+	 */
 	rocket_core_reset(core);
 
+	iommu_detach_group(NULL, core->iommu_group);
+
 	if (put_job_ref)
 		pm_runtime_put_autosuspend(core->dev);
 

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 2/7] accel/rocket: Reset the core before detaching its IOMMU
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

Midgy Balon posted the same change in an RK3568 RFC series [1].

A timed-out job leaves the NPU master hung on the bus. The IOMMU then
cannot enter stall mode, the detach fails and the IOMMU core warns:

  rk_iommu fdab9000.iommu: Enable stall request timed out, status: 0x0001cb
  WARNING: drivers/iommu/iommu.c:157 at __iommu_group_set_core_domain+0x5c/0x98

Reset the core first, as the vendor driver does.

Link: https://lore.kernel.org/r/20260613070116.438906-5-midgy971@gmail.com [1]
Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Cc: Midgy BALON <midgy971@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 3fcf1d4ee85f..d83306eaeb86 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -426,15 +426,17 @@ rocket_reset(struct rocket_core *core, struct drm_sched_job *bad)
 	 */
 	scoped_guard(mutex, &core->job_lock) {
 		put_job_ref = core->in_flight_job;
-
-		iommu_detach_group(NULL, core->iommu_group);
-
 		core->in_flight_job = NULL;
 	}
 
-	/* Proceed with reset now. */
+	/*
+	 * Reset before detaching: the IOMMU cannot stall while a hung job
+	 * keeps the bus busy, and then the detach fails.
+	 */
 	rocket_core_reset(core);
 
+	iommu_detach_group(NULL, core->iommu_group);
+
 	if (put_job_ref)
 		pm_runtime_put_autosuspend(core->dev);
 

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 3/7] accel/rocket: Stop the scheduler before releasing the IOMMU group
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

rocket_core_fini() disables runtime PM and drops the IOMMU group before
it stops the scheduler. A job that times out in between runs
rocket_reset(), which detaches a NULL group and drops a runtime PM
reference of a disabled device.

Stop the scheduler first.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index d4c06ad4ba95..e51b64845a8b 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);
 }
 
 void rocket_core_reset(struct rocket_core *core)

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 3/7] accel/rocket: Stop the scheduler before releasing the IOMMU group
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

rocket_core_fini() disables runtime PM and drops the IOMMU group before
it stops the scheduler. A job that times out in between runs
rocket_reset(), which detaches a NULL group and drops a runtime PM
reference of a disabled device.

Stop the scheduler first.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index d4c06ad4ba95..e51b64845a8b 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);
 }
 
 void rocket_core_reset(struct rocket_core *core)

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 3/7] accel/rocket: Stop the scheduler before releasing the IOMMU group
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

rocket_core_fini() disables runtime PM and drops the IOMMU group before
it stops the scheduler. A job that times out in between runs
rocket_reset(), which detaches a NULL group and drops a runtime PM
reference of a disabled device.

Stop the scheduler first.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index d4c06ad4ba95..e51b64845a8b 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);
 }
 
 void rocket_core_reset(struct rocket_core *core)

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 4/7] accel/rocket: Serialise core probe and removal
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].

rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound, and can
put a core whose probe is still running in the file's entity:
drm_sched_init() marks it ready before runtime PM is enabled. Two
unbinds through sysfs can run at once and race on num_cores.

Take the first free slot, clear it at removal, open on a bound core,
and serialise probe, removal and open under a mutex.

Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 55 ++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 13 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..ccaedb004d19 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
+#include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
 static struct platform_device *drm_dev;
 static struct rocket_device *rdev;
 static void *rdev_group;
+/* Serialises core probe, removal and open */
+static DEFINE_MUTEX(rocket_cores_lock);
 
 static void
 rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_device *rdev = to_rocket_device(dev);
 	struct rocket_file_priv *rocket_priv;
+	unsigned int core;
 	int ret;
 
 	if (!try_module_get(THIS_MODULE))
@@ -95,17 +99,28 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 	}
 
 	rocket_priv->rdev = rdev;
-	rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
-	if (IS_ERR(rocket_priv->vm)) {
-		ret = PTR_ERR(rocket_priv->vm);
-		goto err_free;
-	}
+	rocket_priv->vm = ERR_PTR(-ENODEV);
+
+	scoped_guard(mutex, &rocket_cores_lock) {
+		for (core = 0; core < rdev->max_cores; core++) {
+			if (rdev->cores[core].dev) {
+				rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+				break;
+			}
+		}
 
-	file->driver_priv = rocket_priv;
+		if (IS_ERR(rocket_priv->vm)) {
+			ret = PTR_ERR(rocket_priv->vm);
+			goto err_free;
+		}
 
-	ret = rocket_job_open(rocket_priv);
-	if (ret)
-		goto err_vm_put;
+		file->driver_priv = rocket_priv;
+
+		/* Not on a core whose probe is still running */
+		ret = rocket_job_open(rocket_priv);
+		if (ret)
+			goto err_vm_put;
+	}
 
 	return 0;
 
@@ -195,11 +210,14 @@ static int rocket_core_hw_index(struct device *dev)
 static int rocket_probe(struct platform_device *pdev)
 {
 	int index = rocket_core_hw_index(&pdev->dev);
+	unsigned int core;
 	int ret;
 
 	if (index < 0)
 		return index;
 
+	guard(mutex)(&rocket_cores_lock);
+
 	if (rdev == NULL) {
 		/* First core probing, initialize DRM device. */
 		rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,18 +235,25 @@ static int rocket_probe(struct platform_device *pdev)
 		devres_close_group(&drm_dev->dev, rdev_group);
 	}
 
-	unsigned int core = rdev->num_cores;
+	/* Cores can unbind and rebind in any order */
+	for (core = 0; core < rdev->max_cores; core++)
+		if (!rdev->cores[core].dev)
+			break;
+	if (WARN_ON(core == rdev->max_cores))
+		return -EBUSY;
 
 	dev_set_drvdata(&pdev->dev, rdev);
 
 	rdev->cores[core].rdev = rdev;
-	rdev->cores[core].dev = &pdev->dev;
+	/* Runtime PM looks the core up without the lock */
+	WRITE_ONCE(rdev->cores[core].dev, &pdev->dev);
 	rdev->cores[core].index = index;
 
 	rdev->num_cores++;
 
 	ret = rocket_core_init(&rdev->cores[core]);
 	if (ret) {
+		WRITE_ONCE(rdev->cores[core].dev, NULL);
 		rdev->num_cores--;
 
 		if (rdev->num_cores == 0) {
@@ -246,12 +271,16 @@ static int find_core_for_dev(struct device *dev);
 static void rocket_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	int core = find_core_for_dev(dev);
+	int core;
+
+	guard(mutex)(&rocket_cores_lock);
 
+	core = find_core_for_dev(dev);
 	if (core < 0)
 		return;
 
 	rocket_core_fini(&rdev->cores[core]);
+	WRITE_ONCE(rdev->cores[core].dev, NULL);
 	rdev->num_cores--;
 
 	if (rdev->num_cores == 0) {
@@ -273,7 +302,7 @@ static int find_core_for_dev(struct device *dev)
 	struct rocket_device *rdev = dev_get_drvdata(dev);
 
 	for (unsigned int core = 0; core < rdev->max_cores; core++) {
-		if (dev == rdev->cores[core].dev)
+		if (dev == READ_ONCE(rdev->cores[core].dev))
 			return core;
 	}
 

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 4/7] accel/rocket: Serialise core probe and removal
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].

rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound, and can
put a core whose probe is still running in the file's entity:
drm_sched_init() marks it ready before runtime PM is enabled. Two
unbinds through sysfs can run at once and race on num_cores.

Take the first free slot, clear it at removal, open on a bound core,
and serialise probe, removal and open under a mutex.

Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 55 ++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 13 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..ccaedb004d19 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
+#include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
 static struct platform_device *drm_dev;
 static struct rocket_device *rdev;
 static void *rdev_group;
+/* Serialises core probe, removal and open */
+static DEFINE_MUTEX(rocket_cores_lock);
 
 static void
 rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_device *rdev = to_rocket_device(dev);
 	struct rocket_file_priv *rocket_priv;
+	unsigned int core;
 	int ret;
 
 	if (!try_module_get(THIS_MODULE))
@@ -95,17 +99,28 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 	}
 
 	rocket_priv->rdev = rdev;
-	rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
-	if (IS_ERR(rocket_priv->vm)) {
-		ret = PTR_ERR(rocket_priv->vm);
-		goto err_free;
-	}
+	rocket_priv->vm = ERR_PTR(-ENODEV);
+
+	scoped_guard(mutex, &rocket_cores_lock) {
+		for (core = 0; core < rdev->max_cores; core++) {
+			if (rdev->cores[core].dev) {
+				rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+				break;
+			}
+		}
 
-	file->driver_priv = rocket_priv;
+		if (IS_ERR(rocket_priv->vm)) {
+			ret = PTR_ERR(rocket_priv->vm);
+			goto err_free;
+		}
 
-	ret = rocket_job_open(rocket_priv);
-	if (ret)
-		goto err_vm_put;
+		file->driver_priv = rocket_priv;
+
+		/* Not on a core whose probe is still running */
+		ret = rocket_job_open(rocket_priv);
+		if (ret)
+			goto err_vm_put;
+	}
 
 	return 0;
 
@@ -195,11 +210,14 @@ static int rocket_core_hw_index(struct device *dev)
 static int rocket_probe(struct platform_device *pdev)
 {
 	int index = rocket_core_hw_index(&pdev->dev);
+	unsigned int core;
 	int ret;
 
 	if (index < 0)
 		return index;
 
+	guard(mutex)(&rocket_cores_lock);
+
 	if (rdev == NULL) {
 		/* First core probing, initialize DRM device. */
 		rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,18 +235,25 @@ static int rocket_probe(struct platform_device *pdev)
 		devres_close_group(&drm_dev->dev, rdev_group);
 	}
 
-	unsigned int core = rdev->num_cores;
+	/* Cores can unbind and rebind in any order */
+	for (core = 0; core < rdev->max_cores; core++)
+		if (!rdev->cores[core].dev)
+			break;
+	if (WARN_ON(core == rdev->max_cores))
+		return -EBUSY;
 
 	dev_set_drvdata(&pdev->dev, rdev);
 
 	rdev->cores[core].rdev = rdev;
-	rdev->cores[core].dev = &pdev->dev;
+	/* Runtime PM looks the core up without the lock */
+	WRITE_ONCE(rdev->cores[core].dev, &pdev->dev);
 	rdev->cores[core].index = index;
 
 	rdev->num_cores++;
 
 	ret = rocket_core_init(&rdev->cores[core]);
 	if (ret) {
+		WRITE_ONCE(rdev->cores[core].dev, NULL);
 		rdev->num_cores--;
 
 		if (rdev->num_cores == 0) {
@@ -246,12 +271,16 @@ static int find_core_for_dev(struct device *dev);
 static void rocket_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	int core = find_core_for_dev(dev);
+	int core;
+
+	guard(mutex)(&rocket_cores_lock);
 
+	core = find_core_for_dev(dev);
 	if (core < 0)
 		return;
 
 	rocket_core_fini(&rdev->cores[core]);
+	WRITE_ONCE(rdev->cores[core].dev, NULL);
 	rdev->num_cores--;
 
 	if (rdev->num_cores == 0) {
@@ -273,7 +302,7 @@ static int find_core_for_dev(struct device *dev)
 	struct rocket_device *rdev = dev_get_drvdata(dev);
 
 	for (unsigned int core = 0; core < rdev->max_cores; core++) {
-		if (dev == rdev->cores[core].dev)
+		if (dev == READ_ONCE(rdev->cores[core].dev))
 			return core;
 	}
 

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 4/7] accel/rocket: Serialise core probe and removal
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].

rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound, and can
put a core whose probe is still running in the file's entity:
drm_sched_init() marks it ready before runtime PM is enabled. Two
unbinds through sysfs can run at once and race on num_cores.

Take the first free slot, clear it at removal, open on a bound core,
and serialise probe, removal and open under a mutex.

Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_drv.c | 55 ++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 13 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..ccaedb004d19 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
+#include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
 static struct platform_device *drm_dev;
 static struct rocket_device *rdev;
 static void *rdev_group;
+/* Serialises core probe, removal and open */
+static DEFINE_MUTEX(rocket_cores_lock);
 
 static void
 rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 {
 	struct rocket_device *rdev = to_rocket_device(dev);
 	struct rocket_file_priv *rocket_priv;
+	unsigned int core;
 	int ret;
 
 	if (!try_module_get(THIS_MODULE))
@@ -95,17 +99,28 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
 	}
 
 	rocket_priv->rdev = rdev;
-	rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
-	if (IS_ERR(rocket_priv->vm)) {
-		ret = PTR_ERR(rocket_priv->vm);
-		goto err_free;
-	}
+	rocket_priv->vm = ERR_PTR(-ENODEV);
+
+	scoped_guard(mutex, &rocket_cores_lock) {
+		for (core = 0; core < rdev->max_cores; core++) {
+			if (rdev->cores[core].dev) {
+				rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+				break;
+			}
+		}
 
-	file->driver_priv = rocket_priv;
+		if (IS_ERR(rocket_priv->vm)) {
+			ret = PTR_ERR(rocket_priv->vm);
+			goto err_free;
+		}
 
-	ret = rocket_job_open(rocket_priv);
-	if (ret)
-		goto err_vm_put;
+		file->driver_priv = rocket_priv;
+
+		/* Not on a core whose probe is still running */
+		ret = rocket_job_open(rocket_priv);
+		if (ret)
+			goto err_vm_put;
+	}
 
 	return 0;
 
@@ -195,11 +210,14 @@ static int rocket_core_hw_index(struct device *dev)
 static int rocket_probe(struct platform_device *pdev)
 {
 	int index = rocket_core_hw_index(&pdev->dev);
+	unsigned int core;
 	int ret;
 
 	if (index < 0)
 		return index;
 
+	guard(mutex)(&rocket_cores_lock);
+
 	if (rdev == NULL) {
 		/* First core probing, initialize DRM device. */
 		rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,18 +235,25 @@ static int rocket_probe(struct platform_device *pdev)
 		devres_close_group(&drm_dev->dev, rdev_group);
 	}
 
-	unsigned int core = rdev->num_cores;
+	/* Cores can unbind and rebind in any order */
+	for (core = 0; core < rdev->max_cores; core++)
+		if (!rdev->cores[core].dev)
+			break;
+	if (WARN_ON(core == rdev->max_cores))
+		return -EBUSY;
 
 	dev_set_drvdata(&pdev->dev, rdev);
 
 	rdev->cores[core].rdev = rdev;
-	rdev->cores[core].dev = &pdev->dev;
+	/* Runtime PM looks the core up without the lock */
+	WRITE_ONCE(rdev->cores[core].dev, &pdev->dev);
 	rdev->cores[core].index = index;
 
 	rdev->num_cores++;
 
 	ret = rocket_core_init(&rdev->cores[core]);
 	if (ret) {
+		WRITE_ONCE(rdev->cores[core].dev, NULL);
 		rdev->num_cores--;
 
 		if (rdev->num_cores == 0) {
@@ -246,12 +271,16 @@ static int find_core_for_dev(struct device *dev);
 static void rocket_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	int core = find_core_for_dev(dev);
+	int core;
+
+	guard(mutex)(&rocket_cores_lock);
 
+	core = find_core_for_dev(dev);
 	if (core < 0)
 		return;
 
 	rocket_core_fini(&rdev->cores[core]);
+	WRITE_ONCE(rdev->cores[core].dev, NULL);
 	rdev->num_cores--;
 
 	if (rdev->num_cores == 0) {
@@ -273,7 +302,7 @@ static int find_core_for_dev(struct device *dev)
 	struct rocket_device *rdev = dev_get_drvdata(dev);
 
 	for (unsigned int core = 0; core < rdev->max_cores; core++) {
-		if (dev == rdev->cores[core].dev)
+		if (dev == READ_ONCE(rdev->cores[core].dev))
 			return core;
 	}
 

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 5/7] accel/rocket: Reset the core at unbind
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

drm_sched_fini() leaves the job on the NPU running. If it completes
before devres frees the interrupt, rocket_job_handle_irq() detaches
a NULL IOMMU group. If it hangs, its fence never signals and a file
close waiting for it blocks forever.

Reset the core before stopping the scheduler, as on a timeout, and
do not start jobs after that. Timeouts from then on leave the core to
that reset, so none restarts the scheduler during drm_sched_fini().

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.h |  2 ++
 drivers/accel/rocket/rocket_job.c  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/accel/rocket/rocket_core.h b/drivers/accel/rocket/rocket_core.h
index 0b7e82ae7ef2..6bbdba221e9e 100644
--- a/drivers/accel/rocket/rocket_core.h
+++ b/drivers/accel/rocket/rocket_core.h
@@ -64,6 +64,8 @@ struct rocket_core {
 		atomic_t pending;
 	} reset;
 
+	bool removing;
+
 	struct drm_gpu_scheduler sched;
 	u64 fence_context;
 	u64 emit_seqno;
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index d83306eaeb86..b44101800f85 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -330,6 +330,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 	if (unlikely(job->base.s_fence->finished.error))
 		return NULL;
 
+	if (READ_ONCE(core->removing))
+		return ERR_PTR(-ENODEV);
+
 	/*
 	 * Nothing to execute: can happen if the job has finished while
 	 * we were resetting the NPU.
@@ -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);
@@ -466,6 +473,7 @@ static void rocket_reset_work(struct work_struct *work)
 	struct rocket_core *core;
 
 	core = container_of(work, struct rocket_core, reset.work);
+	atomic_set(&core->reset.pending, 1);
 	rocket_reset(core, NULL);
 }
 
@@ -514,6 +522,7 @@ int rocket_job_init(struct rocket_core *core)
 	int ret;
 
 	INIT_WORK(&core->reset.work, rocket_reset_work);
+	core->removing = false;
 	spin_lock_init(&core->fence_lock);
 	mutex_init(&core->job_lock);
 
@@ -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);

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 5/7] accel/rocket: Reset the core at unbind
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_sched_fini() leaves the job on the NPU running. If it completes
before devres frees the interrupt, rocket_job_handle_irq() detaches
a NULL IOMMU group. If it hangs, its fence never signals and a file
close waiting for it blocks forever.

Reset the core before stopping the scheduler, as on a timeout, and
do not start jobs after that. Timeouts from then on leave the core to
that reset, so none restarts the scheduler during drm_sched_fini().

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.h |  2 ++
 drivers/accel/rocket/rocket_job.c  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/accel/rocket/rocket_core.h b/drivers/accel/rocket/rocket_core.h
index 0b7e82ae7ef2..6bbdba221e9e 100644
--- a/drivers/accel/rocket/rocket_core.h
+++ b/drivers/accel/rocket/rocket_core.h
@@ -64,6 +64,8 @@ struct rocket_core {
 		atomic_t pending;
 	} reset;
 
+	bool removing;
+
 	struct drm_gpu_scheduler sched;
 	u64 fence_context;
 	u64 emit_seqno;
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index d83306eaeb86..b44101800f85 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -330,6 +330,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 	if (unlikely(job->base.s_fence->finished.error))
 		return NULL;
 
+	if (READ_ONCE(core->removing))
+		return ERR_PTR(-ENODEV);
+
 	/*
 	 * Nothing to execute: can happen if the job has finished while
 	 * we were resetting the NPU.
@@ -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);
@@ -466,6 +473,7 @@ static void rocket_reset_work(struct work_struct *work)
 	struct rocket_core *core;
 
 	core = container_of(work, struct rocket_core, reset.work);
+	atomic_set(&core->reset.pending, 1);
 	rocket_reset(core, NULL);
 }
 
@@ -514,6 +522,7 @@ int rocket_job_init(struct rocket_core *core)
 	int ret;
 
 	INIT_WORK(&core->reset.work, rocket_reset_work);
+	core->removing = false;
 	spin_lock_init(&core->fence_lock);
 	mutex_init(&core->job_lock);
 
@@ -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);

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 5/7] accel/rocket: Reset the core at unbind
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_sched_fini() leaves the job on the NPU running. If it completes
before devres frees the interrupt, rocket_job_handle_irq() detaches
a NULL IOMMU group. If it hangs, its fence never signals and a file
close waiting for it blocks forever.

Reset the core before stopping the scheduler, as on a timeout, and
do not start jobs after that. Timeouts from then on leave the core to
that reset, so none restarts the scheduler during drm_sched_fini().

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.h |  2 ++
 drivers/accel/rocket/rocket_job.c  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/accel/rocket/rocket_core.h b/drivers/accel/rocket/rocket_core.h
index 0b7e82ae7ef2..6bbdba221e9e 100644
--- a/drivers/accel/rocket/rocket_core.h
+++ b/drivers/accel/rocket/rocket_core.h
@@ -64,6 +64,8 @@ struct rocket_core {
 		atomic_t pending;
 	} reset;
 
+	bool removing;
+
 	struct drm_gpu_scheduler sched;
 	u64 fence_context;
 	u64 emit_seqno;
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index d83306eaeb86..b44101800f85 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -330,6 +330,9 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)
 	if (unlikely(job->base.s_fence->finished.error))
 		return NULL;
 
+	if (READ_ONCE(core->removing))
+		return ERR_PTR(-ENODEV);
+
 	/*
 	 * Nothing to execute: can happen if the job has finished while
 	 * we were resetting the NPU.
@@ -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);
@@ -466,6 +473,7 @@ static void rocket_reset_work(struct work_struct *work)
 	struct rocket_core *core;
 
 	core = container_of(work, struct rocket_core, reset.work);
+	atomic_set(&core->reset.pending, 1);
 	rocket_reset(core, NULL);
 }
 
@@ -514,6 +522,7 @@ int rocket_job_init(struct rocket_core *core)
 	int ret;
 
 	INIT_WORK(&core->reset.work, rocket_reset_work);
+	core->removing = false;
 	spin_lock_init(&core->fence_lock);
 	mutex_init(&core->job_lock);
 
@@ -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);

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 6/7] accel/rocket: Free the jobs left at scheduler teardown
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

drm_sched_fini() frees the jobs still on the pending list only if the
driver has a .cancel_job callback. Rocket has none, so a job pending
when a core is unbound leaks with its BO and VM references.

Add .cancel_job: signal the job's hardware fence with -ECANCELED.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index b44101800f85..53f0751d7a1e 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -477,10 +477,21 @@ static void rocket_reset_work(struct work_struct *work)
 	rocket_reset(core, NULL);
 }
 
+static void rocket_job_cancel(struct drm_sched_job *sched_job)
+{
+	struct rocket_job *job = to_rocket_job(sched_job);
+
+	if (job->done_fence && !dma_fence_is_signaled(job->done_fence)) {
+		dma_fence_set_error(job->done_fence, -ECANCELED);
+		dma_fence_signal(job->done_fence);
+	}
+}
+
 static const struct drm_sched_backend_ops rocket_sched_ops = {
 	.run_job = rocket_job_run,
 	.timedout_job = rocket_job_timedout,
-	.free_job = rocket_job_free
+	.free_job = rocket_job_free,
+	.cancel_job = rocket_job_cancel,
 };
 
 static irqreturn_t rocket_job_irq_handler_thread(int irq, void *data)

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 6/7] accel/rocket: Free the jobs left at scheduler teardown
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_sched_fini() frees the jobs still on the pending list only if the
driver has a .cancel_job callback. Rocket has none, so a job pending
when a core is unbound leaks with its BO and VM references.

Add .cancel_job: signal the job's hardware fence with -ECANCELED.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index b44101800f85..53f0751d7a1e 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -477,10 +477,21 @@ static void rocket_reset_work(struct work_struct *work)
 	rocket_reset(core, NULL);
 }
 
+static void rocket_job_cancel(struct drm_sched_job *sched_job)
+{
+	struct rocket_job *job = to_rocket_job(sched_job);
+
+	if (job->done_fence && !dma_fence_is_signaled(job->done_fence)) {
+		dma_fence_set_error(job->done_fence, -ECANCELED);
+		dma_fence_signal(job->done_fence);
+	}
+}
+
 static const struct drm_sched_backend_ops rocket_sched_ops = {
 	.run_job = rocket_job_run,
 	.timedout_job = rocket_job_timedout,
-	.free_job = rocket_job_free
+	.free_job = rocket_job_free,
+	.cancel_job = rocket_job_cancel,
 };
 
 static irqreturn_t rocket_job_irq_handler_thread(int irq, void *data)

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 6/7] accel/rocket: Free the jobs left at scheduler teardown
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

drm_sched_fini() frees the jobs still on the pending list only if the
driver has a .cancel_job callback. Rocket has none, so a job pending
when a core is unbound leaks with its BO and VM references.

Add .cancel_job: signal the job's hardware fence with -ECANCELED.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_job.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index b44101800f85..53f0751d7a1e 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -477,10 +477,21 @@ static void rocket_reset_work(struct work_struct *work)
 	rocket_reset(core, NULL);
 }
 
+static void rocket_job_cancel(struct drm_sched_job *sched_job)
+{
+	struct rocket_job *job = to_rocket_job(sched_job);
+
+	if (job->done_fence && !dma_fence_is_signaled(job->done_fence)) {
+		dma_fence_set_error(job->done_fence, -ECANCELED);
+		dma_fence_signal(job->done_fence);
+	}
+}
+
 static const struct drm_sched_backend_ops rocket_sched_ops = {
 	.run_job = rocket_job_run,
 	.timedout_job = rocket_job_timedout,
-	.free_job = rocket_job_free
+	.free_job = rocket_job_free,
+	.cancel_job = rocket_job_cancel,
 };
 
 static irqreturn_t rocket_job_irq_handler_thread(int irq, void *data)

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 7/7] accel/rocket: Move open files off a core at unbind
  2026-12-06  7:17 ` Arun Iyengar via B4 Relay
  (?)
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  -1 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

A file's scheduler entity can stay on the run queue of a core that is
unbound. drm_sched_fini() frees that run queue, and the next submit or
the file's close then uses it. Jobs queued on that core never run.

At unbind, destroy each entity on the unbound core, which waits until
its queued jobs have started (they fail with -ENODEV), and build it
again on the cores that are up. Wait for the file's last job before the
rebuild, or the new entity could run another job next to it. The other
entities, and all of them at bind, only get the new core list.
Jobs submitted on a file left with no core are dropped (-ENODEV inside;
rocket_ioctl_submit() returns it only with commit 3185975d75f8
("accel/rocket: Propagate job submission errors")).

Keep sched_lock and the core array until the DRM device is released,
as files closed after the last core is unbound still use them. Close
waits until the file's jobs are freed: killed jobs are freed later, from
a work item that uses their core.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.h    |   8 ++
 drivers/accel/rocket/rocket_job.c    | 139 ++++++++++++++++++++++++++++++-----
 drivers/accel/rocket/rocket_job.h    |   2 +-
 6 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index e51b64845a8b..f49efc18a66e 100644
--- a/drivers/accel/rocket/rocket_core.c
+++ b/drivers/accel/rocket/rocket_core.c
@@ -95,6 +95,8 @@ int rocket_core_init(struct rocket_core *core)
 
 	dev_info(dev, "Rockchip NPU core %d version: %d\n", core->index, version);
 
+	rocket_job_reinit_entities(core->rdev);
+
 	return 0;
 }
 
diff --git a/drivers/accel/rocket/rocket_device.c b/drivers/accel/rocket/rocket_device.c
index efd004194c1a..26a65e1b8a24 100644
--- a/drivers/accel/rocket/rocket_device.c
+++ b/drivers/accel/rocket/rocket_device.c
@@ -2,6 +2,7 @@
 /* Copyright 2024-2025 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
 
 #include <drm/drm_drv.h>
+#include <drm/drm_managed.h>
 #include <linux/array_size.h>
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
@@ -33,7 +34,7 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 
 	rdev->max_cores = num_cores;
 
-	rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
+	rdev->cores = drmm_kcalloc(ddev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
 	if (!rdev->cores)
 		return ERR_PTR(-ENOMEM);
 
@@ -43,10 +44,12 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 	if (err)
 		return ERR_PTR(err);
 
-	err = devm_mutex_init(dev, &rdev->sched_lock);
+	err = drmm_mutex_init(ddev, &rdev->sched_lock);
 	if (err)
 		return ERR_PTR(-ENOMEM);
 
+	INIT_LIST_HEAD(&rdev->files);
+
 	err = drm_dev_register(ddev, 0);
 	if (err)
 		return ERR_PTR(err);
diff --git a/drivers/accel/rocket/rocket_device.h b/drivers/accel/rocket/rocket_device.h
index c62d56701069..4ee8935def26 100644
--- a/drivers/accel/rocket/rocket_device.h
+++ b/drivers/accel/rocket/rocket_device.h
@@ -16,6 +16,8 @@ struct rocket_device {
 	struct drm_device ddev;
 
 	struct mutex sched_lock;
+	/* Open files, under @sched_lock */
+	struct list_head files;
 
 	struct rocket_core *cores;
 	unsigned int num_cores;
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index f7a77ea98467..c8e9cad31625 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -24,8 +24,16 @@ struct rocket_file_priv {
 
 	struct rocket_vm *vm;
 
+	struct list_head node;
+
 	struct drm_gpu_scheduler **scheds;
+	unsigned int num_scheds;
 	struct drm_sched_entity sched_entity;
+	/* Serialises @sched_entity changes at close, core unbind and bind */
+	struct mutex entity_lock;
+	bool closed;
+	/* Jobs not freed yet */
+	atomic_t jobs;
 
 	struct dma_fence *last_job_fence;
 };
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 53f0751d7a1e..c57bbbfe55d2 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -13,6 +13,7 @@
 #include <linux/iommu.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/wait_bit.h>
 
 #include "rocket_core.h"
 #include "rocket_device.h"
@@ -232,6 +233,11 @@ static int rocket_job_push(struct rocket_job *job)
 		goto err;
 
 	scoped_guard(mutex, &rdev->sched_lock) {
+		if (!job->file_priv->num_scheds) {
+			ret = -ENODEV;
+			goto err_unlock;
+		}
+
 		drm_sched_job_arm(&job->base);
 
 		job->inference_done_fence = dma_fence_get(&job->base.s_fence->finished);
@@ -266,6 +272,7 @@ static void rocket_job_cleanup(struct kref *ref)
 {
 	struct rocket_job *job = container_of(ref, struct rocket_job,
 						refcount);
+	struct rocket_file_priv *file_priv = job->file_priv;
 	unsigned int i;
 
 	rocket_vm_put(job->vm);
@@ -290,6 +297,9 @@ static void rocket_job_cleanup(struct kref *ref)
 	kvfree(job->tasks);
 
 	kfree(job);
+
+	if (atomic_dec_and_test(&file_priv->jobs))
+		wake_up_var(&file_priv->jobs);
 }
 
 static void rocket_job_put(struct rocket_job *job)
@@ -520,6 +530,86 @@ static irqreturn_t rocket_job_irq_handler(int irq, void *data)
 	return IRQ_WAKE_THREAD;
 }
 
+/* List the cores that are up. Called with sched_lock held. */
+static unsigned int rocket_job_up_scheds(struct rocket_file_priv *rocket_priv)
+{
+	struct rocket_device *rdev = rocket_priv->rdev;
+	unsigned int core, n = 0;
+
+	for (core = 0; core < rdev->max_cores; core++) {
+		struct rocket_core *c = &rdev->cores[core];
+
+		if (!READ_ONCE(c->removing) && drm_sched_wqueue_ready(&c->sched))
+			rocket_priv->scheds[n++] = &c->sched;
+	}
+
+	return n;
+}
+
+/* Build the entity on the cores that are up. Called with sched_lock held. */
+static int rocket_job_entity_init(struct rocket_file_priv *rocket_priv)
+{
+	unsigned int n = rocket_job_up_scheds(rocket_priv);
+	int ret;
+
+	if (!n)
+		return -ENODEV;
+
+	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
+				    DRM_SCHED_PRIORITY_NORMAL,
+				    rocket_priv->scheds, n, NULL);
+	if (!ret)
+		rocket_priv->num_scheds = n;
+
+	return ret;
+}
+
+/* Called with sched_lock held: jobs are armed under it, so entity->rq is stable */
+static bool rocket_job_on_removing_core(struct drm_sched_entity *entity)
+{
+	return READ_ONCE(container_of(entity->rq->sched, struct rocket_core,
+				      sched)->removing);
+}
+
+/*
+ * Move every open file's entity onto the cores that are up. An entity on a
+ * removing core is rebuilt, as drm_sched_fini() frees its run queue: the
+ * flush in drm_sched_entity_destroy() runs its queued jobs, which fail.
+ */
+void rocket_job_reinit_entities(struct rocket_device *rdev)
+{
+	struct rocket_file_priv *rocket_priv;
+
+	guard(mutex)(&rdev->sched_lock);
+
+	list_for_each_entry(rocket_priv, &rdev->files, node) {
+		struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+
+		guard(mutex)(&rocket_priv->entity_lock);
+
+		if (rocket_priv->closed)
+			continue;
+
+		if (rocket_priv->num_scheds && !rocket_job_on_removing_core(entity)) {
+			rocket_priv->num_scheds = rocket_job_up_scheds(rocket_priv);
+			drm_sched_entity_modify_sched(entity, rocket_priv->scheds,
+						      rocket_priv->num_scheds);
+			continue;
+		}
+
+		if (rocket_priv->num_scheds) {
+			drm_sched_entity_destroy(entity);
+			rocket_priv->num_scheds = 0;
+
+			/* No second job of the file on the NPU */
+			if (rocket_priv->last_job_fence)
+				dma_fence_wait(rocket_priv->last_job_fence, false);
+		}
+
+		rocket_job_entity_init(rocket_priv);
+	}
+}
+
 int rocket_job_init(struct rocket_core *core)
 {
 	struct drm_sched_init_args args = {
@@ -581,6 +671,9 @@ void rocket_job_fini(struct rocket_core *core)
 	queue_work(core->reset.wq, &core->reset.work);
 	flush_work(&core->reset.work);
 
+	/* drm_sched_fini() frees the run queues the entities are on */
+	rocket_job_reinit_entities(core->rdev);
+
 	drm_sched_fini(&core->sched);
 
 	cancel_work_sync(&core->reset.work);
@@ -590,40 +683,51 @@ void rocket_job_fini(struct rocket_core *core)
 int rocket_job_open(struct rocket_file_priv *rocket_priv)
 {
 	struct rocket_device *rdev = rocket_priv->rdev;
-	struct drm_gpu_scheduler **scheds = kmalloc_objs(*scheds,
-							 rdev->num_cores);
-	unsigned int core;
 	int ret;
 
-	if (!scheds)
+	rocket_priv->scheds = kmalloc_objs(*rocket_priv->scheds, rdev->max_cores);
+	if (!rocket_priv->scheds)
 		return -ENOMEM;
 
-	for (core = 0; core < rdev->num_cores; core++)
-		scheds[core] = &rdev->cores[core].sched;
+	mutex_init(&rocket_priv->entity_lock);
 
-	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
-				    DRM_SCHED_PRIORITY_NORMAL,
-				    scheds,
-				    rdev->num_cores, NULL);
-	if (ret)
-		kfree(scheds);
-	else
-		rocket_priv->scheds = scheds;
+	guard(mutex)(&rdev->sched_lock);
 
-	return ret;
+	ret = rocket_job_entity_init(rocket_priv);
+	if (ret) {
+		mutex_destroy(&rocket_priv->entity_lock);
+		kfree(rocket_priv->scheds);
+		return ret;
+	}
+
+	list_add(&rocket_priv->node, &rdev->files);
+
+	return 0;
 }
 
 void rocket_job_close(struct rocket_file_priv *rocket_priv)
 {
-	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+	struct rocket_device *rdev = rocket_priv->rdev;
 
-	drm_sched_entity_destroy(entity);
+	scoped_guard(mutex, &rocket_priv->entity_lock) {
+		if (rocket_priv->num_scheds)
+			drm_sched_entity_destroy(&rocket_priv->sched_entity);
+		rocket_priv->num_scheds = 0;
+		rocket_priv->closed = true;
+	}
+
+	scoped_guard(mutex, &rdev->sched_lock)
+		list_del(&rocket_priv->node);
 
 	if (rocket_priv->last_job_fence) {
 		dma_fence_wait(rocket_priv->last_job_fence, false);
 		dma_fence_put(rocket_priv->last_job_fence);
 	}
 
+	/* Killed jobs are freed later, from a work item that uses the core */
+	wait_var_event(&rocket_priv->jobs, !atomic_read(&rocket_priv->jobs));
+
+	mutex_destroy(&rocket_priv->entity_lock);
 	kfree(rocket_priv->scheds);
 }
 
@@ -655,6 +759,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 
 	rjob->rdev = rdev;
 	rjob->file_priv = file_priv;
+	atomic_inc(&file_priv->jobs);
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 27db6f861250..f018920c8f3f 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,7 +20,6 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
-	/* Not valid after rocket_job_close() */
 	struct rocket_file_priv *file_priv;
 
 	struct drm_gem_object **in_bos;
@@ -48,6 +47,7 @@ int rocket_ioctl_submit(struct drm_device *dev, void *data, struct drm_file *fil
 
 int rocket_job_init(struct rocket_core *core);
 void rocket_job_fini(struct rocket_core *core);
+void rocket_job_reinit_entities(struct rocket_device *rdev);
 int rocket_job_open(struct rocket_file_priv *rocket_priv);
 void rocket_job_close(struct rocket_file_priv *rocket_priv);
 int rocket_job_is_idle(struct rocket_core *core);

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 7/7] accel/rocket: Move open files off a core at unbind
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

A file's scheduler entity can stay on the run queue of a core that is
unbound. drm_sched_fini() frees that run queue, and the next submit or
the file's close then uses it. Jobs queued on that core never run.

At unbind, destroy each entity on the unbound core, which waits until
its queued jobs have started (they fail with -ENODEV), and build it
again on the cores that are up. Wait for the file's last job before the
rebuild, or the new entity could run another job next to it. The other
entities, and all of them at bind, only get the new core list.
Jobs submitted on a file left with no core are dropped (-ENODEV inside;
rocket_ioctl_submit() returns it only with commit 3185975d75f8
("accel/rocket: Propagate job submission errors")).

Keep sched_lock and the core array until the DRM device is released,
as files closed after the last core is unbound still use them. Close
waits until the file's jobs are freed: killed jobs are freed later, from
a work item that uses their core.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.h    |   8 ++
 drivers/accel/rocket/rocket_job.c    | 139 ++++++++++++++++++++++++++++++-----
 drivers/accel/rocket/rocket_job.h    |   2 +-
 6 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index e51b64845a8b..f49efc18a66e 100644
--- a/drivers/accel/rocket/rocket_core.c
+++ b/drivers/accel/rocket/rocket_core.c
@@ -95,6 +95,8 @@ int rocket_core_init(struct rocket_core *core)
 
 	dev_info(dev, "Rockchip NPU core %d version: %d\n", core->index, version);
 
+	rocket_job_reinit_entities(core->rdev);
+
 	return 0;
 }
 
diff --git a/drivers/accel/rocket/rocket_device.c b/drivers/accel/rocket/rocket_device.c
index efd004194c1a..26a65e1b8a24 100644
--- a/drivers/accel/rocket/rocket_device.c
+++ b/drivers/accel/rocket/rocket_device.c
@@ -2,6 +2,7 @@
 /* Copyright 2024-2025 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
 
 #include <drm/drm_drv.h>
+#include <drm/drm_managed.h>
 #include <linux/array_size.h>
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
@@ -33,7 +34,7 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 
 	rdev->max_cores = num_cores;
 
-	rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
+	rdev->cores = drmm_kcalloc(ddev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
 	if (!rdev->cores)
 		return ERR_PTR(-ENOMEM);
 
@@ -43,10 +44,12 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 	if (err)
 		return ERR_PTR(err);
 
-	err = devm_mutex_init(dev, &rdev->sched_lock);
+	err = drmm_mutex_init(ddev, &rdev->sched_lock);
 	if (err)
 		return ERR_PTR(-ENOMEM);
 
+	INIT_LIST_HEAD(&rdev->files);
+
 	err = drm_dev_register(ddev, 0);
 	if (err)
 		return ERR_PTR(err);
diff --git a/drivers/accel/rocket/rocket_device.h b/drivers/accel/rocket/rocket_device.h
index c62d56701069..4ee8935def26 100644
--- a/drivers/accel/rocket/rocket_device.h
+++ b/drivers/accel/rocket/rocket_device.h
@@ -16,6 +16,8 @@ struct rocket_device {
 	struct drm_device ddev;
 
 	struct mutex sched_lock;
+	/* Open files, under @sched_lock */
+	struct list_head files;
 
 	struct rocket_core *cores;
 	unsigned int num_cores;
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index f7a77ea98467..c8e9cad31625 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -24,8 +24,16 @@ struct rocket_file_priv {
 
 	struct rocket_vm *vm;
 
+	struct list_head node;
+
 	struct drm_gpu_scheduler **scheds;
+	unsigned int num_scheds;
 	struct drm_sched_entity sched_entity;
+	/* Serialises @sched_entity changes at close, core unbind and bind */
+	struct mutex entity_lock;
+	bool closed;
+	/* Jobs not freed yet */
+	atomic_t jobs;
 
 	struct dma_fence *last_job_fence;
 };
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 53f0751d7a1e..c57bbbfe55d2 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -13,6 +13,7 @@
 #include <linux/iommu.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/wait_bit.h>
 
 #include "rocket_core.h"
 #include "rocket_device.h"
@@ -232,6 +233,11 @@ static int rocket_job_push(struct rocket_job *job)
 		goto err;
 
 	scoped_guard(mutex, &rdev->sched_lock) {
+		if (!job->file_priv->num_scheds) {
+			ret = -ENODEV;
+			goto err_unlock;
+		}
+
 		drm_sched_job_arm(&job->base);
 
 		job->inference_done_fence = dma_fence_get(&job->base.s_fence->finished);
@@ -266,6 +272,7 @@ static void rocket_job_cleanup(struct kref *ref)
 {
 	struct rocket_job *job = container_of(ref, struct rocket_job,
 						refcount);
+	struct rocket_file_priv *file_priv = job->file_priv;
 	unsigned int i;
 
 	rocket_vm_put(job->vm);
@@ -290,6 +297,9 @@ static void rocket_job_cleanup(struct kref *ref)
 	kvfree(job->tasks);
 
 	kfree(job);
+
+	if (atomic_dec_and_test(&file_priv->jobs))
+		wake_up_var(&file_priv->jobs);
 }
 
 static void rocket_job_put(struct rocket_job *job)
@@ -520,6 +530,86 @@ static irqreturn_t rocket_job_irq_handler(int irq, void *data)
 	return IRQ_WAKE_THREAD;
 }
 
+/* List the cores that are up. Called with sched_lock held. */
+static unsigned int rocket_job_up_scheds(struct rocket_file_priv *rocket_priv)
+{
+	struct rocket_device *rdev = rocket_priv->rdev;
+	unsigned int core, n = 0;
+
+	for (core = 0; core < rdev->max_cores; core++) {
+		struct rocket_core *c = &rdev->cores[core];
+
+		if (!READ_ONCE(c->removing) && drm_sched_wqueue_ready(&c->sched))
+			rocket_priv->scheds[n++] = &c->sched;
+	}
+
+	return n;
+}
+
+/* Build the entity on the cores that are up. Called with sched_lock held. */
+static int rocket_job_entity_init(struct rocket_file_priv *rocket_priv)
+{
+	unsigned int n = rocket_job_up_scheds(rocket_priv);
+	int ret;
+
+	if (!n)
+		return -ENODEV;
+
+	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
+				    DRM_SCHED_PRIORITY_NORMAL,
+				    rocket_priv->scheds, n, NULL);
+	if (!ret)
+		rocket_priv->num_scheds = n;
+
+	return ret;
+}
+
+/* Called with sched_lock held: jobs are armed under it, so entity->rq is stable */
+static bool rocket_job_on_removing_core(struct drm_sched_entity *entity)
+{
+	return READ_ONCE(container_of(entity->rq->sched, struct rocket_core,
+				      sched)->removing);
+}
+
+/*
+ * Move every open file's entity onto the cores that are up. An entity on a
+ * removing core is rebuilt, as drm_sched_fini() frees its run queue: the
+ * flush in drm_sched_entity_destroy() runs its queued jobs, which fail.
+ */
+void rocket_job_reinit_entities(struct rocket_device *rdev)
+{
+	struct rocket_file_priv *rocket_priv;
+
+	guard(mutex)(&rdev->sched_lock);
+
+	list_for_each_entry(rocket_priv, &rdev->files, node) {
+		struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+
+		guard(mutex)(&rocket_priv->entity_lock);
+
+		if (rocket_priv->closed)
+			continue;
+
+		if (rocket_priv->num_scheds && !rocket_job_on_removing_core(entity)) {
+			rocket_priv->num_scheds = rocket_job_up_scheds(rocket_priv);
+			drm_sched_entity_modify_sched(entity, rocket_priv->scheds,
+						      rocket_priv->num_scheds);
+			continue;
+		}
+
+		if (rocket_priv->num_scheds) {
+			drm_sched_entity_destroy(entity);
+			rocket_priv->num_scheds = 0;
+
+			/* No second job of the file on the NPU */
+			if (rocket_priv->last_job_fence)
+				dma_fence_wait(rocket_priv->last_job_fence, false);
+		}
+
+		rocket_job_entity_init(rocket_priv);
+	}
+}
+
 int rocket_job_init(struct rocket_core *core)
 {
 	struct drm_sched_init_args args = {
@@ -581,6 +671,9 @@ void rocket_job_fini(struct rocket_core *core)
 	queue_work(core->reset.wq, &core->reset.work);
 	flush_work(&core->reset.work);
 
+	/* drm_sched_fini() frees the run queues the entities are on */
+	rocket_job_reinit_entities(core->rdev);
+
 	drm_sched_fini(&core->sched);
 
 	cancel_work_sync(&core->reset.work);
@@ -590,40 +683,51 @@ void rocket_job_fini(struct rocket_core *core)
 int rocket_job_open(struct rocket_file_priv *rocket_priv)
 {
 	struct rocket_device *rdev = rocket_priv->rdev;
-	struct drm_gpu_scheduler **scheds = kmalloc_objs(*scheds,
-							 rdev->num_cores);
-	unsigned int core;
 	int ret;
 
-	if (!scheds)
+	rocket_priv->scheds = kmalloc_objs(*rocket_priv->scheds, rdev->max_cores);
+	if (!rocket_priv->scheds)
 		return -ENOMEM;
 
-	for (core = 0; core < rdev->num_cores; core++)
-		scheds[core] = &rdev->cores[core].sched;
+	mutex_init(&rocket_priv->entity_lock);
 
-	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
-				    DRM_SCHED_PRIORITY_NORMAL,
-				    scheds,
-				    rdev->num_cores, NULL);
-	if (ret)
-		kfree(scheds);
-	else
-		rocket_priv->scheds = scheds;
+	guard(mutex)(&rdev->sched_lock);
 
-	return ret;
+	ret = rocket_job_entity_init(rocket_priv);
+	if (ret) {
+		mutex_destroy(&rocket_priv->entity_lock);
+		kfree(rocket_priv->scheds);
+		return ret;
+	}
+
+	list_add(&rocket_priv->node, &rdev->files);
+
+	return 0;
 }
 
 void rocket_job_close(struct rocket_file_priv *rocket_priv)
 {
-	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+	struct rocket_device *rdev = rocket_priv->rdev;
 
-	drm_sched_entity_destroy(entity);
+	scoped_guard(mutex, &rocket_priv->entity_lock) {
+		if (rocket_priv->num_scheds)
+			drm_sched_entity_destroy(&rocket_priv->sched_entity);
+		rocket_priv->num_scheds = 0;
+		rocket_priv->closed = true;
+	}
+
+	scoped_guard(mutex, &rdev->sched_lock)
+		list_del(&rocket_priv->node);
 
 	if (rocket_priv->last_job_fence) {
 		dma_fence_wait(rocket_priv->last_job_fence, false);
 		dma_fence_put(rocket_priv->last_job_fence);
 	}
 
+	/* Killed jobs are freed later, from a work item that uses the core */
+	wait_var_event(&rocket_priv->jobs, !atomic_read(&rocket_priv->jobs));
+
+	mutex_destroy(&rocket_priv->entity_lock);
 	kfree(rocket_priv->scheds);
 }
 
@@ -655,6 +759,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 
 	rjob->rdev = rdev;
 	rjob->file_priv = file_priv;
+	atomic_inc(&file_priv->jobs);
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 27db6f861250..f018920c8f3f 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,7 +20,6 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
-	/* Not valid after rocket_job_close() */
 	struct rocket_file_priv *file_priv;
 
 	struct drm_gem_object **in_bos;
@@ -48,6 +47,7 @@ int rocket_ioctl_submit(struct drm_device *dev, void *data, struct drm_file *fil
 
 int rocket_job_init(struct rocket_core *core);
 void rocket_job_fini(struct rocket_core *core);
+void rocket_job_reinit_entities(struct rocket_device *rdev);
 int rocket_job_open(struct rocket_file_priv *rocket_priv);
 void rocket_job_close(struct rocket_file_priv *rocket_priv);
 int rocket_job_is_idle(struct rocket_core *core);

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 7/7] accel/rocket: Move open files off a core at unbind
@ 2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  0 siblings, 0 replies; 26+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-06  7:17 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Danilo Krummrich, Matthew Brost, Igor Paunovic,
	Midgy BALON, Jiaxing Hu, dri-devel, linux-rockchip, linux-kernel,
	linux-media, linaro-mm-sig, stable, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

A file's scheduler entity can stay on the run queue of a core that is
unbound. drm_sched_fini() frees that run queue, and the next submit or
the file's close then uses it. Jobs queued on that core never run.

At unbind, destroy each entity on the unbound core, which waits until
its queued jobs have started (they fail with -ENODEV), and build it
again on the cores that are up. Wait for the file's last job before the
rebuild, or the new entity could run another job next to it. The other
entities, and all of them at bind, only get the new core list.
Jobs submitted on a file left with no core are dropped (-ENODEV inside;
rocket_ioctl_submit() returns it only with commit 3185975d75f8
("accel/rocket: Propagate job submission errors")).

Keep sched_lock and the core array until the DRM device is released,
as files closed after the last core is unbound still use them. Close
waits until the file's jobs are freed: killed jobs are freed later, from
a work item that uses their core.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/accel/rocket/rocket_core.c   |   2 +
 drivers/accel/rocket/rocket_device.c |   7 +-
 drivers/accel/rocket/rocket_device.h |   2 +
 drivers/accel/rocket/rocket_drv.h    |   8 ++
 drivers/accel/rocket/rocket_job.c    | 139 ++++++++++++++++++++++++++++++-----
 drivers/accel/rocket/rocket_job.h    |   2 +-
 6 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
index e51b64845a8b..f49efc18a66e 100644
--- a/drivers/accel/rocket/rocket_core.c
+++ b/drivers/accel/rocket/rocket_core.c
@@ -95,6 +95,8 @@ int rocket_core_init(struct rocket_core *core)
 
 	dev_info(dev, "Rockchip NPU core %d version: %d\n", core->index, version);
 
+	rocket_job_reinit_entities(core->rdev);
+
 	return 0;
 }
 
diff --git a/drivers/accel/rocket/rocket_device.c b/drivers/accel/rocket/rocket_device.c
index efd004194c1a..26a65e1b8a24 100644
--- a/drivers/accel/rocket/rocket_device.c
+++ b/drivers/accel/rocket/rocket_device.c
@@ -2,6 +2,7 @@
 /* Copyright 2024-2025 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
 
 #include <drm/drm_drv.h>
+#include <drm/drm_managed.h>
 #include <linux/array_size.h>
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
@@ -33,7 +34,7 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 
 	rdev->max_cores = num_cores;
 
-	rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
+	rdev->cores = drmm_kcalloc(ddev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
 	if (!rdev->cores)
 		return ERR_PTR(-ENOMEM);
 
@@ -43,10 +44,12 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
 	if (err)
 		return ERR_PTR(err);
 
-	err = devm_mutex_init(dev, &rdev->sched_lock);
+	err = drmm_mutex_init(ddev, &rdev->sched_lock);
 	if (err)
 		return ERR_PTR(-ENOMEM);
 
+	INIT_LIST_HEAD(&rdev->files);
+
 	err = drm_dev_register(ddev, 0);
 	if (err)
 		return ERR_PTR(err);
diff --git a/drivers/accel/rocket/rocket_device.h b/drivers/accel/rocket/rocket_device.h
index c62d56701069..4ee8935def26 100644
--- a/drivers/accel/rocket/rocket_device.h
+++ b/drivers/accel/rocket/rocket_device.h
@@ -16,6 +16,8 @@ struct rocket_device {
 	struct drm_device ddev;
 
 	struct mutex sched_lock;
+	/* Open files, under @sched_lock */
+	struct list_head files;
 
 	struct rocket_core *cores;
 	unsigned int num_cores;
diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
index f7a77ea98467..c8e9cad31625 100644
--- a/drivers/accel/rocket/rocket_drv.h
+++ b/drivers/accel/rocket/rocket_drv.h
@@ -24,8 +24,16 @@ struct rocket_file_priv {
 
 	struct rocket_vm *vm;
 
+	struct list_head node;
+
 	struct drm_gpu_scheduler **scheds;
+	unsigned int num_scheds;
 	struct drm_sched_entity sched_entity;
+	/* Serialises @sched_entity changes at close, core unbind and bind */
+	struct mutex entity_lock;
+	bool closed;
+	/* Jobs not freed yet */
+	atomic_t jobs;
 
 	struct dma_fence *last_job_fence;
 };
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 53f0751d7a1e..c57bbbfe55d2 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -13,6 +13,7 @@
 #include <linux/iommu.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/wait_bit.h>
 
 #include "rocket_core.h"
 #include "rocket_device.h"
@@ -232,6 +233,11 @@ static int rocket_job_push(struct rocket_job *job)
 		goto err;
 
 	scoped_guard(mutex, &rdev->sched_lock) {
+		if (!job->file_priv->num_scheds) {
+			ret = -ENODEV;
+			goto err_unlock;
+		}
+
 		drm_sched_job_arm(&job->base);
 
 		job->inference_done_fence = dma_fence_get(&job->base.s_fence->finished);
@@ -266,6 +272,7 @@ static void rocket_job_cleanup(struct kref *ref)
 {
 	struct rocket_job *job = container_of(ref, struct rocket_job,
 						refcount);
+	struct rocket_file_priv *file_priv = job->file_priv;
 	unsigned int i;
 
 	rocket_vm_put(job->vm);
@@ -290,6 +297,9 @@ static void rocket_job_cleanup(struct kref *ref)
 	kvfree(job->tasks);
 
 	kfree(job);
+
+	if (atomic_dec_and_test(&file_priv->jobs))
+		wake_up_var(&file_priv->jobs);
 }
 
 static void rocket_job_put(struct rocket_job *job)
@@ -520,6 +530,86 @@ static irqreturn_t rocket_job_irq_handler(int irq, void *data)
 	return IRQ_WAKE_THREAD;
 }
 
+/* List the cores that are up. Called with sched_lock held. */
+static unsigned int rocket_job_up_scheds(struct rocket_file_priv *rocket_priv)
+{
+	struct rocket_device *rdev = rocket_priv->rdev;
+	unsigned int core, n = 0;
+
+	for (core = 0; core < rdev->max_cores; core++) {
+		struct rocket_core *c = &rdev->cores[core];
+
+		if (!READ_ONCE(c->removing) && drm_sched_wqueue_ready(&c->sched))
+			rocket_priv->scheds[n++] = &c->sched;
+	}
+
+	return n;
+}
+
+/* Build the entity on the cores that are up. Called with sched_lock held. */
+static int rocket_job_entity_init(struct rocket_file_priv *rocket_priv)
+{
+	unsigned int n = rocket_job_up_scheds(rocket_priv);
+	int ret;
+
+	if (!n)
+		return -ENODEV;
+
+	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
+				    DRM_SCHED_PRIORITY_NORMAL,
+				    rocket_priv->scheds, n, NULL);
+	if (!ret)
+		rocket_priv->num_scheds = n;
+
+	return ret;
+}
+
+/* Called with sched_lock held: jobs are armed under it, so entity->rq is stable */
+static bool rocket_job_on_removing_core(struct drm_sched_entity *entity)
+{
+	return READ_ONCE(container_of(entity->rq->sched, struct rocket_core,
+				      sched)->removing);
+}
+
+/*
+ * Move every open file's entity onto the cores that are up. An entity on a
+ * removing core is rebuilt, as drm_sched_fini() frees its run queue: the
+ * flush in drm_sched_entity_destroy() runs its queued jobs, which fail.
+ */
+void rocket_job_reinit_entities(struct rocket_device *rdev)
+{
+	struct rocket_file_priv *rocket_priv;
+
+	guard(mutex)(&rdev->sched_lock);
+
+	list_for_each_entry(rocket_priv, &rdev->files, node) {
+		struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+
+		guard(mutex)(&rocket_priv->entity_lock);
+
+		if (rocket_priv->closed)
+			continue;
+
+		if (rocket_priv->num_scheds && !rocket_job_on_removing_core(entity)) {
+			rocket_priv->num_scheds = rocket_job_up_scheds(rocket_priv);
+			drm_sched_entity_modify_sched(entity, rocket_priv->scheds,
+						      rocket_priv->num_scheds);
+			continue;
+		}
+
+		if (rocket_priv->num_scheds) {
+			drm_sched_entity_destroy(entity);
+			rocket_priv->num_scheds = 0;
+
+			/* No second job of the file on the NPU */
+			if (rocket_priv->last_job_fence)
+				dma_fence_wait(rocket_priv->last_job_fence, false);
+		}
+
+		rocket_job_entity_init(rocket_priv);
+	}
+}
+
 int rocket_job_init(struct rocket_core *core)
 {
 	struct drm_sched_init_args args = {
@@ -581,6 +671,9 @@ void rocket_job_fini(struct rocket_core *core)
 	queue_work(core->reset.wq, &core->reset.work);
 	flush_work(&core->reset.work);
 
+	/* drm_sched_fini() frees the run queues the entities are on */
+	rocket_job_reinit_entities(core->rdev);
+
 	drm_sched_fini(&core->sched);
 
 	cancel_work_sync(&core->reset.work);
@@ -590,40 +683,51 @@ void rocket_job_fini(struct rocket_core *core)
 int rocket_job_open(struct rocket_file_priv *rocket_priv)
 {
 	struct rocket_device *rdev = rocket_priv->rdev;
-	struct drm_gpu_scheduler **scheds = kmalloc_objs(*scheds,
-							 rdev->num_cores);
-	unsigned int core;
 	int ret;
 
-	if (!scheds)
+	rocket_priv->scheds = kmalloc_objs(*rocket_priv->scheds, rdev->max_cores);
+	if (!rocket_priv->scheds)
 		return -ENOMEM;
 
-	for (core = 0; core < rdev->num_cores; core++)
-		scheds[core] = &rdev->cores[core].sched;
+	mutex_init(&rocket_priv->entity_lock);
 
-	ret = drm_sched_entity_init(&rocket_priv->sched_entity,
-				    DRM_SCHED_PRIORITY_NORMAL,
-				    scheds,
-				    rdev->num_cores, NULL);
-	if (ret)
-		kfree(scheds);
-	else
-		rocket_priv->scheds = scheds;
+	guard(mutex)(&rdev->sched_lock);
 
-	return ret;
+	ret = rocket_job_entity_init(rocket_priv);
+	if (ret) {
+		mutex_destroy(&rocket_priv->entity_lock);
+		kfree(rocket_priv->scheds);
+		return ret;
+	}
+
+	list_add(&rocket_priv->node, &rdev->files);
+
+	return 0;
 }
 
 void rocket_job_close(struct rocket_file_priv *rocket_priv)
 {
-	struct drm_sched_entity *entity = &rocket_priv->sched_entity;
+	struct rocket_device *rdev = rocket_priv->rdev;
 
-	drm_sched_entity_destroy(entity);
+	scoped_guard(mutex, &rocket_priv->entity_lock) {
+		if (rocket_priv->num_scheds)
+			drm_sched_entity_destroy(&rocket_priv->sched_entity);
+		rocket_priv->num_scheds = 0;
+		rocket_priv->closed = true;
+	}
+
+	scoped_guard(mutex, &rdev->sched_lock)
+		list_del(&rocket_priv->node);
 
 	if (rocket_priv->last_job_fence) {
 		dma_fence_wait(rocket_priv->last_job_fence, false);
 		dma_fence_put(rocket_priv->last_job_fence);
 	}
 
+	/* Killed jobs are freed later, from a work item that uses the core */
+	wait_var_event(&rocket_priv->jobs, !atomic_read(&rocket_priv->jobs));
+
+	mutex_destroy(&rocket_priv->entity_lock);
 	kfree(rocket_priv->scheds);
 }
 
@@ -655,6 +759,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 
 	rjob->rdev = rdev;
 	rjob->file_priv = file_priv;
+	atomic_inc(&file_priv->jobs);
 	rjob->vm = rocket_vm_get(file_priv);
 
 	ret = drm_sched_job_init(&rjob->base,
diff --git a/drivers/accel/rocket/rocket_job.h b/drivers/accel/rocket/rocket_job.h
index 27db6f861250..f018920c8f3f 100644
--- a/drivers/accel/rocket/rocket_job.h
+++ b/drivers/accel/rocket/rocket_job.h
@@ -20,7 +20,6 @@ struct rocket_job {
 
 	struct rocket_device *rdev;
 
-	/* Not valid after rocket_job_close() */
 	struct rocket_file_priv *file_priv;
 
 	struct drm_gem_object **in_bos;
@@ -48,6 +47,7 @@ int rocket_ioctl_submit(struct drm_device *dev, void *data, struct drm_file *fil
 
 int rocket_job_init(struct rocket_core *core);
 void rocket_job_fini(struct rocket_core *core);
+void rocket_job_reinit_entities(struct rocket_device *rdev);
 int rocket_job_open(struct rocket_file_priv *rocket_priv);
 void rocket_job_close(struct rocket_file_priv *rocket_priv);
 int rocket_job_is_idle(struct rocket_core *core);

-- 
2.55.0



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 5/7] accel/rocket: Reset the core at unbind
  2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  (?)
  (?)
@ 2026-12-06  7:41   ` sashiko-bot
  -1 siblings, 0 replies; 26+ messages in thread
From: sashiko-bot @ 2026-12-06  7:41 UTC (permalink / raw)
  To: Arun Iyengar; +Cc: dri-devel, media-ci

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 4/7] accel/rocket: Serialise core probe and removal
  2026-12-06  7:17   ` Arun Iyengar via B4 Relay
  (?)
  (?)
@ 2026-12-06  7:42   ` sashiko-bot
  -1 siblings, 0 replies; 26+ messages in thread
From: sashiko-bot @ 2026-12-06  7:42 UTC (permalink / raw)
  To: Arun Iyengar; +Cc: dri-devel, media-ci

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] accel/rocket: devm_request_threaded_irq() outlives core slot
  and rdev->cores
--

commit 54867f95a258b72cc2f95c965d1a7ae51bc6960f
Author: Arun Iyengar <aiyengar1990@gmail.com>

accel/rocket: Serialise core probe and removal

This commit serialises core probe, removal, and open under a mutex,
clears core slots on removal, and picks the first free slot on probe
and a bound core on open.

Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]

> diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
> index e45b3c22b31e6..ccaedb004d195 100644
> --- a/drivers/accel/rocket/rocket_drv.c
> +++ b/drivers/accel/rocket/rocket_drv.c

[ ... ]

> @@ -246,12 +271,16 @@ static int find_core_for_dev(struct device *dev);
>  static void rocket_remove(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	int core = find_core_for_dev(dev);
> +	int core;
> +
> +	guard(mutex)(&rocket_cores_lock);
>  
> +	core = find_core_for_dev(dev);
>  	if (core < 0)
>  		return;
>  
>  	rocket_core_fini(&rdev->cores[core]);
> +	WRITE_ONCE(rdev->cores[core].dev, NULL);
>  	rdev->num_cores--;
>  
>  	if (rdev->num_cores == 0) {

[Severity: Medium]
Can the shared IRQ handler registered by rocket_job_init() run after
core->dev is cleared or rdev->cores is freed?

rocket_job_init() registers its IRQF_SHARED handler via
devm_request_threaded_irq() with core (&rdev->cores[core]) as dev_id,
binding the IRQ lifetime to &pdev->dev.

Neither rocket_core_fini() nor rocket_job_fini() frees the IRQ, so
free_irq() only runs later in device_unbind_cleanup() ->
devres_release_all() after rocket_remove() (or a failed rocket_probe())
returns and releases rocket_cores_lock:

CPU0                              CPU1
rocket_remove()
  rocket_core_fini(core)
  WRITE_ONCE(core->dev, NULL)
  /* unlocks rocket_cores_lock */
                                  rocket_probe()
                                    /* reuses slot for new core */
                                  <shared IRQ>
                                    rocket_job_irq_handler(..., core)
                                      <-- races with reused slot
device_unbind_cleanup()
  devres_release_all()
    free_irq()

In that window, rocket_job_handle_irq() also dereferences a NULL
core->dev in pm_runtime_mark_last_busy().  On last-core removal, freeing
rdev->cores via devres_release_group() before free_irq() runs causes a
use-after-free on a shared IRQ or in __free_irq() under CONFIG_DEBUG_SHIRQ.

Freeing the IRQ in rocket_job_fini() with devm_free_irq() (or switching
to request_threaded_irq() and free_irq()) would ensure the handler cannot
outlive the core slot.

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2026-12-06  7:43 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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:42   ` sashiko-bot
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
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

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.