Skip to contentSkip to conversation

drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

PATCH Superseded Maarten Lankhorst 3 participants 34 messages Dec 16, 2021 – Dec 17, 2021

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

Previously, short term pinning in execbuf was required because i915_vma was effectively independent from objects, and has its own refcount, locking, lifetime rules and pinning.

This series removes the separate locking, by requiring vma->obj->resv to be held when pinning and unbinding. This will also be required for VM_BIND work.

With pinning required for pinning and unbinding, the lock is enough to prevent unbinding when trying to pin with the lock held, for example in execbuf.

This makes binding/unbinding similar to ttm_bo_validate()'s use, which just cares that an object is in a certain place, without pinning it in place.

Having the VMA part of gem bo removes a lot of the vma refcounting, and makes i915_vma more a part of the bo, instead of its own floating object that just happens to be part of a bo. This is also required to make it more compatible with TTM, and migration in general.

For future work, it makes things a lot simpler and clear. We want to end up with i915_vma just being a specific mapping of the BO, just like is the case in other drivers. i915_vma->active removal is the next step there, and makes it when object is destroyed, the bindings are destroyed (after idle), instead of object being destroyed when bindings are idle.

---
This is version 3, I changed the ordering of the patches slightly to be more natural, and divided up some commits in different ways.

In particular, I added the ww ctx to trylock first, then converted i915_gem_evict_vm(), the shrinker, and the other eviction functions all in separate commits. Functionally the same, but easier to review and bisect.

In theory, it was already reviewed, but leaving those r-b's out as they're technically different patches now.

The first patches prepare for vma->obj->resv requirement, by ensuring that we unbind as needed, and take the ww lock in some places where they're required, including when freeing the object.

After that we convert the shrinker, eviction functions, and then we can start requiring the object lock for i915_vma_unbind.

Now that the conversion and requirement is added, we can remove ther special case of assert_object_held_shared, which was added because we didn't always require the object lock.

As last step we can remove the short term pins from execbuf. We still pin when evicting the entire VM, but if it turns out to be an issue, it can be removed, and replaced with unpinning the entire VM.

Maarten Lankhorst (17):
drm/i915: Remove unused bits of i915_vma/active api drm/i915: Change shrink ordering to use locking around unbinding. drm/i915: Remove pages_mutex and intel_gtt->vma_ops.set/clear_pages
members, v3.
drm/i915: Take object lock in i915_ggtt_pin if ww is not set drm/i915: Force ww lock for i915_gem_object_ggtt_pin_ww, v2. drm/i915: Ensure gem_contexts selftests work with unbind changes, v2. drm/i915: Ensure i915_vma tests do not get -ENOSPC with the locking
changes.
drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC
errors
drm/i915: Trylock the object when shrinking
drm/i915: Require object lock when freeing pages during destruction drm/i915: Add ww ctx to i915_gem_object_trylock
drm/i915: Add locking to i915_gem_evict_vm()
drm/i915: Add object locking to i915_gem_evict_for_node and
i915_gem_evict_something
drm/i915: Add i915_vma_unbind_unlocked, and take obj lock for

    i915_vma_unbind, v2.

drm/i915: Remove assert_object_held_shared drm/i915: Remove support for unlocked i915_vma unbind drm/i915: Remove short-term pins from execbuf, v5.

 drivers/gpu/drm/i915/display/intel_dpt.c      |   2 -
 drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 250 ++++----
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  18 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c    |   9 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |  22 +-
 drivers/gpu/drm/i915/gem/i915_gem_pages.c     |  12 +-
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c  |  44 +-
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |   2 +-
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   2 +-
 .../i915/gem/selftests/i915_gem_client_blt.c  |   2 +-
 .../drm/i915/gem/selftests/i915_gem_context.c |  59 +-
 .../drm/i915/gem/selftests/i915_gem_mman.c    |   6 +
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |  15 -
 drivers/gpu/drm/i915/gt/intel_engine_pm.c     |   2 +-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          | 454 ++------------
 drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c  |   1 -
 drivers/gpu/drm/i915/gt/intel_gtt.c           |  13 -
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   7 -
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |  12 -
 drivers/gpu/drm/i915/gt/mock_engine.c         |   2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +-
 drivers/gpu/drm/i915/gt/selftest_migrate.c    |   2 +-
 drivers/gpu/drm/i915/gvt/aperture_gm.c        |   2 +-
 drivers/gpu/drm/i915/i915_active.c            |  28 +-
 drivers/gpu/drm/i915/i915_active.h            |  17 +-
 drivers/gpu/drm/i915/i915_drv.h               |  12 +-
 drivers/gpu/drm/i915/i915_gem.c               |  32 +-
 drivers/gpu/drm/i915/i915_gem_evict.c         |  64 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c           |   8 +-
 drivers/gpu/drm/i915/i915_gem_gtt.h           |   4 +
 drivers/gpu/drm/i915/i915_vgpu.c              |   2 +-
 drivers/gpu/drm/i915/i915_vma.c               | 579 +++++++++++++++---
 drivers/gpu/drm/i915/i915_vma.h               |   6 +-
 drivers/gpu/drm/i915/i915_vma_types.h         |   1 -
 .../gpu/drm/i915/selftests/i915_gem_evict.c   |  27 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  50 +-
 drivers/gpu/drm/i915/selftests/i915_vma.c     |  19 +-
 drivers/gpu/drm/i915/selftests/mock_gtt.c     |   4 -
 40 files changed, 951 insertions(+), 846 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/17 drm/i915: Remove unused bits of i915_vma/active api

When reworking the code to move the eviction fence to the object, the best code is removed code.

Remove some functions that are unused, and change the function definition if it's only used in 1 place.

[mlankhorst: Remove new use of i915_active_has_exclusive]
---
 drivers/gpu/drm/i915/i915_active.c | 28 +++-------------------------
 drivers/gpu/drm/i915/i915_active.h | 17 +----------------
 drivers/gpu/drm/i915/i915_vma.c    | 24 ++++++++++--------------
 drivers/gpu/drm/i915/i915_vma.h    |  2 --
 4 files changed, 14 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_active.c +3 -25
index 3103c1e1fd14..ee2b3a375362 100644
@@ -426,8 +426,9 @@ replace_barrier(struct i915_active *ref, struct i915_active_fence *active)
 	return true;
 }
 
-int i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence)
+int i915_active_add_request(struct i915_active *ref, struct i915_request *rq)
 {
+	struct dma_fence *fence = &rq->fence;
 	struct i915_active_fence *active;
 	int err;
 
@@ -436,7 +437,7 @@ int i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence)
 	if (err)
 		return err;
 
-	active = active_instance(ref, idx);
+	active = active_instance(ref, i915_request_timeline(rq)->fence_context);
 	if (!active) {
 		err = -ENOMEM;
 		goto out;
@@ -477,29 +478,6 @@ __i915_active_set_fence(struct i915_active *ref,
 	return prev;
 }
 
-static struct i915_active_fence *
-__active_fence(struct i915_active *ref, u64 idx)
-{
-	struct active_node *it;
-
-	it = __active_lookup(ref, idx);
-	if (unlikely(!it)) { /* Contention with parallel tree builders! */
-		spin_lock_irq(&ref->tree_lock);
-		it = __active_lookup(ref, idx);
-		spin_unlock_irq(&ref->tree_lock);
-	}
-	GEM_BUG_ON(!it); /* slot must be preallocated */
-
-	return &it->base;
-}
-
-struct dma_fence *
-__i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence)
-{
-	/* Only valid while active, see i915_active_acquire_for_context() */
-	return __i915_active_set_fence(ref, __active_fence(ref, idx), fence);
-}
-
 struct dma_fence *
 i915_active_set_exclusive(struct i915_active *ref, struct dma_fence *f)
 {
drivers/gpu/drm/i915/i915_active.h +1 -16
index 5fcdb0e2bc9e..7eb44132183a 100644
@@ -164,26 +164,11 @@ void __i915_active_init(struct i915_active *ref,
 	__i915_active_init(ref, active, retire, flags, &__mkey, &__wkey);	\
 } while (0)
 
-struct dma_fence *
-__i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence);
-int i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence);
-
-static inline int
-i915_active_add_request(struct i915_active *ref, struct i915_request *rq)
-{
-	return i915_active_ref(ref,
-			       i915_request_timeline(rq)->fence_context,
-			       &rq->fence);
-}
+int i915_active_add_request(struct i915_active *ref, struct i915_request *rq);
 
 struct dma_fence *
 i915_active_set_exclusive(struct i915_active *ref, struct dma_fence *f);
 
-static inline bool i915_active_has_exclusive(struct i915_active *ref)
-{
-	return rcu_access_pointer(ref->excl.fence);
-}
-
 int __i915_active_wait(struct i915_active *ref, int state);
 static inline int i915_active_wait(struct i915_active *ref)
 {
drivers/gpu/drm/i915/i915_vma.c +10 -14
index 927f0d4f8e11..921d5b946c32 100644
@@ -356,22 +356,18 @@ int i915_vma_wait_for_bind(struct i915_vma *vma)
 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
 static int i915_vma_verify_bind_complete(struct i915_vma *vma)
 {
-	int err = 0;
-
-	if (i915_active_has_exclusive(&vma->active)) {
-		struct dma_fence *fence =
-			i915_active_fence_get(&vma->active.excl);
+	struct dma_fence *fence = i915_active_fence_get(&vma->active.excl);
+	int err;
 
-		if (!fence)
-			return 0;
+	if (!fence)
+		return 0;
 
-		if (dma_fence_is_signaled(fence))
-			err = fence->error;
-		else
-			err = -EBUSY;
+	if (dma_fence_is_signaled(fence))
+		err = fence->error;
+	else
+		err = -EBUSY;
 
-		dma_fence_put(fence);
-	}
+	dma_fence_put(fence);
 
 	return err;
 }
@@ -1249,7 +1245,7 @@ __i915_request_await_bind(struct i915_request *rq, struct i915_vma *vma)
 	return __i915_request_await_exclusive(rq, &vma->active);
 }
 
-int __i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *rq)
+static int __i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *rq)
 {
 	int err;
 
drivers/gpu/drm/i915/i915_vma.h +0 -2
index 4033aa08d5e4..9a931ecb09e5 100644
@@ -55,8 +55,6 @@ static inline bool i915_vma_is_active(const struct i915_vma *vma)
 /* do not reserve memory to prevent deadlocks */
 #define __EXEC_OBJECT_NO_RESERVE BIT(31)
 
-int __must_check __i915_vma_move_to_active(struct i915_vma *vma,
-					   struct i915_request *rq);
 int __must_check _i915_vma_move_to_active(struct i915_vma *vma,
 					  struct i915_request *rq,
 					  struct dma_fence *fence,
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/17 drm/i915: Change shrink ordering to use locking around unbinding.

In reply to Maarten Lankhorst

Call drop_pages with the gem object lock held, instead of the other way around. This will allow us to drop the vma bindings with the gem object lock held.

We plan to require the object lock for unpinning in the future, and this is an easy target.

---
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 38 ++++++++++----------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +18 -20
index 157a9765f483..eebff4735781 100644
@@ -36,8 +36,8 @@ static bool can_release_pages(struct drm_i915_gem_object *obj)
 	return swap_available() || obj->mm.madv == I915_MADV_DONTNEED;
 }
 
-static bool unsafe_drop_pages(struct drm_i915_gem_object *obj,
-			      unsigned long shrink, bool trylock_vm)
+static int drop_pages(struct drm_i915_gem_object *obj,
+		       unsigned long shrink, bool trylock_vm)
 {
 	unsigned long flags;
 
@@ -214,26 +214,24 @@ i915_gem_shrink(struct i915_gem_ww_ctx *ww,
 
 			spin_unlock_irqrestore(&i915->mm.obj_lock, flags);
 
-			err = 0;
-			if (unsafe_drop_pages(obj, shrink, trylock_vm)) {
-				/* May arrive from get_pages on another bo */
-				if (!ww) {
-					if (!i915_gem_object_trylock(obj))
-						goto skip;
-				} else {
-					err = i915_gem_object_lock(obj, ww);
-					if (err)
-						goto skip;
-				}
-
-				if (!__i915_gem_object_put_pages(obj)) {
-					if (!try_to_writeback(obj, shrink))
-						count += obj->base.size >> PAGE_SHIFT;
-				}
-				if (!ww)
-					i915_gem_object_unlock(obj);
+			/* May arrive from get_pages on another bo */
+			if (!ww) {
+				if (!i915_gem_object_trylock(obj))
+					goto skip;
+			} else {
+				err = i915_gem_object_lock(obj, ww);
+				if (err)
+					goto skip;
 			}
 
+			if (drop_pages(obj, shrink, trylock_vm) &&
+			    !__i915_gem_object_put_pages(obj) &&
+			    !try_to_writeback(obj, shrink))
+				count += obj->base.size >> PAGE_SHIFT;
+
+			if (!ww)
+				i915_gem_object_unlock(obj);
+
 			scanned += obj->base.size >> PAGE_SHIFT;
 skip:
 			i915_gem_object_put(obj);
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/17 drm/i915: Remove pages_mutex and intel_gtt->vma_ops.set/clear_pages members, v3.

In reply to Maarten Lankhorst

Big delta, but boils down to moving set_pages to i915_vma.c, and removing the special handling, all callers use the defaults anyway. We only remap in ggtt, so default case will fall through.

Because we still don't require locking in i915_vma_unpin(), handle this by using xchg in get_pages(), as it's locked with obj->mutex, and cmpxchg in unpin, which only fails if we race a against a new pin.

Changes since v1:
- aliasing gtt sets ZERO_SIZE_PTR, not -ENODEV, remove special case from __i915_vma_get_pages(). (Matt)
Changes since v2:
- Free correct old pages in __i915_vma_get_pages(). (Matt) Remove race of clearing vma->pages accidentally from put, free it but leave it set, as only get has the lock.

---
 drivers/gpu/drm/i915/display/intel_dpt.c      |   2 -
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |  15 -
 drivers/gpu/drm/i915/gt/intel_ggtt.c          | 403 ----------------
 drivers/gpu/drm/i915/gt/intel_gtt.c           |  13 -
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   7 -
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |  12 -
 drivers/gpu/drm/i915/i915_vma.c               | 449 ++++++++++++++++--
 drivers/gpu/drm/i915/i915_vma.h               |   3 +
 drivers/gpu/drm/i915/i915_vma_types.h         |   1 -
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  14 +-
 drivers/gpu/drm/i915/selftests/mock_gtt.c     |   4 -
 11 files changed, 429 insertions(+), 494 deletions(-)
drivers/gpu/drm/i915/display/intel_dpt.c +0 -2
index 963ca7155b06..cb1b956ca175 100644
@@ -279,8 +279,6 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
 	vm->vma_ops.bind_vma    = dpt_bind_vma;
 	vm->vma_ops.unbind_vma  = dpt_unbind_vma;
-	vm->vma_ops.set_pages   = ggtt_set_pages;
-	vm->vma_ops.clear_pages = clear_pages;
 
 	vm->pte_encode = gen8_ggtt_pte_encode;
 
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +0 -15
index c0d149f04949..6e9292918bfc 100644
@@ -269,19 +269,6 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
 	free_pd(&ppgtt->base.vm, ppgtt->base.pd);
 }
 
-static int pd_vma_set_pages(struct i915_vma *vma)
-{
-	vma->pages = ERR_PTR(-ENODEV);
-	return 0;
-}
-
-static void pd_vma_clear_pages(struct i915_vma *vma)
-{
-	GEM_BUG_ON(!vma->pages);
-
-	vma->pages = NULL;
-}
-
 static void pd_vma_bind(struct i915_address_space *vm,
 			struct i915_vm_pt_stash *stash,
 			struct i915_vma *vma,
@@ -321,8 +308,6 @@ static void pd_vma_unbind(struct i915_address_space *vm, struct i915_vma *vma)
 }
 
 static const struct i915_vma_ops pd_vma_ops = {
-	.set_pages = pd_vma_set_pages,
-	.clear_pages = pd_vma_clear_pages,
 	.bind_vma = pd_vma_bind,
 	.unbind_vma = pd_vma_unbind,
 };
drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -403

436 lines not on this page · raw message

drivers/gpu/drm/i915/gt/intel_gtt.c +0 -13
index 30683c06b344..a94be0306464 100644
@@ -224,19 +224,6 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass)
 	INIT_LIST_HEAD(&vm->bound_list);
 }
 
-void clear_pages(struct i915_vma *vma)
-{
-	GEM_BUG_ON(!vma->pages);
-
-	if (vma->pages != vma->obj->mm.pages) {
-		sg_free_table(vma->pages);
-		kfree(vma->pages);
-	}
-	vma->pages = NULL;
-
-	memset(&vma->page_sizes, 0, sizeof(vma->page_sizes));
-}
-
 void *__px_vaddr(struct drm_i915_gem_object *p)
 {
 	enum i915_map_type type;
drivers/gpu/drm/i915/gt/intel_gtt.h +0 -7
index 15b98321e89a..177b42b935a1 100644
@@ -209,9 +209,6 @@ struct i915_vma_ops {
 	 */
 	void (*unbind_vma)(struct i915_address_space *vm,
 			   struct i915_vma *vma);
-
-	int (*set_pages)(struct i915_vma *vma);
-	void (*clear_pages)(struct i915_vma *vma);
 };
 
 struct i915_address_space {
@@ -601,10 +598,6 @@ release_pd_entry(struct i915_page_directory * const pd,
 		 const struct drm_i915_gem_object * const scratch);
 void gen6_ggtt_invalidate(struct i915_ggtt *ggtt);
 
-int ggtt_set_pages(struct i915_vma *vma);
-int ppgtt_set_pages(struct i915_vma *vma);
-void clear_pages(struct i915_vma *vma);
-
 void ppgtt_bind_vma(struct i915_address_space *vm,
 		    struct i915_vm_pt_stash *stash,
 		    struct i915_vma *vma,
drivers/gpu/drm/i915/gt/intel_ppgtt.c +0 -12
index 4396bfd630d8..083b3090c69c 100644
@@ -289,16 +289,6 @@ void i915_vm_free_pt_stash(struct i915_address_space *vm,
 	}
 }
 
-int ppgtt_set_pages(struct i915_vma *vma)
-{
-	GEM_BUG_ON(vma->pages);
-
-	vma->pages = vma->obj->mm.pages;
-	vma->page_sizes = vma->obj->mm.page_sizes;
-
-	return 0;
-}
-
 void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt,
 		unsigned long lmem_pt_obj_flags)
 {
@@ -315,6 +305,4 @@ void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt,
 
 	ppgtt->vm.vma_ops.bind_vma    = ppgtt_bind_vma;
 	ppgtt->vm.vma_ops.unbind_vma  = ppgtt_unbind_vma;
-	ppgtt->vm.vma_ops.set_pages   = ppgtt_set_pages;
-	ppgtt->vm.vma_ops.clear_pages = clear_pages;
 }
drivers/gpu/drm/i915/i915_vma.c +417 -32

511 lines not on this page · raw message

drivers/gpu/drm/i915/i915_vma.h +3 -0
index 9a931ecb09e5..32719431b3df 100644
@@ -431,4 +431,7 @@ static inline int i915_vma_sync(struct i915_vma *vma)
 void i915_vma_module_exit(void);
 int i915_vma_module_init(void);
 
+I915_SELFTEST_DECLARE(int i915_vma_get_pages(struct i915_vma *vma));
+I915_SELFTEST_DECLARE(void i915_vma_put_pages(struct i915_vma *vma));
+
 #endif
drivers/gpu/drm/i915/i915_vma_types.h +0 -1
index f03fa96a1701..ca575e129ced 100644
@@ -270,7 +270,6 @@ struct i915_vma {
 #define I915_VMA_PAGES_BIAS 24
 #define I915_VMA_PAGES_ACTIVE (BIT(24) | 1)
 	atomic_t pages_count; /* number of active binds to the pages */
-	struct mutex pages_mutex; /* protect acquire/release of backing pages */
 
 	/**
 	 * Support different GGTT views into the same object.
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +9 -5
index 46f4236039a9..88b3a4d9e27e 100644
@@ -1275,7 +1275,7 @@ static void track_vma_bind(struct i915_vma *vma)
 
 	__i915_gem_object_pin_pages(obj);
 
-	GEM_BUG_ON(vma->pages);
+	GEM_BUG_ON(atomic_read(&vma->pages_count));
 	atomic_set(&vma->pages_count, I915_VMA_PAGES_ACTIVE);
 	__i915_gem_object_pin_pages(obj);
 	vma->pages = obj->mm.pages;
@@ -1953,7 +1953,9 @@ static int igt_cs_tlb(void *arg)
 				goto end;
 			}
 
-			err = vma->ops->set_pages(vma);
+			i915_gem_object_lock(bbe, NULL);
+			err = i915_vma_get_pages(vma);
+			i915_gem_object_unlock(bbe);
 			if (err)
 				goto end;
 
@@ -1994,7 +1996,7 @@ static int igt_cs_tlb(void *arg)
 				i915_request_put(rq);
 			}
 
-			vma->ops->clear_pages(vma);
+			i915_vma_put_pages(vma);
 
 			err = context_sync(ce);
 			if (err) {
@@ -2009,7 +2011,9 @@ static int igt_cs_tlb(void *arg)
 				goto end;
 			}
 
-			err = vma->ops->set_pages(vma);
+			i915_gem_object_lock(act, NULL);
+			err = i915_vma_get_pages(vma);
+			i915_gem_object_unlock(act);
 			if (err)
 				goto end;
 
@@ -2047,7 +2051,7 @@ static int igt_cs_tlb(void *arg)
 			}
 			end_spin(batch, count - 1);
 
-			vma->ops->clear_pages(vma);
+			i915_vma_put_pages(vma);
 
 			err = context_sync(ce);
 			if (err) {
drivers/gpu/drm/i915/selftests/mock_gtt.c +0 -4
index 32ca8962d0ab..19537191bf03 100644
@@ -87,8 +87,6 @@ struct i915_ppgtt *mock_ppgtt(struct drm_i915_private *i915, const char *name)
 
 	ppgtt->vm.vma_ops.bind_vma    = mock_bind_ppgtt;
 	ppgtt->vm.vma_ops.unbind_vma  = mock_unbind_ppgtt;
-	ppgtt->vm.vma_ops.set_pages   = ppgtt_set_pages;
-	ppgtt->vm.vma_ops.clear_pages = clear_pages;
 
 	return ppgtt;
 }
@@ -128,8 +126,6 @@ void mock_init_ggtt(struct drm_i915_private *i915, struct i915_ggtt *ggtt)
 
 	ggtt->vm.vma_ops.bind_vma    = mock_bind_ggtt;
 	ggtt->vm.vma_ops.unbind_vma  = mock_unbind_ggtt;
-	ggtt->vm.vma_ops.set_pages   = ggtt_set_pages;
-	ggtt->vm.vma_ops.clear_pages = clear_pages;
 
 	i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
 	i915->gt.ggtt = ggtt;
Signature · 1 line
2.34.1
Reviewed-by on v3 3/17
#4 lore raw

Re: [Intel-gfx] [PATCH v3 03/17] drm/i915: Remove pages_mutex and intel_gtt->vma_ops.set/clear_pages members, v3.

Quoted 17 lines · Maarten Lankhorst

Big delta, but boils down to moving set_pages to i915_vma.c, and removing the special handling, all callers use the defaults anyway. We only remap in ggtt, so default case will fall through.

Because we still don't require locking in i915_vma_unpin(), handle this by using xchg in get_pages(), as it's locked with obj->mutex, and cmpxchg in unpin, which only fails if we race a against a new pin.

Changes since v1:
- aliasing gtt sets ZERO_SIZE_PTR, not -ENODEV, remove special case from __i915_vma_get_pages(). (Matt)
Changes since v2:
- Free correct old pages in __i915_vma_get_pages(). (Matt) Remove race of clearing vma->pages accidentally from put, free it but leave it set, as only get has the lock.

Quoted 1 line
#5 lore raw

PATCH v3 4/17 drm/i915: Take object lock in i915_ggtt_pin if ww is not set

In reply to Maarten Lankhorst

i915_vma_wait_for_bind needs the vma lock held, fix the caller.

---
 drivers/gpu/drm/i915/i915_vma.c | 40 +++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +28 -12
index 8eb531b04d3e..de24e4b3b19b 100644
@@ -1441,23 +1441,15 @@ static void flush_idle_contexts(struct intel_gt *gt)
 	intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
 }
 
-int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
-		  u32 align, unsigned int flags)
+static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+			   u32 align, unsigned int flags)
 {
 	struct i915_address_space *vm = vma->vm;
 	int err;
 
-	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
-
-#ifdef CONFIG_LOCKDEP
-	WARN_ON(!ww && dma_resv_held(vma->obj->base.resv));
-#endif
-
 	do {
-		if (ww)
-			err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
-		else
-			err = i915_vma_pin(vma, 0, align, flags | PIN_GLOBAL);
+		err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
+
 		if (err != -ENOSPC) {
 			if (!err) {
 				err = i915_vma_wait_for_bind(vma);
@@ -1476,6 +1468,30 @@ int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 	} while (1);
 }
 
+int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+		  u32 align, unsigned int flags)
+{
+	struct i915_gem_ww_ctx _ww;
+	int err;
+
+	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
+
+	if (ww)
+		return __i915_ggtt_pin(vma, ww, align, flags);
+
+#ifdef CONFIG_LOCKDEP
+	WARN_ON(dma_resv_held(vma->obj->base.resv));
+#endif
+
+	for_i915_gem_ww(&_ww, err, true) {
+		err = i915_gem_object_lock(vma->obj, &_ww);
+		if (!err)
+			err = __i915_ggtt_pin(vma, &_ww, align, flags);
+	}
+
+	return err;
+}
+
 static void __vma_close(struct i915_vma *vma, struct intel_gt *gt)
 {
 	/*
Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 5/17 drm/i915: Force ww lock for i915_gem_object_ggtt_pin_ww, v2.

In reply to Maarten Lankhorst

We will need the lock to unbind the vma, and wait for bind to complete. Remove the special casing for the !ww path, and force ww locking for all.

Changes since v1:
- Pass err to for_i915_gem_ww handling for -EDEADLK handling.

---
 drivers/gpu/drm/i915/i915_drv.h |  7 ++-----
 drivers/gpu/drm/i915/i915_gem.c | 30 ++++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -5
index ed48179bacd8..d51628d10f9d 100644
@@ -1652,13 +1652,10 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
 			    const struct i915_ggtt_view *view,
 			    u64 size, u64 alignment, u64 flags);
 
-static inline struct i915_vma * __must_check
+struct i915_vma * __must_check
 i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
 			 const struct i915_ggtt_view *view,
-			 u64 size, u64 alignment, u64 flags)
-{
-	return i915_gem_object_ggtt_pin_ww(obj, NULL, view, size, alignment, flags);
-}
+			 u64 size, u64 alignment, u64 flags);
 
 int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 			   unsigned long flags);
drivers/gpu/drm/i915/i915_gem.c +26 -4
index 527228d4da7e..6002045bd194 100644
@@ -877,6 +877,8 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
 	struct i915_vma *vma;
 	int ret;
 
+	GEM_WARN_ON(!ww);
+
 	if (flags & PIN_MAPPABLE &&
 	    (!view || view->type == I915_GGTT_VIEW_NORMAL)) {
 		/*
@@ -936,10 +938,7 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
 			return ERR_PTR(ret);
 	}
 
-	if (ww)
-		ret = i915_vma_pin_ww(vma, ww, size, alignment, flags | PIN_GLOBAL);
-	else
-		ret = i915_vma_pin(vma, size, alignment, flags | PIN_GLOBAL);
+	ret = i915_vma_pin_ww(vma, ww, size, alignment, flags | PIN_GLOBAL);
 
 	if (ret)
 		return ERR_PTR(ret);
@@ -959,6 +958,29 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
 	return vma;
 }
 
+struct i915_vma * __must_check
+i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
+			 const struct i915_ggtt_view *view,
+			 u64 size, u64 alignment, u64 flags)
+{
+	struct i915_gem_ww_ctx ww;
+	struct i915_vma *ret;
+	int err;
+
+	for_i915_gem_ww(&ww, err, true) {
+		err = i915_gem_object_lock(obj, &ww);
+		if (err)
+			continue;
+
+		ret = i915_gem_object_ggtt_pin_ww(obj, &ww, view, size,
+						  alignment, flags);
+		if (IS_ERR(ret))
+			err = PTR_ERR(ret);
+	}
+
+	return err ? ERR_PTR(err) : ret;
+}
+
 int
 i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv)
Signature · 1 line
2.34.1
Reviewed-by on v3 5/17
#8 lore raw

Re: [Intel-gfx] [PATCH v3 05/17] drm/i915: Force ww lock for i915_gem_object_ggtt_pin_ww, v2.

Quoted 8 lines · Maarten Lankhorst

We will need the lock to unbind the vma, and wait for bind to complete. Remove the special casing for the !ww path, and force ww locking for all.

Changes since v1:
- Pass err to for_i915_gem_ww handling for -EDEADLK handling.

Deja-vu,

#9 lore raw

PATCH v3 6/17 drm/i915: Ensure gem_contexts selftests work with unbind changes, v2.

In reply to Maarten Lankhorst

In the next commits, we may not evict when refcount = 0.

igt_vm_isolation() continuously tries to pin/unpin at same address, but also calls put() on the object, which means the object may not be unpinned in time.

Instead of this, re-use the same object over and over, so they can be unbound as required.

Changes since v1:
- Fix cleaning up obj_b on failure. (Matt)

---
 .../drm/i915/gem/selftests/i915_gem_context.c | 59 +++++++++++--------
 1 file changed, 35 insertions(+), 24 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +35 -24
index 21b71568cd5f..786c58412733 100644
@@ -1481,10 +1481,10 @@ static int check_scratch(struct i915_address_space *vm, u64 offset)
 
 static int write_to_scratch(struct i915_gem_context *ctx,
 			    struct intel_engine_cs *engine,
+			    struct drm_i915_gem_object *obj,
 			    u64 offset, u32 value)
 {
 	struct drm_i915_private *i915 = ctx->i915;
-	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 	struct i915_request *rq;
 	struct i915_vma *vma;
@@ -1497,15 +1497,9 @@ static int write_to_scratch(struct i915_gem_context *ctx,
 	if (err)
 		return err;
 
-	obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
-	if (IS_ERR(obj))
-		return PTR_ERR(obj);
-
 	cmd = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
-	if (IS_ERR(cmd)) {
-		err = PTR_ERR(cmd);
-		goto out;
-	}
+	if (IS_ERR(cmd))
+		return PTR_ERR(cmd);
 
 	*cmd++ = MI_STORE_DWORD_IMM_GEN4;
 	if (GRAPHICS_VER(i915) >= 8) {
@@ -1569,17 +1563,19 @@ static int write_to_scratch(struct i915_gem_context *ctx,
 	i915_vma_unpin(vma);
 out_vm:
 	i915_vm_put(vm);
-out:
-	i915_gem_object_put(obj);
+
+	if (!err)
+		err = i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT);
+
 	return err;
 }
 
 static int read_from_scratch(struct i915_gem_context *ctx,
 			     struct intel_engine_cs *engine,
+			     struct drm_i915_gem_object *obj,
 			     u64 offset, u32 *value)
 {
 	struct drm_i915_private *i915 = ctx->i915;
-	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 	const u32 result = 0x100;
 	struct i915_request *rq;
@@ -1594,10 +1590,6 @@ static int read_from_scratch(struct i915_gem_context *ctx,
 	if (err)
 		return err;
 
-	obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
-	if (IS_ERR(obj))
-		return PTR_ERR(obj);
-
 	if (GRAPHICS_VER(i915) >= 8) {
 		const u32 GPR0 = engine->mmio_base + 0x600;
 
@@ -1615,7 +1607,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,
 		cmd = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
 		if (IS_ERR(cmd)) {
 			err = PTR_ERR(cmd);
-			goto out;
+			goto err_unpin;
 		}
 
 		memset(cmd, POISON_INUSE, PAGE_SIZE);
@@ -1651,7 +1643,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,
 		cmd = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
 		if (IS_ERR(cmd)) {
 			err = PTR_ERR(cmd);
-			goto out;
+			goto err_unpin;
 		}
 
 		memset(cmd, POISON_INUSE, PAGE_SIZE);
@@ -1722,8 +1714,10 @@ static int read_from_scratch(struct i915_gem_context *ctx,
 	i915_vma_unpin(vma);
 out_vm:
 	i915_vm_put(vm);
-out:
-	i915_gem_object_put(obj);
+
+	if (!err)
+		err = i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT);
+
 	return err;
 }
 
@@ -1757,6 +1751,7 @@ static int igt_vm_isolation(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
 	struct i915_gem_context *ctx_a, *ctx_b;
+	struct drm_i915_gem_object *obj_a, *obj_b;
 	unsigned long num_engines, count;
 	struct intel_engine_cs *engine;
 	struct igt_live_test t;
@@ -1810,6 +1805,18 @@ static int igt_vm_isolation(void *arg)
 	vm_total = ctx_a->vm->total;
 	GEM_BUG_ON(ctx_b->vm->total != vm_total);
 
+	obj_a = i915_gem_object_create_internal(i915, PAGE_SIZE);
+	if (IS_ERR(obj_a)) {
+		err = PTR_ERR(obj_a);
+		goto out_file;
+	}
+
+	obj_b = i915_gem_object_create_internal(i915, PAGE_SIZE);
+	if (IS_ERR(obj_b)) {
+		err = PTR_ERR(obj_b);
+		goto put_a;
+	}
+
 	count = 0;
 	num_engines = 0;
 	for_each_uabi_engine(engine, i915) {
@@ -1832,13 +1839,13 @@ static int igt_vm_isolation(void *arg)
 						   I915_GTT_PAGE_SIZE, vm_total,
 						   sizeof(u32), alignof_dword);
 
-			err = write_to_scratch(ctx_a, engine,
+			err = write_to_scratch(ctx_a, engine, obj_a,
 					       offset, 0xdeadbeef);
 			if (err == 0)
-				err = read_from_scratch(ctx_b, engine,
+				err = read_from_scratch(ctx_b, engine, obj_b,
 							offset, &value);
 			if (err)
-				goto out_file;
+				goto put_b;
 
 			if (value != expected) {
 				pr_err("%s: Read %08x from scratch (offset 0x%08x_%08x), after %lu reads!\n",
@@ -1847,7 +1854,7 @@ static int igt_vm_isolation(void *arg)
 				       lower_32_bits(offset),
 				       this);
 				err = -EINVAL;
-				goto out_file;
+				goto put_b;
 			}
 
 			this++;
@@ -1858,6 +1865,10 @@ static int igt_vm_isolation(void *arg)
 	pr_info("Checked %lu scratch offsets across %lu engines\n",
 		count, num_engines);
 
+put_b:
+	i915_gem_object_put(obj_b);
+put_a:
+	i915_gem_object_put(obj_a);
 out_file:
 	if (igt_live_test_end(&t))
 		err = -EIO;
Signature · 1 line
2.34.1
#10 lore raw

PATCH v3 7/17 drm/i915: Ensure i915_vma tests do not get -ENOSPC with the locking changes.

In reply to Maarten Lankhorst

Now that we require locking to evict, multiple vmas from the same object might not be evicted. This is expected and required, because execbuf will move to short-term pinning by using the lock only. This will cause these tests to fail, because they create a ton of vma's for the same object.

Unbind manually to prevent spurious -ENOSPC in those mock tests.

---
 drivers/gpu/drm/i915/selftests/i915_vma.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/selftests/i915_vma.c +16 -1
index 1f10fe36619b..5c5809dfe9b2 100644
@@ -691,7 +691,11 @@ static int igt_vma_rotate_remap(void *arg)
 					}
 
 					i915_vma_unpin(vma);
-
+					err = i915_vma_unbind(vma);
+					if (err) {
+						pr_err("Unbinding returned %i\n", err);
+						goto out_object;
+					}
 					cond_resched();
 				}
 			}
@@ -848,6 +852,11 @@ static int igt_vma_partial(void *arg)
 
 				i915_vma_unpin(vma);
 				nvma++;
+				err = i915_vma_unbind(vma);
+				if (err) {
+					pr_err("Unbinding returned %i\n", err);
+					goto out_object;
+				}
 
 				cond_resched();
 			}
@@ -882,6 +891,12 @@ static int igt_vma_partial(void *arg)
 
 		i915_vma_unpin(vma);
 
+		err = i915_vma_unbind(vma);
+		if (err) {
+			pr_err("Unbinding returned %i\n", err);
+			goto out_object;
+		}
+
 		count = 0;
 		list_for_each_entry(vma, &obj->vma.list, obj_link)
 			count++;
Signature · 1 line
2.34.1
Reviewed-by on v3 7/17
#11 lore raw

Re: [PATCH v3 07/17] drm/i915: Ensure i915_vma tests do not get -ENOSPC with the locking changes.

Quoted 9 lines · Maarten Lankhorst

Now that we require locking to evict, multiple vmas from the same object might not be evicted. This is expected and required, because execbuf will move to short-term pinning by using the lock only. This will cause these tests to fail, because they create a ton of vma's for the same object.

Unbind manually to prevent spurious -ENOSPC in those mock tests.

#12 lore raw

PATCH v3 8/17 drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors

In reply to Maarten Lankhorst

Now that we cannot unbind kill the currently locked object directly because we're removing short term pinning, we may have to unbind the object from gtt manually, using a i915_gem_evict_vm() call.

---
 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +16 -2
index af81d6c3332a..00cd9642669a 100644
@@ -358,8 +358,22 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
 			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
 		}
 
-		/* The entire mappable GGTT is pinned? Unexpected! */
-		GEM_BUG_ON(vma == ERR_PTR(-ENOSPC));
+		/*
+		 * The entire mappable GGTT is pinned? Unexpected!
+		 * Try to evict the object we locked too, as normally we skip it
+		 * due to lack of short term pinning inside execbuf.
+		 */
+		if (vma == ERR_PTR(-ENOSPC)) {
+			ret = mutex_lock_interruptible(&ggtt->vm.mutex);
+			if (!ret) {
+				ret = i915_gem_evict_vm(&ggtt->vm);
+				mutex_unlock(&ggtt->vm.mutex);
+			}
+			if (ret)
+				goto err_reset;
+			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
+		}
+		GEM_WARN_ON(vma == ERR_PTR(-ENOSPC));
 	}
 	if (IS_ERR(vma)) {
 		ret = PTR_ERR(vma);
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v3 08/17] drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors

Quoted 2 lines · Maarten Lankhorst

Now that we cannot unbind kill the currently locked object directly

"unbind kill"

Quoted 4 lines

because we're removing short term pinning, we may have to unbind the object from gtt manually, using a i915_gem_evict_vm() call.

Maybe mention that this only in preparation for some future patches, once the actual eviction is trylock and evict_for_vm can also handle shared dma-resv? At this point in the series we shouldn't expect to hit -ENOSPC, right?

Quoted 20 lines
---
 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +6 -2
index af81d6c3332a..00cd9642669a 100644
@@ -358,8 +358,22 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
                        vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
                }
 
-               /* The entire mappable GGTT is pinned? Unexpected! */
-               GEM_BUG_ON(vma == ERR_PTR(-ENOSPC));
+               /*
+                * The entire mappable GGTT is pinned? Unexpected!
+                * Try to evict the object we locked too, as normally we skip it
+                * due to lack of short term pinning inside execbuf.
+                */
+               if (vma == ERR_PTR(-ENOSPC)) {

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault *vmf) · line 376

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +10 -0
+                       ret = mutex_lock_interruptible(&ggtt->vm.mutex);
+                       if (!ret) {
+                               ret = i915_gem_evict_vm(&ggtt->vm);
+                               mutex_unlock(&ggtt->vm.mutex);
+                       }
+                       if (ret)
+                               goto err_reset;
+                       vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
+               }
+               GEM_WARN_ON(vma == ERR_PTR(-ENOSPC));

Looks like this is being triggered in CI, I assume because the trylock could easily fail, due to contention? Is this expected for now? Do we keep the WARN and track it as a known issue?

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0 -1
        }
        if (IS_ERR(vma)) {
                ret = PTR_ERR(vma);
--

2.34.1

#14 lore raw

Re: [PATCH v3 08/17] drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors

Quoted 39 lines · Matthew Auld
Quoted 1 line · Maarten Lankhorst

Now that we cannot unbind kill the currently locked object directly

"unbind kill"

Quoted 4 lines

because we're removing short term pinning, we may have to unbind the object from gtt manually, using a i915_gem_evict_vm() call.

Maybe mention that this only in preparation for some future patches, once the actual eviction is trylock and evict_for_vm can also handle shared dma-resv? At this point in the series we shouldn't expect to hit -ENOSPC, right?

Quoted 25 lines
---
 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +11 -2
index af81d6c3332a..00cd9642669a 100644
@@ -358,8 +358,22 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
                        vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
                }
 
-               /* The entire mappable GGTT is pinned? Unexpected! */
-               GEM_BUG_ON(vma == ERR_PTR(-ENOSPC));
+               /*
+                * The entire mappable GGTT is pinned? Unexpected!
+                * Try to evict the object we locked too, as normally we skip it
+                * due to lack of short term pinning inside execbuf.
+                */
+               if (vma == ERR_PTR(-ENOSPC)) {
+                       ret = mutex_lock_interruptible(&ggtt->vm.mutex);
+                       if (!ret) {
+                               ret = i915_gem_evict_vm(&ggtt->vm);
+                               mutex_unlock(&ggtt->vm.mutex);
+                       }
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault *vmf) · line 376

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +5 -0
+                       if (ret)
+                               goto err_reset;
+                       vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
+               }
+               GEM_WARN_ON(vma == ERR_PTR(-ENOSPC));

Looks like this is being triggered in CI, I assume because the trylock could easily fail, due to contention? Is this expected for now? Do we keep the WARN and track it as a known issue?

I think it makes sense. I can probably fix i915_gem_evict_vm to attempt to take all objects in a blocking way.

I had some primitives that could lock for eviction, and keep a refcount on the object. i915_gem_evict_vm could probably be changed to use it.

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0 -1
        }
        if (IS_ERR(vma)) {
                ret = PTR_ERR(vma);
--

2.34.1

#15 lore raw

PATCH v3 9/17 drm/i915: Trylock the object when shrinking

In reply to Maarten Lankhorst

We're working on requiring the obj->resv lock during unbind, fix the shrinker to take the objectl ock.

---
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +6 -0
index eebff4735781..ad2123369e0d 100644
@@ -405,12 +405,18 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
 	list_for_each_entry_safe(vma, next,
 				 &i915->ggtt.vm.bound_list, vm_link) {
 		unsigned long count = vma->node.size >> PAGE_SHIFT;
+		struct drm_i915_gem_object *obj = vma->obj;
 
 		if (!vma->iomap || i915_vma_is_active(vma))
 			continue;
 
+		if (!i915_gem_object_trylock(obj))
+			continue;
+
 		if (__i915_vma_unbind(vma) == 0)
 			freed_pages += count;
+
+		i915_gem_object_unlock(obj);
 	}
 	mutex_unlock(&i915->ggtt.vm.mutex);
 
Signature · 1 line
2.34.1
#17 lore raw

PATCH v3 10/17 drm/i915: Require object lock when freeing pages during destruction

In reply to Maarten Lankhorst

TTM already requires this, and we require it for delayed destroy.

---
 drivers/gpu/drm/i915/gem/i915_gem_object.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_object.c +5 -0
index 5fac9b560b73..39cd563544a5 100644
@@ -262,6 +262,8 @@ static void __i915_gem_object_free_mmaps(struct drm_i915_gem_object *obj)
  */
 void __i915_gem_object_pages_fini(struct drm_i915_gem_object *obj)
 {
+	assert_object_held(obj);
+
 	if (!list_empty(&obj->vma.list)) {
 		struct i915_vma *vma;
 
@@ -328,7 +330,10 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
 			obj->ops->delayed_free(obj);
 			continue;
 		}
+
+		i915_gem_object_lock(obj, NULL);
 		__i915_gem_object_pages_fini(obj);
+		i915_gem_object_unlock(obj);
 		__i915_gem_free_object(obj);
 
 		/* But keep the pointer alive for RCU-protected lookups */
Signature · 1 line
2.34.1
#18 lore raw

PATCH v3 11/17 drm/i915: Add ww ctx to i915_gem_object_trylock

In reply to Maarten Lankhorst

This is required for i915_gem_evict_vm, to be able to evict the entire VM, including objects that are already locked to the current ww ctx.

---
 drivers/gpu/drm/i915/gem/i915_gem_object.h   | 8 ++++++--
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 4 ++--
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c   | 2 +-
 drivers/gpu/drm/i915/gt/intel_engine_pm.c    | 2 +-
 drivers/gpu/drm/i915/gt/mock_engine.c        | 2 +-
 drivers/gpu/drm/i915/gt/selftest_migrate.c   | 2 +-
 6 files changed, 12 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +6 -2
index 66f20b803b01..f66d46882ea7 100644
@@ -210,9 +210,13 @@ static inline int i915_gem_object_lock_interruptible(struct drm_i915_gem_object
 	return __i915_gem_object_lock(obj, ww, true);
 }
 
-static inline bool i915_gem_object_trylock(struct drm_i915_gem_object *obj)
+static inline bool i915_gem_object_trylock(struct drm_i915_gem_object *obj,
+					   struct i915_gem_ww_ctx *ww)
 {
-	return dma_resv_trylock(obj->base.resv);
+	if (!ww)
+		return dma_resv_trylock(obj->base.resv);
+	else
+		return ww_mutex_trylock(&obj->base.resv->lock, &ww->ctx);
 }
 
 static inline void i915_gem_object_unlock(struct drm_i915_gem_object *obj)
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +2 -2
index ad2123369e0d..85ff182ddbc2 100644
@@ -216,7 +216,7 @@ i915_gem_shrink(struct i915_gem_ww_ctx *ww,
 
 			/* May arrive from get_pages on another bo */
 			if (!ww) {
-				if (!i915_gem_object_trylock(obj))
+				if (!i915_gem_object_trylock(obj, NULL))
 					goto skip;
 			} else {
 				err = i915_gem_object_lock(obj, ww);
@@ -410,7 +410,7 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
 		if (!vma->iomap || i915_vma_is_active(vma))
 			continue;
 
-		if (!i915_gem_object_trylock(obj))
+		if (!i915_gem_object_trylock(obj, NULL))
 			continue;
 
 		if (__i915_vma_unbind(vma) == 0)
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +1 -1
index ad7a8e9e13e7..7df50fd6cc7b 100644
@@ -656,7 +656,7 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,
 	cache_level = HAS_LLC(mem->i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
 	i915_gem_object_set_cache_coherency(obj, cache_level);
 
-	if (WARN_ON(!i915_gem_object_trylock(obj)))
+	if (WARN_ON(!i915_gem_object_trylock(obj, NULL)))
 		return -EBUSY;
 
 	i915_gem_object_init_memory_region(obj, mem);
drivers/gpu/drm/i915/gt/intel_engine_pm.c +1 -1
index a8a2ad44b7e3..b0a4a2dbe3ee 100644
@@ -26,7 +26,7 @@ static void dbg_poison_ce(struct intel_context *ce)
 		int type = i915_coherent_map_type(ce->engine->i915, obj, true);
 		void *map;
 
-		if (!i915_gem_object_trylock(obj))
+		if (!i915_gem_object_trylock(obj, NULL))
 			return;
 
 		map = i915_gem_object_pin_map(obj, type);
drivers/gpu/drm/i915/gt/mock_engine.c +1 -1
index bb99fc03f503..240265354274 100644
@@ -17,7 +17,7 @@ static int mock_timeline_pin(struct intel_timeline *tl)
 {
 	int err;
 
-	if (WARN_ON(!i915_gem_object_trylock(tl->hwsp_ggtt->obj)))
+	if (WARN_ON(!i915_gem_object_trylock(tl->hwsp_ggtt->obj, NULL)))
 		return -EBUSY;
 
 	err = intel_timeline_pin_map(tl);
drivers/gpu/drm/i915/gt/selftest_migrate.c +1 -1
index e21787301bbd..cb574ea6b29d 100644
@@ -465,7 +465,7 @@ create_init_lmem_internal(struct intel_gt *gt, size_t sz, bool try_lmem)
 			return obj;
 	}
 
-	i915_gem_object_trylock(obj);
+	i915_gem_object_trylock(obj, NULL);
 	err = i915_gem_object_pin_pages(obj);
 	if (err) {
 		i915_gem_object_unlock(obj);
Signature · 1 line
2.34.1
#20 lore raw

PATCH v3 12/17 drm/i915: Add locking to i915_gem_evict_vm()

In reply to Maarten Lankhorst

i915_gem_evict_vm will need to be able to evict objects that are locked by the current ctx. By testing if the current context already locked the object, we can do this correctly. This allows us to evict the entire vm even if we already hold some objects' locks.

Previously, this was spread over several commits, but it makes more sense to commit the changes to i915_gem_evict_vm separately from the changes to i915_gem_evict_something() and i915_gem_evict_for_node().

---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  2 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  2 +-
 drivers/gpu/drm/i915/i915_drv.h               |  3 +-
 drivers/gpu/drm/i915/i915_gem_evict.c         | 30 +++++++++++++++++--
 drivers/gpu/drm/i915/i915_vma.c               |  7 ++++-
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 10 +++++--
 6 files changed, 46 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
index 2213f7b613da..eb3649e844ff 100644
@@ -766,7 +766,7 @@ static int eb_reserve(struct i915_execbuffer *eb)
 		case 1:
 			/* Too fragmented, unbind everything and retry */
 			mutex_lock(&eb->context->vm->mutex);
-			err = i915_gem_evict_vm(eb->context->vm);
+			err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
 			mutex_unlock(&eb->context->vm->mutex);
 			if (err)
 				return err;
drivers/gpu/drm/i915/gem/i915_gem_mman.c +1 -1
index 00cd9642669a..2856098cb449 100644
@@ -366,7 +366,7 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
 		if (vma == ERR_PTR(-ENOSPC)) {
 			ret = mutex_lock_interruptible(&ggtt->vm.mutex);
 			if (!ret) {
-				ret = i915_gem_evict_vm(&ggtt->vm);
+				ret = i915_gem_evict_vm(&ggtt->vm, &ww);
 				mutex_unlock(&ggtt->vm.mutex);
 			}
 			if (ret)
drivers/gpu/drm/i915/i915_drv.h +2 -1
index d51628d10f9d..c180019c607f 100644
@@ -1725,7 +1725,8 @@ int __must_check i915_gem_evict_something(struct i915_address_space *vm,
 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
 					 struct drm_mm_node *node,
 					 unsigned int flags);
-int i915_gem_evict_vm(struct i915_address_space *vm);
+int i915_gem_evict_vm(struct i915_address_space *vm,
+		      struct i915_gem_ww_ctx *ww);
 
 /* i915_gem_internal.c */
 struct drm_i915_gem_object *
drivers/gpu/drm/i915/i915_gem_evict.c +28 -2
index 2b73ddb11c66..bfd66f539fc1 100644
@@ -367,7 +367,7 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
  * To clarify: This is for freeing up virtual address space, not for freeing
  * memory in e.g. the shrinker.
  */
-int i915_gem_evict_vm(struct i915_address_space *vm)
+int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
 {
 	int ret = 0;
 
@@ -388,24 +388,50 @@ int i915_gem_evict_vm(struct i915_address_space *vm)
 	do {
 		struct i915_vma *vma, *vn;
 		LIST_HEAD(eviction_list);
+		LIST_HEAD(locked_eviction_list);
 
 		list_for_each_entry(vma, &vm->bound_list, vm_link) {
 			if (i915_vma_is_pinned(vma))
 				continue;
 
+			/*
+			 * If we already own the lock, trylock fails. In case the resv
+			 * is shared among multiple objects, we still need the object ref.
+			 */
+			if (ww && (dma_resv_locking_ctx(vma->obj->base.resv) == &ww->ctx)) {
+				__i915_vma_pin(vma);
+				list_add(&vma->evict_link, &locked_eviction_list);
+				continue;
+			}
+
+			if (!i915_gem_object_trylock(vma->obj, ww))
+				continue;
+
 			__i915_vma_pin(vma);
 			list_add(&vma->evict_link, &eviction_list);
 		}
-		if (list_empty(&eviction_list))
+		if (list_empty(&eviction_list) && list_empty(&locked_eviction_list))
 			break;
 
 		ret = 0;
+		/* Unbind locked objects first, before unlocking the eviction_list */
+		list_for_each_entry_safe(vma, vn, &locked_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;
+		}
+
 		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;
+
+			i915_gem_object_unlock(vma->obj);
 		}
 	} while (ret == 0);
 
drivers/gpu/drm/i915/i915_vma.c +6 -1
index de24e4b3b19b..d24e90eac948 100644
@@ -1462,7 +1462,12 @@ static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 		/* Unlike i915_vma_pin, we don't take no for an answer! */
 		flush_idle_contexts(vm->gt);
 		if (mutex_lock_interruptible(&vm->mutex) == 0) {
-			i915_gem_evict_vm(vm);
+			/*
+			 * We pass NULL ww here, as we don't want to unbind
+			 * locked objects when called from execbuf when pinning
+			 * is removed. This would probably regress badly.
+			 */
+			i915_gem_evict_vm(vm, NULL);
 			mutex_unlock(&vm->mutex);
 		}
 	} while (1);
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +8 -2
index 7e0658a77659..7178811366af 100644
@@ -331,6 +331,7 @@ static int igt_evict_vm(void *arg)
 {
 	struct intel_gt *gt = arg;
 	struct i915_ggtt *ggtt = gt->ggtt;
+	struct i915_gem_ww_ctx ww;
 	LIST_HEAD(objects);
 	int err;
 
@@ -342,7 +343,7 @@ static int igt_evict_vm(void *arg)
 
 	/* Everything is pinned, nothing should happen */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_vm(&ggtt->vm);
+	err = i915_gem_evict_vm(&ggtt->vm, NULL);
 	mutex_unlock(&ggtt->vm.mutex);
 	if (err) {
 		pr_err("i915_gem_evict_vm on a full GGTT returned err=%d]\n",
@@ -352,9 +353,14 @@ static int igt_evict_vm(void *arg)
 
 	unpin_ggtt(ggtt);
 
+	i915_gem_ww_ctx_init(&ww, false);
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_vm(&ggtt->vm);
+	err = i915_gem_evict_vm(&ggtt->vm, &ww);
 	mutex_unlock(&ggtt->vm.mutex);
+
+	/* no -EDEADLK handling; can't happen with vm.mutex in place */
+	i915_gem_ww_ctx_fini(&ww);
+
 	if (err) {
 		pr_err("i915_gem_evict_vm on a full GGTT returned err=%d]\n",
 		       err);
Signature · 1 line
2.34.1
Reviewed-by on v3 12/17
#21 lore raw

Re: [Intel-gfx] [PATCH v3 12/17] drm/i915: Add locking to i915_gem_evict_vm()

Quoted 77 lines · Maarten Lankhorst

i915_gem_evict_vm will need to be able to evict objects that are locked by the current ctx. By testing if the current context already locked the object, we can do this correctly. This allows us to evict the entire vm even if we already hold some objects' locks.

Previously, this was spread over several commits, but it makes more sense to commit the changes to i915_gem_evict_vm separately from the changes to i915_gem_evict_something() and i915_gem_evict_for_node().

---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  2 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  2 +-
 drivers/gpu/drm/i915/i915_drv.h               |  3 +-
 drivers/gpu/drm/i915/i915_gem_evict.c         | 30 +++++++++++++++++--
 drivers/gpu/drm/i915/i915_vma.c               |  7 ++++-
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 10 +++++--
 6 files changed, 46 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
index 2213f7b613da..eb3649e844ff 100644
@@ -766,7 +766,7 @@ static int eb_reserve(struct i915_execbuffer *eb)
                case 1:
                        /* Too fragmented, unbind everything and retry */
                        mutex_lock(&eb->context->vm->mutex);
-                       err = i915_gem_evict_vm(eb->context->vm);
+                       err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
                        mutex_unlock(&eb->context->vm->mutex);
                        if (err)
                                return err;
drivers/gpu/drm/i915/gem/i915_gem_mman.c +1 -1
index 00cd9642669a..2856098cb449 100644
@@ -366,7 +366,7 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
                if (vma == ERR_PTR(-ENOSPC)) {
                        ret = mutex_lock_interruptible(&ggtt->vm.mutex);
                        if (!ret) {
-                               ret = i915_gem_evict_vm(&ggtt->vm);
+                               ret = i915_gem_evict_vm(&ggtt->vm, &ww);
                                mutex_unlock(&ggtt->vm.mutex);
                        }
                        if (ret)
drivers/gpu/drm/i915/i915_drv.h +2 -1
index d51628d10f9d..c180019c607f 100644
@@ -1725,7 +1725,8 @@ int __must_check i915_gem_evict_something(struct i915_address_space *vm,
 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
                                         struct drm_mm_node *node,
                                         unsigned int flags);
-int i915_gem_evict_vm(struct i915_address_space *vm);
+int i915_gem_evict_vm(struct i915_address_space *vm,
+                     struct i915_gem_ww_ctx *ww);
 
 /* i915_gem_internal.c */
 struct drm_i915_gem_object *
drivers/gpu/drm/i915/i915_gem_evict.c +1 -1
index 2b73ddb11c66..bfd66f539fc1 100644
@@ -367,7 +367,7 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
  * To clarify: This is for freeing up virtual address space, not for freeing
  * memory in e.g. the shrinker.
  */
-int i915_gem_evict_vm(struct i915_address_space *vm)
+int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
 {
        int ret = 0;
 
@@ -388,24 +388,50 @@ int i915_gem_evict_vm(struct i915_address_space *vm)
        do {
                struct i915_vma *vma, *vn;

drivers/gpu/drm/i915/i915_gem_evict.c int i915_gem_evict_vm(struct i915_address_space *vm) · line 399

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_evict.c +4 -0
                LIST_HEAD(eviction_list);
+               LIST_HEAD(locked_eviction_list);
 
                list_for_each_entry(vma, &vm->bound_list, vm_link) {
                        if (i915_vma_is_pinned(vma))
                                continue;
 
+                       /*
+                        * If we already own the lock, trylock fails. In case the resv
+                        * is shared among multiple objects, we still need the object ref.

What is "object ref" here? I assume it's just leftovers...

Otherwise,

Quoted 97 lines
drivers/gpu/drm/i915/i915_gem_evict.c +23 -1
+                        */
+                       if (ww && (dma_resv_locking_ctx(vma->obj->base.resv) == &ww->ctx)) {
+                               __i915_vma_pin(vma);
+                               list_add(&vma->evict_link, &locked_eviction_list);
+                               continue;
+                       }
+
+                       if (!i915_gem_object_trylock(vma->obj, ww))
+                               continue;
+
                        __i915_vma_pin(vma);
                        list_add(&vma->evict_link, &eviction_list);
                }
-               if (list_empty(&eviction_list))
+               if (list_empty(&eviction_list) && list_empty(&locked_eviction_list))
                        break;
 
                ret = 0;
+               /* Unbind locked objects first, before unlocking the eviction_list */
+               list_for_each_entry_safe(vma, vn, &locked_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;
+               }
+
                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;
+
+                       i915_gem_object_unlock(vma->obj);
                }
        } while (ret == 0);
 
drivers/gpu/drm/i915/i915_vma.c +6 -1
index de24e4b3b19b..d24e90eac948 100644
@@ -1462,7 +1462,12 @@ static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
                /* Unlike i915_vma_pin, we don't take no for an answer! */
                flush_idle_contexts(vm->gt);
                if (mutex_lock_interruptible(&vm->mutex) == 0) {
-                       i915_gem_evict_vm(vm);
+                       /*
+                        * We pass NULL ww here, as we don't want to unbind
+                        * locked objects when called from execbuf when pinning
+                        * is removed. This would probably regress badly.
+                        */
+                       i915_gem_evict_vm(vm, NULL);
                        mutex_unlock(&vm->mutex);
                }
        } while (1);
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +8 -3
index 7e0658a77659..7178811366af 100644
@@ -331,6 +331,7 @@ static int igt_evict_vm(void *arg)
 {
        struct intel_gt *gt = arg;
        struct i915_ggtt *ggtt = gt->ggtt;
+       struct i915_gem_ww_ctx ww;
        LIST_HEAD(objects);
        int err;
 
@@ -342,7 +343,7 @@ static int igt_evict_vm(void *arg)
 
        /* Everything is pinned, nothing should happen */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_vm(&ggtt->vm);
+       err = i915_gem_evict_vm(&ggtt->vm, NULL);
        mutex_unlock(&ggtt->vm.mutex);
        if (err) {
                pr_err("i915_gem_evict_vm on a full GGTT returned err=%d]\n",
@@ -352,9 +353,14 @@ static int igt_evict_vm(void *arg)
 
        unpin_ggtt(ggtt);
 
+       i915_gem_ww_ctx_init(&ww, false);
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_vm(&ggtt->vm);
+       err = i915_gem_evict_vm(&ggtt->vm, &ww);
        mutex_unlock(&ggtt->vm.mutex);
+
+       /* no -EDEADLK handling; can't happen with vm.mutex in place */
+       i915_gem_ww_ctx_fini(&ww);
+
        if (err) {
                pr_err("i915_gem_evict_vm on a full GGTT returned err=%d]\n",
                       err);
--

2.34.1

#22 lore raw

PATCH v3 13/17 drm/i915: Add object locking to i915_gem_evict_for_node and i915_gem_evict_something

In reply to Maarten Lankhorst

Because we will start to require the obj->resv lock for unbinding, ensure these shrinker functions also take the lock.

This requires some function signature changes, to ensure that the ww context is passed around, but is mostly straightforward.

Previously this was split up into several patches, but reworking should allow for easier bisection.

---
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |  2 +-
 drivers/gpu/drm/i915/gvt/aperture_gm.c        |  2 +-
 drivers/gpu/drm/i915/i915_drv.h               |  2 ++
 drivers/gpu/drm/i915/i915_gem_evict.c         | 34 +++++++++++++++----
 drivers/gpu/drm/i915/i915_gem_gtt.c           |  8 +++--
 drivers/gpu/drm/i915/i915_gem_gtt.h           |  3 ++
 drivers/gpu/drm/i915/i915_vgpu.c              |  2 +-
 drivers/gpu/drm/i915/i915_vma.c               |  9 ++---
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 17 +++++-----
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 14 ++++----
 11 files changed, 63 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gt/intel_ggtt.c +1 -1
index a287c9186ec9..ed43e9c80aaa 100644
@@ -504,7 +504,7 @@ static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt)
 	GEM_BUG_ON(ggtt->vm.total <= GUC_GGTT_TOP);
 	size = ggtt->vm.total - GUC_GGTT_TOP;
 
-	ret = i915_gem_gtt_reserve(&ggtt->vm, &ggtt->uc_fw, size,
+	ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &ggtt->uc_fw, size,
 				   GUC_GGTT_TOP, I915_COLOR_UNEVICTABLE,
 				   PIN_NOEVICT);
 	if (ret)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index e5ad4d5a91c0..a3597a6bb805 100644
@@ -1382,7 +1382,7 @@ static int evict_vma(void *data)
 	complete(&arg->completion);
 
 	mutex_lock(&vm->mutex);
-	err = i915_gem_evict_for_node(vm, &evict, 0);
+	err = i915_gem_evict_for_node(vm, NULL, &evict, 0);
 	mutex_unlock(&vm->mutex);
 
 	return err;
drivers/gpu/drm/i915/gvt/aperture_gm.c +1 -1
index 0d6d59871308..c08098a167e9 100644
@@ -63,7 +63,7 @@ static int alloc_gm(struct intel_vgpu *vgpu, bool high_gm)
 
 	mutex_lock(&gt->ggtt->vm.mutex);
 	mmio_hw_access_pre(gt);
-	ret = i915_gem_gtt_insert(&gt->ggtt->vm, node,
+	ret = i915_gem_gtt_insert(&gt->ggtt->vm, NULL, node,
 				  size, I915_GTT_PAGE_SIZE,
 				  I915_COLOR_UNEVICTABLE,
 				  start, end, flags);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index c180019c607f..2a98192a89c1 100644
@@ -1718,11 +1718,13 @@ i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id)
 
 /* i915_gem_evict.c */
 int __must_check i915_gem_evict_something(struct i915_address_space *vm,
+					  struct i915_gem_ww_ctx *ww,
 					  u64 min_size, u64 alignment,
 					  unsigned long color,
 					  u64 start, u64 end,
 					  unsigned flags);
 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
+					 struct i915_gem_ww_ctx *ww,
 					 struct drm_mm_node *node,
 					 unsigned int flags);
 int i915_gem_evict_vm(struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_evict.c +28 -6
index bfd66f539fc1..f502a617b35c 100644
@@ -51,6 +51,7 @@ static int ggtt_flush(struct intel_gt *gt)
 
 static bool
 mark_free(struct drm_mm_scan *scan,
+	  struct i915_gem_ww_ctx *ww,
 	  struct i915_vma *vma,
 	  unsigned int flags,
 	  struct list_head *unwind)
@@ -58,6 +59,9 @@ mark_free(struct drm_mm_scan *scan,
 	if (i915_vma_is_pinned(vma))
 		return false;
 
+	if (!i915_gem_object_trylock(vma->obj, ww))
+		return false;
+
 	list_add(&vma->evict_link, unwind);
 	return drm_mm_scan_add_block(scan, &vma->node);
 }
@@ -98,6 +102,7 @@ static bool defer_evict(struct i915_vma *vma)
  */
 int
 i915_gem_evict_something(struct i915_address_space *vm,
+			 struct i915_gem_ww_ctx *ww,
 			 u64 min_size, u64 alignment,
 			 unsigned long color,
 			 u64 start, u64 end,
@@ -170,7 +175,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
 			continue;
 		}
 
-		if (mark_free(&scan, vma, flags, &eviction_list))
+		if (mark_free(&scan, ww, vma, flags, &eviction_list))
 			goto found;
 	}
 
@@ -178,6 +183,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
 	list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
 		ret = drm_mm_scan_remove_block(&scan, &vma->node);
 		BUG_ON(ret);
+		i915_gem_object_unlock(vma->obj);
 	}
 
 	/*
@@ -222,10 +228,12 @@ i915_gem_evict_something(struct i915_address_space *vm,
 	 * of any of our objects, thus corrupting the list).
 	 */
 	list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
-		if (drm_mm_scan_remove_block(&scan, &vma->node))
+		if (drm_mm_scan_remove_block(&scan, &vma->node)) {
 			__i915_vma_pin(vma);
-		else
+		} else {
 			list_del(&vma->evict_link);
+			i915_gem_object_unlock(vma->obj);
+		}
 	}
 
 	/* Unbinding will emit any required flushes */
@@ -234,16 +242,22 @@ i915_gem_evict_something(struct i915_address_space *vm,
 		__i915_vma_unpin(vma);
 		if (ret == 0)
 			ret = __i915_vma_unbind(vma);
+
+		i915_gem_object_unlock(vma->obj);
 	}
 
 	while (ret == 0 && (node = drm_mm_scan_color_evict(&scan))) {
 		vma = container_of(node, struct i915_vma, node);
 
+
 		/* If we find any non-objects (!vma), we cannot evict them */
-		if (vma->node.color != I915_COLOR_UNEVICTABLE)
+		if (vma->node.color != I915_COLOR_UNEVICTABLE &&
+		    i915_gem_object_trylock(vma->obj, ww)) {
 			ret = __i915_vma_unbind(vma);
-		else
-			ret = -ENOSPC; /* XXX search failed, try again? */
+			i915_gem_object_unlock(vma->obj);
+		} else {
+			ret = -ENOSPC;
+		}
 	}
 
 	return ret;
@@ -261,6 +275,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
  * memory in e.g. the shrinker.
  */
 int i915_gem_evict_for_node(struct i915_address_space *vm,
+			    struct i915_gem_ww_ctx *ww,
 			    struct drm_mm_node *target,
 			    unsigned int flags)
 {
@@ -333,6 +348,11 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
 			break;
 		}
 
+		if (!i915_gem_object_trylock(vma->obj, ww)) {
+			ret = -ENOSPC;
+			break;
+		}
+
 		/*
 		 * Never show fear in the face of dragons!
 		 *
@@ -350,6 +370,8 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
 		__i915_vma_unpin(vma);
 		if (ret == 0)
 			ret = __i915_vma_unbind(vma);
+
+		i915_gem_object_unlock(vma->obj);
 	}
 
 	return ret;
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -3
index cd5f2348a187..c810da476c2b 100644
@@ -93,6 +93,7 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+			 struct i915_gem_ww_ctx *ww,
 			 struct drm_mm_node *node,
 			 u64 size, u64 offset, unsigned long color,
 			 unsigned int flags)
@@ -117,7 +118,7 @@ int i915_gem_gtt_reserve(struct i915_address_space *vm,
 	if (flags & PIN_NOEVICT)
 		return -ENOSPC;
 
-	err = i915_gem_evict_for_node(vm, node, flags);
+	err = i915_gem_evict_for_node(vm, ww, node, flags);
 	if (err == 0)
 		err = drm_mm_reserve_node(&vm->mm, node);
 
@@ -184,6 +185,7 @@ static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+			struct i915_gem_ww_ctx *ww,
 			struct drm_mm_node *node,
 			u64 size, u64 alignment, unsigned long color,
 			u64 start, u64 end, unsigned int flags)
@@ -269,7 +271,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
 	 */
 	offset = random_offset(start, end,
 			       size, alignment ?: I915_GTT_MIN_ALIGNMENT);
-	err = i915_gem_gtt_reserve(vm, node, size, offset, color, flags);
+	err = i915_gem_gtt_reserve(vm, ww, node, size, offset, color, flags);
 	if (err != -ENOSPC)
 		return err;
 
@@ -277,7 +279,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
 		return -ENOSPC;
 
 	/* Randomly selected placement is pinned, do a search */
-	err = i915_gem_evict_something(vm, size, alignment, color,
+	err = i915_gem_evict_something(vm, ww, size, alignment, color,
 				       start, end, flags);
 	if (err)
 		return err;
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -0
index c9b0ee5e1d23..e4938aba3fe9 100644
@@ -16,6 +16,7 @@
 
 struct drm_i915_gem_object;
 struct i915_address_space;
+struct i915_gem_ww_ctx;
 
 int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
 					    struct sg_table *pages);
@@ -23,11 +24,13 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
 			       struct sg_table *pages);
 
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+			 struct i915_gem_ww_ctx *ww,
 			 struct drm_mm_node *node,
 			 u64 size, u64 offset, unsigned long color,
 			 unsigned int flags);
 
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+			struct i915_gem_ww_ctx *ww,
 			struct drm_mm_node *node,
 			u64 size, u64 alignment, unsigned long color,
 			u64 start, u64 end, unsigned int flags);
drivers/gpu/drm/i915/i915_vgpu.c +1 -1
index 31a105bc1792..c97323973f9b 100644
@@ -197,7 +197,7 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt,
 	drm_info(&dev_priv->drm,
 		 "balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",
 		 start, end, size / 1024);
-	ret = i915_gem_gtt_reserve(&ggtt->vm, node,
+	ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, node,
 				   size, start, I915_COLOR_UNEVICTABLE,
 				   0);
 	if (!ret)
drivers/gpu/drm/i915/i915_vma.c +5 -4
index d24e90eac948..83df1290df5e 100644
@@ -650,7 +650,8 @@ bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long color)
  * 0 on success, negative error code otherwise.
  */
 static int
-i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
+i915_vma_insert(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+		u64 size, u64 alignment, u64 flags)
 {
 	unsigned long color;
 	u64 start, end;
@@ -702,7 +703,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 		    range_overflows(offset, size, end))
 			return -EINVAL;
 
-		ret = i915_gem_gtt_reserve(vma->vm, &vma->node,
+		ret = i915_gem_gtt_reserve(vma->vm, ww, &vma->node,
 					   size, offset, color,
 					   flags);
 		if (ret)
@@ -741,7 +742,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 				size = round_up(size, I915_GTT_PAGE_SIZE_2M);
 		}
 
-		ret = i915_gem_gtt_insert(vma->vm, &vma->node,
+		ret = i915_gem_gtt_insert(vma->vm, ww, &vma->node,
 					  size, alignment, color,
 					  start, end, flags);
 		if (ret)
@@ -1382,7 +1383,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 		goto err_unlock;
 
 	if (!(bound & I915_VMA_BIND_MASK)) {
-		err = i915_vma_insert(vma, size, alignment, flags);
+		err = i915_vma_insert(vma, ww, size, alignment, flags);
 		if (err)
 			goto err_active;
 
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +9 -8
index 7178811366af..c80e1483d603 100644
@@ -117,7 +117,7 @@ static int igt_evict_something(void *arg)
 
 	/* Everything is pinned, nothing should happen */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_something(&ggtt->vm,
+	err = i915_gem_evict_something(&ggtt->vm, NULL,
 				       I915_GTT_PAGE_SIZE, 0, 0,
 				       0, U64_MAX,
 				       0);
@@ -132,11 +132,12 @@ static int igt_evict_something(void *arg)
 
 	/* Everything is unpinned, we should be able to evict something */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_something(&ggtt->vm,
+	err = i915_gem_evict_something(&ggtt->vm, NULL,
 				       I915_GTT_PAGE_SIZE, 0, 0,
 				       0, U64_MAX,
 				       0);
 	mutex_unlock(&ggtt->vm.mutex);
+
 	if (err) {
 		pr_err("i915_gem_evict_something failed on a full GGTT with err=%d\n",
 		       err);
@@ -204,7 +205,7 @@ static int igt_evict_for_vma(void *arg)
 
 	/* Everything is pinned, nothing should happen */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+	err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
 	mutex_unlock(&ggtt->vm.mutex);
 	if (err != -ENOSPC) {
 		pr_err("i915_gem_evict_for_node on a full GGTT returned err=%d\n",
@@ -216,7 +217,7 @@ static int igt_evict_for_vma(void *arg)
 
 	/* Everything is unpinned, we should be able to evict the node */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+	err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
 	mutex_unlock(&ggtt->vm.mutex);
 	if (err) {
 		pr_err("i915_gem_evict_for_node returned err=%d\n",
@@ -297,7 +298,7 @@ static int igt_evict_for_cache_color(void *arg)
 
 	/* Remove just the second vma */
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+	err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
 	mutex_unlock(&ggtt->vm.mutex);
 	if (err) {
 		pr_err("[0]i915_gem_evict_for_node returned err=%d\n", err);
@@ -310,7 +311,7 @@ static int igt_evict_for_cache_color(void *arg)
 	target.color = I915_CACHE_L3_LLC;
 
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+	err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
 	mutex_unlock(&ggtt->vm.mutex);
 	if (!err) {
 		pr_err("[1]i915_gem_evict_for_node returned err=%d\n", err);
@@ -408,7 +409,7 @@ static int igt_evict_contexts(void *arg)
 	/* Reserve a block so that we know we have enough to fit a few rq */
 	memset(&hole, 0, sizeof(hole));
 	mutex_lock(&ggtt->vm.mutex);
-	err = i915_gem_gtt_insert(&ggtt->vm, &hole,
+	err = i915_gem_gtt_insert(&ggtt->vm, NULL, &hole,
 				  PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE,
 				  0, ggtt->vm.total,
 				  PIN_NOEVICT);
@@ -428,7 +429,7 @@ static int igt_evict_contexts(void *arg)
 			goto out_locked;
 		}
 
-		if (i915_gem_gtt_insert(&ggtt->vm, &r->node,
+		if (i915_gem_gtt_insert(&ggtt->vm, NULL, &r->node,
 					1ul << 20, 0, I915_COLOR_UNEVICTABLE,
 					0, ggtt->vm.total,
 					PIN_NOEVICT)) {
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +7 -7
index 88b3a4d9e27e..169e2330b386 100644
@@ -1378,7 +1378,7 @@ static int igt_gtt_reserve(void *arg)
 		}
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
 					   obj->base.size,
 					   total,
 					   obj->cache_level,
@@ -1430,7 +1430,7 @@ static int igt_gtt_reserve(void *arg)
 		}
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
 					   obj->base.size,
 					   total,
 					   obj->cache_level,
@@ -1477,7 +1477,7 @@ static int igt_gtt_reserve(void *arg)
 					   I915_GTT_MIN_ALIGNMENT);
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
 					   obj->base.size,
 					   offset,
 					   obj->cache_level,
@@ -1552,7 +1552,7 @@ static int igt_gtt_insert(void *arg)
 	/* Check a couple of obviously invalid requests */
 	for (ii = invalid_insert; ii->size; ii++) {
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_insert(&ggtt->vm, &tmp,
+		err = i915_gem_gtt_insert(&ggtt->vm, NULL, &tmp,
 					  ii->size, ii->alignment,
 					  I915_COLOR_UNEVICTABLE,
 					  ii->start, ii->end,
@@ -1594,7 +1594,7 @@ static int igt_gtt_insert(void *arg)
 		}
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
 					  obj->base.size, 0, obj->cache_level,
 					  0, ggtt->vm.total,
 					  0);
@@ -1654,7 +1654,7 @@ static int igt_gtt_insert(void *arg)
 		}
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
 					  obj->base.size, 0, obj->cache_level,
 					  0, ggtt->vm.total,
 					  0);
@@ -1703,7 +1703,7 @@ static int igt_gtt_insert(void *arg)
 		}
 
 		mutex_lock(&ggtt->vm.mutex);
-		err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+		err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
 					  obj->base.size, 0, obj->cache_level,
 					  0, ggtt->vm.total,
 					  0);
Signature · 1 line
2.34.1
Reviewed-by on v3 13/17
#23 lore raw

Re: [Intel-gfx] [PATCH v3 13/17] drm/i915: Add object locking to i915_gem_evict_for_node and i915_gem_evict_something

Quoted 6 lines · Maarten Lankhorst

Because we will start to require the obj->resv lock for unbinding, ensure these shrinker functions also take the lock.

This requires some function signature changes, to ensure that the ww context is passed around, but is mostly straightforward.

Do we even need this? We aren't handling the shared dma-resv for these ones, right? Or more just to have a consistent-ish interface?

Quoted 140 lines

Previously this was split up into several patches, but reworking should allow for easier bisection.

---
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |  2 +-
 drivers/gpu/drm/i915/gvt/aperture_gm.c        |  2 +-
 drivers/gpu/drm/i915/i915_drv.h               |  2 ++
 drivers/gpu/drm/i915/i915_gem_evict.c         | 34 +++++++++++++++----
 drivers/gpu/drm/i915/i915_gem_gtt.c           |  8 +++--
 drivers/gpu/drm/i915/i915_gem_gtt.h           |  3 ++
 drivers/gpu/drm/i915/i915_vgpu.c              |  2 +-
 drivers/gpu/drm/i915/i915_vma.c               |  9 ++---
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 17 +++++-----
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 14 ++++----
 11 files changed, 63 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gt/intel_ggtt.c +1 -1
index a287c9186ec9..ed43e9c80aaa 100644
@@ -504,7 +504,7 @@ static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt)
        GEM_BUG_ON(ggtt->vm.total <= GUC_GGTT_TOP);
        size = ggtt->vm.total - GUC_GGTT_TOP;
 
-       ret = i915_gem_gtt_reserve(&ggtt->vm, &ggtt->uc_fw, size,
+       ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &ggtt->uc_fw, size,
                                   GUC_GGTT_TOP, I915_COLOR_UNEVICTABLE,
                                   PIN_NOEVICT);
        if (ret)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index e5ad4d5a91c0..a3597a6bb805 100644
@@ -1382,7 +1382,7 @@ static int evict_vma(void *data)
        complete(&arg->completion);
 
        mutex_lock(&vm->mutex);
-       err = i915_gem_evict_for_node(vm, &evict, 0);
+       err = i915_gem_evict_for_node(vm, NULL, &evict, 0);
        mutex_unlock(&vm->mutex);
 
        return err;
drivers/gpu/drm/i915/gvt/aperture_gm.c +1 -1
index 0d6d59871308..c08098a167e9 100644
@@ -63,7 +63,7 @@ static int alloc_gm(struct intel_vgpu *vgpu, bool high_gm)
 
        mutex_lock(&gt->ggtt->vm.mutex);
        mmio_hw_access_pre(gt);
-       ret = i915_gem_gtt_insert(&gt->ggtt->vm, node,
+       ret = i915_gem_gtt_insert(&gt->ggtt->vm, NULL, node,
                                  size, I915_GTT_PAGE_SIZE,
                                  I915_COLOR_UNEVICTABLE,
                                  start, end, flags);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index c180019c607f..2a98192a89c1 100644
@@ -1718,11 +1718,13 @@ i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id)
 
 /* i915_gem_evict.c */
 int __must_check i915_gem_evict_something(struct i915_address_space *vm,
+                                         struct i915_gem_ww_ctx *ww,
                                          u64 min_size, u64 alignment,
                                          unsigned long color,
                                          u64 start, u64 end,
                                          unsigned flags);
 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
+                                        struct i915_gem_ww_ctx *ww,
                                         struct drm_mm_node *node,
                                         unsigned int flags);
 int i915_gem_evict_vm(struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_evict.c +11 -3
index bfd66f539fc1..f502a617b35c 100644
@@ -51,6 +51,7 @@ static int ggtt_flush(struct intel_gt *gt)
 
 static bool
 mark_free(struct drm_mm_scan *scan,
+         struct i915_gem_ww_ctx *ww,
          struct i915_vma *vma,
          unsigned int flags,
          struct list_head *unwind)
@@ -58,6 +59,9 @@ mark_free(struct drm_mm_scan *scan,
        if (i915_vma_is_pinned(vma))
                return false;
 
+       if (!i915_gem_object_trylock(vma->obj, ww))
+               return false;
+
        list_add(&vma->evict_link, unwind);
        return drm_mm_scan_add_block(scan, &vma->node);
 }
@@ -98,6 +102,7 @@ static bool defer_evict(struct i915_vma *vma)
  */
 int
 i915_gem_evict_something(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         u64 min_size, u64 alignment,
                         unsigned long color,
                         u64 start, u64 end,
@@ -170,7 +175,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
                        continue;
                }
 
-               if (mark_free(&scan, vma, flags, &eviction_list))
+               if (mark_free(&scan, ww, vma, flags, &eviction_list))
                        goto found;
        }
 
@@ -178,6 +183,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
        list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
                ret = drm_mm_scan_remove_block(&scan, &vma->node);
                BUG_ON(ret);
+               i915_gem_object_unlock(vma->obj);
        }
 
        /*
@@ -222,10 +228,12 @@ i915_gem_evict_something(struct i915_address_space *vm,
         * of any of our objects, thus corrupting the list).
         */
        list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
-               if (drm_mm_scan_remove_block(&scan, &vma->node))
+               if (drm_mm_scan_remove_block(&scan, &vma->node)) {
                        __i915_vma_pin(vma);
-               else
+               } else {
                        list_del(&vma->evict_link);
+                       i915_gem_object_unlock(vma->obj);
+               }
        }
 
        /* Unbinding will emit any required flushes */
@@ -234,16 +242,22 @@ i915_gem_evict_something(struct i915_address_space *vm,
                __i915_vma_unpin(vma);

drivers/gpu/drm/i915/i915_gem_evict.c i915_gem_evict_something(struct i915_address_space *vm, · line 252

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_evict.c +3 -0
                if (ret == 0)
                        ret = __i915_vma_unbind(vma);
+
+               i915_gem_object_unlock(vma->obj);
        }
 
        while (ret == 0 && (node = drm_mm_scan_color_evict(&scan))) {
                vma = container_of(node, struct i915_vma, node);
 
+

Spurious new line.

Otherwise,

Quoted 321 lines
drivers/gpu/drm/i915/i915_gem_evict.c +14 -3
                /* If we find any non-objects (!vma), we cannot evict them */
-               if (vma->node.color != I915_COLOR_UNEVICTABLE)
+               if (vma->node.color != I915_COLOR_UNEVICTABLE &&
+                   i915_gem_object_trylock(vma->obj, ww)) {
                        ret = __i915_vma_unbind(vma);
-               else
-                       ret = -ENOSPC; /* XXX search failed, try again? */
+                       i915_gem_object_unlock(vma->obj);
+               } else {
+                       ret = -ENOSPC;
+               }
        }
 
        return ret;
@@ -261,6 +275,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
  * memory in e.g. the shrinker.
  */
 int i915_gem_evict_for_node(struct i915_address_space *vm,
+                           struct i915_gem_ww_ctx *ww,
                            struct drm_mm_node *target,
                            unsigned int flags)
 {
@@ -333,6 +348,11 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
                        break;
                }
 
+               if (!i915_gem_object_trylock(vma->obj, ww)) {
+                       ret = -ENOSPC;
+                       break;
+               }
+
                /*
                 * Never show fear in the face of dragons!
                 *
@@ -350,6 +370,8 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
                __i915_vma_unpin(vma);
                if (ret == 0)
                        ret = __i915_vma_unbind(vma);
+
+               i915_gem_object_unlock(vma->obj);
        }
 
        return ret;
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -3
index cd5f2348a187..c810da476c2b 100644
@@ -93,6 +93,7 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         struct drm_mm_node *node,
                         u64 size, u64 offset, unsigned long color,
                         unsigned int flags)
@@ -117,7 +118,7 @@ int i915_gem_gtt_reserve(struct i915_address_space *vm,
        if (flags & PIN_NOEVICT)
                return -ENOSPC;
 
-       err = i915_gem_evict_for_node(vm, node, flags);
+       err = i915_gem_evict_for_node(vm, ww, node, flags);
        if (err == 0)
                err = drm_mm_reserve_node(&vm->mm, node);
 
@@ -184,6 +185,7 @@ static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+                       struct i915_gem_ww_ctx *ww,
                        struct drm_mm_node *node,
                        u64 size, u64 alignment, unsigned long color,
                        u64 start, u64 end, unsigned int flags)
@@ -269,7 +271,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
         */
        offset = random_offset(start, end,
                               size, alignment ?: I915_GTT_MIN_ALIGNMENT);
-       err = i915_gem_gtt_reserve(vm, node, size, offset, color, flags);
+       err = i915_gem_gtt_reserve(vm, ww, node, size, offset, color, flags);
        if (err != -ENOSPC)
                return err;
 
@@ -277,7 +279,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
                return -ENOSPC;
 
        /* Randomly selected placement is pinned, do a search */
-       err = i915_gem_evict_something(vm, size, alignment, color,
+       err = i915_gem_evict_something(vm, ww, size, alignment, color,
                                       start, end, flags);
        if (err)
                return err;
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -0
index c9b0ee5e1d23..e4938aba3fe9 100644
@@ -16,6 +16,7 @@
 
 struct drm_i915_gem_object;
 struct i915_address_space;
+struct i915_gem_ww_ctx;
 
 int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
                                            struct sg_table *pages);
@@ -23,11 +24,13 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
                               struct sg_table *pages);
 
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         struct drm_mm_node *node,
                         u64 size, u64 offset, unsigned long color,
                         unsigned int flags);
 
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+                       struct i915_gem_ww_ctx *ww,
                        struct drm_mm_node *node,
                        u64 size, u64 alignment, unsigned long color,
                        u64 start, u64 end, unsigned int flags);
drivers/gpu/drm/i915/i915_vgpu.c +1 -1
index 31a105bc1792..c97323973f9b 100644
@@ -197,7 +197,7 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt,
        drm_info(&dev_priv->drm,
                 "balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",
                 start, end, size / 1024);
-       ret = i915_gem_gtt_reserve(&ggtt->vm, node,
+       ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, node,
                                   size, start, I915_COLOR_UNEVICTABLE,
                                   0);
        if (!ret)
drivers/gpu/drm/i915/i915_vma.c +5 -4
index d24e90eac948..83df1290df5e 100644
@@ -650,7 +650,8 @@ bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long color)
  * 0 on success, negative error code otherwise.
  */
 static int
-i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
+i915_vma_insert(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+               u64 size, u64 alignment, u64 flags)
 {
        unsigned long color;
        u64 start, end;
@@ -702,7 +703,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
                    range_overflows(offset, size, end))
                        return -EINVAL;
 
-               ret = i915_gem_gtt_reserve(vma->vm, &vma->node,
+               ret = i915_gem_gtt_reserve(vma->vm, ww, &vma->node,
                                           size, offset, color,
                                           flags);
                if (ret)
@@ -741,7 +742,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
                                size = round_up(size, I915_GTT_PAGE_SIZE_2M);
                }
 
-               ret = i915_gem_gtt_insert(vma->vm, &vma->node,
+               ret = i915_gem_gtt_insert(vma->vm, ww, &vma->node,
                                          size, alignment, color,
                                          start, end, flags);
                if (ret)
@@ -1382,7 +1383,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
                goto err_unlock;
 
        if (!(bound & I915_VMA_BIND_MASK)) {
-               err = i915_vma_insert(vma, size, alignment, flags);
+               err = i915_vma_insert(vma, ww, size, alignment, flags);
                if (err)
                        goto err_active;
 
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +9 -8
index 7178811366af..c80e1483d603 100644
@@ -117,7 +117,7 @@ static int igt_evict_something(void *arg)
 
        /* Everything is pinned, nothing should happen */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_something(&ggtt->vm,
+       err = i915_gem_evict_something(&ggtt->vm, NULL,
                                       I915_GTT_PAGE_SIZE, 0, 0,
                                       0, U64_MAX,
                                       0);
@@ -132,11 +132,12 @@ static int igt_evict_something(void *arg)
 
        /* Everything is unpinned, we should be able to evict something */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_something(&ggtt->vm,
+       err = i915_gem_evict_something(&ggtt->vm, NULL,
                                       I915_GTT_PAGE_SIZE, 0, 0,
                                       0, U64_MAX,
                                       0);
        mutex_unlock(&ggtt->vm.mutex);
+
        if (err) {
                pr_err("i915_gem_evict_something failed on a full GGTT with err=%d\n",
                       err);
@@ -204,7 +205,7 @@ static int igt_evict_for_vma(void *arg)
 
        /* Everything is pinned, nothing should happen */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err != -ENOSPC) {
                pr_err("i915_gem_evict_for_node on a full GGTT returned err=%d\n",
@@ -216,7 +217,7 @@ static int igt_evict_for_vma(void *arg)
 
        /* Everything is unpinned, we should be able to evict the node */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err) {
                pr_err("i915_gem_evict_for_node returned err=%d\n",
@@ -297,7 +298,7 @@ static int igt_evict_for_cache_color(void *arg)
 
        /* Remove just the second vma */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err) {
                pr_err("[0]i915_gem_evict_for_node returned err=%d\n", err);
@@ -310,7 +311,7 @@ static int igt_evict_for_cache_color(void *arg)
        target.color = I915_CACHE_L3_LLC;
 
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (!err) {
                pr_err("[1]i915_gem_evict_for_node returned err=%d\n", err);
@@ -408,7 +409,7 @@ static int igt_evict_contexts(void *arg)
        /* Reserve a block so that we know we have enough to fit a few rq */
        memset(&hole, 0, sizeof(hole));
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_gtt_insert(&ggtt->vm, &hole,
+       err = i915_gem_gtt_insert(&ggtt->vm, NULL, &hole,
                                  PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE,
                                  0, ggtt->vm.total,
                                  PIN_NOEVICT);
@@ -428,7 +429,7 @@ static int igt_evict_contexts(void *arg)
                        goto out_locked;
                }
 
-               if (i915_gem_gtt_insert(&ggtt->vm, &r->node,
+               if (i915_gem_gtt_insert(&ggtt->vm, NULL, &r->node,
                                        1ul << 20, 0, I915_COLOR_UNEVICTABLE,
                                        0, ggtt->vm.total,
                                        PIN_NOEVICT)) {
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +7 -8
index 88b3a4d9e27e..169e2330b386 100644
@@ -1378,7 +1378,7 @@ static int igt_gtt_reserve(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           total,
                                           obj->cache_level,
@@ -1430,7 +1430,7 @@ static int igt_gtt_reserve(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           total,
                                           obj->cache_level,
@@ -1477,7 +1477,7 @@ static int igt_gtt_reserve(void *arg)
                                           I915_GTT_MIN_ALIGNMENT);
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           offset,
                                           obj->cache_level,
@@ -1552,7 +1552,7 @@ static int igt_gtt_insert(void *arg)
        /* Check a couple of obviously invalid requests */
        for (ii = invalid_insert; ii->size; ii++) {
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &tmp,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &tmp,
                                          ii->size, ii->alignment,
                                          I915_COLOR_UNEVICTABLE,
                                          ii->start, ii->end,
@@ -1594,7 +1594,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
@@ -1654,7 +1654,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
@@ -1703,7 +1703,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
--

2.34.1

#24 lore raw

Re: [Intel-gfx] [PATCH v3 13/17] drm/i915: Add object locking to i915_gem_evict_for_node and i915_gem_evict_something

Quoted 9 lines · Matthew Auld
Quoted 5 lines · Maarten Lankhorst

Because we will start to require the obj->resv lock for unbinding, ensure these shrinker functions also take the lock.

This requires some function signature changes, to ensure that the ww context is passed around, but is mostly straightforward.

Do we even need this? We aren't handling the shared dma-resv for these ones, right? Or more just to have a consistent-ish interface?

Yeah, we don't currently use it, but it will allow for easier eviction in the future, with -EDEADLK handling

when required. It will currently only annotate the objects as being held by the ww context, which can cause -EDEADLK when other threads try to lock.

Ideally we'd take a ref to the object and perform a blocking lock, but our locking and eviction code can't handle that right now.

Quoted 476 lines
Quoted 139 lines

Previously this was split up into several patches, but reworking should allow for easier bisection.

---
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |  2 +-
 drivers/gpu/drm/i915/gvt/aperture_gm.c        |  2 +-
 drivers/gpu/drm/i915/i915_drv.h               |  2 ++
 drivers/gpu/drm/i915/i915_gem_evict.c         | 34 +++++++++++++++----
 drivers/gpu/drm/i915/i915_gem_gtt.c           |  8 +++--
 drivers/gpu/drm/i915/i915_gem_gtt.h           |  3 ++
 drivers/gpu/drm/i915/i915_vgpu.c              |  2 +-
 drivers/gpu/drm/i915/i915_vma.c               |  9 ++---
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 17 +++++-----
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 14 ++++----
 11 files changed, 63 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gt/intel_ggtt.c +1 -1
index a287c9186ec9..ed43e9c80aaa 100644
@@ -504,7 +504,7 @@ static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt)
        GEM_BUG_ON(ggtt->vm.total <= GUC_GGTT_TOP);
        size = ggtt->vm.total - GUC_GGTT_TOP;
 
-       ret = i915_gem_gtt_reserve(&ggtt->vm, &ggtt->uc_fw, size,
+       ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &ggtt->uc_fw, size,
                                   GUC_GGTT_TOP, I915_COLOR_UNEVICTABLE,
                                   PIN_NOEVICT);
        if (ret)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index e5ad4d5a91c0..a3597a6bb805 100644
@@ -1382,7 +1382,7 @@ static int evict_vma(void *data)
        complete(&arg->completion);
 
        mutex_lock(&vm->mutex);
-       err = i915_gem_evict_for_node(vm, &evict, 0);
+       err = i915_gem_evict_for_node(vm, NULL, &evict, 0);
        mutex_unlock(&vm->mutex);
 
        return err;
drivers/gpu/drm/i915/gvt/aperture_gm.c +1 -1
index 0d6d59871308..c08098a167e9 100644
@@ -63,7 +63,7 @@ static int alloc_gm(struct intel_vgpu *vgpu, bool high_gm)
 
        mutex_lock(&gt->ggtt->vm.mutex);
        mmio_hw_access_pre(gt);
-       ret = i915_gem_gtt_insert(&gt->ggtt->vm, node,
+       ret = i915_gem_gtt_insert(&gt->ggtt->vm, NULL, node,
                                  size, I915_GTT_PAGE_SIZE,
                                  I915_COLOR_UNEVICTABLE,
                                  start, end, flags);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index c180019c607f..2a98192a89c1 100644
@@ -1718,11 +1718,13 @@ i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id)
 
 /* i915_gem_evict.c */
 int __must_check i915_gem_evict_something(struct i915_address_space *vm,
+                                         struct i915_gem_ww_ctx *ww,
                                          u64 min_size, u64 alignment,
                                          unsigned long color,
                                          u64 start, u64 end,
                                          unsigned flags);
 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
+                                        struct i915_gem_ww_ctx *ww,
                                         struct drm_mm_node *node,
                                         unsigned int flags);
 int i915_gem_evict_vm(struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_evict.c +11 -3
index bfd66f539fc1..f502a617b35c 100644
@@ -51,6 +51,7 @@ static int ggtt_flush(struct intel_gt *gt)
 
 static bool
 mark_free(struct drm_mm_scan *scan,
+         struct i915_gem_ww_ctx *ww,
          struct i915_vma *vma,
          unsigned int flags,
          struct list_head *unwind)
@@ -58,6 +59,9 @@ mark_free(struct drm_mm_scan *scan,
        if (i915_vma_is_pinned(vma))
                return false;
 
+       if (!i915_gem_object_trylock(vma->obj, ww))
+               return false;
+
        list_add(&vma->evict_link, unwind);
        return drm_mm_scan_add_block(scan, &vma->node);
 }
@@ -98,6 +102,7 @@ static bool defer_evict(struct i915_vma *vma)
  */
 int
 i915_gem_evict_something(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         u64 min_size, u64 alignment,
                         unsigned long color,
                         u64 start, u64 end,
@@ -170,7 +175,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
                        continue;
                }
 
-               if (mark_free(&scan, vma, flags, &eviction_list))
+               if (mark_free(&scan, ww, vma, flags, &eviction_list))
                        goto found;
        }
 
@@ -178,6 +183,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
        list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
                ret = drm_mm_scan_remove_block(&scan, &vma->node);
                BUG_ON(ret);
+               i915_gem_object_unlock(vma->obj);
        }
 
        /*
@@ -222,10 +228,12 @@ i915_gem_evict_something(struct i915_address_space *vm,
         * of any of our objects, thus corrupting the list).
         */
        list_for_each_entry_safe(vma, next, &eviction_list, evict_link) {
-               if (drm_mm_scan_remove_block(&scan, &vma->node))
+               if (drm_mm_scan_remove_block(&scan, &vma->node)) {
                        __i915_vma_pin(vma);
-               else
+               } else {
                        list_del(&vma->evict_link);
+                       i915_gem_object_unlock(vma->obj);
+               }
        }
 
        /* Unbinding will emit any required flushes */
@@ -234,16 +242,22 @@ i915_gem_evict_something(struct i915_address_space *vm,
                __i915_vma_unpin(vma);

drivers/gpu/drm/i915/i915_gem_evict.c i915_gem_evict_something(struct i915_address_space *vm, · line 252

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_evict.c +3 -0
                if (ret == 0)
                        ret = __i915_vma_unbind(vma);
+
+               i915_gem_object_unlock(vma->obj);
        }
 
        while (ret == 0 && (node = drm_mm_scan_color_evict(&scan))) {
                vma = container_of(node, struct i915_vma, node);
 
+

Spurious new line.

Otherwise,

Quoted 321 lines
drivers/gpu/drm/i915/i915_gem_evict.c +14 -3
                /* If we find any non-objects (!vma), we cannot evict them */
-               if (vma->node.color != I915_COLOR_UNEVICTABLE)
+               if (vma->node.color != I915_COLOR_UNEVICTABLE &&
+                   i915_gem_object_trylock(vma->obj, ww)) {
                        ret = __i915_vma_unbind(vma);
-               else
-                       ret = -ENOSPC; /* XXX search failed, try again? */
+                       i915_gem_object_unlock(vma->obj);
+               } else {
+                       ret = -ENOSPC;
+               }
        }
 
        return ret;
@@ -261,6 +275,7 @@ i915_gem_evict_something(struct i915_address_space *vm,
  * memory in e.g. the shrinker.
  */
 int i915_gem_evict_for_node(struct i915_address_space *vm,
+                           struct i915_gem_ww_ctx *ww,
                            struct drm_mm_node *target,
                            unsigned int flags)
 {
@@ -333,6 +348,11 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
                        break;
                }
 
+               if (!i915_gem_object_trylock(vma->obj, ww)) {
+                       ret = -ENOSPC;
+                       break;
+               }
+
                /*
                 * Never show fear in the face of dragons!
                 *
@@ -350,6 +370,8 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
                __i915_vma_unpin(vma);
                if (ret == 0)
                        ret = __i915_vma_unbind(vma);
+
+               i915_gem_object_unlock(vma->obj);
        }
 
        return ret;
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -3
index cd5f2348a187..c810da476c2b 100644
@@ -93,6 +93,7 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         struct drm_mm_node *node,
                         u64 size, u64 offset, unsigned long color,
                         unsigned int flags)
@@ -117,7 +118,7 @@ int i915_gem_gtt_reserve(struct i915_address_space *vm,
        if (flags & PIN_NOEVICT)
                return -ENOSPC;
 
-       err = i915_gem_evict_for_node(vm, node, flags);
+       err = i915_gem_evict_for_node(vm, ww, node, flags);
        if (err == 0)
                err = drm_mm_reserve_node(&vm->mm, node);
 
@@ -184,6 +185,7 @@ static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
  * asked to wait for eviction and interrupted.
  */
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+                       struct i915_gem_ww_ctx *ww,
                        struct drm_mm_node *node,
                        u64 size, u64 alignment, unsigned long color,
                        u64 start, u64 end, unsigned int flags)
@@ -269,7 +271,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
         */
        offset = random_offset(start, end,
                               size, alignment ?: I915_GTT_MIN_ALIGNMENT);
-       err = i915_gem_gtt_reserve(vm, node, size, offset, color, flags);
+       err = i915_gem_gtt_reserve(vm, ww, node, size, offset, color, flags);
        if (err != -ENOSPC)
                return err;
 
@@ -277,7 +279,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
                return -ENOSPC;
 
        /* Randomly selected placement is pinned, do a search */
-       err = i915_gem_evict_something(vm, size, alignment, color,
+       err = i915_gem_evict_something(vm, ww, size, alignment, color,
                                       start, end, flags);
        if (err)
                return err;
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -0
index c9b0ee5e1d23..e4938aba3fe9 100644
@@ -16,6 +16,7 @@
 
 struct drm_i915_gem_object;
 struct i915_address_space;
+struct i915_gem_ww_ctx;
 
 int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
                                            struct sg_table *pages);
@@ -23,11 +24,13 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
                               struct sg_table *pages);
 
 int i915_gem_gtt_reserve(struct i915_address_space *vm,
+                        struct i915_gem_ww_ctx *ww,
                         struct drm_mm_node *node,
                         u64 size, u64 offset, unsigned long color,
                         unsigned int flags);
 
 int i915_gem_gtt_insert(struct i915_address_space *vm,
+                       struct i915_gem_ww_ctx *ww,
                        struct drm_mm_node *node,
                        u64 size, u64 alignment, unsigned long color,
                        u64 start, u64 end, unsigned int flags);
drivers/gpu/drm/i915/i915_vgpu.c +1 -1
index 31a105bc1792..c97323973f9b 100644
@@ -197,7 +197,7 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt,
        drm_info(&dev_priv->drm,
                 "balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",
                 start, end, size / 1024);
-       ret = i915_gem_gtt_reserve(&ggtt->vm, node,
+       ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, node,
                                   size, start, I915_COLOR_UNEVICTABLE,
                                   0);
        if (!ret)
drivers/gpu/drm/i915/i915_vma.c +5 -4
index d24e90eac948..83df1290df5e 100644
@@ -650,7 +650,8 @@ bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long color)
  * 0 on success, negative error code otherwise.
  */
 static int
-i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
+i915_vma_insert(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+               u64 size, u64 alignment, u64 flags)
 {
        unsigned long color;
        u64 start, end;
@@ -702,7 +703,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
                    range_overflows(offset, size, end))
                        return -EINVAL;
 
-               ret = i915_gem_gtt_reserve(vma->vm, &vma->node,
+               ret = i915_gem_gtt_reserve(vma->vm, ww, &vma->node,
                                           size, offset, color,
                                           flags);
                if (ret)
@@ -741,7 +742,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
                                size = round_up(size, I915_GTT_PAGE_SIZE_2M);
                }
 
-               ret = i915_gem_gtt_insert(vma->vm, &vma->node,
+               ret = i915_gem_gtt_insert(vma->vm, ww, &vma->node,
                                          size, alignment, color,
                                          start, end, flags);
                if (ret)
@@ -1382,7 +1383,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
                goto err_unlock;
 
        if (!(bound & I915_VMA_BIND_MASK)) {
-               err = i915_vma_insert(vma, size, alignment, flags);
+               err = i915_vma_insert(vma, ww, size, alignment, flags);
                if (err)
                        goto err_active;
 
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +9 -8
index 7178811366af..c80e1483d603 100644
@@ -117,7 +117,7 @@ static int igt_evict_something(void *arg)
 
        /* Everything is pinned, nothing should happen */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_something(&ggtt->vm,
+       err = i915_gem_evict_something(&ggtt->vm, NULL,
                                       I915_GTT_PAGE_SIZE, 0, 0,
                                       0, U64_MAX,
                                       0);
@@ -132,11 +132,12 @@ static int igt_evict_something(void *arg)
 
        /* Everything is unpinned, we should be able to evict something */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_something(&ggtt->vm,
+       err = i915_gem_evict_something(&ggtt->vm, NULL,
                                       I915_GTT_PAGE_SIZE, 0, 0,
                                       0, U64_MAX,
                                       0);
        mutex_unlock(&ggtt->vm.mutex);
+
        if (err) {
                pr_err("i915_gem_evict_something failed on a full GGTT with err=%d\n",
                       err);
@@ -204,7 +205,7 @@ static int igt_evict_for_vma(void *arg)
 
        /* Everything is pinned, nothing should happen */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err != -ENOSPC) {
                pr_err("i915_gem_evict_for_node on a full GGTT returned err=%d\n",
@@ -216,7 +217,7 @@ static int igt_evict_for_vma(void *arg)
 
        /* Everything is unpinned, we should be able to evict the node */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err) {
                pr_err("i915_gem_evict_for_node returned err=%d\n",
@@ -297,7 +298,7 @@ static int igt_evict_for_cache_color(void *arg)
 
        /* Remove just the second vma */
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (err) {
                pr_err("[0]i915_gem_evict_for_node returned err=%d\n", err);
@@ -310,7 +311,7 @@ static int igt_evict_for_cache_color(void *arg)
        target.color = I915_CACHE_L3_LLC;
 
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_evict_for_node(&ggtt->vm, &target, 0);
+       err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);
        mutex_unlock(&ggtt->vm.mutex);
        if (!err) {
                pr_err("[1]i915_gem_evict_for_node returned err=%d\n", err);
@@ -408,7 +409,7 @@ static int igt_evict_contexts(void *arg)
        /* Reserve a block so that we know we have enough to fit a few rq */
        memset(&hole, 0, sizeof(hole));
        mutex_lock(&ggtt->vm.mutex);
-       err = i915_gem_gtt_insert(&ggtt->vm, &hole,
+       err = i915_gem_gtt_insert(&ggtt->vm, NULL, &hole,
                                  PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE,
                                  0, ggtt->vm.total,
                                  PIN_NOEVICT);
@@ -428,7 +429,7 @@ static int igt_evict_contexts(void *arg)
                        goto out_locked;
                }
 
-               if (i915_gem_gtt_insert(&ggtt->vm, &r->node,
+               if (i915_gem_gtt_insert(&ggtt->vm, NULL, &r->node,
                                        1ul << 20, 0, I915_COLOR_UNEVICTABLE,
                                        0, ggtt->vm.total,
                                        PIN_NOEVICT)) {
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +7 -8
index 88b3a4d9e27e..169e2330b386 100644
@@ -1378,7 +1378,7 @@ static int igt_gtt_reserve(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           total,
                                           obj->cache_level,
@@ -1430,7 +1430,7 @@ static int igt_gtt_reserve(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           total,
                                           obj->cache_level,
@@ -1477,7 +1477,7 @@ static int igt_gtt_reserve(void *arg)
                                           I915_GTT_MIN_ALIGNMENT);
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_reserve(&ggtt->vm, NULL, &vma->node,
                                           obj->base.size,
                                           offset,
                                           obj->cache_level,
@@ -1552,7 +1552,7 @@ static int igt_gtt_insert(void *arg)
        /* Check a couple of obviously invalid requests */
        for (ii = invalid_insert; ii->size; ii++) {
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &tmp,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &tmp,
                                          ii->size, ii->alignment,
                                          I915_COLOR_UNEVICTABLE,
                                          ii->start, ii->end,
@@ -1594,7 +1594,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
@@ -1654,7 +1654,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
@@ -1703,7 +1703,7 @@ static int igt_gtt_insert(void *arg)
                }
 
                mutex_lock(&ggtt->vm.mutex);
-               err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
+               err = i915_gem_gtt_insert(&ggtt->vm, NULL, &vma->node,
                                          obj->base.size, 0, obj->cache_level,
                                          0, ggtt->vm.total,
                                          0);
--

2.34.1

#25 lore raw

PATCH v3 14/17 drm/i915: Add i915_vma_unbind_unlocked, and take obj lock for i915_vma_unbind, v2.

In reply to Maarten Lankhorst

We want to remove more members of i915_vma, which requires the locking to be held more often.

Start requiring gem object lock for i915_vma_unbind, as it's one of the callers that may unpin pages.

Some special care is needed when evicting, because the last reference to the object may be held by the VMA, so after __i915_vma_unbind, vma may be garbage, and we need to cache vma->obj before unlocking.

Changes since v1:
- Make trylock failing a WARN. (Matt)
- Remove double i915_vma_wait_for_bind() (Matt)
- Move atomic_set to right before mutex_unlock(), to make it more clear they belong together. (Matt)

---
 drivers/gpu/drm/i915/display/intel_fb_pin.c   |  2 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |  2 +-
 .../i915/gem/selftests/i915_gem_client_blt.c  |  2 +-
 .../drm/i915/gem/selftests/i915_gem_mman.c    |  6 +++
 drivers/gpu/drm/i915/gt/intel_ggtt.c          | 49 ++++++++++++++++---
 drivers/gpu/drm/i915/i915_gem.c               |  2 +
 drivers/gpu/drm/i915/i915_vma.c               | 27 +++++++++-
 drivers/gpu/drm/i915/i915_vma.h               |  1 +
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 22 ++++-----
 drivers/gpu/drm/i915/selftests/i915_vma.c     |  8 +--
 10 files changed, 95 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -1
index 31c15e5fca95..9c555f6d1958 100644
@@ -47,7 +47,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
 		goto err;
 
 	if (i915_vma_misplaced(vma, 0, alignment, 0)) {
-		ret = i915_vma_unbind(vma);
+		ret = i915_vma_unbind_unlocked(vma);
 		if (ret) {
 			vma = ERR_PTR(ret);
 			goto err;
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +1 -1
index c69c7d45aabc..0db62652e3ba 100644
@@ -647,7 +647,7 @@ static int igt_mock_ppgtt_misaligned_dma(void *arg)
 		 * pages.
 		 */
 		for (offset = 4096; offset < page_size; offset += 4096) {
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			if (err)
 				goto out_unpin;
 
drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c +1 -1
index 8402ed925a69..8fb5be799b3c 100644
@@ -318,7 +318,7 @@ static int pin_buffer(struct i915_vma *vma, u64 addr)
 	int err;
 
 	if (drm_mm_node_allocated(&vma->node) && vma->node.start != addr) {
-		err = i915_vma_unbind(vma);
+		err = i915_vma_unbind_unlocked(vma);
 		if (err)
 			return err;
 	}
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +6 -0
index 6d30cdfa80f3..e69e8861352d 100644
@@ -165,7 +165,9 @@ static int check_partial_mapping(struct drm_i915_gem_object *obj,
 	kunmap(p);
 
 out:
+	i915_gem_object_lock(obj, NULL);
 	__i915_vma_put(vma);
+	i915_gem_object_unlock(obj);
 	return err;
 }
 
@@ -259,7 +261,9 @@ static int check_partial_mappings(struct drm_i915_gem_object *obj,
 		if (err)
 			return err;
 
+		i915_gem_object_lock(obj, NULL);
 		__i915_vma_put(vma);
+		i915_gem_object_unlock(obj);
 
 		if (igt_timeout(end_time,
 				"%s: timed out after tiling=%d stride=%d\n",
@@ -1349,7 +1353,9 @@ static int __igt_mmap_revoke(struct drm_i915_private *i915,
 	 * for other objects. Ergo we have to revoke the previous mmap PTE
 	 * access as it no longer points to the same object.
 	 */
+	i915_gem_object_lock(obj, NULL);
 	err = i915_gem_object_unbind(obj, I915_GEM_OBJECT_UNBIND_ACTIVE);
+	i915_gem_object_unlock(obj);
 	if (err) {
 		pr_err("Failed to unbind object!\n");
 		goto out_unmap;
drivers/gpu/drm/i915/gt/intel_ggtt.c +43 -6

76 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem.c +2 -0
index 6002045bd194..c31ef87397f1 100644
@@ -118,6 +118,8 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	struct i915_vma *vma;
 	int ret;
 
+	assert_object_held(obj);
+
 	if (list_empty(&obj->vma.list))
 		return 0;
 
drivers/gpu/drm/i915/i915_vma.c +25 -2
index 83df1290df5e..565819c8bf49 100644
@@ -1604,8 +1604,16 @@ void i915_vma_parked(struct intel_gt *gt)
 		struct drm_i915_gem_object *obj = vma->obj;
 		struct i915_address_space *vm = vma->vm;
 
-		INIT_LIST_HEAD(&vma->closed_link);
-		__i915_vma_put(vma);
+		if (i915_gem_object_trylock(obj, NULL)) {
+			INIT_LIST_HEAD(&vma->closed_link);
+			__i915_vma_put(vma);
+			i915_gem_object_unlock(obj);
+		} else {
+			/* back you go.. */
+			spin_lock_irq(&gt->closed_lock);
+			list_add(&vma->closed_link, &gt->closed_vma);
+			spin_unlock_irq(&gt->closed_lock);
+		}
 
 		i915_gem_object_put(obj);
 		i915_vm_close(vm);
@@ -1721,6 +1729,7 @@ int _i915_vma_move_to_active(struct i915_vma *vma,
 void __i915_vma_evict(struct i915_vma *vma)
 {
 	GEM_BUG_ON(i915_vma_is_pinned(vma));
+	assert_object_held_shared(vma->obj);
 
 	if (i915_vma_is_map_and_fenceable(vma)) {
 		/* Force a pagefault for domain tracking on next user access */
@@ -1766,6 +1775,7 @@ int __i915_vma_unbind(struct i915_vma *vma)
 	int ret;
 
 	lockdep_assert_held(&vma->vm->mutex);
+	assert_object_held_shared(vma->obj);
 
 	if (!drm_mm_node_allocated(&vma->node))
 		return 0;
@@ -1797,6 +1807,8 @@ int i915_vma_unbind(struct i915_vma *vma)
 	intel_wakeref_t wakeref = 0;
 	int err;
 
+	assert_object_held_shared(vma->obj);
+
 	/* Optimistic wait before taking the mutex */
 	err = i915_vma_sync(vma);
 	if (err)
@@ -1827,6 +1839,17 @@ int i915_vma_unbind(struct i915_vma *vma)
 	return err;
 }
 
+int i915_vma_unbind_unlocked(struct i915_vma *vma)
+{
+	int err;
+
+	i915_gem_object_lock(vma->obj, NULL);
+	err = i915_vma_unbind(vma);
+	i915_gem_object_unlock(vma->obj);
+
+	return err;
+}
+
 struct i915_vma *i915_vma_make_unshrinkable(struct i915_vma *vma)
 {
 	i915_gem_object_make_unshrinkable(vma->obj);
drivers/gpu/drm/i915/i915_vma.h +1 -0
index 32719431b3df..da69ecb1b860 100644
@@ -214,6 +214,7 @@ void i915_vma_revoke_mmap(struct i915_vma *vma);
 void __i915_vma_evict(struct i915_vma *vma);
 int __i915_vma_unbind(struct i915_vma *vma);
 int __must_check i915_vma_unbind(struct i915_vma *vma);
+int __must_check i915_vma_unbind_unlocked(struct i915_vma *vma);
 void i915_vma_unlink_ctx(struct i915_vma *vma);
 void i915_vma_close(struct i915_vma *vma);
 void i915_vma_reopen(struct i915_vma *vma);
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +11 -11
index 169e2330b386..cafe7936fb6f 100644
@@ -385,7 +385,7 @@ static void close_object_list(struct list_head *objects,
 
 		vma = i915_vma_instance(obj, vm, NULL);
 		if (!IS_ERR(vma))
-			ignored = i915_vma_unbind(vma);
+			ignored = i915_vma_unbind_unlocked(vma);
 
 		list_del(&obj->st_link);
 		i915_gem_object_put(obj);
@@ -496,7 +496,7 @@ static int fill_hole(struct i915_address_space *vm,
 						goto err;
 					}
 
-					err = i915_vma_unbind(vma);
+					err = i915_vma_unbind_unlocked(vma);
 					if (err) {
 						pr_err("%s(%s) (forward) unbind of vma.node=%llx + %llx failed with err=%d\n",
 						       __func__, p->name, vma->node.start, vma->node.size,
@@ -569,7 +569,7 @@ static int fill_hole(struct i915_address_space *vm,
 						goto err;
 					}
 
-					err = i915_vma_unbind(vma);
+					err = i915_vma_unbind_unlocked(vma);
 					if (err) {
 						pr_err("%s(%s) (backward) unbind of vma.node=%llx + %llx failed with err=%d\n",
 						       __func__, p->name, vma->node.start, vma->node.size,
@@ -655,7 +655,7 @@ static int walk_hole(struct i915_address_space *vm,
 				goto err_put;
 			}
 
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			if (err) {
 				pr_err("%s unbind failed at %llx + %llx  with err=%d\n",
 				       __func__, addr, vma->size, err);
@@ -732,13 +732,13 @@ static int pot_hole(struct i915_address_space *vm,
 				pr_err("%s incorrect at %llx + %llx\n",
 				       __func__, addr, vma->size);
 				i915_vma_unpin(vma);
-				err = i915_vma_unbind(vma);
+				err = i915_vma_unbind_unlocked(vma);
 				err = -EINVAL;
 				goto err_obj;
 			}
 
 			i915_vma_unpin(vma);
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			GEM_BUG_ON(err);
 		}
 
@@ -832,13 +832,13 @@ static int drunk_hole(struct i915_address_space *vm,
 				pr_err("%s incorrect at %llx + %llx\n",
 				       __func__, addr, BIT_ULL(size));
 				i915_vma_unpin(vma);
-				err = i915_vma_unbind(vma);
+				err = i915_vma_unbind_unlocked(vma);
 				err = -EINVAL;
 				goto err_obj;
 			}
 
 			i915_vma_unpin(vma);
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			GEM_BUG_ON(err);
 
 			if (igt_timeout(end_time,
@@ -906,7 +906,7 @@ static int __shrink_hole(struct i915_address_space *vm,
 			pr_err("%s incorrect at %llx + %llx\n",
 			       __func__, addr, size);
 			i915_vma_unpin(vma);
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			err = -EINVAL;
 			break;
 		}
@@ -1465,7 +1465,7 @@ static int igt_gtt_reserve(void *arg)
 			goto out;
 		}
 
-		err = i915_vma_unbind(vma);
+		err = i915_vma_unbind_unlocked(vma);
 		if (err) {
 			pr_err("i915_vma_unbind failed with err=%d!\n", err);
 			goto out;
@@ -1647,7 +1647,7 @@ static int igt_gtt_insert(void *arg)
 		GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
 		offset = vma->node.start;
 
-		err = i915_vma_unbind(vma);
+		err = i915_vma_unbind_unlocked(vma);
 		if (err) {
 			pr_err("i915_vma_unbind failed with err=%d!\n", err);
 			goto out;
drivers/gpu/drm/i915/selftests/i915_vma.c +4 -4
index 5c5809dfe9b2..2c73f7448df7 100644
@@ -340,7 +340,7 @@ static int igt_vma_pin1(void *arg)
 
 		if (!err) {
 			i915_vma_unpin(vma);
-			err = i915_vma_unbind(vma);
+			err = i915_vma_unbind_unlocked(vma);
 			if (err) {
 				pr_err("Failed to unbind single page from GGTT, err=%d\n", err);
 				goto out;
@@ -691,7 +691,7 @@ static int igt_vma_rotate_remap(void *arg)
 					}
 
 					i915_vma_unpin(vma);
-					err = i915_vma_unbind(vma);
+					err = i915_vma_unbind_unlocked(vma);
 					if (err) {
 						pr_err("Unbinding returned %i\n", err);
 						goto out_object;
@@ -852,7 +852,7 @@ static int igt_vma_partial(void *arg)
 
 				i915_vma_unpin(vma);
 				nvma++;
-				err = i915_vma_unbind(vma);
+				err = i915_vma_unbind_unlocked(vma);
 				if (err) {
 					pr_err("Unbinding returned %i\n", err);
 					goto out_object;
@@ -891,7 +891,7 @@ static int igt_vma_partial(void *arg)
 
 		i915_vma_unpin(vma);
 
-		err = i915_vma_unbind(vma);
+		err = i915_vma_unbind_unlocked(vma);
 		if (err) {
 			pr_err("Unbinding returned %i\n", err);
 			goto out_object;
Signature · 1 line
2.34.1
#26 lore raw

PATCH v3 15/17 drm/i915: Remove assert_object_held_shared

In reply to Maarten Lankhorst

This duck tape workaround is no longer required, unbind and destroy are fixed to take the obj->resv mutex before destroying and obj->mm.lock has been removed, always requiring obj->resv as well.

---
 drivers/gpu/drm/i915/gem/i915_gem_object.c  |  4 ++--
 drivers/gpu/drm/i915/gem/i915_gem_object.h  | 14 --------------
 drivers/gpu/drm/i915/gem/i915_gem_pages.c   | 12 ++++++------
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c |  2 +-
 drivers/gpu/drm/i915/i915_vma.c             |  6 +++---
 5 files changed, 12 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.c +2 -2
index 39cd563544a5..0ae86812ed66 100644
@@ -544,7 +544,7 @@ bool i915_gem_object_has_struct_page(const struct drm_i915_gem_object *obj)
 #ifdef CONFIG_LOCKDEP
 	if (IS_DGFX(to_i915(obj->base.dev)) &&
 	    i915_gem_object_evictable((void __force *)obj))
-		assert_object_held_shared(obj);
+		assert_object_held(obj);
 #endif
 	return obj->mem_flags & I915_BO_FLAG_STRUCT_PAGE;
 }
@@ -563,7 +563,7 @@ bool i915_gem_object_has_iomem(const struct drm_i915_gem_object *obj)
 #ifdef CONFIG_LOCKDEP
 	if (IS_DGFX(to_i915(obj->base.dev)) &&
 	    i915_gem_object_evictable((void __force *)obj))
-		assert_object_held_shared(obj);
+		assert_object_held(obj);
 #endif
 	return obj->mem_flags & I915_BO_FLAG_IOMEM;
 }
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -14
index f66d46882ea7..09cf1c92373a 100644
@@ -157,20 +157,6 @@ i915_gem_object_put(struct drm_i915_gem_object *obj)
 
 #define assert_object_held(obj) dma_resv_assert_held((obj)->base.resv)
 
-/*
- * If more than one potential simultaneous locker, assert held.
- */
-static inline void assert_object_held_shared(const struct drm_i915_gem_object *obj)
-{
-	/*
-	 * Note mm list lookup is protected by
-	 * kref_get_unless_zero().
-	 */
-	if (IS_ENABLED(CONFIG_LOCKDEP) &&
-	    kref_read(&obj->base.refcount) > 0)
-		assert_object_held(obj);
-}
-
 static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
 					 struct i915_gem_ww_ctx *ww,
 					 bool intr)
drivers/gpu/drm/i915/gem/i915_gem_pages.c +6 -6
index 89b70f5cde7a..95f2744e504c 100644
@@ -19,7 +19,7 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
 	bool shrinkable;
 	int i;
 
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	if (i915_gem_object_is_volatile(obj))
 		obj->mm.madv = I915_MADV_DONTNEED;
@@ -95,7 +95,7 @@ int ____i915_gem_object_get_pages(struct drm_i915_gem_object *obj)
 	struct drm_i915_private *i915 = to_i915(obj->base.dev);
 	int err;
 
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	if (unlikely(obj->mm.madv != I915_MADV_WILLNEED)) {
 		drm_dbg(&i915->drm,
@@ -122,7 +122,7 @@ int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj)
 
 	assert_object_held(obj);
 
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	if (unlikely(!i915_gem_object_has_pages(obj))) {
 		GEM_BUG_ON(i915_gem_object_has_pinned_pages(obj));
@@ -171,7 +171,7 @@ int i915_gem_object_truncate(struct drm_i915_gem_object *obj)
 /* Try to discard unwanted pages */
 void i915_gem_object_writeback(struct drm_i915_gem_object *obj)
 {
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 	GEM_BUG_ON(i915_gem_object_has_pages(obj));
 
 	if (obj->ops->writeback)
@@ -202,7 +202,7 @@ __i915_gem_object_unset_pages(struct drm_i915_gem_object *obj)
 {
 	struct sg_table *pages;
 
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	pages = fetch_and_zero(&obj->mm.pages);
 	if (IS_ERR_OR_NULL(pages))
@@ -233,7 +233,7 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)
 		return -EBUSY;
 
 	/* May be called by shrinker from within get_pages() (on another bo) */
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	i915_gem_object_release_mmap_offset(obj);
 
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -1
index 3173c9f9a040..a315c010f635 100644
@@ -109,7 +109,7 @@ static void i915_gem_object_userptr_drop_ref(struct drm_i915_gem_object *obj)
 {
 	struct page **pvec = NULL;
 
-	assert_object_held_shared(obj);
+	assert_object_held(obj);
 
 	if (!--obj->userptr.page_ref) {
 		pvec = obj->userptr.pvec;
drivers/gpu/drm/i915/i915_vma.c +3 -3
index 565819c8bf49..97093ecc3f97 100644
@@ -1729,7 +1729,7 @@ int _i915_vma_move_to_active(struct i915_vma *vma,
 void __i915_vma_evict(struct i915_vma *vma)
 {
 	GEM_BUG_ON(i915_vma_is_pinned(vma));
-	assert_object_held_shared(vma->obj);
+	assert_object_held(vma->obj);
 
 	if (i915_vma_is_map_and_fenceable(vma)) {
 		/* Force a pagefault for domain tracking on next user access */
@@ -1775,7 +1775,7 @@ int __i915_vma_unbind(struct i915_vma *vma)
 	int ret;
 
 	lockdep_assert_held(&vma->vm->mutex);
-	assert_object_held_shared(vma->obj);
+	assert_object_held(vma->obj);
 
 	if (!drm_mm_node_allocated(&vma->node))
 		return 0;
@@ -1807,7 +1807,7 @@ int i915_vma_unbind(struct i915_vma *vma)
 	intel_wakeref_t wakeref = 0;
 	int err;
 
-	assert_object_held_shared(vma->obj);
+	assert_object_held(vma->obj);
 
 	/* Optimistic wait before taking the mutex */
 	err = i915_vma_sync(vma);
Signature · 1 line
2.34.1
#27 lore raw

PATCH v3 16/17 drm/i915: Remove support for unlocked i915_vma unbind

In reply to Maarten Lankhorst

Now that we require the object lock for all ops, some code handling race conditions can be removed.

This is required to not take short-term pins inside execbuf.

---
 drivers/gpu/drm/i915/i915_vma.c | 55 +++++----------------------------
 1 file changed, 8 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +8 -47
index 97093ecc3f97..bdd348fc755c 100644
@@ -776,7 +776,6 @@ i915_vma_detach(struct i915_vma *vma)
 static bool try_qad_pin(struct i915_vma *vma, unsigned int flags)
 {
 	unsigned int bound;
-	bool pinned = true;
 
 	bound = atomic_read(&vma->flags);
 	do {
@@ -786,34 +785,10 @@ static bool try_qad_pin(struct i915_vma *vma, unsigned int flags)
 		if (unlikely(bound & (I915_VMA_OVERFLOW | I915_VMA_ERROR)))
 			return false;
 
-		if (!(bound & I915_VMA_PIN_MASK))
-			goto unpinned;
-
 		GEM_BUG_ON(((bound + 1) & I915_VMA_PIN_MASK) == 0);
 	} while (!atomic_try_cmpxchg(&vma->flags, &bound, bound + 1));
 
 	return true;
-
-unpinned:
-	/*
-	 * If pin_count==0, but we are bound, check under the lock to avoid
-	 * racing with a concurrent i915_vma_unbind().
-	 */
-	mutex_lock(&vma->vm->mutex);
-	do {
-		if (unlikely(bound & (I915_VMA_OVERFLOW | I915_VMA_ERROR))) {
-			pinned = false;
-			break;
-		}
-
-		if (unlikely(flags & ~bound)) {
-			pinned = false;
-			break;
-		}
-	} while (!atomic_try_cmpxchg(&vma->flags, &bound, bound + 1));
-	mutex_unlock(&vma->vm->mutex);
-
-	return pinned;
 }
 
 static struct scatterlist *
@@ -1152,7 +1127,6 @@ static int
 __i915_vma_get_pages(struct i915_vma *vma)
 {
 	struct sg_table *pages;
-	int ret;
 
 	/*
 	 * The vma->pages are only valid within the lifespan of the borrowed
@@ -1185,18 +1159,16 @@ __i915_vma_get_pages(struct i915_vma *vma)
 		break;
 	}
 
-	ret = 0;
 	if (IS_ERR(pages)) {
-		ret = PTR_ERR(pages);
-		pages = NULL;
 		drm_err(&vma->vm->i915->drm,
-			"Failed to get pages for VMA view type %u (%d)!\n",
-			vma->ggtt_view.type, ret);
+			"Failed to get pages for VMA view type %u (%ld)!\n",
+			vma->ggtt_view.type, PTR_ERR(pages));
+		return PTR_ERR(pages);
 	}
 
 	vma->pages = pages;
 
-	return ret;
+	return 0;
 }
 
 I915_SELFTEST_EXPORT int i915_vma_get_pages(struct i915_vma *vma)
@@ -1228,25 +1200,14 @@ I915_SELFTEST_EXPORT int i915_vma_get_pages(struct i915_vma *vma)
 static void __vma_put_pages(struct i915_vma *vma, unsigned int count)
 {
 	/* We allocate under vma_get_pages, so beware the shrinker */
-	struct sg_table *pages = READ_ONCE(vma->pages);
-
 	GEM_BUG_ON(atomic_read(&vma->pages_count) < count);
 
 	if (atomic_sub_return(count, &vma->pages_count) == 0) {
-		/*
-		 * The atomic_sub_return is a read barrier for the READ_ONCE of
-		 * vma->pages above.
-		 *
-		 * READ_ONCE is safe because this is either called from the same
-		 * function (i915_vma_pin_ww), or guarded by vma->vm->mutex.
-		 *
-		 * TODO: We're leaving vma->pages dangling, until vma->obj->resv
-		 * lock is required.
-		 */
-		if (pages != vma->obj->mm.pages) {
-			sg_free_table(pages);
-			kfree(pages);
+		if (vma->pages != vma->obj->mm.pages) {
+			sg_free_table(vma->pages);
+			kfree(vma->pages);
 		}
+		vma->pages = NULL;
 
 		i915_gem_object_unpin_pages(vma->obj);
 	}
Signature · 1 line
2.34.1
#28 lore raw

PATCH v3 17/17 drm/i915: Remove short-term pins from execbuf, v5.

In reply to Maarten Lankhorst

Add a flag PIN_VALIDATE, to indicate we don't need to pin and only protected by the object lock.

This removes the need to unpin, which is done by just releasing the lock.

eb_reserve is slightly reworked for readability, but the same steps are still done:
- First pass pins with NONBLOCK.
- Second pass unbinds all objects first, then pins.
- Third pass is only called when not all objects are softpinned, and unbinds all objects, then calls i915_gem_evict_vm(), then pins.

When evicting the entire vm in eb_reserve() we do temporarily pin objects that are marked with EXEC_OBJECT_PINNED. This is because they are already at their destination, and i915_gem_evict_vm() would otherwise unbind them.

However, we reduce the visibility of those pins by limiting the pin to our call to i915_gem_evict_vm() only, and pin with vm->mutex held, instead of the entire duration of the execbuf.

Not sure the latter matters, one can hope..
In theory we could kill the pinning by adding an extra flag to the vma to temporarily prevent unbinding for gtt for i915_gem_evict_vm only, but I think that might be overkill. We're still holding the object lock, and we don't have blocking eviction yet. It's likely sufficient to simply enforce EXEC_OBJECT_PINNED for all objects on >= gen12.

Changes since v1:
- Split out eb_reserve() into separate functions for readability. Changes since v2:
- Make batch buffer mappable on platforms where only GGTT is available, to prevent moving the batch buffer during relocations.
Changes since v3:
- Preserve current behavior for batch buffer, instead be cautious when calling i915_gem_object_ggtt_pin_ww, and re-use the current batch vma if it's inside ggtt and map-and-fenceable.
- Remove impossible condition check from eb_reserve. (Matt)

---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 250 ++++++++++--------
 drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c  |   1 -
 drivers/gpu/drm/i915/i915_gem_gtt.h           |   1 +
 drivers/gpu/drm/i915/i915_vma.c               |  24 +-
 4 files changed, 158 insertions(+), 118 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +139 -111
index eb3649e844ff..3fe5d5811cdb 100644
@@ -441,7 +441,7 @@ eb_pin_vma(struct i915_execbuffer *eb,
 	else
 		pin_flags = entry->offset & PIN_OFFSET_MASK;
 
-	pin_flags |= PIN_USER | PIN_NOEVICT | PIN_OFFSET_FIXED;
+	pin_flags |= PIN_USER | PIN_NOEVICT | PIN_OFFSET_FIXED | PIN_VALIDATE;
 	if (unlikely(ev->flags & EXEC_OBJECT_NEEDS_GTT))
 		pin_flags |= PIN_GLOBAL;
 
@@ -459,17 +459,15 @@ eb_pin_vma(struct i915_execbuffer *eb,
 					     entry->pad_to_size,
 					     entry->alignment,
 					     eb_pin_flags(entry, ev->flags) |
-					     PIN_USER | PIN_NOEVICT);
+					     PIN_USER | PIN_NOEVICT | PIN_VALIDATE);
 		if (unlikely(err))
 			return err;
 	}
 
 	if (unlikely(ev->flags & EXEC_OBJECT_NEEDS_FENCE)) {
 		err = i915_vma_pin_fence(vma);
-		if (unlikely(err)) {
-			i915_vma_unpin(vma);
+		if (unlikely(err))
 			return err;
-		}
 
 		if (vma->fence)
 			ev->flags |= __EXEC_OBJECT_HAS_FENCE;
@@ -485,13 +483,9 @@ eb_pin_vma(struct i915_execbuffer *eb,
 static inline void
 eb_unreserve_vma(struct eb_vma *ev)
 {
-	if (!(ev->flags & __EXEC_OBJECT_HAS_PIN))
-		return;
-
 	if (unlikely(ev->flags & __EXEC_OBJECT_HAS_FENCE))
 		__i915_vma_unpin_fence(ev->vma);
 
-	__i915_vma_unpin(ev->vma);
 	ev->flags &= ~__EXEC_OBJECT_RESERVED;
 }
 
@@ -684,10 +678,8 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,
 
 	if (unlikely(ev->flags & EXEC_OBJECT_NEEDS_FENCE)) {
 		err = i915_vma_pin_fence(vma);
-		if (unlikely(err)) {
-			i915_vma_unpin(vma);
+		if (unlikely(err))
 			return err;
-		}
 
 		if (vma->fence)
 			ev->flags |= __EXEC_OBJECT_HAS_FENCE;
@@ -699,85 +691,125 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,
 	return 0;
 }
 
-static int eb_reserve(struct i915_execbuffer *eb)
+static int eb_evict_vm(struct i915_execbuffer *eb)
 {
 	const unsigned int count = eb->buffer_count;
-	unsigned int pin_flags = PIN_USER | PIN_NONBLOCK;
+	unsigned int i;
+	int err;
+
+	err = mutex_lock_interruptible(&eb->context->vm->mutex);
+	if (err)
+		return err;
+
+	/* pin to protect against i915_gem_evict_vm evicting below */
+	for (i = 0; i < count; i++) {
+		struct eb_vma *ev = &eb->vma[i];
+
+		if (ev->flags & __EXEC_OBJECT_HAS_PIN)
+			__i915_vma_pin(ev->vma);
+	}
+
+	/* Too fragmented, unbind everything and retry */
+	err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
+
+	/* unpin objects.. */
+	for (i = 0; i < count; i++) {
+		struct eb_vma *ev = &eb->vma[i];
+
+		if (ev->flags & __EXEC_OBJECT_HAS_PIN)
+			i915_vma_unpin(ev->vma);
+	}
+
+	mutex_unlock(&eb->context->vm->mutex);
+
+	return err;
+}
+
+static bool eb_unbind(struct i915_execbuffer *eb)
+{
+	const unsigned int count = eb->buffer_count;
+	unsigned int i;
 	struct list_head last;
+	bool unpinned = false;
+
+	/* Resort *all* the objects into priority order */
+	INIT_LIST_HEAD(&eb->unbound);
+	INIT_LIST_HEAD(&last);
+
+	for (i = 0; i < count; i++) {
+		struct eb_vma *ev = &eb->vma[i];
+		unsigned int flags = ev->flags;
+
+		if (flags & EXEC_OBJECT_PINNED &&
+		    flags & __EXEC_OBJECT_HAS_PIN)
+			continue;
+
+		unpinned = true;
+		eb_unreserve_vma(ev);
+
+		if (flags & EXEC_OBJECT_PINNED)
+			/* Pinned must have their slot */
+			list_add(&ev->bind_link, &eb->unbound);
+		else if (flags & __EXEC_OBJECT_NEEDS_MAP)
+			/* Map require the lowest 256MiB (aperture) */
+			list_add_tail(&ev->bind_link, &eb->unbound);
+		else if (!(flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS))
+			/* Prioritise 4GiB region for restricted bo */
+			list_add(&ev->bind_link, &last);
+		else
+			list_add_tail(&ev->bind_link, &last);
+	}
+
+	list_splice_tail(&last, &eb->unbound);
+	return unpinned;
+}
+
+static int eb_reserve(struct i915_execbuffer *eb)
+{
 	struct eb_vma *ev;
-	unsigned int i, pass;
+	unsigned int pass;
 	int err = 0;
+	bool unpinned;
 
 	/*
 	 * Attempt to pin all of the buffers into the GTT.
-	 * This is done in 3 phases:
+	 * This is done in 2 phases:
 	 *
-	 * 1a. Unbind all objects that do not match the GTT constraints for
-	 *     the execbuffer (fenceable, mappable, alignment etc).
-	 * 1b. Increment pin count for already bound objects.
-	 * 2.  Bind new objects.
-	 * 3.  Decrement pin count.
+	 * 1. Unbind all objects that do not match the GTT constraints for
+	 *    the execbuffer (fenceable, mappable, alignment etc).
+	 * 2. Bind new objects.
 	 *
 	 * This avoid unnecessary unbinding of later objects in order to make
 	 * room for the earlier objects *unless* we need to defragment.
+	 *
+	 * Defragmenting is skipped if all objects are pinned at a fixed location.
 	 */
-	pass = 0;
-	do {
-		list_for_each_entry(ev, &eb->unbound, bind_link) {
-			err = eb_reserve_vma(eb, ev, pin_flags);
-			if (err)
-				break;
-		}
-		if (err != -ENOSPC)
-			return err;
+	for (pass = 0; pass <= 2; pass++) {
+		int pin_flags = PIN_USER | PIN_VALIDATE;
 
-		/* Resort *all* the objects into priority order */
-		INIT_LIST_HEAD(&eb->unbound);
-		INIT_LIST_HEAD(&last);
-		for (i = 0; i < count; i++) {
-			unsigned int flags;
+		if (pass == 0)
+			pin_flags |= PIN_NONBLOCK;
 
-			ev = &eb->vma[i];
-			flags = ev->flags;
-			if (flags & EXEC_OBJECT_PINNED &&
-			    flags & __EXEC_OBJECT_HAS_PIN)
-				continue;
+		if (pass >= 1)
+			unpinned = eb_unbind(eb);
 
-			eb_unreserve_vma(ev);
-
-			if (flags & EXEC_OBJECT_PINNED)
-				/* Pinned must have their slot */
-				list_add(&ev->bind_link, &eb->unbound);
-			else if (flags & __EXEC_OBJECT_NEEDS_MAP)
-				/* Map require the lowest 256MiB (aperture) */
-				list_add_tail(&ev->bind_link, &eb->unbound);
-			else if (!(flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS))
-				/* Prioritise 4GiB region for restricted bo */
-				list_add(&ev->bind_link, &last);
-			else
-				list_add_tail(&ev->bind_link, &last);
-		}
-		list_splice_tail(&last, &eb->unbound);
-
-		switch (pass++) {
-		case 0:
-			break;
-
-		case 1:
-			/* Too fragmented, unbind everything and retry */
-			mutex_lock(&eb->context->vm->mutex);
-			err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
-			mutex_unlock(&eb->context->vm->mutex);
+		if (pass == 2) {
+			err = eb_evict_vm(eb);
 			if (err)
 				return err;
-			break;
+		}
 
-		default:
-			return -ENOSPC;
+		list_for_each_entry(ev, &eb->unbound, bind_link) {
+			err = eb_reserve_vma(eb, ev, pin_flags);
+			if (err)
+				break;
 		}
 
-		pin_flags = PIN_USER;
-	} while (1);
+		if (err != -ENOSPC)
+			break;
+	}
+
+	return err;
 }
 
 static int eb_select_context(struct i915_execbuffer *eb)
@@ -1184,10 +1216,11 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj,
 	return vaddr;
 }
 
-static void *reloc_iomap(struct drm_i915_gem_object *obj,
+static void *reloc_iomap(struct i915_vma *batch,
 			 struct i915_execbuffer *eb,
 			 unsigned long page)
 {
+	struct drm_i915_gem_object *obj = batch->obj;
 	struct reloc_cache *cache = &eb->reloc_cache;
 	struct i915_ggtt *ggtt = cache_to_ggtt(cache);
 	unsigned long offset;
@@ -1197,7 +1230,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,
 		intel_gt_flush_ggtt_writes(ggtt->vm.gt);
 		io_mapping_unmap_atomic((void __force __iomem *) unmask_page(cache->vaddr));
 	} else {
-		struct i915_vma *vma;
+		struct i915_vma *vma = ERR_PTR(-ENODEV);
 		int err;
 
 		if (i915_gem_object_is_tiled(obj))
@@ -1210,10 +1243,23 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,
 		if (err)
 			return ERR_PTR(err);
 
-		vma = i915_gem_object_ggtt_pin_ww(obj, &eb->ww, NULL, 0, 0,
-						  PIN_MAPPABLE |
-						  PIN_NONBLOCK /* NOWARN */ |
-						  PIN_NOEVICT);
+		/*
+		 * i915_gem_object_ggtt_pin_ww may attempt to remove the batch
+		 * VMA from the object list because we no longer pin.
+		 *
+		 * Only attempt to pin the batch buffer to ggtt if the current batch
+		 * is not inside ggtt, or the batch buffer is not misplaced.
+		 */
+		if (!i915_is_ggtt(batch->vm)) {
+			vma = i915_gem_object_ggtt_pin_ww(obj, &eb->ww, NULL, 0, 0,
+							  PIN_MAPPABLE |
+							  PIN_NONBLOCK /* NOWARN */ |
+							  PIN_NOEVICT);
+		} else if (i915_vma_is_map_and_fenceable(batch)) {
+			__i915_vma_pin(batch);
+			vma = batch;
+		}
+
 		if (vma == ERR_PTR(-EDEADLK))
 			return vma;
 
@@ -1251,7 +1297,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,
 	return vaddr;
 }
 
-static void *reloc_vaddr(struct drm_i915_gem_object *obj,
+static void *reloc_vaddr(struct i915_vma *vma,
 			 struct i915_execbuffer *eb,
 			 unsigned long page)
 {
@@ -1263,9 +1309,9 @@ static void *reloc_vaddr(struct drm_i915_gem_object *obj,
 	} else {
 		vaddr = NULL;
 		if ((cache->vaddr & KMAP) == 0)
-			vaddr = reloc_iomap(obj, eb, page);
+			vaddr = reloc_iomap(vma, eb, page);
 		if (!vaddr)
-			vaddr = reloc_kmap(obj, cache, page);
+			vaddr = reloc_kmap(vma->obj, cache, page);
 	}
 
 	return vaddr;
@@ -1306,7 +1352,7 @@ relocate_entry(struct i915_vma *vma,
 	void *vaddr;
 
 repeat:
-	vaddr = reloc_vaddr(vma->obj, eb,
+	vaddr = reloc_vaddr(vma, eb,
 			    offset >> PAGE_SHIFT);
 	if (IS_ERR(vaddr))
 		return PTR_ERR(vaddr);
@@ -2161,7 +2207,7 @@ shadow_batch_pin(struct i915_execbuffer *eb,
 	if (IS_ERR(vma))
 		return vma;
 
-	err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, flags);
+	err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, flags | PIN_VALIDATE);
 	if (err)
 		return ERR_PTR(err);
 
@@ -2175,7 +2221,7 @@ static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i9
 	 * batch" bit. Hence we need to pin secure batches into the global gtt.
 	 * hsw should have this fixed, but bdw mucks it up again. */
 	if (eb->batch_flags & I915_DISPATCH_SECURE)
-		return i915_gem_object_ggtt_pin_ww(vma->obj, &eb->ww, NULL, 0, 0, 0);
+		return i915_gem_object_ggtt_pin_ww(vma->obj, &eb->ww, NULL, 0, 0, PIN_VALIDATE);
 
 	return NULL;
 }
@@ -2226,13 +2272,12 @@ static int eb_parse(struct i915_execbuffer *eb)
 
 	err = i915_gem_object_lock(pool->obj, &eb->ww);
 	if (err)
-		goto err;
+		return err;
 
 	shadow = shadow_batch_pin(eb, pool->obj, eb->context->vm, PIN_USER);
-	if (IS_ERR(shadow)) {
-		err = PTR_ERR(shadow);
-		goto err;
-	}
+	if (IS_ERR(shadow))
+		return PTR_ERR(shadow);
+
 	intel_gt_buffer_pool_mark_used(pool);
 	i915_gem_object_set_readonly(shadow->obj);
 	shadow->private = pool;
@@ -2244,25 +2289,21 @@ static int eb_parse(struct i915_execbuffer *eb)
 		shadow = shadow_batch_pin(eb, pool->obj,
 					  &eb->gt->ggtt->vm,
 					  PIN_GLOBAL);
-		if (IS_ERR(shadow)) {
-			err = PTR_ERR(shadow);
-			shadow = trampoline;
-			goto err_shadow;
-		}
+		if (IS_ERR(shadow))
+			return PTR_ERR(shadow);
+
 		shadow->private = pool;
 
 		eb->batch_flags |= I915_DISPATCH_SECURE;
 	}
 
 	batch = eb_dispatch_secure(eb, shadow);
-	if (IS_ERR(batch)) {
-		err = PTR_ERR(batch);
-		goto err_trampoline;
-	}
+	if (IS_ERR(batch))
+		return PTR_ERR(batch);
 
 	err = dma_resv_reserve_shared(shadow->obj->base.resv, 1);
 	if (err)
-		goto err_trampoline;
+		return err;
 
 	err = intel_engine_cmd_parser(eb->context->engine,
 				      eb->batches[0]->vma,
@@ -2270,7 +2311,7 @@ static int eb_parse(struct i915_execbuffer *eb)
 				      eb->batch_len[0],
 				      shadow, trampoline);
 	if (err)
-		goto err_unpin_batch;
+		return err;
 
 	eb->batches[0] = &eb->vma[eb->buffer_count++];
 	eb->batches[0]->vma = i915_vma_get(shadow);
@@ -2289,17 +2330,6 @@ static int eb_parse(struct i915_execbuffer *eb)
 		eb->batches[0]->vma = i915_vma_get(batch);
 	}
 	return 0;
-
-err_unpin_batch:
-	if (batch)
-		i915_vma_unpin(batch);
-err_trampoline:
-	if (trampoline)
-		i915_vma_unpin(trampoline);
-err_shadow:
-	i915_vma_unpin(shadow);
-err:
-	return err;
 }
 
 static int eb_request_submit(struct i915_execbuffer *eb,
@@ -3420,8 +3450,6 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 
 err_vma:
 	eb_release_vmas(&eb, true);
-	if (eb.trampoline)
-		i915_vma_unpin(eb.trampoline);
 	WARN_ON(err == -EDEADLK);
 	i915_gem_ww_ctx_fini(&eb.ww);
 
drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c +0 -1
index f8948de72036..bbcd0522f68e 100644
@@ -425,7 +425,6 @@ int i915_vma_pin_fence(struct i915_vma *vma)
 	 * must keep the device awake whilst using the fence.
 	 */
 	assert_rpm_wakelock_held(vma->vm->gt->uncore->rpm);
-	GEM_BUG_ON(!i915_vma_is_pinned(vma));
 	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
 
 	err = mutex_lock_interruptible(&vma->vm->mutex);
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
index e4938aba3fe9..8c2f57eb5dda 100644
@@ -44,6 +44,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
 #define PIN_HIGH		BIT_ULL(5)
 #define PIN_OFFSET_BIAS		BIT_ULL(6)
 #define PIN_OFFSET_FIXED	BIT_ULL(7)
+#define PIN_VALIDATE		BIT_ULL(8) /* validate placement only, no need to call unpin() */
 
 #define PIN_GLOBAL		BIT_ULL(10) /* I915_VMA_GLOBAL_BIND */
 #define PIN_USER		BIT_ULL(11) /* I915_VMA_LOCAL_BIND */
drivers/gpu/drm/i915/i915_vma.c +18 -6
index bdd348fc755c..aa951a246802 100644
@@ -778,6 +778,15 @@ static bool try_qad_pin(struct i915_vma *vma, unsigned int flags)
 	unsigned int bound;
 
 	bound = atomic_read(&vma->flags);
+
+	if (flags & PIN_VALIDATE) {
+		flags &= I915_VMA_BIND_MASK;
+
+		return (flags & bound) == flags;
+	}
+
+	/* with the lock mandatory for unbind, we don't race here */
+	flags &= I915_VMA_BIND_MASK;
 	do {
 		if (unlikely(flags & ~bound))
 			return false;
@@ -1253,7 +1262,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 	GEM_BUG_ON(!(flags & (PIN_USER | PIN_GLOBAL)));
 
 	/* First try and grab the pin without rebinding the vma */
-	if (try_qad_pin(vma, flags & I915_VMA_BIND_MASK))
+	if (try_qad_pin(vma, flags))
 		return 0;
 
 	err = i915_vma_get_pages(vma);
@@ -1335,7 +1344,8 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 	}
 
 	if (unlikely(!(flags & ~bound & I915_VMA_BIND_MASK))) {
-		__i915_vma_pin(vma);
+		if (!(flags & PIN_VALIDATE))
+			__i915_vma_pin(vma);
 		goto err_unlock;
 	}
 
@@ -1364,8 +1374,10 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 	atomic_add(I915_VMA_PAGES_ACTIVE, &vma->pages_count);
 	list_move_tail(&vma->vm_link, &vma->vm->bound_list);
 
-	__i915_vma_pin(vma);
-	GEM_BUG_ON(!i915_vma_is_pinned(vma));
+	if (!(flags & PIN_VALIDATE)) {
+		__i915_vma_pin(vma);
+		GEM_BUG_ON(!i915_vma_is_pinned(vma));
+	}
 	GEM_BUG_ON(!i915_vma_is_bound(vma, flags));
 	GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags));
 
@@ -1625,8 +1637,6 @@ static int __i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *
 {
 	int err;
 
-	GEM_BUG_ON(!i915_vma_is_pinned(vma));
-
 	/* Wait for the vma to be bound before we start! */
 	err = __i915_request_await_bind(rq, vma);
 	if (err)
@@ -1645,6 +1655,8 @@ int _i915_vma_move_to_active(struct i915_vma *vma,
 
 	assert_object_held(obj);
 
+	GEM_BUG_ON(!vma->pages);
+
 	err = __i915_vma_move_to_active(vma, rq);
 	if (unlikely(err))
 		return err;
Signature · 1 line
2.34.1
#29 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Remove short term pins from execbuf by requiring lock to unbind.
URL : https://patchwork.freedesktop.org/series/98137/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
bc08f58eeb3f drm/i915: Remove unused bits of i915_vma/active api
91bcecf270f0 drm/i915: Change shrink ordering to use locking around unbinding.
-:28: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#28: FILE: drivers/gpu/drm/i915/gem/i915_gem_shrinker.c:40:
+static int drop_pages(struct drm_i915_gem_object *obj,
+		       unsigned long shrink, bool trylock_vm)

total: 0 errors, 0 warnings, 1 checks, 52 lines checked
316d336c98ea drm/i915: Remove pages_mutex and intel_gtt->vma_ops.set/clear_pages members, v3. 9d385c135ad3 drm/i915: Take object lock in i915_ggtt_pin if ww is not set c293606bcd36 drm/i915: Force ww lock for i915_gem_object_ggtt_pin_ww, v2. e7fbd118c9b2 drm/i915: Ensure gem_contexts selftests work with unbind changes, v2. c9892c726d3c drm/i915: Ensure i915_vma tests do not get -ENOSPC with the locking changes. cc5dd7eac42f drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors 1631c2059017 drm/i915: Trylock the object when shrinking
d1406f612444 drm/i915: Require object lock when freeing pages during destruction 97cc19bfa2a0 drm/i915: Add ww ctx to i915_gem_object_trylock
44fc65c4b062 drm/i915: Add locking to i915_gem_evict_vm()
8b8d9bb4ffaa drm/i915: Add object locking to i915_gem_evict_for_node and i915_gem_evict_something -:148: CHECK:LINE_SPACING: Please don't use multiple blank lines
#148: FILE: drivers/gpu/drm/i915/i915_gem_evict.c:252:

+

total: 0 errors, 0 warnings, 1 checks, 364 lines checked
d2242714f33e drm/i915: Add i915_vma_unbind_unlocked, and take obj lock for i915_vma_unbind, v2. -:7: WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #7:
We want to remove more members of i915_vma, which requires the locking to be

total: 0 errors, 1 warnings, 0 checks, 317 lines checked ece7fb471984 drm/i915: Remove assert_object_held_shared d5c98a7587ba drm/i915: Remove support for unlocked i915_vma unbind c54bb29dd0de drm/i915: Remove short-term pins from execbuf, v5.

#30 lore raw

[Intel-gfx] ✗ Fi.CI.SPARSE: warning for drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Remove short term pins from execbuf by requiring lock to unbind.
URL : https://patchwork.freedesktop.org/series/98137/
State : warning

== Summary ==

$ dim sparse --fast origin/drm-tip
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
#31 lore raw

[Intel-gfx] ✗ Fi.CI.DOCS: warning for drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Remove short term pins from execbuf by requiring lock to unbind.
URL : https://patchwork.freedesktop.org/series/98137/
State : warning

== Summary ==

$ make htmldocs 2>&1 > /dev/null | grep i915
./drivers/gpu/drm/i915/i915_gem_evict.c:110: warning: Function parameter or member 'ww' not described in 'i915_gem_evict_something'
./drivers/gpu/drm/i915/i915_gem_evict.c:281: warning: Function parameter or member 'ww' not described in 'i915_gem_evict_for_node'
./drivers/gpu/drm/i915/i915_gem_evict.c:393: warning: Function parameter or member 'ww' not described in 'i915_gem_evict_vm'
./drivers/gpu/drm/i915/i915_gem_gtt.c:100: warning: Function parameter or member 'ww' not described in 'i915_gem_gtt_reserve'
./drivers/gpu/drm/i915/i915_gem_gtt.c:192: warning: Function parameter or member 'ww' not described in 'i915_gem_gtt_insert'
#32 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Remove short term pins from execbuf by requiring lock to unbind.
URL : https://patchwork.freedesktop.org/series/98137/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_11009 -> Patchwork_21861
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/index.html

Participating hosts (43 -> 34)
------------------------------

Additional (1): fi-pnv-d510
Missing (10): fi-kbl-soraka bat-dg1-6 bat-dg1-5 fi-icl-u2 fi-bsw-cyan bat-adlp-6 bat-adlp-4 fi-bdw-samus bat-jsl-2 bat-jsl-1

Known issues
------------

Here are the changes found in Patchwork_21861 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_suspend@basic-s0:
- fi-tgl-1115g4: [PASS][1] -> [FAIL][2] ([i915#1888])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/fi-tgl-1115g4/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/fi-tgl-1115g4/igt@[email protected]

* igt@gem_exec_suspend@basic-s3:
- fi-skl-6600u: [PASS][3] -> [INCOMPLETE][4] ([i915#4547])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/fi-skl-6600u/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/fi-skl-6600u/igt@[email protected]

* igt@prime_vgem@basic-userptr:
- fi-pnv-d510: NOTRUN -> [SKIP][5] ([fdo#109271]) +57 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/fi-pnv-d510/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s3:
- fi-tgl-1115g4: [FAIL][6] ([i915#1888]) -> [PASS][7]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/fi-tgl-1115g4/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/fi-tgl-1115g4/igt@[email protected]

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1888]: https://gitlab.freedesktop.org/drm/intel/issues/1888
[i915#4547]: https://gitlab.freedesktop.org/drm/intel/issues/4547

Build changes
-------------

* Linux: CI_DRM_11009 -> Patchwork_21861

CI-20190529: 20190529
CI_DRM_11009: 9efbfd937cc876674559ddf8fb1897a00c10019b @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6313: 1793ed798cc09966c27bf478781e0c1d6bb23bad @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_21861: c54bb29dd0de9657c0becea36437f5bcca1b36fd @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

c54bb29dd0de drm/i915: Remove short-term pins from execbuf, v5.
d5c98a7587ba drm/i915: Remove support for unlocked i915_vma unbind
ece7fb471984 drm/i915: Remove assert_object_held_shared
d2242714f33e drm/i915: Add i915_vma_unbind_unlocked, and take obj lock for i915_vma_unbind, v2. 8b8d9bb4ffaa drm/i915: Add object locking to i915_gem_evict_for_node and i915_gem_evict_something 44fc65c4b062 drm/i915: Add locking to i915_gem_evict_vm()
97cc19bfa2a0 drm/i915: Add ww ctx to i915_gem_object_trylock
d1406f612444 drm/i915: Require object lock when freeing pages during destruction 1631c2059017 drm/i915: Trylock the object when shrinking
cc5dd7eac42f drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors c9892c726d3c drm/i915: Ensure i915_vma tests do not get -ENOSPC with the locking changes. e7fbd118c9b2 drm/i915: Ensure gem_contexts selftests work with unbind changes, v2. c293606bcd36 drm/i915: Force ww lock for i915_gem_object_ggtt_pin_ww, v2. 9d385c135ad3 drm/i915: Take object lock in i915_ggtt_pin if ww is not set 316d336c98ea drm/i915: Remove pages_mutex and intel_gtt->vma_ops.set/clear_pages members, v3. 91bcecf270f0 drm/i915: Change shrink ordering to use locking around unbinding. bc08f58eeb3f drm/i915: Remove unused bits of i915_vma/active api

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/index.html

#33 lore raw

[Intel-gfx] ✗ Fi.CI.IGT: failure for drm/i915: Remove short term pins from execbuf by requiring lock to unbind.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Remove short term pins from execbuf by requiring lock to unbind.
URL : https://patchwork.freedesktop.org/series/98137/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_11009_full -> Patchwork_21861_full
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_21861_full absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_21861_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

Participating hosts (10 -> 10)
------------------------------

No changes in participating hosts

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_21861_full:

### IGT changes ###

#### Possible regressions ####

* igt@gem_exec_suspend@basic-s3:
- shard-skl: [PASS][1] -> [INCOMPLETE][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-skl9/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl6/igt@[email protected]

* igt@gem_mmap_gtt@cpuset-big-copy-xy:
- shard-iclb: [PASS][3] -> [INCOMPLETE][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-iclb1/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb3/igt@[email protected]
- shard-glk: [PASS][5] -> [INCOMPLETE][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk5/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk8/igt@[email protected]
- shard-tglb: [PASS][7] -> [INCOMPLETE][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb7/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb3/igt@[email protected]

* igt@gem_ppgtt@blt-vs-render-ctx0:
- shard-tglb: [PASS][9] -> [FAIL][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb5/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb3/igt@[email protected]

* igt@i915_pm_dc@dc6-psr:
- shard-skl: NOTRUN -> [CRASH][11]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl3/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_21861_full that come from known issues:

### CI changes ###

#### Possible fixes ####

* boot:
- shard-glk: ([PASS][12], [PASS][13], [PASS][14], [FAIL][15], [PASS][16], [PASS][17], [PASS][18], [PASS][19], [PASS][20], [PASS][21], [PASS][22], [PASS][23], [PASS][24], [PASS][25], [PASS][26], [PASS][27], [PASS][28], [PASS][29], [PASS][30], [PASS][31], [PASS][32], [PASS][33], [PASS][34], [PASS][35], [PASS][36]) ([i915#4392]) -> ([PASS][37], [PASS][38], [PASS][39], [PASS][40], [PASS][41], [PASS][42], [PASS][43], [PASS][44], [PASS][45], [PASS][46], [PASS][47], [PASS][48], [PASS][49], [PASS][50], [PASS][51], [PASS][52], [PASS][53], [PASS][54], [PASS][55], [PASS][56], [PASS][57], [PASS][58], [PASS][59], [PASS][60], [PASS][61])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk2/boot.html
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk9/boot.html
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk9/boot.html
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk8/boot.html
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk8/boot.html
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk8/boot.html
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk8/boot.html
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk1/boot.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk7/boot.html
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk7/boot.html
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk6/boot.html
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk6/boot.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk5/boot.html
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk5/boot.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk5/boot.html
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk4/boot.html
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk1/boot.html
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk4/boot.html
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk4/boot.html
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk3/boot.html
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk1/boot.html
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk3/boot.html
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk3/boot.html
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk2/boot.html
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk2/boot.html
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk9/boot.html
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk9/boot.html
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk8/boot.html
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk8/boot.html
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk8/boot.html
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk7/boot.html
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk7/boot.html
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk7/boot.html
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/boot.html
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/boot.html
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk5/boot.html
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk5/boot.html
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk5/boot.html
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk5/boot.html
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk4/boot.html
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk4/boot.html
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk3/boot.html
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk3/boot.html
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk3/boot.html
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk2/boot.html
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk2/boot.html
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk2/boot.html
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk1/boot.html
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk1/boot.html
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk1/boot.html

### IGT changes ###

#### Issues hit ####

* igt@feature_discovery@display-4x:
- shard-iclb: NOTRUN -> [SKIP][62] ([i915#1839])
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@feature_discovery@psr2:
- shard-iclb: NOTRUN -> [SKIP][63] ([i915#658])
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb6/igt@[email protected]

* igt@gem_ctx_isolation@preservation-s3@vcs1:
- shard-tglb: [PASS][64] -> [INCOMPLETE][65] ([i915#456])
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb5/igt@gem_ctx_isolation@[email protected]
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb8/igt@gem_ctx_isolation@[email protected]

* igt@gem_ctx_persistence@many-contexts:
- shard-tglb: [PASS][66] -> [FAIL][67] ([i915#2410])
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb2/igt@[email protected]
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb7/igt@[email protected]

* igt@gem_eio@unwedge-stress:
- shard-skl: NOTRUN -> [TIMEOUT][68] ([i915#3063])
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]

* igt@gem_exec_capture@pi@bcs0:
- shard-skl: [PASS][69] -> [INCOMPLETE][70] ([i915#4547])
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-skl5/igt@gem_exec_capture@[email protected]
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl8/igt@gem_exec_capture@[email protected]

* igt@gem_exec_capture@pi@rcs0:
- shard-tglb: [PASS][71] -> [INCOMPLETE][72] ([i915#3371])
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb6/igt@gem_exec_capture@[email protected]
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb1/igt@gem_exec_capture@[email protected]

* igt@gem_exec_fair@basic-deadline:
- shard-glk: [PASS][73] -> [FAIL][74] ([i915#2846])
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk3/igt@[email protected]
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk3/igt@[email protected]

* igt@gem_exec_fair@basic-pace-share@rcs0:
- shard-apl: [PASS][75] -> [FAIL][76] ([i915#2842])
[75]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-apl2/igt@gem_exec_fair@[email protected]
[76]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@vcs1:
- shard-iclb: NOTRUN -> [FAIL][77] ([i915#2842]) +1 similar issue
[77]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb2/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@vecs0:
- shard-kbl: [PASS][78] -> [FAIL][79] ([i915#2842]) +2 similar issues
[78]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-kbl3/igt@gem_exec_fair@[email protected]
[79]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl2/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-throttle@rcs0:
- shard-iclb: [PASS][80] -> [FAIL][81] ([i915#2849])
[80]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-iclb3/igt@gem_exec_fair@[email protected]
[81]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_flush@basic-batch-kernel-default-uc:
- shard-glk: [PASS][82] -> [DMESG-WARN][83] ([i915#118]) +1 similar issue
[82]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk6/igt@[email protected]
[83]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk9/igt@[email protected]

* igt@gem_lmem_swapping@parallel-random:
- shard-apl: NOTRUN -> [SKIP][84] ([fdo#109271] / [i915#4613])
[84]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@[email protected]
- shard-kbl: NOTRUN -> [SKIP][85] ([fdo#109271] / [i915#4613]) +1 similar issue
[85]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl2/igt@[email protected]

* igt@gem_lmem_swapping@verify-random:
- shard-skl: NOTRUN -> [SKIP][86] ([fdo#109271] / [i915#4613]) +4 similar issues
[86]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl1/igt@[email protected]

* igt@gem_ppgtt@flink-and-close-vma-leak:
- shard-apl: [PASS][87] -> [FAIL][88] ([i915#644])
[87]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-apl4/igt@[email protected]
[88]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl2/igt@[email protected]

* igt@gem_pread@exhaustion:
- shard-skl: NOTRUN -> [WARN][89] ([i915#2658])
[89]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl1/igt@[email protected]

* igt@gem_render_copy@yf-tiled-to-vebox-linear:
- shard-iclb: NOTRUN -> [SKIP][90] ([i915#768]) +1 similar issue
[90]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@gen7_exec_parse@basic-allocation:
- shard-glk: NOTRUN -> [SKIP][91] ([fdo#109271]) +34 similar issues
[91]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]

* igt@i915_pm_dc@dc6-dpms:
- shard-skl: NOTRUN -> [FAIL][92] ([i915#454])
[92]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]

* igt@i915_pm_dc@dc9-dpms:
- shard-iclb: [PASS][93] -> [SKIP][94] ([i915#4281])
[93]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-iclb1/igt@[email protected]
[94]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb3/igt@[email protected]

* igt@i915_pm_rpm@gem-execbuf-stress-pc8:
- shard-iclb: NOTRUN -> [SKIP][95] ([fdo#109293] / [fdo#109506])
[95]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@i915_selftest@live@gt_pm:
- shard-skl: NOTRUN -> [DMESG-FAIL][96] ([i915#1886] / [i915#2291])
[96]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl3/igt@i915_selftest@live@gt_pm.html

* igt@kms_big_fb@x-tiled-max-hw-stride-32bpp-rotate-180-async-flip:
- shard-skl: NOTRUN -> [FAIL][97] ([i915#3743]) +1 similar issue
[97]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl5/igt@kms_big_fb@x-tiled-max-hw-stride-32bpp-rotate-180-async-flip.html

* igt@kms_big_fb@x-tiled-max-hw-stride-64bpp-rotate-180-hflip:
- shard-glk: NOTRUN -> [SKIP][98] ([fdo#109271] / [i915#3777])
[98]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]

* igt@kms_big_fb@y-tiled-64bpp-rotate-90:
- shard-iclb: NOTRUN -> [SKIP][99] ([fdo#110725] / [fdo#111614]) +2 similar issues
[99]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_big_fb@y-tiled-max-hw-stride-64bpp-rotate-0-async-flip:
- shard-tglb: [PASS][100] -> [FAIL][101] ([i915#3743])
[100]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb3/igt@[email protected]
[101]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb1/igt@[email protected]
- shard-skl: NOTRUN -> [FAIL][102] ([i915#3763])
[102]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]

* igt@kms_big_fb@y-tiled-max-hw-stride-64bpp-rotate-0-hflip:
- shard-skl: NOTRUN -> [SKIP][103] ([fdo#109271] / [i915#3777])
[103]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl10/igt@[email protected]

* igt@kms_ccs@pipe-a-crc-sprite-planes-basic-y_tiled_gen12_mc_ccs:
- shard-apl: NOTRUN -> [SKIP][104] ([fdo#109271] / [i915#3886]) +1 similar issue
[104]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@kms_ccs@pipe-a-crc-sprite-planes-basic-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-b-bad-rotation-90-y_tiled_gen12_mc_ccs:
- shard-kbl: NOTRUN -> [SKIP][105] ([fdo#109271] / [i915#3886]) +3 similar issues
[105]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl2/igt@kms_ccs@pipe-b-bad-rotation-90-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-b-crc-primary-basic-y_tiled_gen12_rc_ccs_cc:
- shard-iclb: NOTRUN -> [SKIP][106] ([fdo#109278] / [i915#3886])
[106]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@kms_ccs@pipe-b-crc-primary-basic-y_tiled_gen12_rc_ccs_cc.html

* igt@kms_ccs@pipe-b-crc-primary-rotation-180-y_tiled_gen12_rc_ccs_cc:
- shard-skl: NOTRUN -> [SKIP][107] ([fdo#109271] / [i915#3886]) +12 similar issues
[107]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl9/igt@kms_ccs@pipe-b-crc-primary-rotation-180-y_tiled_gen12_rc_ccs_cc.html

* igt@kms_ccs@pipe-c-crc-sprite-planes-basic-y_tiled_gen12_rc_ccs_cc:
- shard-glk: NOTRUN -> [SKIP][108] ([fdo#109271] / [i915#3886]) +1 similar issue
[108]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@kms_ccs@pipe-c-crc-sprite-planes-basic-y_tiled_gen12_rc_ccs_cc.html

* igt@kms_ccs@pipe-d-crc-sprite-planes-basic-y_tiled_gen12_rc_ccs_cc:
- shard-skl: NOTRUN -> [SKIP][109] ([fdo#109271]) +282 similar issues
[109]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl9/igt@kms_ccs@pipe-d-crc-sprite-planes-basic-y_tiled_gen12_rc_ccs_cc.html

* igt@kms_cdclk@mode-transition:
- shard-iclb: NOTRUN -> [SKIP][110] ([i915#3742])
[110]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_chamelium@dp-hpd:
- shard-iclb: NOTRUN -> [SKIP][111] ([fdo#109284] / [fdo#111827])
[111]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_chamelium@hdmi-crc-single:
- shard-glk: NOTRUN -> [SKIP][112] ([fdo#109271] / [fdo#111827]) +3 similar issues
[112]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]

* igt@kms_chamelium@vga-hpd-after-suspend:
- shard-skl: NOTRUN -> [SKIP][113] ([fdo#109271] / [fdo#111827]) +21 similar issues
[113]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]

* igt@kms_color@pipe-b-ctm-0-25:
- shard-skl: [PASS][114] -> [DMESG-WARN][115] ([i915#1982])
[114]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-skl7/igt@[email protected]
[115]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl8/igt@[email protected]

* igt@kms_color@pipe-d-ctm-0-25:
- shard-iclb: NOTRUN -> [SKIP][116] ([fdo#109278] / [i915#1149])
[116]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_color_chamelium@pipe-a-ctm-0-5:
- shard-apl: NOTRUN -> [SKIP][117] ([fdo#109271] / [fdo#111827]) +3 similar issues
[117]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl6/igt@[email protected]

* igt@kms_color_chamelium@pipe-a-ctm-blue-to-red:
- shard-kbl: NOTRUN -> [SKIP][118] ([fdo#109271] / [fdo#111827]) +9 similar issues
[118]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl4/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-512x512-random:
- shard-iclb: NOTRUN -> [SKIP][119] ([fdo#109278] / [fdo#109279])
[119]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_cursor_crc@pipe-d-cursor-128x128-onscreen:
- shard-apl: NOTRUN -> [SKIP][120] ([fdo#109271]) +47 similar issues
[120]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@[email protected]

* igt@kms_cursor_crc@pipe-d-cursor-suspend:
- shard-tglb: [PASS][121] -> [INCOMPLETE][122] ([i915#2411] / [i915#4211])
[121]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-tglb5/igt@[email protected]
[122]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-tglb7/igt@[email protected]

* igt@kms_cursor_legacy@2x-cursor-vs-flip-atomic:
- shard-iclb: NOTRUN -> [SKIP][123] ([fdo#109274] / [fdo#109278]) +1 similar issue
[123]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-varying-size:
- shard-iclb: [PASS][124] -> [FAIL][125] ([i915#2346])
[124]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-iclb3/igt@[email protected]
[125]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb7/igt@[email protected]

* igt@kms_flip@2x-absolute-wf_vblank-interruptible:
- shard-iclb: NOTRUN -> [SKIP][126] ([fdo#109274]) +2 similar issues
[126]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb6/igt@kms_flip@2x-absolute-wf_vblank-interruptible.html

* igt@kms_flip@plain-flip-fb-recreate@c-edp1:
- shard-skl: [PASS][127] -> [FAIL][128] ([i915#2122]) +1 similar issue
[127]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-skl5/igt@kms_flip@[email protected]
[128]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl3/igt@kms_flip@[email protected]

* igt@kms_flip_scaled_crc@flip-32bpp-ytile-to-32bpp-ytileccs:
- shard-skl: NOTRUN -> [INCOMPLETE][129] ([i915#3699])
[129]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl10/igt@[email protected]

* igt@kms_flip_scaled_crc@flip-64bpp-ytile-to-32bpp-ytilercccs:
- shard-skl: NOTRUN -> [SKIP][130] ([fdo#109271] / [i915#2672])
[130]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]
- shard-kbl: NOTRUN -> [SKIP][131] ([fdo#109271] / [i915#2672])
[131]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl2/igt@[email protected]
- shard-apl: NOTRUN -> [SKIP][132] ([fdo#109271] / [i915#2672])
[132]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-draw-blt:
- shard-kbl: NOTRUN -> [SKIP][133] ([fdo#109271]) +119 similar issues
[133]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl4/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-kbl: [PASS][134] -> [DMESG-WARN][135] ([i915#180]) +5 similar issues
[134]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-kbl3/igt@[email protected]
[135]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl7/igt@[email protected]
- shard-apl: [PASS][136] -> [DMESG-WARN][137] ([i915#180]) +3 similar issues
[136]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-apl4/igt@[email protected]
[137]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl2/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-2p-primscrn-pri-indfb-draw-mmap-cpu:
- shard-iclb: NOTRUN -> [SKIP][138] ([fdo#109280]) +6 similar issues
[138]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@kms_frontbuffer_tracking@psr-2p-primscrn-pri-indfb-draw-mmap-cpu.html

* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
- shard-glk: NOTRUN -> [SKIP][139] ([fdo#109271] / [i915#533])
[139]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]

* igt@kms_pipe_crc_basic@read-crc-pipe-d:
- shard-skl: NOTRUN -> [SKIP][140] ([fdo#109271] / [i915#533]) +1 similar issue
[140]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@[email protected]

* igt@kms_pipe_crc_basic@read-crc-pipe-d-frame-sequence:
- shard-iclb: NOTRUN -> [SKIP][141] ([fdo#109278]) +9 similar issues
[141]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-alpha-7efc:
- shard-skl: NOTRUN -> [FAIL][142] ([fdo#108145] / [i915#265]) +2 similar issues
[142]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl10/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-alpha-transparent-fb:
- shard-apl: NOTRUN -> [FAIL][143] ([i915#265])
[143]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl6/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
- shard-skl: [PASS][144] -> [FAIL][145] ([fdo#108145] / [i915#265])
[144]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-skl8/igt@[email protected]
[145]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl10/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-b-alpha-opaque-fb:
- shard-glk: NOTRUN -> [FAIL][146] ([fdo#108145] / [i915#265]) +1 similar issue
[146]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]

* igt@kms_plane_lowres@pipe-c-tiling-x:
- shard-iclb: NOTRUN -> [SKIP][147] ([i915#3536])
[147]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb6/igt@[email protected]

* igt@kms_psr2_sf@overlay-primary-update-sf-dmg-area:
- shard-kbl: NOTRUN -> [SKIP][148] ([fdo#109271] / [i915#658])
[148]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl4/igt@[email protected]

* igt@kms_psr@psr2_primary_mmap_gtt:
- shard-iclb: NOTRUN -> [SKIP][149] ([fdo#109441])
[149]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb8/igt@kms_psr@psr2_primary_mmap_gtt.html

* igt@kms_psr@psr2_sprite_plane_move:
- shard-iclb: [PASS][150] -> [SKIP][151] ([fdo#109441]) +2 similar issues
[150]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-iclb2/igt@kms_psr@psr2_sprite_plane_move.html
[151]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb4/igt@kms_psr@psr2_sprite_plane_move.html

* igt@kms_sysfs_edid_timing:
- shard-apl: NOTRUN -> [FAIL][152] ([IGT#2])
[152]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-apl7/igt@kms_sysfs_edid_timing.html
- shard-kbl: NOTRUN -> [FAIL][153] ([IGT#2])
[153]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl2/igt@kms_sysfs_edid_timing.html
- shard-skl: NOTRUN -> [FAIL][154] ([IGT#2])
[154]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl7/igt@kms_sysfs_edid_timing.html

* igt@kms_writeback@writeback-fb-id:
- shard-kbl: NOTRUN -> [SKIP][155] ([fdo#109271] / [i915#2437])
[155]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl4/igt@[email protected]
- shard-skl: NOTRUN -> [SKIP][156] ([fdo#109271] / [i915#2437])
[156]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl9/igt@[email protected]

* igt@perf@polling-parameterized:
- shard-glk: [PASS][157] -> [FAIL][158] ([i915#1542])
[157]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-glk3/igt@[email protected]
[158]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk4/igt@[email protected]

* igt@sysfs_clients@fair-7:
- shard-iclb: NOTRUN -> [SKIP][159] ([i915#2994])
[159]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-iclb6/igt@[email protected]

* igt@sysfs_clients@recycle-many:
- shard-glk: NOTRUN -> [SKIP][160] ([fdo#109271] / [i915#2994])
[160]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-glk6/igt@[email protected]
- shard-skl: NOTRUN -> [SKIP][161] ([fdo#109271] / [i915#2994]) +2 similar issues
[161]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-skl3/igt@[email protected]

#### Possible fixes ####

* igt@gem_ctx_isolation@preservation-s3@vecs0:
- shard-kbl: [DMESG-WARN][162] ([i915#180]) -> [PASS][163] +4 similar issues
[162]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11009/shard-kbl4/igt@gem_ctx_isolation@[email protected]
[163]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/shard-kbl7/igt@gem_ctx_isolation@preserv

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21861/index.html