FAILED: patch "[PATCH] drm/amdkfd: stop restore retries on device unplug" failed to apply to 6.6-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 3254ed0b15f2fe656c9cb36ccb59b92422440bf8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 3254ed0b15f2fe656c9cb36ccb59b92422440bf8 Mon Sep 17 00:00:00 2001
From: Olivier Kaloudoff <[email protected]>
Date: Tue, 13 Oct 2026 20:53:12 +0200
Subject: [PATCH] drm/amdkfd: stop restore retries on device unplug
amdgpu_amdkfd_restore_userptr_worker() and svm_range_restore_work() reschedule themselves when validation fails with evicted objects pending. After a surprise removal the restore paths fail with -ENODEV permanently, so rescheduling just spins the worker uselessly until cancel_delayed_work_sync() in fini finally stops it - which can take a while, since process teardown itself is delayed by the dead device.
Treat -ENODEV as terminal in both workers.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 18 +++++++++++++----- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +13 -5
@@ -2854,6 +2854,7 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)struct task_struct *usertask;struct mm_struct *mm;uint32_t evicted_bos; +int ret;mutex_lock (&process_info->notifier_lock); evicted_bos = process_info->evicted_bos;
@@ -2873,14 +2874,16 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)mutex_lock (&process_info->lock); -if (update_invalid_user_pages (process_info, mm)) + ret =update_invalid_user_pages (process_info, mm); +if (ret) goto unlock_out;/* userptr_inval_list can be empty if all evicted userptr BOs * have been freed. In that case there is nothing to validate * and we can just restart the queues. */ if (!list_empty (&process_info->userptr_inval_list)) { -if (validate_invalid_user_pages (process_info)) + ret =validate_invalid_user_pages (process_info); +if (ret) goto unlock_out; }/* Final check for concurrent evicton and atomic update. If
@@ -2889,11 +2892,14 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)* reference counting inside KFD will handle this case. */ mutex_lock (&process_info->notifier_lock); -if (process_info->evicted_bos != evicted_bos) +if (process_info->evicted_bos != evicted_bos) { + ret = -EAGAIN ; goto unlock_notifier_out; + }if (confirm_valid_user_pages_locked (process_info)) {WARN (1 ,"User pages unexpectedly invalid" ); + ret = -EINVAL ; goto unlock_notifier_out; }
@@ -2911,8 +2917,10 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work) unlock_out:mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_bos) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_bos && ret != -ENODEV ) {queue_delayed_work (system_freezable_wq, &process_info->restore_userptr_work,msecs_to_jiffies (AMDGPU_USERPTR_RESTORE_DELAY_MS ));
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -3
@@ -1963,7 +1963,7 @@ static void svm_range_restore_work(struct work_struct *work)struct mm_struct *mm;int evicted_ranges;int invalid; -int r; +int r =0 ; svms = container_of(dwork, struct svm_range_list, restore_work); evicted_ranges =atomic_read (&svms->evicted_ranges);
@@ -2037,8 +2037,10 @@ static void svm_range_restore_work(struct work_struct *work)mmap_write_unlock (mm);mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_ranges) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_ranges && r != -ENODEV ) {pr_debug ("reschedule to restore svm range\n" );queue_delayed_work (system_freezable_wq, &svms->restore_work,msecs_to_jiffies (AMDGPU_SVM_RANGE_RESTORE_DELAY_MS ));
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 drm/amdkfd: Run restore_workers on freezable WQs
From: Felix Kuehling <[email protected]>
[ Upstream commit 9a1c1339abf972477aeef4ea037e650f49c5892d ]
Make restore workers freezable so we don't have to explicitly flush them in suspend and GPU reset code paths, and we don't accidentally try to restore BOs while the GPU is suspended. Not having to flush restore_work also helps avoid lock/fence dependencies in the GPU reset case where we're not allowed to wait for fences.
A side effect of this is, that we can now have multiple concurrent threads trying to signal the same eviction fence. Rework eviction fence signaling and replacement to account for that.
The GPU reset path can no longer rely on restore_process_worker to resume queues because evict/restore workers can run independently of it. Instead call a new restore_process_helper directly.
This is an RFC and request for testing.
v2:
- Reworked eviction fence signaling
- Introduced restore_process_helper
v3:
- Handle unsignaled eviction fences in restore_process_bos
Stable-dep-of: 3254ed0b15f2 ("drm/amdkfd: stop restore retries on device unplug")
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 68 +++++++++++---- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 87 +++++++++++-------- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 4 +- 3 files changed, 104 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +49 -19
@@ -1348,7 +1348,6 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, amdgpu_amdkfd_restore_userptr_worker); *process_info = info; - *ef =dma_fence_get (&info->eviction_fence->base); }if (cmpxchg (&vm->process_info,NULL , *process_info) !=NULL ) {
@@ -1382,6 +1381,8 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,list_add_tail (&vm->vm_list_node, &(vm->process_info->vm_list_head)); vm->process_info->n_vms++; + + *ef =dma_fence_get (&vm->process_info->eviction_fence->base);mutex_unlock (&vm->process_info->lock);return 0 ;
@@ -1394,10 +1395,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, vm->process_info =NULL ; already_acquired:if (info) { -/* Two fence references: one in info and one in *ef */ dma_fence_put (&info->eviction_fence->base); -dma_fence_put (*ef); - *ef =NULL ; *process_info =NULL ;put_pid (info->pid); create_evict_fence_fail:
@@ -1591,7 +1589,8 @@ int amdgpu_amdkfd_criu_resume(void *p) goto out_unlock; }WRITE_ONCE (pinfo->block_mmu_notifications, false); -schedule_delayed_work (&pinfo->restore_userptr_work,0 ); +queue_delayed_work (system_freezable_wq, + &pinfo->restore_userptr_work,0 ); out_unlock:mutex_unlock (&pinfo->lock);
@@ -2425,7 +2424,8 @@ int amdgpu_amdkfd_evict_userptr(struct mmu_interval_notifier *mni, KFD_QUEUE_EVICTION_TRIGGER_USERPTR);if (r)pr_err ("Failed to quiesce KFD\n" ); -schedule_delayed_work (&process_info->restore_userptr_work, +queue_delayed_work (system_freezable_wq, + &process_info->restore_userptr_work,msecs_to_jiffies (AMDGPU_USERPTR_RESTORE_DELAY_MS )); }mutex_unlock (&process_info->notifier_lock);
@@ -2748,7 +2748,8 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)/* If validation failed, reschedule another attempt */ if (evicted_bos) { -schedule_delayed_work (&process_info->restore_userptr_work, +queue_delayed_work (system_freezable_wq, + &process_info->restore_userptr_work,msecs_to_jiffies (AMDGPU_USERPTR_RESTORE_DELAY_MS ));kfd_smi_event_queue_restore_rescheduled (mm);
@@ -2757,6 +2758,23 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)put_task_struct (usertask); } +static void replace_eviction_fence (struct dma_fence **ef, +struct dma_fence *new_ef) +{ +struct dma_fence *old_ef =rcu_replace_pointer (*ef, new_ef, true +/* protected by process_info->lock */ ); + +/* If we're replacing an unsignaled eviction fence, that fence will +* never be signaled, and if anyone is still waiting on that fence, +* they will hang forever. This should never happen. We should only +* replace the fence in restore_work that only gets scheduled after +* eviction work signaled the fence. +*/ +WARN_ONCE (!dma_fence_is_signaled (old_ef), +"Replacing unsignaled eviction fence" ); +dma_fence_put (old_ef); +} +/** amdgpu_amdkfd_gpuvm_restore_process_bos - Restore all BOs for the given * KFD process identified by process_info *
@@ -2780,7 +2798,6 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)struct amdkfd_process_info *process_info = info;struct amdgpu_vm *peer_vm;struct kgd_mem *mem; -struct amdgpu_amdkfd_fence *new_fence;struct list_head duplicate_save;struct amdgpu_sync sync_obj;unsigned long failed_size =0 ;
@@ -2887,22 +2904,35 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)/* Wait for validate and PT updates to finish */ amdgpu_sync_wait (&sync_obj, false); -/* Release old eviction fence and create new one, because fence only -* goes from unsignaled to signaled, fence cannot be reused. -* Use context and mm from the old fence. +/* The old eviction fence may be unsignaled if restore happens +* after a GPU reset or suspend/resume. Keep the old fence in that +* case. Otherwise release the old eviction fence and create new +* one, because fence only goes from unsignaled to signaled once +* and cannot be reused. Use context and mm from the old fence. +* +* If an old eviction fence signals after this check, that's OK. +* Anyone signaling an eviction fence must stop the queues first +* and schedule another restore worker. */ - new_fence =amdgpu_amdkfd_fence_create ( +if (dma_fence_is_signaled (&process_info->eviction_fence->base)) { +struct amdgpu_amdkfd_fence *new_fence = +amdgpu_amdkfd_fence_create ( process_info->eviction_fence->base.context, process_info->eviction_fence->mm,NULL ); -if (!new_fence) { -pr_err ("Failed to create eviction fence\n" ); - ret = -ENOMEM ; - goto validate_map_fail; + +if (!new_fence) { +pr_err ("Failed to create eviction fence\n" ); + ret = -ENOMEM ; + goto validate_map_fail; + } +dma_fence_put (&process_info->eviction_fence->base); + process_info->eviction_fence = new_fence; +replace_eviction_fence (ef,dma_fence_get (&new_fence->base)); + }else { +WARN_ONCE (*ef != &process_info->eviction_fence->base, +"KFD eviction fence doesn't match KGD process_info" ); } -dma_fence_put (&process_info->eviction_fence->base); - process_info->eviction_fence = new_fence; - *ef =dma_fence_get (&new_fence->base);/* Attach new eviction fence to all BOs except pinned ones */ list_for_each_entry (mem, &process_info->kfd_bo_list, validate_list) {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +53 -34
159 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
@@ -1898,7 +1898,7 @@ static void svm_range_restore_work(struct work_struct *work)/* If validation failed, reschedule another attempt */ if (evicted_ranges) {pr_debug ("reschedule to restore svm range\n" ); -schedule_delayed_work (&svms->restore_work, +queue_delayed_work (system_freezable_wq, &svms->restore_work,msecs_to_jiffies (AMDGPU_SVM_RANGE_RESTORE_DELAY_MS ));kfd_smi_event_queue_restore_rescheduled (mm);
@@ -1974,7 +1974,7 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,pr_debug ("failed to quiesce KFD\n" );pr_debug ("schedule to restore svm %p ranges\n" , svms); -schedule_delayed_work (&svms->restore_work, +queue_delayed_work (system_freezable_wq, &svms->restore_work,msecs_to_jiffies (AMDGPU_SVM_RANGE_RESTORE_DELAY_MS )); }else {unsigned long s, l;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 drm/amdkfd: stop restore retries on device unplug
From: Olivier Kaloudoff <[email protected]>
[ Upstream commit 3254ed0b15f2fe656c9cb36ccb59b92422440bf8 ]
amdgpu_amdkfd_restore_userptr_worker() and svm_range_restore_work() reschedule themselves when validation fails with evicted objects pending. After a surprise removal the restore paths fail with -ENODEV permanently, so rescheduling just spins the worker uselessly until cancel_delayed_work_sync() in fini finally stops it - which can take a while, since process teardown itself is delayed by the dead device.
Treat -ENODEV as terminal in both workers.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 18 +++++++++++++----- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +13 -5
@@ -2689,6 +2689,7 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)struct task_struct *usertask;struct mm_struct *mm;uint32_t evicted_bos; +int ret;mutex_lock (&process_info->notifier_lock); evicted_bos = process_info->evicted_bos;
@@ -2708,14 +2709,16 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)mutex_lock (&process_info->lock); -if (update_invalid_user_pages (process_info, mm)) + ret =update_invalid_user_pages (process_info, mm); +if (ret) goto unlock_out;/* userptr_inval_list can be empty if all evicted userptr BOs * have been freed. In that case there is nothing to validate * and we can just restart the queues. */ if (!list_empty (&process_info->userptr_inval_list)) { -if (validate_invalid_user_pages (process_info)) + ret =validate_invalid_user_pages (process_info); +if (ret) goto unlock_out; }/* Final check for concurrent evicton and atomic update. If
@@ -2724,11 +2727,14 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)* reference counting inside KFD will handle this case. */ mutex_lock (&process_info->notifier_lock); -if (process_info->evicted_bos != evicted_bos) +if (process_info->evicted_bos != evicted_bos) { + ret = -EAGAIN ; goto unlock_notifier_out; + }if (confirm_valid_user_pages_locked (process_info)) {WARN (1 ,"User pages unexpectedly invalid" ); + ret = -EINVAL ; goto unlock_notifier_out; }
@@ -2746,8 +2752,10 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work) unlock_out:mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_bos) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_bos && ret != -ENODEV ) {queue_delayed_work (system_freezable_wq, &process_info->restore_userptr_work,msecs_to_jiffies (AMDGPU_USERPTR_RESTORE_DELAY_MS ));
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -3
@@ -1821,7 +1821,7 @@ static void svm_range_restore_work(struct work_struct *work)struct mm_struct *mm;int evicted_ranges;int invalid; -int r; +int r =0 ; svms = container_of(dwork, struct svm_range_list, restore_work); evicted_ranges =atomic_read (&svms->evicted_ranges);
@@ -1895,8 +1895,10 @@ static void svm_range_restore_work(struct work_struct *work)mmap_write_unlock (mm);mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_ranges) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_ranges && r != -ENODEV ) {pr_debug ("reschedule to restore svm range\n" );queue_delayed_work (system_freezable_wq, &svms->restore_work,msecs_to_jiffies (AMDGPU_SVM_RANGE_RESTORE_DELAY_MS ));
Signature · 1 line
2.53.0