drm/amdkfd: Fix false positive queue buffer free warning
Subsystems (3)
PATCH v2 1/2 drm/amdkfd: Fix false positive queue buffer free warning
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,bool unmap_parent;uint32_t i; -if (atomic_read (&prange->queue_refcount)) { + p =kfd_lookup_process_by_mm (mm); + +if (p &&atomic_read (&prange->queue_refcount)) {int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,pr_debug ("failed %d to quiesce KFD queues\n" , r); } - p =kfd_lookup_process_by_mm (mm);if (!p)return ; svms = &p->svms;
Signature · 1 line
2.49.0
PATCH v2 2/2 drm/amdkfd: Stop user queues when process mm released
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +6 -1
@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn)static void kfd_process_notifier_release_internal (struct kfd_process *p) { -int i; +int i, r;cancel_delayed_work_sync (&p->eviction_work);cancel_delayed_work_sync (&p->restore_work); +WARN (debug_evictions,"Evicting pid %d" , p->lead_thread->pid); + r =kfd_process_evict_queues (p,KFD_QUEUE_EVICTION_TRIGGER_SVM ); +if (r) +pr_debug ("failed %d to quiesce KFD queues\n" , r); +for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i];
Signature · 1 line
2.49.0
Re: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
Quoted 14 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling<[email protected]>Signed-off-by Philip Yang<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1229
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-1@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn)static void kfd_process_notifier_release_internal (struct kfd_process *p) { -int i; +int i, r;cancel_delayed_work_sync (&p->eviction_work);cancel_delayed_work_sync (&p->restore_work); +WARN (debug_evictions,"Evicting pid %d" , p->lead_thread->pid);
Use warning message or debug message? I saw this WARN are used several places. If the queues from kfd process p are still running when come here we need to stop them. It is not error. debug message is more suitable I think.
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1230
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0+ r =kfd_process_evict_queues (p,KFD_QUEUE_EVICTION_TRIGGER_SVM );
The evict reason KFD_QUEUE_EVICTION_TRIGGER_SVM is not good here as it is general kfd process release. Maybe need another enum value.
Regards
Xiaogagn
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (r) +pr_debug ("failed %d to quiesce KFD queues\n" , r); +for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i];
Re: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
Quoted 23 lines · Xiaogang
Quoted 20 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling<[email protected]>Signed-off-by Philip Yang<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-1@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn)static void kfd_process_notifier_release_internal (struct kfd_process *p) { -int i; +int i, r;
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1229
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0cancel_delayed_work_sync (&p->eviction_work);cancel_delayed_work_sync (&p->restore_work); +WARN (debug_evictions,"Evicting pid %d" , p->lead_thread->pid);Use warning message or debug message? I saw this WARN are used several places. If the queues from kfd process p are still running when come here we need to stop them. It is not error. debug message is more suitable I think.
The module parameter debug_evictions can be set to true, use WARN to dump call back trace to help understand why queue is evicted, by default debug_evictions is false.
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1230
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0+ r =kfd_process_evict_queues (p,KFD_QUEUE_EVICTION_TRIGGER_SVM );The evict reason
KFD_QUEUE_EVICTION_TRIGGER_SVMis not good here as it is general kfd process release. Maybe need another enum value.
Define new profiling event requires rocprofiler API change, KFD_QUEUE_EVICTION_TRIGGER_SVM seems the closest event from mmu notifier.
Regards,
Philip
Quoted 10 lines
Regards
Xiaogagn
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (r) +pr_debug ("failed %d to quiesce KFD queues\n" , r); +for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i];
Re: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
Quoted 30 lines · Philip Yang
Quoted 12 lines · Xiaogang
Quoted 9 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling<[email protected]>Signed-off-by Philip Yang<[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_process.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct · line 1227
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-1@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn) static void kfd_process_notifier_release_internal(struct kfd_process *p) { - int i; + int i, r; cancel_delayed_work_sync(&p->eviction_work); cancel_delayed_work_sync(&p->restore_work); + WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);Use warning message or debug message? I saw this WARN are used several places. If the queues from kfd process p are still running when come here we need to stop them. It is not error. debug message is more suitable I think.
Quoted 1 line
The module parameter
debug_evictionscan be set to true, use WARN to dump call back trace to help understand why queue is evicted, by defaultdebug_evictionsis false.
I agree stopping kfd process's queues during kfd process release. Just wonder if change WARN to debug message form. We can use dump_stack() to dump stack anyway, but it is not relevant to this patch.
Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1230
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0+ r = kfd_process_evict_queues(p, KFD_QUEUE_EVICTION_TRIGGER_SVM);The evict reason
KFD_QUEUE_EVICTION_TRIGGER_SVMis not good here as it is general kfd process release. Maybe need another enum value.Define new profiling event requires rocprofiler API change,
KFD_QUEUE_EVICTION_TRIGGER_SVMseems the closest event from mmu notifier.
That is awkward. We may add a emu value at end that rocprofile would not know for now.
Regards
Xiaogang
Quoted 14 lines
Regards,
Philip
Quoted 9 lines
Regards
Xiaogagn
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+ if (r) + pr_debug("failed %d to quiesce KFD queues\n", r); + for (i = 0; i < p->n_pdds; i++) { struct kfd_process_device *pdd = p->pdds[i];
Felix Kuehling
maintainerRe: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
Quoted 35 lines · Xiaogang
Quoted 30 lines · Philip Yang
Quoted 12 lines · Xiaogang
Quoted 9 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling<[email protected]>Signed-off-by Philip Yang<[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_process.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void · line 1227
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-1@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn) static void kfd_process_notifier_release_internal(struct kfd_process *p) { - int i; + int i, r; cancel_delayed_work_sync(&p->eviction_work); cancel_delayed_work_sync(&p->restore_work); + WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);Use warning message or debug message? I saw this WARN are used several places. If the queues from kfd process p are still running when come here we need to stop them. It is not error. debug message is more suitable I think.
Quoted 1 line
The module parameter
debug_evictionscan be set to true, use WARN to dump call back trace to help understand why queue is evicted, by defaultdebug_evictionsis false.I agree stopping kfd process's queues during kfd process release. Just wonder if change WARN to debug message form. We can use
dump_stack()to dump stack anyway, but it is not relevant to this patch.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1230
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0+ r = kfd_process_evict_queues(p, KFD_QUEUE_EVICTION_TRIGGER_SVM);The evict reason
KFD_QUEUE_EVICTION_TRIGGER_SVMis not good here as it is general kfd process release. Maybe need another enum value.Define new profiling event requires rocprofiler API change,
KFD_QUEUE_EVICTION_TRIGGER_SVMseems the closest event from mmu notifier.That is awkward. We may add a emu value at end that rocprofile would not know for now.
roc-profile collects events in the running process context. This only happens on process termination. roc-profile will never see these events. So it really doesn't matter.
Regards,
Felix
Quoted 20 lines
Regards
Xiaogang
Quoted 14 lines
Regards,
Philip
Quoted 9 lines
Regards
Xiaogagn
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+ if (r) + pr_debug("failed %d to quiesce KFD queues\n", r); + for (i = 0; i < p->n_pdds; i++) { struct kfd_process_device *pdd = p->pdds[i];
Felix Kuehling
maintainerRe: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
In reply to Philip YangQuoted 15 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn)
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct mmu_notifier *mn) · line 1230
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-1static void kfd_process_notifier_release_internal (struct kfd_process *p) { -int i; +int i, r;cancel_delayed_work_sync (&p->eviction_work);cancel_delayed_work_sync (&p->restore_work); +WARN (debug_evictions,"Evicting pid %d" , p->lead_thread->pid); + r =kfd_process_evict_queues (p,KFD_QUEUE_EVICTION_TRIGGER_SVM );
Is there a reason why we can't just call kfd_process_dequeue_from_all_devices here, and remove that call from kfd_process_wq_release? We don't need to call this an eviction. The queues get removed on process termination anyway. We're just doing it a bit earlier now.
Regards,
Felix
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (r) +pr_debug ("failed %d to quiesce KFD queues\n" , r); +for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i];
Re: [PATCH v2 2/2] drm/amdkfd: Stop user queues when process mm released
Quoted 11 lines · Felix Kuehling
Quoted 9 lines · Philip Yang
In mmu notifier release callback, stop user queues to be safe because the SVM memory is going to unmap from CPU.
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_process.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_notifier(struct · line 1228
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-1@@ -1221,11 +1221,16 @@ static void kfd_process_free_notifier(struct mmu_notifier *mn) static void kfd_process_notifier_release_internal(struct kfd_process *p) { - int i; + int i, r; cancel_delayed_work_sync(&p->eviction_work); cancel_delayed_work_sync(&p->restore_work); + WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid); + r = kfd_process_evict_queues(p, KFD_QUEUE_EVICTION_TRIGGER_SVM);Is there a reason why we can't just call
kfd_process_dequeue_from_all_deviceshere, and remove that call fromkfd_process_wq_release? We don't need to call this an eviction. The queues get removed on process termination anyway. We're just doing it a bit earlier now.
MMU release notifier callback don't hold mmap lock, it is safe to call kfd_process_dequeue_from_all_devices here, will send new version for review.
Regards,
Philip
Quoted 10 lines
Regards,
FelixQuoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+ if (r) + pr_debug("failed %d to quiesce KFD queues\n", r); + for (i = 0; i < p->n_pdds; i++) { struct kfd_process_device *pdd = p->pdds[i];
Quoted 5 lines · Philip Yang
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If
kfd_lookup_process_by_mmreturn NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.
But another question is why a prange is still alive, its kfd process is gone?
When unmap a prange the queues that use it should have been stopped. If not, there is problem somewhere. This warning message need be sent no matter kfd process exists or not.
I think a real problem here is kfd process need be alive as long as any of its resource is still alive. In this case since prange is still alive its kfd process should not be released(p should not be null). If not we need wait all pranges from this process got released, then release this kfd process.
Regards
Xiaogang
Quoted 30 lines
Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-2@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,bool unmap_parent;uint32_t i; -if (atomic_read (&prange->queue_refcount)) { + p =kfd_lookup_process_by_mm (mm); + +if (p &&atomic_read (&prange->queue_refcount)) {int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,pr_debug ("failed %d to quiesce KFD queues\n" , r); } - p =kfd_lookup_process_by_mm (mm);if (!p)return ; svms = &p->svms;
Quoted 9 lines · Xiaogang
Quoted 5 lines · Philip Yang
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If
kfd_lookup_process_by_mmreturn NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.But another question is why a prange is still alive, its kfd process is gone?
It is application process exited, kfd process structure still exist and available. The issue is race condition:
do_exit
exit_mmap
a. mmu mm release notifier, schedule kfd release wq to destroy queue unmap_vmas
b. mmu_notifier_range(.. MMU_NOTIFY_UNMAP...)
the step b is executed to unmap CWSR svm range, before step a kfd release wq destroy queue.
Quoted 4 lines
When unmap a prange the queues that use it should have been stopped. If not, there is problem somewhere. This warning message need be sent no matter kfd process exists or not.
I think a real problem here is kfd process need be alive as long as any of its resource is still alive. In this case since prange is still alive its kfd process should not be released(p should not be null). If not we need wait all pranges from this process got released, then release this kfd process.
kfd process structure is freed in kfd_process_wq_release after svm_range_list_fini.
Regards,
Philip
Quoted 34 lines
Regards
Xiaogang
Quoted 29 lines
Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-0@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm,struct svm_range *prange, bool unmap_parent; uint32_t i; - if (atomic_read(&prange->queue_refcount)) { + p = kfd_lookup_process_by_mm(mm); + + if (p && atomic_read(&prange->queue_refcount)) { int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, pr_debug("failed %d to quiesce KFD queues\n", r); } - p = kfd_lookup_process_by_mm(mm); if (!p) return;svms =
&p->svms;
Quoted 23 lines · Philip Yang
Quoted 9 lines · Xiaogang
Quoted 5 lines · Philip Yang
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If
kfd_lookup_process_by_mmreturn NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.But another question is why a prange is still alive, its kfd process is gone?
It is application process exited, kfd process structure still exist and available. The issue is race condition:
do_exit
exit_mmap
a. mmu mm release notifier, schedule kfd release wq to destroy queueunmap_vmas
b. mmu_notifier_range(..MMU_NOTIFY_UNMAP...)the step b is executed to unmap CWSR svm range, before step a kfd release wq destroy queue.
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
When unmap a prange the queues that use it should have been stopped. If not, there is problem somewhere. This warning message need be sent no matter kfd process exists or not.
I think a real problem here is kfd process need be alive as long as any of its resource is still alive. In this case since prange is still alive its kfd process should not be released(p should not be null). If not we need wait all pranges from this process got released, then release this kfd process.
kfd process structure is freed in
kfd_process_wq_releaseaftersvm_range_list_fini.
I wanted to say: delay remove kfd process p from kfd_processes_table until all resources of p got released. So when any p's resources is getting released p is available. That needs change kfd process release logic.
Regards
Xiaogang
Quoted 39 lines
Regards,
Philip
Quoted 34 lines
Regards
Xiaogang
Quoted 29 lines
Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-0@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm,struct svm_range *prange, bool unmap_parent; uint32_t i; - if (atomic_read(&prange->queue_refcount)) { + p = kfd_lookup_process_by_mm(mm); + + if (p && atomic_read(&prange->queue_refcount)) { int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, pr_debug("failed %d to quiesce KFD queues\n", r); } - p = kfd_lookup_process_by_mm(mm); if (!p) return;svms =
&p->svms;
Quoted 25 lines · Xiaogang
Quoted 23 lines · Philip Yang
Quoted 9 lines · Xiaogang
Quoted 5 lines · Philip Yang
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If
kfd_lookup_process_by_mmreturn NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.But another question is why a prange is still alive, its kfd process is gone?
It is application process exited, kfd process structure still exist and available. The issue is race condition:
do_exit
exit_mmap
a. mmu mm release notifier, schedule kfd release wq to destroy queueunmap_vmas
b. mmu_notifier_range(..MMU_NOTIFY_UNMAP...)the step b is executed to unmap CWSR svm range, before step a kfd release wq destroy queue.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
When unmap a prange the queues that use it should have been stopped. If not, there is problem somewhere. This warning message need be sent no matter kfd process exists or not.
I think a real problem here is kfd process need be alive as long as any of its resource is still alive. In this case since prange is still alive its kfd process should not be released(p should not be null). If not we need wait all pranges from this process got released, then release this kfd process.
kfd process structure is freed in
kfd_process_wq_releaseaftersvm_range_list_fini.I wanted to say: delay remove kfd process p from
kfd_processes_tableuntil all resources of p got released. So when any p's resources is getting released p is available. That needs change kfd process release logic.
prange->queue_refcount will be 0 after queue is destroyed (not evicted), we should warn user space and evict queues if prange is freed with prange->queue_refcount not zero. This patch is to fix the race that generate false warning after process exited to free prange. I don't think that keep kfd process in kfd_processes_table after mmu release notifier will solve this race issue.
Regards,
Philip
Quoted 48 lines
Regards
Xiaogang
Quoted 39 lines
Regards,
Philip
Quoted 34 lines
Regards
Xiaogang
Quoted 29 lines
Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-0@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, bool unmap_parent; uint32_t i; - if (atomic_read(&prange->queue_refcount)) { + p = kfd_lookup_process_by_mm(mm); + + if (p && atomic_read(&prange->queue_refcount)) { int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, pr_debug("failed %d to quiesce KFD queues\n", r); } - p = kfd_lookup_process_by_mm(mm); if (!p) return;svms =
&p->svms;
Felix Kuehling
maintainerQuoted 25 lines · Xiaogang
Quoted 23 lines · Philip Yang
Quoted 9 lines · Xiaogang
Quoted 5 lines · Philip Yang
Only show warning message if process mm is still alive when queue buffer is freed to evcit the queues.
If
kfd_lookup_process_by_mmreturn NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.But another question is why a prange is still alive, its kfd process is gone?
It is application process exited, kfd process structure still exist and available. The issue is race condition:
do_exit
exit_mmap
a. mmu mm release notifier, schedule kfd release wq to destroy queueunmap_vmas
b. mmu_notifier_range(..MMU_NOTIFY_UNMAP...)the step b is executed to unmap CWSR svm range, before step a kfd release wq destroy queue.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
When unmap a prange the queues that use it should have been stopped. If not, there is problem somewhere. This warning message need be sent no matter kfd process exists or not.
I think a real problem here is kfd process need be alive as long as any of its resource is still alive. In this case since prange is still alive its kfd process should not be released(p should not be null). If not we need wait all pranges from this process got released, then release this kfd process.
kfd process structure is freed in
kfd_process_wq_releaseaftersvm_range_list_fini.I wanted to say: delay remove kfd process p from
kfd_processes_tableuntil all resources of p got released. So when any p's resources is getting released p is available. That needs change kfd process release logic.
That would complicate the cleanup a lot, because now other threads can still look up the kfd_process and use or modify it concurrently while the cleanup is happening. We remove the process from the kfd_processes_table first to ensure that it is safe to clean up all the process resources.
Regards,
Felix
Quoted 48 lines
Regards
Xiaogang
Quoted 39 lines
Regards,
Philip
Quoted 34 lines
Regards
Xiaogang
Quoted 29 lines
Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-0@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, bool unmap_parent; uint32_t i; - if (atomic_read(&prange->queue_refcount)) { + p = kfd_lookup_process_by_mm(mm); + + if (p && atomic_read(&prange->queue_refcount)) { int r; pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, pr_debug("failed %d to quiesce KFD queues\n", r); } - p = kfd_lookup_process_by_mm(mm); if (!p) return;svms =
&p->svms;