* [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; 5+ 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] 5+ 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:37 ` sashiko-bot
2026-12-01 7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
1 sibling, 1 reply; 5+ 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 related [flat|nested] 5+ 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
2026-12-01 7:32 ` sashiko-bot
1 sibling, 1 reply; 5+ 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 related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU
2026-12-01 7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
@ 2026-12-01 7:32 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-01 7:32 UTC (permalink / raw)
To: Arun Iyengar; +Cc: dri-devel, media-ci
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] accel/rocket: use-after-free and NULL pointer dereference
in rocket_core_fini() [1]
--
commit 3c0ae1c947c1bfa587406e1f23468f81ff1b2fca
Author: Arun Iyengar <aiyengar1990@gmail.com>
accel/rocket: Reset the core before detaching its IOMMU
This commit moves the rocket_core_reset() call in rocket_reset() ahead of
iommu_detach_group() so that a hung NPU job does not block the IOMMU from
entering stall mode during detach.
Link: https://lore.kernel.org/r/20260613070116.438906-5-midgy971@gmail.com [1]
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index 32926afb0144c..8bc0b80d9190b 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);
[Severity: Critical]
This problem wasn't introduced by this patch, but can rocket_reset() hit a
NULL pointer dereference in iommu_detach_group() and operate on disabled
runtime PM during teardown [1]?
In rocket_core_fini(), runtime PM is disabled and core->iommu_group is
released and cleared before rocket_job_fini() stops the scheduler:
drivers/accel/rocket/rocket_core.c:rocket_core_fini() {
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);
}
If an in-flight job times out before or during rocket_job_fini(),
rocket_reset() passes a NULL core->iommu_group to iommu_detach_group() and
calls pm_runtime_put_autosuspend() after runtime PM has been disabled.
Calling rocket_job_fini() first in rocket_core_fini() would avoid this.
[1] https://sashiko.dev/#/bug/linux-ef3ef432-292a-4ee1-addd-1b0440571e2d
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
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:37 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-01 7:37 UTC (permalink / raw)
To: Arun Iyengar; +Cc: dri-devel, media-ci
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] accel/rocket: ignored return value in rocket_ioctl_submit() [1]
--
commit 56d4424db2bb4cd4fc68f8a260274639d95da94e
Author: Arun Iyengar <aiyengar1990@gmail.com>
accel/rocket: Wait for in-flight jobs before releasing the file's BOs
This commit tears down the scheduler entity and waits for the file's last
submitted job in the release file operation before drm_release() drops the
file's GEM handles.
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index 454d465a39e37..32926afb0144c 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
[ ... ]
> @@ -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;
>
[Severity: High]
This problem wasn't introduced by this patch, but does
rocket_ioctl_submit() ignore the return value of
rocket_ioctl_submit_job() [1]?
drivers/accel/rocket/rocket_job.c:rocket_ioctl_submit() {
...
for (i = 0; i < args->job_count; i++)
rocket_ioctl_submit_job(dev, file, &jobs[i]);
exit:
kvfree(jobs);
return ret;
}
When rocket_ioctl_submit_job() fails (for example, due to an invalid GEM
handle or an allocation failure in rocket_job_push()), ret stays 0 and the
ioctl reports success to userspace for a job that was never queued.
[1] https://sashiko.dev/#/bug/linux-78e2eefa-f18b-4b54-bd1e-b3dcf1458b36
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 7:37 UTC | newest]
Thread overview: 5+ 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:37 ` sashiko-bot
2026-12-01 7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
2026-12-01 7:32 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox