Fix amdgpu_vm_pt_free warning
Subsystems (2)
cover Fix amdgpu_vm_pt_free warning
When SVM range is unmapped from CPU, the mmu notifier callback update GPU page table to unmap the SVM range from GPU, this is the unlocked page table update context as we cannot take vm reservation lock. If unmapping from GPU free pt bo, this cause warning as vm reservation lock is not hold.
To fix the warning/race issue, we schedule pt_free_work to free pt bo. This has another race to remove vm_bo entry from vm status lists. Some of the vm status lists are protected by vm invalidate lock and the rest of lists are protected by vm reservation lock.
The purpose of this patch series is to use one vm status_lock to protect all vm status lists, and use it in pt_free_work to fix the race and remove the warning.
Philip Yang (7):
drm/amdgpu: Rename vm invalidate lock to status_lock drm/amdgpu: Use vm status_lock to protect relocated list drm/amdgpu: Use vm status_lock to protect vm idle list drm/amdgpu: Use vm status_lock to protect vm moved list drm/amdgpu: Use vm status_lock to protect vm evicted list drm/amdgpu: Use vm status_lock to protect pt free drm/amdgpu: Fix amdgpu_vm_pt_free warning
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 97 ++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 9 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 44 +++++++++- 3 files changed, 117 insertions(+), 33 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/7 drm/amdgpu: Rename vm invalidate lock to status_lock
The vm status_lock will be used to protect all vm status lists.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 30 +++++++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 +++- 2 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -15
@@ -225,9 +225,9 @@ static void amdgpu_vm_bo_idle(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_invalidated (struct amdgpu_vm_bo_base *vm_bo) { -spin_lock (&vm_bo->vm->invalidated_lock); +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->invalidated); -spin_unlock (&vm_bo->vm->invalidated_lock); +spin_unlock (&vm_bo->vm->status_lock); }/**
@@ -256,9 +256,9 @@ static void amdgpu_vm_bo_relocated(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_done (struct amdgpu_vm_bo_base *vm_bo) { -spin_lock (&vm_bo->vm->invalidated_lock); +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->done); -spin_unlock (&vm_bo->vm->invalidated_lock); +spin_unlock (&vm_bo->vm->status_lock); }/**
@@ -936,7 +936,7 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem,amdgpu_bo_get_memory (bo_va->base.bo, vram_mem, gtt_mem, cpu_mem); } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;
@@ -949,7 +949,7 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem,amdgpu_bo_get_memory (bo_va->base.bo, vram_mem, gtt_mem, cpu_mem); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock); }/** * amdgpu_vm_bo_update - update all BO mappings in the vm page table
@@ -1290,12 +1290,12 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,return r; } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);while (!list_empty (&vm->invalidated)) { bo_va = list_first_entry(&vm->invalidated, struct amdgpu_bo_va, base.vm_status); resv = bo_va->base.bo->tbo.base.resv; -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);/* Try to reserve the BO to avoid clearing its ptes */ if (!amdgpu_vm_debug &&dma_resv_trylock (resv))
@@ -1310,9 +1310,9 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,if (!clear)dma_resv_unlock (resv); -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);return 0 ; }
@@ -1763,9 +1763,9 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, } } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_del (&bo_va->base.vm_status); -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);list_for_each_entry_safe (mapping, next, &bo_va->valids, list) {list_del (&mapping->list);
@@ -2019,7 +2019,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)INIT_LIST_HEAD (&vm->moved);INIT_LIST_HEAD (&vm->idle);INIT_LIST_HEAD (&vm->invalidated); -spin_lock_init (&vm->invalidated_lock); +spin_lock_init (&vm->status_lock);INIT_LIST_HEAD (&vm->freed);INIT_LIST_HEAD (&vm->done);
@@ -2584,7 +2584,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m) id =0 ;seq_puts (m,"\tInvalidated BOs:\n" ); -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;
@@ -2599,7 +2599,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m)continue ; total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock); total_done_objs = id; seq_printf(m, "\tTotal idle size: %12lld\tobjs:\t%d\n", total_idle,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -1
@@ -268,7 +268,9 @@ struct amdgpu_vm {/* regular invalidated BOs, but not yet updated in the PT */ struct list_head invalidated; -spinlock_t invalidated_lock; + +/* Lock to protect vm_bo add/del/move on all lists of vm */ +spinlock_t status_lock;/* BO mappings freed, but not yet updated in the PT */ struct list_head freed;
Signature · 1 line
2.35.1
Christian König
maintainerRe: [PATCH 1/7] drm/amdgpu: Rename vm invalidate lock to status_lock
Am 16.09.22 um 17:05 schrieb Philip Yang:
Quoted 125 lines
The vm
status_lockwill be used to protect all vm status lists.Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 30 +++++++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 +++- 2 files changed, 18 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-15@@ -225,9 +225,9 @@ static void amdgpu_vm_bo_idle(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_invalidated (struct amdgpu_vm_bo_base *vm_bo) { -spin_lock (&vm_bo->vm->invalidated_lock); +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->invalidated); -spin_unlock (&vm_bo->vm->invalidated_lock); +spin_unlock (&vm_bo->vm->status_lock); }/** @@ -256,9 +256,9 @@ static void amdgpu_vm_bo_relocated(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_done (struct amdgpu_vm_bo_base *vm_bo) { -spin_lock (&vm_bo->vm->invalidated_lock); +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->done); -spin_unlock (&vm_bo->vm->invalidated_lock); +spin_unlock (&vm_bo->vm->status_lock); }/** @@ -936,7 +936,7 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem,amdgpu_bo_get_memory (bo_va->base.bo, vram_mem, gtt_mem, cpu_mem); } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;@@ -949,7 +949,7 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem,amdgpu_bo_get_memory (bo_va->base.bo, vram_mem, gtt_mem, cpu_mem); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock); }/** * amdgpu_vm_bo_update - update all BO mappings in the vm page table @@ -1290,12 +1290,12 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,return r; } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);while (!list_empty (&vm->invalidated)) { bo_va = list_first_entry(&vm->invalidated, struct amdgpu_bo_va, base.vm_status); resv = bo_va->base.bo->tbo.base.resv; -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);/* Try to reserve the BO to avoid clearing its ptes */ if (!amdgpu_vm_debug &&dma_resv_trylock (resv))@@ -1310,9 +1310,9 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,if (!clear)dma_resv_unlock (resv); -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);return 0 ; }@@ -1763,9 +1763,9 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, } } -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_del (&bo_va->base.vm_status); -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock);list_for_each_entry_safe (mapping, next, &bo_va->valids, list) {list_del (&mapping->list);@@ -2019,7 +2019,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)INIT_LIST_HEAD (&vm->moved);INIT_LIST_HEAD (&vm->idle);INIT_LIST_HEAD (&vm->invalidated); -spin_lock_init (&vm->invalidated_lock); +spin_lock_init (&vm->status_lock);INIT_LIST_HEAD (&vm->freed);INIT_LIST_HEAD (&vm->done);@@ -2584,7 +2584,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m) id =0 ;seq_puts (m,"\tInvalidated BOs:\n" ); -spin_lock (&vm->invalidated_lock); +spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;@@ -2599,7 +2599,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m)continue ; total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); } -spin_unlock (&vm->invalidated_lock); +spin_unlock (&vm->status_lock); total_done_objs = id; seq_printf(m, "\tTotal idle size: %12lld\tobjs:\t%d\n", total_idle,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 273
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3
-1@@ -268,7 +268,9 @@ struct amdgpu_vm {/* regular invalidated BOs, but not yet updated in the PT */ struct list_head invalidated; -spinlock_t invalidated_lock; + +/* Lock to protect vm_bo add/del/move on all lists of vm */ +spinlock_t status_lock;
Maybe move that field before all the list_head members. Otherwise somebody could think that the invalidated list is not protected.
Apart from that Reviewed-by: Christian König <[email protected]>
Thanks,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0/* BO mappings freed, but not yet updated in the PT */ struct list_head freed;
PATCH 2/7 drm/amdgpu: Use vm status_lock to protect relocated list
In reply to Philip Yang--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -8
@@ -240,10 +240,13 @@ static void amdgpu_vm_bo_invalidated(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) { -if (vm_bo->bo->parent) +if (vm_bo->bo->parent) { +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); -else +spin_unlock (&vm_bo->vm->status_lock); + }else {amdgpu_vm_bo_idle (vm_bo); + } }/**
@@ -680,9 +683,14 @@ int amdgpu_vm_update_pdes(struct amdgpu_device *adev,struct amdgpu_vm_update_params params;struct amdgpu_vm_bo_base *entry;bool flush_tlb_needed = false; +LIST_HEAD (relocated);int r, idx; -if (list_empty (&vm->relocated)) +spin_lock (&vm->status_lock); +list_splice_init (&vm->relocated, &relocated); +spin_unlock (&vm->status_lock); + +if (list_empty (&relocated))return 0 ;if (!drm_dev_enter (adev_to_drm (adev), &idx))
@@ -697,7 +705,7 @@ int amdgpu_vm_update_pdes(struct amdgpu_device *adev,if (r) goto error; -list_for_each_entry (entry, &vm->relocated, vm_status) { +list_for_each_entry (entry, &relocated, vm_status) {/* vm_flush_needed after updating moved PDEs */ flush_tlb_needed |= entry->moved;
@@ -713,9 +721,8 @@ int amdgpu_vm_update_pdes(struct amdgpu_device *adev,if (flush_tlb_needed)atomic64_inc (&vm->tlb_seq); -while (!list_empty (&vm->relocated)) { - entry =list_first_entry (&vm->relocated, - struct amdgpu_vm_bo_base, +while (!list_empty (&relocated)) { + entry = list_first_entry(&relocated, struct amdgpu_vm_bo_base, vm_status);amdgpu_vm_bo_idle (entry); }
@@ -912,6 +919,7 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem, {struct amdgpu_bo_va *bo_va, *tmp; +spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->idle, base.vm_status) {if (!bo_va->base.bo)continue ;
@@ -936,7 +944,6 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm, uint64_t *vram_mem,amdgpu_bo_get_memory (bo_va->base.bo, vram_mem, gtt_mem, cpu_mem); } -spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;
Signature · 1 line
2.35.1
PATCH 3/7 drm/amdgpu: Use vm status_lock to protect vm idle list
In reply to Philip Yang--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -1
@@ -211,7 +211,9 @@ static void amdgpu_vm_bo_moved(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) { +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->idle); +spin_unlock (&vm_bo->vm->status_lock); vm_bo->moved = false; }
@@ -2554,6 +2556,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m)unsigned int total_done_objs =0 ;unsigned int id =0 ; +spin_lock (&vm->status_lock);seq_puts (m,"\tIdle BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->idle, base.vm_status) {if (!bo_va->base.bo)
@@ -2591,7 +2594,6 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m) id =0 ;seq_puts (m,"\tInvalidated BOs:\n" ); -spin_lock (&vm->status_lock);list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ;
Signature · 1 line
2.35.1
PATCH 4/7 drm/amdgpu: Use vm status_lock to protect vm moved list
In reply to Philip Yang--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -3
@@ -198,7 +198,9 @@ static void amdgpu_vm_bo_evicted(struct amdgpu_vm_bo_base *vm_bo)*/ static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) { +spin_lock (&vm_bo->vm->status_lock);list_move (&vm_bo->vm_status, &vm_bo->vm->moved); +spin_unlock (&vm_bo->vm->status_lock); }/**
@@ -1287,19 +1289,24 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,int amdgpu_vm_handle_moved (struct amdgpu_device *adev,struct amdgpu_vm *vm) { -struct amdgpu_bo_va *bo_va, *tmp; +struct amdgpu_bo_va *bo_va;struct dma_resv *resv;bool clear;int r; -list_for_each_entry_safe (bo_va, tmp, &vm->moved, base.vm_status) { +spin_lock (&vm->status_lock); +while (!list_empty (&vm->moved)) { + bo_va = list_first_entry(&vm->moved, struct amdgpu_bo_va, + base.vm_status); +spin_unlock (&vm->status_lock); +/* Per VM BOs never need to bo cleared in the page tables */ r =amdgpu_vm_bo_update (adev, bo_va, false);if (r)return r; +spin_lock (&vm->status_lock); } -spin_lock (&vm->status_lock);while (!list_empty (&vm->invalidated)) { bo_va = list_first_entry(&vm->invalidated, struct amdgpu_bo_va, base.vm_status);
@@ -1396,7 +1403,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && !bo_va->base.moved) { +spin_lock (&vm->status_lock);list_move (&bo_va->base.vm_status, &vm->moved); +spin_unlock (&vm->status_lock); }trace_amdgpu_vm_bo_map (bo_va, mapping); }
Signature · 1 line
2.35.1
PATCH 5/7 drm/amdgpu: Use vm status_lock to protect vm evicted list
In reply to Philip Yang--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22 -5
@@ -183,10 +183,12 @@ static void amdgpu_vm_bo_evicted(struct amdgpu_vm_bo_base *vm_bo)struct amdgpu_bo *bo = vm_bo->bo; vm_bo->moved = true; +spin_lock (&vm_bo->vm->status_lock);if (bo->tbo.type == ttm_bo_type_kernel)list_move (&vm_bo->vm_status, &vm->evicted);else list_move_tail (&vm_bo->vm_status, &vm->evicted); +spin_unlock (&vm_bo->vm->status_lock); }/** * amdgpu_vm_bo_moved - vm_bo is moved
@@ -370,12 +372,20 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*validate)(void *p,struct amdgpu_bo *bo), void *param) { - struct amdgpu_vm_bo_base *bo_base, *tmp; + struct amdgpu_vm_bo_base *bo_base; +struct amdgpu_bo *shadow; +struct amdgpu_bo *bo;int r; -list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; -struct amdgpu_bo *shadow =amdgpu_bo_shadowed (bo); +spin_lock (&vm->status_lock); +while (!list_empty (&vm->evicted)) { + bo_base =list_first_entry (&vm->evicted, + struct amdgpu_vm_bo_base, + vm_status); +spin_unlock (&vm->status_lock); + + bo = bo_base->bo; + shadow =amdgpu_bo_shadowed (bo); r =validate (param, bo);if (r)
@@ -392,7 +402,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, vm->update_funcs->map_table (to_amdgpu_bo_vm (bo));amdgpu_vm_bo_relocated (bo_base); } +spin_lock (&vm->status_lock); } +spin_unlock (&vm->status_lock);amdgpu_vm_eviction_lock (vm); vm->evicting = false;
@@ -413,13 +425,18 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,*/ bool amdgpu_vm_ready (struct amdgpu_vm *vm) { +bool empty;bool ret;amdgpu_vm_eviction_lock (vm); ret = !vm->evicting;amdgpu_vm_eviction_unlock (vm); -return ret &&list_empty (&vm->evicted); +spin_lock (&vm->status_lock); + empty =list_empty (&vm->evicted); +spin_unlock (&vm->status_lock); + +return ret && empty; }/**
Signature · 1 line
2.35.1
PATCH 6/7 drm/amdgpu: Use vm status_lock to protect pt free
In reply to Philip Yang--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +3 -0
@@ -637,7 +637,10 @@ static void amdgpu_vm_pt_free(struct amdgpu_vm_bo_base *entry) }ttm_bo_set_bulk_move (&entry->bo->tbo,NULL ); entry->bo->vm_bo =NULL ; + +spin_lock (&entry->vm->status_lock);list_del (&entry->vm_status); +spin_unlock (&entry->vm->status_lock);amdgpu_bo_unref (&entry->bo); }
Signature · 1 line
2.35.1
PATCH 7/7 drm/amdgpu: Fix amdgpu_vm_pt_free warning
In reply to Philip YangFree page table BO from vm resv unlocked context generate below warnings.
Add a pt_free_work in vm to free page table BO from vm->pt_freed list. pass vm resv unlock status from page table update caller, and add vm_bo entry to vm->pt_freed list and schedule the pt_free_work if calling with vm resv unlocked.
WARNING: CPU: 12 PID: 3238 at drivers/gpu/drm/ttm/ttm_bo.c:106 ttm_bo_set_bulk_move+0xa1/0xc0 Call Trace: amdgpu_vm_pt_free+0x42/0xd0 [amdgpu] amdgpu_vm_pt_free_dfs+0xb3/0xf0 [amdgpu] amdgpu_vm_ptes_update+0x52d/0x850 [amdgpu] amdgpu_vm_update_range+0x2a6/0x640 [amdgpu] svm_range_unmap_from_gpus+0x110/0x300 [amdgpu] svm_range_cpu_invalidate_pagetables+0x535/0x600 [amdgpu] __mmu_notifier_invalidate_range_start+0x1cd/0x230 unmap_vmas+0x9d/0x140 unmap_region+0xa8/0x110
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 41 +++++++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -2057,6 +2057,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)spin_lock_init (&vm->status_lock);INIT_LIST_HEAD (&vm->freed);INIT_LIST_HEAD (&vm->done); +INIT_LIST_HEAD (&vm->pt_freed); +INIT_WORK (&vm->pt_free_work, amdgpu_vm_pt_free_work);/* create scheduler entities for page table updates */ r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL,
@@ -2258,6 +2260,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_amdkfd_gpuvm_destroy_cb (adev, vm); +flush_work (&vm->pt_free_work); + root =amdgpu_bo_ref (vm->root.bo);amdgpu_bo_reserve (root, true);amdgpu_vm_set_pasid (adev, vm,0 );
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -0
@@ -278,6 +278,10 @@ struct amdgpu_vm {/* BOs which are invalidated, has been updated in the PTs */ struct list_head done; +/* PT BOs scheduled to free and fill with zero if vm_resv is not hold */ +struct list_head pt_freed; +struct work_struct pt_free_work; +/* contains the page directory */ struct amdgpu_vm_bo_base root;struct dma_fence *last_update;
@@ -473,6 +477,7 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params *params,int amdgpu_vm_ptes_update (struct amdgpu_vm_update_params *params,uint64_t start,uint64_t end,uint64_t dst,uint64_t flags); +void amdgpu_vm_pt_free_work (struct work_struct *work);#if defined(CONFIG_DEBUG_FS )void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct seq_file *m);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +38 -3
69 lines not on this page · raw message
Signature · 1 line
2.35.1
Christian König
maintainerRe: [PATCH 7/7] drm/amdgpu: Fix amdgpu_vm_pt_free warning
Am 16.09.22 um 17:05 schrieb Philip Yang:
Quoted 84 lines
Free page table BO from vm resv unlocked context generate below warnings.
Add a
pt_free_workin vm to free page table BO fromvm->pt_freedlist. pass vm resv unlock status from page table update caller, and addvm_boentry tovm->pt_freedlist and schedule thept_free_workif calling with vm resv unlocked.WARNING: CPU: 12 PID: 3238 at drivers/gpu/drm/ttm/ttm_bo.c:106 ttm_bo_set_bulk_move+0xa1/0xc0 Call Trace: amdgpu_vm_pt_free+0x42/0xd0 [amdgpu] amdgpu_vm_pt_free_dfs+0xb3/0xf0 [amdgpu] amdgpu_vm_ptes_update+0x52d/0x850 [amdgpu] amdgpu_vm_update_range+0x2a6/0x640 [amdgpu] svm_range_unmap_from_gpus+0x110/0x300 [amdgpu] svm_range_cpu_invalidate_pagetables+0x535/0x600 [amdgpu] __mmu_notifier_invalidate_range_start+0x1cd/0x230 unmap_vmas+0x9d/0x140 unmap_region+0xa8/0x110Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 41 +++++++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -2057,6 +2057,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)spin_lock_init (&vm->status_lock);INIT_LIST_HEAD (&vm->freed);INIT_LIST_HEAD (&vm->done); +INIT_LIST_HEAD (&vm->pt_freed); +INIT_WORK (&vm->pt_free_work, amdgpu_vm_pt_free_work);/* create scheduler entities for page table updates */ r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL,@@ -2258,6 +2260,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_amdkfd_gpuvm_destroy_cb (adev, vm); +flush_work (&vm->pt_free_work); + root =amdgpu_bo_ref (vm->root.bo);amdgpu_bo_reserve (root, true);amdgpu_vm_set_pasid (adev, vm,0 );drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5
-0@@ -278,6 +278,10 @@ struct amdgpu_vm {/* BOs which are invalidated, has been updated in the PTs */ struct list_head done; +/* PT BOs scheduled to free and fill with zero if vm_resv is not hold */ +struct list_head pt_freed; +struct work_struct pt_free_work; +/* contains the page directory */ struct amdgpu_vm_bo_base root;struct dma_fence *last_update;@@ -473,6 +477,7 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params *params,int amdgpu_vm_ptes_update (struct amdgpu_vm_update_params *params,uint64_t start,uint64_t end,uint64_t dst,uint64_t flags); +void amdgpu_vm_pt_free_work (struct work_struct *work);#if defined(CONFIG_DEBUG_FS )void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct seq_file *m);drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +3
-0@@ -644,6 +644,27 @@ static void amdgpu_vm_pt_free(struct amdgpu_vm_bo_base *entry)amdgpu_bo_unref (&entry->bo); } +void amdgpu_vm_pt_free_work (struct work_struct *work) +{ +struct amdgpu_vm_bo_base *entry, *next;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c static void amdgpu_vm_pt_free(struct amdgpu_vm_bo_base *entry) · line 659
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +10
-0+struct amdgpu_vm *vm; +LIST_HEAD (pt_freed); + + vm = container_of(work, struct amdgpu_vm, pt_free_work); + +spin_lock (&vm->status_lock); +list_splice_init (&vm->pt_freed, &pt_freed); +spin_unlock (&vm->status_lock); + +// flush_work in amdgpu_vm_fini ensure vm->root.bo is valid
Please no // style comments in kernel code.
Apart from that the whole series looks really good to me.
Thanks,
Christian.
Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +25
-3+amdgpu_bo_reserve (vm->root.bo, true); + +list_for_each_entry_safe (entry, next, &pt_freed, vm_status) +amdgpu_vm_pt_free (entry); + +amdgpu_bo_unreserve (vm->root.bo); +} +/** * amdgpu_vm_pt_free_dfs - free PD/PT levels * @@ -655,11 +676,24 @@ static void amdgpu_vm_pt_free(struct amdgpu_vm_bo_base *entry)*/ static void amdgpu_vm_pt_free_dfs (struct amdgpu_device *adev,struct amdgpu_vm *vm, -struct amdgpu_vm_pt_cursor *start) +struct amdgpu_vm_pt_cursor *start, +bool unlocked) {struct amdgpu_vm_pt_cursor cursor;struct amdgpu_vm_bo_base *entry; +if (unlocked) { +spin_lock (&vm->status_lock); +for_each_amdgpu_vm_pt_dfs_safe (adev, vm, start, cursor, entry) +list_move (&entry->vm_status, &vm->pt_freed); + +if (start) +list_move (&start->entry->vm_status, &vm->pt_freed); +spin_unlock (&vm->status_lock); +schedule_work (&vm->pt_free_work); +return ; + } +for_each_amdgpu_vm_pt_dfs_safe (adev, vm, start, cursor, entry)amdgpu_vm_pt_free (entry);@@ -676,7 +710,7 @@ static void amdgpu_vm_pt_free_dfs(struct amdgpu_device *adev,*/ void amdgpu_vm_pt_free_root (struct amdgpu_device *adev,struct amdgpu_vm *vm) { -amdgpu_vm_pt_free_dfs (adev, vm,NULL ); +amdgpu_vm_pt_free_dfs (adev, vm,NULL , false); }/** @@ -969,7 +1003,8 @@ int amdgpu_vm_ptes_update(struct amdgpu_vm_update_params *params,if (cursor.entry->bo) { params->table_freed = true;amdgpu_vm_pt_free_dfs (adev, params->vm, - &cursor); + &cursor, + params->unlocked); }amdgpu_vm_pt_next (adev, &cursor); }