* [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU
@ 2026-12-04 6:35 Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-04 6:35 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
Four 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: reset the core at unbind, which also cancels the job on the NPU.
Tested on an Orange Pi 5 (RK3588), 7.3, KASAN. Patches 1-2: 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. Patch 3: core unbound while its
timeout handler ran (forced by a test delay): no oops, core rebound,
inference unchanged (before: NULL dereference in iommu_detach_group()).
Patch 4: core unbound with a job running (5 runs), with a hung job (5)
and idle (3): no oops, file close returns, core rebound, inference
unchanged (before: file close hangs on a hung job; the NULL detach from
the interrupt handler follows from the code, I could not trigger it).
Not fixed: a file that stays open across a core unbind keeps a
scheduler entity on the torn-down scheduler (freed run queue, queued
jobs never run). That needs the entity lifetime reworked.
Developed with Claude (Anthropic), which wrote the code and the commit
messages.
Signed-off-by: Arun Iyengar <aiyengar1990@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 (4):
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: Reset the core at unbind
drivers/accel/rocket/rocket_core.c | 2 +-
drivers/accel/rocket/rocket_core.h | 2 ++
drivers/accel/rocket/rocket_drv.c | 24 ++++++++++++++++++++++--
drivers/accel/rocket/rocket_drv.h | 2 ++
drivers/accel/rocket/rocket_job.c | 37 +++++++++++++++++++++++++++++++------
5 files changed, 58 insertions(+), 9 deletions(-)
---
base-commit: 502ea48d0d8fa5dd0c31dc449efb3d82deef8efe
change-id: 20261130-rocket-fixes-e1438ca23bee
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
2026-12-04 6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
@ 2026-12-04 6:35 ` Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 2/4] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-04 6:35 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 | 24 ++++++++++++++++++++++--
drivers/accel/rocket/rocket_drv.h | 2 ++
drivers/accel/rocket/rocket_job.c | 14 ++++++++++++--
3 files changed, 36 insertions(+), 4 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..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 related [flat|nested] 5+ messages in thread
* [PATCH v2 2/4] accel/rocket: Reset the core before detaching its IOMMU
2026-12-04 6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
@ 2026-12-04 6:35 ` Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 4/4] accel/rocket: Reset the core at unbind Arun Iyengar via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-04 6:35 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 related [flat|nested] 5+ messages in thread
* [PATCH v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group
2026-12-04 6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 2/4] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
@ 2026-12-04 6:35 ` Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 4/4] accel/rocket: Reset the core at unbind Arun Iyengar via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-04 6:35 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>
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] 5+ messages in thread
* [PATCH v2 4/4] accel/rocket: Reset the core at unbind
2026-12-04 6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
` (2 preceding siblings ...)
2026-12-04 6:35 ` [PATCH v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar via B4 Relay
@ 2026-12-04 6:35 ` Arun Iyengar via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-04 6:35 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_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.
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 | 13 +++++++++++++
2 files changed, 15 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 8bc0b80d9190..2d636f983ced 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -334,6 +334,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.
@@ -515,6 +518,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);
@@ -554,6 +558,15 @@ 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, serialised with timeouts; that cancels pending jobs.
+ */
+ WRITE_ONCE(core->removing, true);
+ atomic_set(&core->reset.pending, 1);
+ 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] 5+ messages in thread
end of thread, other threads:[~2026-12-04 6:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 6:35 [PATCH v2 0/4] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 1/4] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 2/4] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 3/4] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar via B4 Relay
2026-12-04 6:35 ` [PATCH v2 4/4] accel/rocket: Reset the core at unbind 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