From: Huang Rui <ray.huang@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
"Philip Yang" <Philip.Yang@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Felix Kuehling" <felix.kuehling@amd.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Matthew Brost" <matthew.brost@intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Aveline Noir" <jm5905938@gmail.com>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: Xiaogang Chen <xiaogang.chen@amd.com>,
Oak Zeng <Oak.Zeng@amd.com>, "Jenny Liu" <Jenny-Jing.Liu@amd.com>,
Zhu Lingshan <lingshan.zhu@amd.com>,
"Honglei Huang" <honglei1.huang@amd.com>,
Junhua Shen <Junhua.Shen@amd.com>, Yiru Ma <yiru.ma@amd.com>,
Huang Rui <ray.huang@amd.com>, Honglei Huang <honghuan@amd.com>,
Yu Huang <Yu.Huang@amd.com>
Subject: [PATCH v11 13/22] drm/amdgpu: make VM eviction lock read/write to match notifier lock
Date: Fri, 27 Nov 2026 16:41:36 +0800 [thread overview]
Message-ID: <20261127084149.925625-14-ray.huang@amd.com> (raw)
In-Reply-To: <20261127084149.925625-1-ray.huang@amd.com>
From: Honglei Huang <honghuan@amd.com>
Make the VM eviction lock read/write to match the drm_gpusvm notifier
lock. This allows VM updates, MMU notifier invalidation and eviction to
share the same rwsem.
Replace the VM eviction mutex with a selectable rwsem. Updates made with
the root BO reserved take the read side. Updates without the root BO
reservation take the write side, as does eviction. A VM using
drm_gpusvm can use the notifier lock as its eviction lock.
Suggested-by: Christian König <christian.koenig@amd.com>
Suggested-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Yu Huang <Yu.Huang@amd.com>
Signed-off-by: Honglei Huang <honghuan@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++++----
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 8 ++++----
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h | 12 ++++++++++--
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8831eb7c7cbc7..6f7043bdd2020 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -673,7 +673,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,
* As soon as all page tables are in place we can start updating them
* again.
*/
- scoped_guard(mutex, &vm->eviction_lock)
+ scoped_guard(rwsem_write, vm->eviction_lock)
vm->evicting = false;
list_for_each_entry_safe(bo_base, tmp, &vm->always_valid.evicted,
@@ -734,7 +734,7 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
amdgpu_vm_assert_locked(vm);
- scoped_guard(mutex, &vm->eviction_lock)
+ scoped_guard(rwsem_read, vm->eviction_lock)
ret = !vm->evicting;
ret &= list_empty(&vm->kernel.evicted);
@@ -2392,7 +2392,7 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)
/* Try to block ongoing updates */
vm = bo_base->vm;
- scoped_cond_guard(mutex_try, return false, &vm->eviction_lock) {
+ scoped_cond_guard(rwsem_write_try, return false, vm->eviction_lock) {
/* Don't evict VM page tables while they are updated */
if (!dma_fence_is_signaled(vm->last_unlocked))
@@ -2767,7 +2767,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
vm->last_tlb_inv = dma_fence_get_stub();
vm->generation = amdgpu_vm_generation(adev, NULL);
- mutex_init(&vm->eviction_lock);
+ init_rwsem(&vm->default_eviction_lock);
+ vm->eviction_lock = &vm->default_eviction_lock;
vm->evicting = false;
vm->tlb_fence_context = dma_fence_context_alloc(1);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index bf752c6959b5c..05e332c1e01f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -27,6 +27,7 @@
#include <linux/idr.h>
#include <linux/kfifo.h>
#include <linux/rbtree.h>
+#include <linux/rwsem.h>
#include <drm/gpu_scheduler.h>
#include <drm/drm_file.h>
#include <drm/ttm/ttm_bo.h>
@@ -288,10 +289,9 @@ struct amdgpu_vm {
/* tree of virtual addresses mapped */
struct rb_root_cached va;
- /* Lock to prevent eviction while we are updating page tables
- * use vm_eviction_lock/unlock(vm)
- */
- struct mutex eviction_lock;
+ /* SVM can replace this pointer with its notifier lock. */
+ struct rw_semaphore default_eviction_lock;
+ struct rw_semaphore *eviction_lock;
bool evicting;
/* Memory statistics for this vm, protected by stats_lock */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
index 8a0e5fcbd55ba..920d0b3935807 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
@@ -160,7 +160,12 @@ void amdgpu_vm_pt_free_dummies(struct amdgpu_device *adev);
*/
static inline int amdgpu_vm_begin_critical(struct amdgpu_vm_update_params *p)
{
- mutex_lock(&p->vm->eviction_lock);
+ /* Use the write lock to serialize updates when the root BO is unlocked. */
+ if (p->unlocked)
+ down_write(p->vm->eviction_lock);
+ else
+ down_read(p->vm->eviction_lock);
+
p->saved_flags = memalloc_noreclaim_save();
if (p->vm->evicting)
return -EBUSY;
@@ -178,7 +183,10 @@ static inline int amdgpu_vm_begin_critical(struct amdgpu_vm_update_params *p)
static inline void amdgpu_vm_end_critical(struct amdgpu_vm_update_params *p)
{
memalloc_noreclaim_restore(p->saved_flags);
- mutex_unlock(&p->vm->eviction_lock);
+ if (p->unlocked)
+ up_write(p->vm->eviction_lock);
+ else
+ up_read(p->vm->eviction_lock);
}
#endif
--
2.53.0
next prev parent reply other threads:[~2026-11-27 8:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 8:41 [PATCH v11 00/22] drm/amdgpu: AMDGPU SVM support based on DRM (Phase 1: single GPU, XNACK on) Huang Rui
2026-11-27 8:41 ` [PATCH v11 01/22] drm/amdgpu: decouple PTE encoding from buffer objects Huang Rui
2026-11-27 8:41 ` [PATCH v11 02/22] drm/amdgpu: add SVM ioctl UAPI definitions Huang Rui
2026-11-27 8:41 ` [PATCH v11 03/22] drm/amdgpu: add SVM core header and VM integration Huang Rui
2026-11-27 8:41 ` [PATCH v11 04/22] drm/amdgpu: implement SVM attribute tree and helper functions Huang Rui
2026-11-27 8:41 ` [PATCH v11 05/22] drm/amdgpu: implement SVM attribute set/get/clear operations Huang Rui
2026-11-27 8:41 ` [PATCH v11 06/22] drm/amdgpu: add SVM range types and work queue interface Huang Rui
2026-11-27 8:41 ` [PATCH v11 07/22] drm/amdgpu: implement SVM range GPU mapping core Huang Rui
2026-11-27 8:41 ` [PATCH v11 08/22] drm/amdgpu: implement SVM range notifier and GC helpers Huang Rui
2026-11-27 8:41 ` [PATCH v11 09/22] drm/amdgpu: add SVM notifier invalidate callback Huang Rui
2026-11-27 8:41 ` [PATCH v11 10/22] drm/amdgpu: implement SVM initialization and lifecycle Huang Rui
2026-11-27 8:41 ` [PATCH v11 11/22] drm/amdgpu: add SVM ioctl entry and fault handler module Huang Rui
2026-11-27 8:41 ` [PATCH v11 12/22] drm/amdgpu: integrate SVM into build system and VM fault path Huang Rui
2026-11-27 8:41 ` Huang Rui [this message]
2026-11-27 8:41 ` [PATCH v11 14/22] drm/amdgpu: recheck range validity after page table allocation Huang Rui
2026-11-27 8:41 ` [PATCH v11 15/22] drm/amdgpu: use drm_gpusvm notifier lock for VM eviction Huang Rui
2026-11-27 8:41 ` [PATCH v11 16/22] drm/pagemap: fix page undercount for compound src entries Huang Rui
2026-11-27 8:41 ` [PATCH v11 17/22] drm/amdgpu: add VRAM migration infrastructure for drm_pagemap Huang Rui
2026-11-27 8:41 ` [PATCH v11 18/22] drm/amdgpu: implement drm_pagemap SDMA migration callbacks Huang Rui
2026-11-27 8:41 ` [PATCH v11 19/22] drm/amdgpu: implement synchronous TTM eviction for SVM BOs Huang Rui
2026-11-27 8:41 ` [PATCH v11 20/22] drm/amdgpu: hook up ZONE_DEVICE registration in device init and reset Huang Rui
2026-11-27 8:41 ` [PATCH v11 21/22] drm/amdgpu: add SVM range migration helpers for drm_pagemap Huang Rui
2026-11-27 8:41 ` [PATCH v11 22/22] drm/amdgpu: integrate VRAM migration into SVM fault and prefetch paths Huang Rui
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=20261127084149.925625-14-ray.huang@amd.com \
--to=ray.huang@amd.com \
--cc=Jenny-Jing.Liu@amd.com \
--cc=Junhua.Shen@amd.com \
--cc=Oak.Zeng@amd.com \
--cc=Philip.Yang@amd.com \
--cc=Yu.Huang@amd.com \
--cc=alexander.deucher@amd.com \
--cc=aliceryhl@google.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
--cc=honghuan@amd.com \
--cc=honglei1.huang@amd.com \
--cc=jm5905938@gmail.com \
--cc=lingshan.zhu@amd.com \
--cc=matthew.brost@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=xiaogang.chen@amd.com \
--cc=yiru.ma@amd.com \
/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.