Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] drm/xe: Ensure write lock is held when calling xe_vma_rebind()
@ 2024-06-05 10:16 Nirmoy Das
  2024-06-05 10:55 ` ✓ CI.Patch_applied: success for " Patchwork
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Nirmoy Das @ 2024-06-05 10:16 UTC (permalink / raw)
  To: intel-xe; +Cc: Nirmoy Das, Matthew Brost, Oak Zeng

xe_vma_rebind() expects write vm lock is held so start out with a
read lock and upgrade if a vma rebind is required.

Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/1894
Fixes: bf69918b7199 ("drm/xe: Use xe_vma_ops to implement page fault rebinds")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Oak Zeng <oak.zeng@intel.com>
Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_pagefault.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
index 040dd142c49c..543cfa9892f6 100644
--- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
+++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
@@ -153,24 +153,15 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		return -EINVAL;
 
 retry_userptr:
-	/*
-	 * TODO: Avoid exclusive lock if VM doesn't have userptrs, or
-	 * start out read-locked?
-	 */
-	down_write(&vm->lock);
-	write_locked = true;
+	/* start out with read-locked and upgrade of vma is needed a rebind */
+	down_read(&vm->lock);
+	write_locked = false;
 	vma = lookup_vma(vm, pf->page_addr);
 	if (!vma) {
 		ret = -EINVAL;
 		goto unlock_vm;
 	}
 
-	if (!xe_vma_is_userptr(vma) ||
-	    !xe_vma_userptr_check_repin(to_userptr_vma(vma))) {
-		downgrade_write(&vm->lock);
-		write_locked = false;
-	}
-
 	trace_xe_vma_pagefault(vma);
 
 	atomic = access_is_atomic(pf->access_type);
@@ -179,9 +170,14 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	if (vma_is_valid(tile, vma) && !atomic)
 		goto unlock_vm;
 
+	/* xe_vma_rebind() expects a write lock so upgrade the vm lock */
+	up_read(&vm->lock);
+	down_write(&vm->lock);
+	write_locked = true;
 	/* TODO: Validate fault */
 
-	if (xe_vma_is_userptr(vma) && write_locked) {
+	if (xe_vma_is_userptr(vma) &&
+	    xe_vma_userptr_check_repin(to_userptr_vma(vma))) {
 		struct xe_userptr_vma *uvma = to_userptr_vma(vma);
 
 		spin_lock(&vm->userptr.invalidated_lock);
@@ -191,9 +187,6 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		ret = xe_vma_userptr_pin_pages(uvma);
 		if (ret)
 			goto unlock_vm;
-
-		downgrade_write(&vm->lock);
-		write_locked = false;
 	}
 
 	/* Lock VM and BOs dma-resv */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-06 16:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-05 10:16 [RFC] drm/xe: Ensure write lock is held when calling xe_vma_rebind() Nirmoy Das
2024-06-05 10:55 ` ✓ CI.Patch_applied: success for " Patchwork
2024-06-05 10:55 ` ✓ CI.checkpatch: " Patchwork
2024-06-05 10:56 ` ✓ CI.KUnit: " Patchwork
2024-06-05 11:07 ` ✓ CI.Build: " Patchwork
2024-06-05 11:08 ` ✗ CI.Hooks: failure " Patchwork
2024-06-05 11:09 ` ✓ CI.checksparse: success " Patchwork
2024-06-05 11:41 ` ✓ CI.BAT: " Patchwork
2024-06-05 16:44 ` [RFC] " Matthew Brost
2024-06-06 10:09   ` Nirmoy Das
2024-06-06 16:30     ` Matthew Brost
2024-06-06  1:43 ` ✗ CI.FULL: failure for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox