return 0;
 }
 
-/*
- * vm eviction_lock can be taken in MMU notifiers. Make sure no reclaim-FS
- * happens while holding this lock anywhere to prevent deadlocks when
- * an MMU notifier runs in reclaim-FS context.
- */
-static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm)
-{
-       mutex_lock(&vm->eviction_lock);
-       vm->saved_flags = memalloc_noreclaim_save();
-}
-
-static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
-{
-       if (mutex_trylock(&vm->eviction_lock)) {
-               vm->saved_flags = memalloc_noreclaim_save();
-               return 1;
-       }
-       return 0;
-}
-
-static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm)
-{
-       memalloc_noreclaim_restore(vm->saved_flags);
-       mutex_unlock(&vm->eviction_lock);
-}
-
 /**
  * amdgpu_vm_bo_evicted - vm_bo is evicted
  *
 
        return atomic64_read(&vm->tlb_seq);
 }
 
+/*
+ * vm eviction_lock can be taken in MMU notifiers. Make sure no reclaim-FS
+ * happens while holding this lock anywhere to prevent deadlocks when
+ * an MMU notifier runs in reclaim-FS context.
+ */
+static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm)
+{
+       mutex_lock(&vm->eviction_lock);
+       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);
+       mutex_unlock(&vm->eviction_lock);
+}
+
 #endif
 
        if (entry->bo)
                return 0;
 
+       amdgpu_vm_eviction_unlock(vm);
        r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
+       amdgpu_vm_eviction_lock(vm);
        if (r)
                return r;