From: Yaohan Li <shunsheng1218@gmail.com>
To: Felix.Kuehling@amd.com, alexander.deucher@amd.com,
christian.koenig@amd.com
Cc: airlied@gmail.com, simona@ffwll.ch, oded.gabbay@gmail.com,
kent.russell@amd.com, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] drm/amdkfd: unlink destroyed event waiters from the wait queue
Date: Tue, 17 Nov 2026 22:54:06 +0800 [thread overview]
Message-ID: <20261117145406.1092636-1-shunsheng1218@gmail.com> (raw)
destroy_event() clears waiter->event and calls wake_up_all() before the
event is removed from the IDR. The waiters use init_wait(), so a
successful wake-up already unlinks the wait_queue_entry through
autoremove_wake_function(). A waiter that is already runnable, though,
is not woken again and stays linked to ev->wq after destroy_event()
returns.
free_waiters() only calls remove_wait_queue() while waiter->event is
still set. destroy_event() has already cleared that field, so a waiter
that is still linked there is freed without being unlinked.
ev itself is released with kfree_rcu(), so a reader that reaches it
through RCU -- kfd_set_event() or the GPU signal interrupt path -- can
take ev->lock afterwards and walk ev->wq in set_event(), writing
waiter->activated into memory that has already been kfreed. The
waitqueue_active() test at the top of set_event() reads the same list.
destroy_event() used to unlink the waiters here. That unlink was lost
when the code was converted to wait_queue_entry_t by 74e4071665da,
which moved the removal into free_waiters() and left the destroyed
path without one.
Unlink whatever is left on the wait queue after wake_up_all(), while
still holding ev->lock, so the wake-up is delivered first and the
remainder can no longer outlive its storage.
Fixes: 74e4071665da ("drm/amdkfd: Use wait_queue_t to implement event waiting")
Cc: stable@vger.kernel.org
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Prepared against v7.4-rc1-1969-g666539eecdf4.
AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant. The author
reviewed the reasoning and takes responsibility for the content.
History: fe528c13acc7 unlinked the waiters here. That unlink was lost
when the code moved to wait_queue_entry_t (74e4071665da).
Testing: compile tested only (x86_64, gcc 11.4). No AMD GPU was
available, so the race was not run.
---
drivers/gpu/drm/amd/amdkfd/kfd_events.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index 6e32a892d56f..adc27f25af4d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
@@ -219,13 +219,25 @@ int kfd_event_init_process(struct kfd_process *p)
static void destroy_event(struct kfd_process *p, struct kfd_event *ev)
{
- struct kfd_event_waiter *waiter;
+ struct kfd_event_waiter *waiter, *tmp;
/* Wake up pending waiters. They will return failure */
spin_lock(&ev->lock);
list_for_each_entry(waiter, &ev->wq.head, wait.entry)
WRITE_ONCE(waiter->event, NULL);
wake_up_all(&ev->wq);
+
+ /*
+ * A wake-up that actually wakes a task detaches its entry through
+ * autoremove_wake_function(), but a waiter that was already runnable
+ * stays on the list. free_waiters() only unlinks a waiter while
+ * waiter->event is still set, so once that field has been cleared
+ * above nothing else will detach the remainder. Leaving them linked
+ * would let a concurrent set_event(), which reaches ev through RCU,
+ * walk a list pointing at already freed waiters.
+ */
+ list_for_each_entry_safe(waiter, tmp, &ev->wq.head, wait.entry)
+ remove_wait_queue(&ev->wq, &waiter->wait);
spin_unlock(&ev->lock);
if (ev->type == KFD_EVENT_TYPE_SIGNAL ||
--
2.34.1
next reply other threads:[~2026-11-17 14:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:54 Yaohan Li [this message]
2026-12-02 19:20 ` Felix Kuehling
2026-12-03 8:52 ` [PATCH v2] drm/amdkfd: mark destroyed events invalid for RCU readers Yaohan Li
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=20261117145406.1092636-1-shunsheng1218@gmail.com \
--to=shunsheng1218@gmail.com \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kent.russell@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oded.gabbay@gmail.com \
--cc=simona@ffwll.ch \
--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
all inboxes | Powered by JetHome®