All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [PATCH 3/5] drm/xe: Fix extobj dropping issue.
Date: Fri, 26 May 2023 14:10:59 +0200	[thread overview]
Message-ID: <20230526121101.1619278-4-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20230526121101.1619278-1-maarten.lankhorst@linux.intel.com>

I believe originally we did the right thing, but now we hit an issue.

Presumably, this was changed when converting from an array to a list
in a squashed commit:
"drm/xe: Use a list for the vm's external objects"

When deleting a vma with an extobj in the list, ensure if it's freed
but still listed on the vm, we take a different vma and add that to
the extobj list instead.

I'll add an igt, and make sure it doesn't happen again.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/194
---
 drivers/gpu/drm/xe/xe_vm.c | 95 +++++++++++++++++++++++---------------
 1 file changed, 58 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index f73e08b60670..dd1335e12d4c 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -909,12 +909,14 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	return vma;
 }
 
-static void vm_remove_extobj(struct xe_vma *vma)
+static bool vm_remove_extobj(struct xe_vma *vma)
 {
 	if (!list_empty(&vma->extobj.link)) {
 		vma->vm->extobj.entries--;
 		list_del_init(&vma->extobj.link);
+		return true;
 	}
+	return false;
 }
 
 static void xe_vma_destroy_late(struct xe_vma *vma)
@@ -955,6 +957,51 @@ static void vma_destroy_work_func(struct work_struct *w)
 	xe_vma_destroy_late(vma);
 }
 
+static struct xe_vma *
+bo_has_vm_references_locked(struct xe_bo *bo, struct xe_vm *vm,
+			    struct xe_vma *ignore)
+{
+	struct xe_vma *vma;
+
+	list_for_each_entry(vma, &bo->vmas, bo_link) {
+		if (vma != ignore && vma->vm == vm && !vma->destroyed)
+			return vma;
+	}
+
+	return NULL;
+}
+
+static bool bo_has_vm_references(struct xe_bo *bo, struct xe_vm *vm,
+				 struct xe_vma *ignore)
+{
+	struct ww_acquire_ctx ww;
+	bool ret;
+
+	xe_bo_lock(bo, &ww, 0, false);
+	ret = !!bo_has_vm_references_locked(bo, vm, ignore);
+	xe_bo_unlock(bo, &ww);
+
+	return ret;
+}
+
+static void __vm_insert_extobj(struct xe_vm *vm, struct xe_vma *vma)
+{
+	list_add(&vma->extobj.link, &vm->extobj.list);
+	vm->extobj.entries++;
+}
+
+static void vm_insert_extobj(struct xe_vm *vm, struct xe_vma *vma)
+{
+	struct xe_bo *bo = vma->bo;
+
+	lockdep_assert_held_write(&vm->lock);
+
+	if (bo_has_vm_references(bo, vm, vma))
+		return;
+
+	__vm_insert_extobj(vm, vma);
+}
+
 static void vma_destroy_cb(struct dma_fence *fence,
 			   struct dma_fence_cb *cb)
 {
@@ -980,11 +1027,19 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 	} else {
 		xe_bo_assert_held(vma->bo);
 		list_del(&vma->bo_link);
+
 		spin_lock(&vm->notifier.list_lock);
 		list_del(&vma->notifier.rebind_link);
 		spin_unlock(&vm->notifier.list_lock);
-		if (!vma->bo->vm)
-			vm_remove_extobj(vma);
+
+		if (!vma->bo->vm && vm_remove_extobj(vma)) {
+			struct xe_vma *other;
+
+			other = bo_has_vm_references_locked(vma->bo, vm, NULL);
+
+			if (other)
+				__vm_insert_extobj(vm, other);
+		}
 	}
 
 	xe_vm_assert_held(vm);
@@ -2481,40 +2536,6 @@ static int vm_bind_ioctl_async(struct xe_vm *vm, struct xe_vma *vma,
 	return err;
 }
 
-static bool bo_has_vm_references(struct xe_bo *bo, struct xe_vm *vm,
-				 struct xe_vma *ignore)
-{
-	struct ww_acquire_ctx ww;
-	struct xe_vma *vma;
-	bool ret = false;
-
-	xe_bo_lock(bo, &ww, 0, false);
-	list_for_each_entry(vma, &bo->vmas, bo_link) {
-		if (vma != ignore && vma->vm == vm && !vma->destroyed) {
-			ret = true;
-			break;
-		}
-	}
-	xe_bo_unlock(bo, &ww);
-
-	return ret;
-}
-
-static int vm_insert_extobj(struct xe_vm *vm, struct xe_vma *vma)
-{
-	struct xe_bo *bo = vma->bo;
-
-	lockdep_assert_held_write(&vm->lock);
-
-	if (bo_has_vm_references(bo, vm, vma))
-		return 0;
-
-	list_add(&vma->extobj.link, &vm->extobj.list);
-	vm->extobj.entries++;
-
-	return 0;
-}
-
 static int __vm_bind_ioctl_lookup_vma(struct xe_vm *vm, struct xe_bo *bo,
 				      u64 addr, u64 range, u32 op)
 {
-- 
2.34.1


  parent reply	other threads:[~2023-05-26 12:11 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 12:10 [Intel-xe] [PATCH 0/5] Robustness fixes with eviction and invalidation Maarten Lankhorst
2023-05-26 12:10 ` [Intel-xe] [PATCH 1/5] drm/xe: Kill small race with userptr invalidation Maarten Lankhorst
2023-05-26 12:26   ` Thomas Hellström
2023-05-26 12:10 ` [Intel-xe] [PATCH 2/5] drm/xe: Add debugfs files to evict everything Maarten Lankhorst
2023-05-26 13:02   ` Thomas Hellström
2023-05-29 13:35     ` Maarten Lankhorst
2023-05-30 14:41       ` Thomas Hellström
2023-05-30 14:54         ` Maarten Lankhorst
2023-05-26 12:10 ` Maarten Lankhorst [this message]
2023-05-26 12:31   ` [Intel-xe] [PATCH 3/5] drm/xe: Fix extobj dropping issue Thomas Hellström
2023-05-26 12:11 ` [Intel-xe] [PATCH 4/5] drm/xe: Prevent evicting for page tables Maarten Lankhorst
2023-05-26 12:35   ` Thomas Hellström
2023-05-29 13:44     ` Maarten Lankhorst
2023-05-29 15:02       ` Thomas Hellström
2023-05-29 15:11         ` Maarten Lankhorst
2023-05-29 15:13           ` Thomas Hellström
2023-05-29 15:23             ` Maarten Lankhorst
2023-05-30  8:45               ` Thomas Hellström
2023-05-30  8:50                 ` Maarten Lankhorst
2023-05-26 12:11 ` [Intel-xe] [PATCH 5/5] drm/xe: Return the correct error when dma_resv_wait_timeout fails Maarten Lankhorst
2023-05-26 12:40   ` Thomas Hellström
2023-05-26 19:15   ` Souza, Jose
2023-05-27  5:17     ` Christopher Snowhill
2023-05-29 15:21       ` Maarten Lankhorst
2023-05-26 12:13 ` [Intel-xe] ✓ CI.Patch_applied: success for Robustness fixes with eviction and invalidation Patchwork
2023-05-26 12:15 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-26 12:19 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-05-26 12:48 ` [Intel-xe] ○ CI.BAT: info " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230526121101.1619278-4-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.