drm/amdkfd: Fix mmap write lock not release
Subsystems (3)
PATCH 1/1 drm/amdkfd: Fix mmap write lock not release
If mmap write lock is taken while draining retry fault, mmap write lock is not released because svm_range_restore_pages calls mmap_read_unlock then returns. This causes deadlock and systen hang later because mmap read or write lock cannot be taken.
Downgrade mmap write lock to read lock if draining retry fault fix this bug.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
@@ -3043,6 +3043,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,if (svms->checkpoint_ts[gpuidx] !=0 ) {if (amdgpu_ih_ts_after_or_equal (ts, svms->checkpoint_ts[gpuidx])) {pr_debug ("draining retry fault, drop fault 0x%llx\n" , addr); +if (write_locked) +mmap_write_downgrade (mm); r = -EAGAIN ; goto out_unlock_svms; }else {
Signature · 1 line
2.49.0
[AMD Official Use Only - AMD Internal Distribution Only]
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Philip Yang
Sent: Tuesday, September 16, 2025 6:41 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Yang, Philip <[email protected]>
Subject: [PATCH] drm/amdkfd: Fix mmap write lock not release
If mmap write lock is taken while draining retry fault, mmap write lock is not released because svm_range_restore_pages calls mmap_read_unlock then returns. This causes deadlock and systen hang later because mmap read or write lock cannot be taken.
Downgrade mmap write lock to read lock if draining retry fault fix this bug.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
@@ -3043,6 +3043,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,if (svms->checkpoint_ts[gpuidx] !=0 ) {if (amdgpu_ih_ts_after_or_equal (ts, svms->checkpoint_ts[gpuidx])) {pr_debug ("draining retry fault, drop fault 0x%llx\n" , addr); +if (write_locked) +mmap_write_downgrade (mm); r = -EAGAIN ; goto out_unlock_svms; }else {
--
2.49.0
Quoted 18 lines · Philip Yang
If mmap write lock is taken while draining retry fault, mmap write lock is not released because
svm_range_restore_pagescallsmmap_read_unlockthen returns. This causes deadlock and systen hang later because mmap read or write lock cannot be taken.Downgrade mmap write lock to read lock if draining retry fault fix this bug.
Signed-off-by Philip Yang<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid, · line 3047
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0@@ -3043,6 +3043,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,if (svms->checkpoint_ts[gpuidx] !=0 ) {if (amdgpu_ih_ts_after_or_equal (ts, svms->checkpoint_ts[gpuidx])) {pr_debug ("draining retry fault, drop fault 0x%llx\n" , addr); +if (write_locked) +mmap_write_downgrade (mm);
Is there unlock order issue? Now it holds svms->lock first, then mmap read lock after mmap_write_downgrade. The unlock should be mmap_read_unlock(mm), then mutex_unlock(&svms->lock). "goto out_unlock_svms" does it in reverse order.
Regards
Xiaogang
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0r = -EAGAIN ; goto out_unlock_svms; }else {
Quoted 16 lines · Xiaogang
Quoted 13 lines · Philip Yang
If mmap write lock is taken while draining retry fault, mmap write lock is not released because
svm_range_restore_pagescallsmmap_read_unlockthen returns. This causes deadlock and systen hang later because mmap read or write lock cannot be taken.Downgrade mmap write lock to read lock if draining retry fault fix this bug.
Signed-off-by Philip Yang<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid, · line 3047
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0@@ -3043,6 +3043,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,if (svms->checkpoint_ts[gpuidx] !=0 ) {if (amdgpu_ih_ts_after_or_equal (ts, svms->checkpoint_ts[gpuidx])) {pr_debug ("draining retry fault, drop fault 0x%llx\n" , addr); +if (write_locked) +mmap_write_downgrade (mm);Is there unlock order issue? Now it holds
svms->lockfirst, then mmap read lock aftermmap_write_downgrade. The unlock should bemmap_read_unlock(mm), then mutex_unlock(&svms->lock). "gotoout_unlock_svms" does it in reverse order.
downgrading write lock doesn't change lock order (not in two steps like up_write, down_read), we downgrade mmap write lock in normal path as well, but missing it in this error handling path.
Regards,
Philip
Quoted 7 lines
Regards
Xiaogang
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0r = -EAGAIN ; goto out_unlock_svms; }else {