Removing all vma from the VM is best effort -- we only remove all those
ready to be removed, so forgive and VMA that becomes pinned. While
forgiving those that become pinned, also take a second look for any that
became unpinned as we waited.

Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem_evict.c | 39 ++++++++++++++++-----------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c 
b/drivers/gpu/drm/i915/i915_gem_evict.c
index 0ff4be9b2954..b1a39ea48c98 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -378,9 +378,7 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
  */
 int i915_gem_evict_vm(struct i915_address_space *vm)
 {
-       struct list_head eviction_list;
-       struct i915_vma *vma, *next;
-       int ret;
+       int ret = 0;
 
        lockdep_assert_held(&vm->mutex);
        trace_i915_gem_evict_vm(vm);
@@ -396,21 +394,30 @@ int i915_gem_evict_vm(struct i915_address_space *vm)
                        return ret;
        }
 
-       INIT_LIST_HEAD(&eviction_list);
-       list_for_each_entry(vma, &vm->bound_list, vm_link) {
-               if (i915_vma_is_pinned(vma))
-                       continue;
+       do {
+               struct i915_vma *vma, *vn;
+               LIST_HEAD(eviction_list);
 
-               __i915_vma_pin(vma);
-               list_add(&vma->evict_link, &eviction_list);
-       }
+               list_for_each_entry(vma, &vm->bound_list, vm_link) {
+                       if (i915_vma_is_pinned(vma))
+                               continue;
+
+                       __i915_vma_pin(vma);
+                       list_add(&vma->evict_link, &eviction_list);
+               }
+               if (list_empty(&eviction_list))
+                       break;
+
+               ret = 0;
+               list_for_each_entry_safe(vma, vn, &eviction_list, evict_link) {
+                       __i915_vma_unpin(vma);
+                       if (ret == 0)
+                               ret = __i915_vma_unbind(vma);
+                       if (ret != -EINTR) /* "Get me out of here!" */
+                               ret = 0;
+               }
+       } while (ret == 0);
 
-       ret = 0;
-       list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
-               __i915_vma_unpin(vma);
-               if (ret == 0)
-                       ret = __i915_vma_unbind(vma);
-       }
        return ret;
 }
 
-- 
2.24.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to