Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [PATCH] drm/xe: Wait on bookkeep dma-resv slots when unmapping / mapping same address
Date: Mon, 22 Jul 2024 20:14:09 -0700	[thread overview]
Message-ID: <20240723031409.1698464-1-matthew.brost@intel.com> (raw)

There is a window between unmap and map of the same address in which the
old and new address is invalid. Avoid this window by waiting bookkeep
dma-resv when unmapping and mapping the same address.

This race is shown when running xe_vm.mmap* on presi platform which by
nature are more susceptible to races.

Fixes: ("drm/xe: Convert multiple bind ops into single job")
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_pt.c       | 5 ++++-
 drivers/gpu/drm/xe/xe_vm.c       | 9 +++++++++
 drivers/gpu/drm/xe/xe_vm_types.h | 2 ++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
index c24e869b7eae..1e92aa8dd241 100644
--- a/drivers/gpu/drm/xe/xe_pt.c
+++ b/drivers/gpu/drm/xe/xe_pt.c
@@ -1757,7 +1757,10 @@ static int op_prepare(struct xe_vm *vm,
 			break;
 
 		err = bind_op_prepare(vm, tile, pt_update_ops, op->map.vma);
-		pt_update_ops->wait_vm_kernel = true;
+		if (op->map.wait_bookkeep)
+			pt_update_ops->wait_vm_bookkeep = true;
+		else
+			pt_update_ops->wait_vm_kernel = true;
 		break;
 	case DRM_GPUVA_OP_REMAP:
 		err = unbind_op_prepare(tile, pt_update_ops,
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 8fa2821d0c64..d0a5703e0967 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -2165,6 +2165,7 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
 	struct xe_tile *tile;
 	u8 id, tile_mask = 0;
 	int err = 0;
+	u64 unmap_addr = 0, unmap_range = 0;
 
 	lockdep_assert_held_write(&vm->lock);
 
@@ -2183,6 +2184,10 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
 		switch (op->base.op) {
 		case DRM_GPUVA_OP_MAP:
 		{
+			if (op->base.map.va.addr == unmap_addr &&
+			    op->base.map.va.range == unmap_range)
+				op->map.wait_bookkeep = true;
+
 			flags |= op->map.read_only ?
 				VMA_CREATE_FLAG_READ_ONLY : 0;
 			flags |= op->map.is_null ?
@@ -2289,6 +2294,10 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
 			break;
 		}
 		case DRM_GPUVA_OP_UNMAP:
+			unmap_addr = op->base.unmap.va->va.addr;
+			unmap_range = op->base.unmap.va->va.range;
+			xe_vma_ops_incr_pt_update_ops(vops, op->tile_mask);
+			break;
 		case DRM_GPUVA_OP_PREFETCH:
 			/* FIXME: Need to skip some prefetch ops */
 			xe_vma_ops_incr_pt_update_ops(vops, op->tile_mask);
diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
index 7f9a303e51d8..b2cfb13bf05f 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -296,6 +296,8 @@ struct xe_vma_op_map {
 	bool is_null;
 	/** @dumpable: whether BO is dumped on GPU hang */
 	bool dumpable;
+	/** @wait_bookkeep: map op waits on bookkeep dma-resv slots */
+	bool wait_bookkeep;
 	/** @pat_index: The pat index to use for this operation. */
 	u16 pat_index;
 };
-- 
2.34.1


             reply	other threads:[~2024-07-23  3:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23  3:14 Matthew Brost [this message]
2024-07-23  3:18 ` ✓ CI.Patch_applied: success for drm/xe: Wait on bookkeep dma-resv slots when unmapping / mapping same address Patchwork
2024-07-23  3:18 ` ✓ CI.checkpatch: " Patchwork
2024-07-23  3:19 ` ✓ CI.KUnit: " Patchwork
2024-07-23  3:31 ` ✓ CI.Build: " Patchwork
2024-07-23  3:34 ` ✓ CI.Hooks: " Patchwork
2024-07-23  3:35 ` ✓ CI.checksparse: " Patchwork
2024-07-23  3:55 ` ✓ CI.BAT: " Patchwork
2024-07-23  5:02 ` ✗ CI.FULL: failure " 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=20240723031409.1698464-1-matthew.brost@intel.com \
    --to=matthew.brost@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox