mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] accel/rocket: Fix file close and reset with a job on the NPU
@ 2026-12-01  7:28 Arun Iyengar via B4 Relay
  2026-12-01  7:28 ` [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
  2026-12-01  7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01  7:28 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, Midgy BALON, Jiaxing Hu, dri-devel,
	linux-rockchip, linux-kernel, linux-media, linaro-mm-sig, stable,
	Arun Iyengar

Patch 2 is the same change as Midgy Balon's RK3568 RFC; see the patch.

Tested on an Orange Pi 5 (RK3588), 7.3 with both patches, KASAN: 70
SIGKILLs during inference, no job timeout (before: 12 in 10 kills); 10
faulting jobs, no IOMMU stall timeout or warning (before: 75 and 10),
also with the next-20261127 rockchip-iommu.c.

Developed with Claude (Anthropic) as a coding assistant; I reviewed and
tested it.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Arun Iyengar (2):
      accel/rocket: Wait for in-flight jobs before releasing the file's BOs
      accel/rocket: Reset the core before detaching its IOMMU

 drivers/accel/rocket/rocket_drv.c | 28 ++++++++++++++++++++++++++--
 drivers/accel/rocket/rocket_drv.h |  2 ++
 drivers/accel/rocket/rocket_job.c | 24 ++++++++++++++++++------
 3 files changed, 46 insertions(+), 8 deletions(-)
---
base-commit: 9f333c38eac95cef6e1d54681b010c6531a7dcb2
change-id: 20261130-rocket-fixes-e1438ca23bee

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



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

* [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
  2026-12-01  7:28 [PATCH 0/2] accel/rocket: Fix file close and reset with a job on the NPU Arun Iyengar via B4 Relay
@ 2026-12-01  7:28 ` Arun Iyengar via B4 Relay
  2026-12-01  7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01  7:28 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, 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 for the
file's last job to finish there.

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 | 28 ++++++++++++++++++++++++++--
 drivers/accel/rocket/rocket_drv.h |  2 ++
 drivers/accel/rocket/rocket_job.c | 14 ++++++++++++--
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e62a20edeca7..9251f2ab0154 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,31 @@ static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = {
 	ROCKET_IOCTL(FINI_BO, fini_bo),
 };
 
-DEFINE_DRM_ACCEL_FOPS(rocket_accel_driver_fops);
+/*
+ * drm_release() drops the GEM handles before calling postclose. Stop the
+ * file's jobs first, as they still use those BOs.
+ */
+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..32926afb0144 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -210,7 +210,8 @@ static void rocket_attach_object_fences(struct drm_gem_object **bos,
 		dma_resv_add_fence(bos[i]->resv, fence, usage);
 }
 
-static int rocket_job_push(struct rocket_job *job)
+static int rocket_job_push(struct rocket_file_priv *file_priv,
+			   struct rocket_job *job)
 {
 	struct rocket_device *rdev = job->rdev;
 	struct drm_gem_object **bos;
@@ -246,6 +247,9 @@ static int rocket_job_push(struct rocket_job *job)
 
 		kref_get(&job->refcount); /* put by scheduler job completion */
 
+		dma_fence_put(file_priv->last_job_fence);
+		file_priv->last_job_fence = dma_fence_get(job->inference_done_fence);
+
 		drm_sched_entity_push_job(&job->base);
 	}
 
@@ -585,6 +589,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);
 }
 
@@ -641,7 +651,7 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
 
 	rjob->out_bo_count = job->out_bo_handle_count;
 
-	ret = rocket_job_push(rjob);
+	ret = rocket_job_push(file_priv, rjob);
 	if (ret)
 		goto out_cleanup_job;
 

-- 
2.55.0



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

* [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU
  2026-12-01  7:28 [PATCH 0/2] accel/rocket: Fix file close and reset with a job on the NPU Arun Iyengar via B4 Relay
  2026-12-01  7:28 ` [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
@ 2026-12-01  7:28 ` Arun Iyengar via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01  7:28 UTC (permalink / raw)
  To: Tomeu Vizoso, Oded Gabbay
  Cc: Heiko Stuebner, Jeff Hugo, Sumit Semwal, Christian König,
	Philipp Stanner, 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 32926afb0144..8bc0b80d9190 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -427,15 +427,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	[flat|nested] 3+ messages in thread

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  7:28 [PATCH 0/2] accel/rocket: Fix file close and reset with a job on the NPU Arun Iyengar via B4 Relay
2026-12-01  7:28 ` [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
2026-12-01  7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®