From: Christian König <[email protected]>

Use scoped_guard/scoped_cond_guard instead.

Saving and restoring the GFP flags is not necessary in those use case.

Signed-off-by: Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 27 +++++++++----------
 .../gpu/drm/amd/amdgpu/amdgpu_vm_internal.h   |  9 -------
 2 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 77437436292c..0930b3fdade7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -616,9 +616,8 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
         * As soon as all page tables are in place we can start updating them
         * again.
         */
-       amdgpu_vm_eviction_lock(vm);
-       vm->evicting = false;
-       amdgpu_vm_eviction_unlock(vm);
+       scoped_guard(mutex, &vm->eviction_lock)
+               vm->evicting = false;
 
        list_for_each_entry_safe(bo_base, tmp, &vm->always_valid.evicted,
                                 vm_status) {
@@ -678,9 +677,8 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
 
        amdgpu_vm_assert_locked(vm);
 
-       amdgpu_vm_eviction_lock(vm);
-       ret = !vm->evicting;
-       amdgpu_vm_eviction_unlock(vm);
+       scoped_guard(mutex, &vm->eviction_lock)
+               ret = !vm->evicting;
 
        ret &= list_empty(&vm->kernel.evicted);
 
@@ -2340,6 +2338,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev,
 bool amdgpu_vm_evictable(struct amdgpu_bo *bo)
 {
        struct amdgpu_vm_bo_base *bo_base = bo->vm_bo;
+       struct amdgpu_vm *vm;
 
        /* Page tables of a destroyed VM can go away immediately */
        if (!bo_base || !bo_base->vm)
@@ -2350,17 +2349,15 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)
                return false;
 
        /* Try to block ongoing updates */
-       if (!amdgpu_vm_eviction_trylock(bo_base->vm))
-               return false;
+       vm = bo_base->vm;
+       scoped_cond_guard(mutex_try, return false, &vm->eviction_lock) {
 
-       /* Don't evict VM page tables while they are updated */
-       if (!dma_fence_is_signaled(bo_base->vm->last_unlocked)) {
-               amdgpu_vm_eviction_unlock(bo_base->vm);
-               return false;
-       }
+               /* Don't evict VM page tables while they are updated */
+               if (!dma_fence_is_signaled(vm->last_unlocked))
+                       return false;
 
-       bo_base->vm->evicting = true;
-       amdgpu_vm_eviction_unlock(bo_base->vm);
+               vm->evicting = true;
+       }
        return true;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
index 1011f49f0478..7f6442d0b647 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
@@ -141,15 +141,6 @@ static inline void amdgpu_vm_eviction_lock(struct 
amdgpu_vm *vm)
        vm->saved_flags = memalloc_noreclaim_save();
 }
 
-static inline bool amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
-{
-       if (mutex_trylock(&vm->eviction_lock)) {
-               vm->saved_flags = memalloc_noreclaim_save();
-               return true;
-       }
-       return false;
-}
-
 static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm)
 {
        memalloc_noreclaim_restore(vm->saved_flags);
-- 
2.53.0

Reply via email to