All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philip Yang <Philip.Yang@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <Felix.Kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Subject: [PATCH 2/2] drm/amdkfd: Downgrade mmap lock in SVM restore work
Date: Tue, 20 Oct 2026 12:31:16 -0400	[thread overview]
Message-ID: <20261020163116.1069749-2-Philip.Yang@amd.com> (raw)
In-Reply-To: <20261020163116.1069749-1-Philip.Yang@amd.com>

svm_range_restore_work holds the mmap write lock across the entire loop
validating and mapping every invalid range, which blocks all mmap,
munmap and page fault activity of the process, not only the KFD paths
waiting for the same locks.

Only the deferred work flush handshake in
svm_range_list_lock_and_flush_work needs the write lock.
svm_range_validate_and_map runs under the read lock, as
svm_range_set_attr already does after its mmap_write_downgrade. The
flush stays valid because svm_range_deferred_list_work takes the write
lock, so it cannot run while the read lock is held.

Downgrade the mmap lock before walking the range list.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 28b687133cf8..f63bd8cf4174 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1987,6 +1987,10 @@ static void svm_range_restore_work(struct work_struct *work)
 
 	mutex_lock(&process_info->lock);
 	svm_range_list_lock_and_flush_work(svms, mm);
+	/* Validate and map needs the read lock only, and deferred list work
+	 * takes the write lock, so the flush above stays valid.
+	 */
+	mmap_write_downgrade(mm);
 	mutex_lock(&svms->lock);
 
 	evicted_ranges = atomic_read(&svms->evicted_ranges);
@@ -2045,7 +2049,7 @@ static void svm_range_restore_work(struct work_struct *work)
 					       AMDGPU_SVM_RANGE_RESTORE_DELAY_MAX_MS);
 
 	mutex_unlock(&svms->lock);
-	mmap_write_unlock(mm);
+	mmap_read_unlock(mm);
 	mutex_unlock(&process_info->lock);
 
 	/* If validation failed, reschedule another attempt */
-- 
2.50.1


  reply	other threads:[~2026-10-20 16:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 16:31 [PATCH 1/2] drm/amdkfd: Back off SVM restore work retry Philip Yang
2026-10-20 16:31 ` Philip Yang [this message]
2026-10-20 17:00   ` [PATCH 2/2] drm/amdkfd: Downgrade mmap lock in SVM restore work Felix Kuehling
2026-10-20 16:58 ` [PATCH 1/2] drm/amdkfd: Back off SVM restore work retry Felix Kuehling

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=20261020163116.1069749-2-Philip.Yang@amd.com \
    --to=philip.yang@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=amd-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.