[PATCH] drm/xe: Wait on bookkeep dma-resv slots when unmapping / mapping same address

Matthew Brost matthew.brost at intel.com
Tue Jul 23 03:14:09 UTC 2024


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 at 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



More information about the Intel-xe mailing list