Skip to content

Commit e034a0d

Browse files
PhilipYangAalexdeucher
authored andcommitted
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 <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 64f6513 commit e034a0d

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,6 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
143143
return 0;
144144
}
145145

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-
172146
/**
173147
* amdgpu_vm_bo_evicted - vm_bo is evicted
174148
*

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,30 @@ static inline uint64_t amdgpu_vm_tlb_seq(struct amdgpu_vm *vm)
510510
return atomic64_read(&vm->tlb_seq);
511511
}
512512

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+
513539
#endif

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ static int amdgpu_vm_pt_alloc(struct amdgpu_device *adev,
597597
if (entry->bo)
598598
return 0;
599599

600+
amdgpu_vm_eviction_unlock(vm);
600601
r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
602+
amdgpu_vm_eviction_lock(vm);
601603
if (r)
602604
return r;
603605

0 commit comments

Comments
 (0)