mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Tomeu Vizoso <tomeu@tomeuvizoso.net>, Oded Gabbay <ogabbay@kernel.org>
Cc: "Heiko Stuebner" <heiko@sntech.de>,
	"Jeff Hugo" <jeff.hugo@oss.qualcomm.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	"Midgy BALON" <midgy971@gmail.com>,
	"Jiaxing Hu" <gahing@gahingwoo.com>,
	dri-devel@lists.freedesktop.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
	stable@vger.kernel.org, "Arun Iyengar" <aiyengar1990@gmail.com>
Subject: [PATCH 1/2] accel/rocket: Wait for in-flight jobs before releasing the file's BOs
Date: Tue, 01 Dec 2026 07:28:08 +0000	[thread overview]
Message-ID: <20261201-rocket-fixes-v1-1-986c3e5ceb44@gmail.com> (raw)
In-Reply-To: <20261201-rocket-fixes-v1-0-986c3e5ceb44@gmail.com>

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



  reply	other threads:[~2026-12-01  7:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-01  7:28 ` [PATCH 2/2] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-rocket-fixes-v1-1-986c3e5ceb44@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gahing@gahingwoo.com \
    --cc=heiko@sntech.de \
    --cc=jeff.hugo@oss.qualcomm.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=midgy971@gmail.com \
    --cc=ogabbay@kernel.org \
    --cc=phasta@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tomeu@tomeuvizoso.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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®