Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: use disable_delayed_work_sync() for hang_detect_work teardown
@ 2026-12-06 10:21 Harsh Parmar
  0 siblings, 0 replies; only message in thread
From: Harsh Parmar @ 2026-12-06 10:21 UTC (permalink / raw)
  To: amd-gfx
  Cc: christian.koenig, alexander.deucher, gregkh, security,
	Harsh Parmar, stable

amdgpu_userq_destroy() cancels hang_detect_work before detaching the
queue's doorbell from the IRQ-visible xarray.  A fence completion IRQ
firing in this window can find the queue via xa_load() and call
amdgpu_userq_start_hang_detect_work(), which re-queues the work via
queue_delayed_work().

The race window spans mutex_lock() (contention-dependent) and
amdgpu_userq_wait_for_last_fence() (blocks on DMA fence, potentially
seconds).  After kfree() the re-queued work fires and dereferences freed
memory.

Replace cancel_delayed_work_sync() with disable_delayed_work_sync()
which atomically prevents any future queueing, closing the window
without reordering teardown.

Fixes: 38f4fe785b5d ("drm/amdgpu: cancel hang_detect_work before taking userq_mutex")
Cc: stable@vger.kernel.org
Signed-off-by: Harsh Parmar <kaii02ctf@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -556,9 +556,10 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_qu

 	cancel_delayed_work_sync(&uq_mgr->resume_work);
-	/* Cancel before taking userq_mutex: cancel_delayed_work_sync() waits
-	 * for any running instance, which itself takes userq_mutex.
+	/* Disable before taking userq_mutex: disable_delayed_work_sync() waits
+	 * for any running instance, which itself takes userq_mutex, and
+	 * atomically prevents the IRQ handler from re-queueing the work.
 	 */
-	cancel_delayed_work_sync(&queue->hang_detect_work);
+	disable_delayed_work_sync(&queue->hang_detect_work);

 	mutex_lock(&uq_mgr->userq_mutex);
 	amdgpu_userq_wait_for_last_fence(queue);
--
2.47.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-06 10:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 10:21 [PATCH] drm/amdgpu: use disable_delayed_work_sync() for hang_detect_work teardown Harsh Parmar

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