Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Drop eviction lock when allocating PT BO

Re-take the eviction lock immediately again after the allocation is
completed, to fix circular locking warning with drm_buddy allocator.

Move amdgpu_vm_eviction_lock/unlock/trylock to amdgpu_vm.h as they are
called from multiple files.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Philip Yang and committed by
Alex Deucher
e034a0d9 64f65135

+28 -26
-26
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 143 143 return 0; 144 144 } 145 145 146 - /* 147 - * vm eviction_lock can be taken in MMU notifiers. Make sure no reclaim-FS 148 - * happens while holding this lock anywhere to prevent deadlocks when 149 - * an MMU notifier runs in reclaim-FS context. 150 - */ 151 - static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm) 152 - { 153 - mutex_lock(&vm->eviction_lock); 154 - vm->saved_flags = memalloc_noreclaim_save(); 155 - } 156 - 157 - static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm) 158 - { 159 - if (mutex_trylock(&vm->eviction_lock)) { 160 - vm->saved_flags = memalloc_noreclaim_save(); 161 - return 1; 162 - } 163 - return 0; 164 - } 165 - 166 - static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm) 167 - { 168 - memalloc_noreclaim_restore(vm->saved_flags); 169 - mutex_unlock(&vm->eviction_lock); 170 - } 171 - 172 146 /** 173 147 * amdgpu_vm_bo_evicted - vm_bo is evicted 174 148 *
+26
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
··· 510 510 return atomic64_read(&vm->tlb_seq); 511 511 } 512 512 513 + /* 514 + * vm eviction_lock can be taken in MMU notifiers. Make sure no reclaim-FS 515 + * happens while holding this lock anywhere to prevent deadlocks when 516 + * an MMU notifier runs in reclaim-FS context. 517 + */ 518 + static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm) 519 + { 520 + mutex_lock(&vm->eviction_lock); 521 + vm->saved_flags = memalloc_noreclaim_save(); 522 + } 523 + 524 + static inline bool amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm) 525 + { 526 + if (mutex_trylock(&vm->eviction_lock)) { 527 + vm->saved_flags = memalloc_noreclaim_save(); 528 + return true; 529 + } 530 + return false; 531 + } 532 + 533 + static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm) 534 + { 535 + memalloc_noreclaim_restore(vm->saved_flags); 536 + mutex_unlock(&vm->eviction_lock); 537 + } 538 + 513 539 #endif
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
··· 597 597 if (entry->bo) 598 598 return 0; 599 599 600 + amdgpu_vm_eviction_unlock(vm); 600 601 r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt); 602 + amdgpu_vm_eviction_lock(vm); 601 603 if (r) 602 604 return r; 603 605