Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Harsh Parmar <kaii02ctf@gmail.com>
To: amd-gfx@lists.freedesktop.org
Cc: christian.koenig@amd.com, alexander.deucher@amd.com,
	gregkh@linuxfoundation.org, security@kernel.org,
	Harsh Parmar <kaii02ctf@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] drm/amdgpu: use disable_delayed_work_sync() for hang_detect_work teardown
Date: Sun,  6 Dec 2026 15:51:21 +0530	[thread overview]
Message-ID: <20261206102121.403566-1-kaii02ctf@gmail.com> (raw)

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

                 reply	other threads:[~2026-12-06 10:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261206102121.403566-1-kaii02ctf@gmail.com \
    --to=kaii02ctf@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    /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