GPUVA split and remap operations rebuild VMAs from create flags. These
flags preserve persistent VMA state, but not runtime-only state such as
cpu_autoreset_active.

Forward XE_VMA_CPU_AUTORESET_ACTIVE explicitly through the MAP/REMAP
pipeline so xe_vma_create() can restore cpu_autoreset_active in the new
VMA. The bit remains pipeline-only and is stripped before storing
vma->gpuva.flags.

Also relax the UNMAP attribute warning for MADVISE_AUTORESET VMAs, since
they may legitimately carry non-default madvise-managed attributes.

v2:
  - Move runtime state to xe_vma bool and keep
    XE_VMA_CPU_AUTORESET_ACTIVE as pipeline-only. (Matt)
  - Add xe_vma_effective_create_flags() to centralise flag handling.

v3:
  - Guard cpu_autoreset_active assignment to CPU_ADDR_MIRROR VMAs only (Matt)

Cc: Matthew Brost <[email protected]>
Cc: Thomas Hellström <[email protected]>
Cc: Himal Prasad Ghimiray <[email protected]>
Signed-off-by: Arvind Yadav <[email protected]>
---
 drivers/gpu/drm/xe/xe_vm.c | 44 ++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 080c2fff0e95..dec5279f08a2 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -1105,7 +1105,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
        vma->gpuva.vm = &vm->gpuvm;
        vma->gpuva.va.addr = start;
        vma->gpuva.va.range = end - start + 1;
-       vma->gpuva.flags = flags;
+       /* Pipeline-only, do not store in gpuva.flags. */
+       vma->gpuva.flags = flags & ~XE_VMA_CPU_AUTORESET_ACTIVE;
+       vma->cpu_autoreset_active =
+               (flags & XE_VMA_SYSTEM_ALLOCATOR) &&
+               (flags & XE_VMA_CPU_AUTORESET_ACTIVE);
 
        for_each_tile(tile, vm->xe, id)
                vma->tile_mask |= 0x1 << id;
@@ -2479,8 +2483,10 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct 
xe_vma_ops *vops,
                                op->map.vma_flags |= XE_VMA_SYSTEM_ALLOCATOR;
                        if (flags & DRM_XE_VM_BIND_FLAG_DUMPABLE)
                                op->map.vma_flags |= XE_VMA_DUMPABLE;
-                       if (flags & DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET)
+                       if (flags & DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET) {
                                op->map.vma_flags |= XE_VMA_MADV_AUTORESET;
+                               op->map.vma_flags |= 
XE_VMA_CPU_AUTORESET_ACTIVE;
+                       }
                        op->map.request_decompress = flags & 
DRM_XE_VM_BIND_FLAG_DECOMPRESS;
                        op->map.pat_index = pat_index;
                        op->map.invalidate_on_bind =
@@ -2800,6 +2806,9 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, 
struct drm_gpuva_ops *ops,
                        };
 
                        flags |= op->map.vma_flags & XE_VMA_CREATE_MASK;
+                       /* Forward pipeline-only state. */
+                       if (op->map.vma_flags & XE_VMA_CPU_AUTORESET_ACTIVE)
+                               flags |= XE_VMA_CPU_AUTORESET_ACTIVE;
 
                        vma = new_vma(vm, &op->base.map, &default_attr,
                                      flags);
@@ -2842,6 +2851,10 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, 
struct drm_gpuva_ops *ops,
                        op->remap.old_range = op->remap.range;
 
                        flags |= op->base.remap.unmap->va->flags & 
XE_VMA_CREATE_MASK;
+                       /* Forward pipeline-only state. */
+                       if (xe_vma_has_cpu_autoreset_active(old))
+                               flags |= XE_VMA_CPU_AUTORESET_ACTIVE;
+
                        if (op->base.remap.prev) {
                                vma = new_vma(vm, op->base.remap.prev,
                                              &old->attr, flags);
@@ -4693,6 +4706,17 @@ int xe_vma_need_vram_for_atomic(struct xe_device *xe, 
struct xe_vma *vma, bool i
        }
 }
 
+/* Add pipeline-only autoreset state when rebuilding a VMA. */
+static unsigned int xe_vma_effective_create_flags(struct xe_vma *vma)
+{
+       unsigned int flags = vma->gpuva.flags;
+
+       if (xe_vma_has_cpu_autoreset_active(vma))
+               flags |= XE_VMA_CPU_AUTORESET_ACTIVE;
+
+       return flags;
+}
+
 static int xe_vm_alloc_vma(struct xe_vm *vm,
                           struct drm_gpuvm_map_req *map_req,
                           bool is_madvise)
@@ -4728,19 +4752,24 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
                if (!is_madvise) {
                        if (__op->op == DRM_GPUVA_OP_UNMAP) {
                                vma = gpuva_to_vma(op->base.unmap.va);
-                               XE_WARN_ON(!xe_vma_has_default_mem_attrs(vma));
+                               /* AUTORESET VMAs may carry madvise-managed 
attrs. */
+                               XE_WARN_ON(!xe_vma_has_default_mem_attrs(vma) &&
+                                          !(vma->gpuva.flags & 
XE_VMA_MADV_AUTORESET));
                                default_pat = vma->attr.default_pat_index;
-                               vma_flags = vma->gpuva.flags;
+                               vma_flags = xe_vma_effective_create_flags(vma);
                        }
 
                        if (__op->op == DRM_GPUVA_OP_REMAP) {
                                vma = gpuva_to_vma(op->base.remap.unmap->va);
                                default_pat = vma->attr.default_pat_index;
-                               vma_flags = vma->gpuva.flags;
+                               vma_flags = xe_vma_effective_create_flags(vma);
                        }
 
                        if (__op->op == DRM_GPUVA_OP_MAP) {
                                op->map.vma_flags |= vma_flags & 
XE_VMA_CREATE_MASK;
+                               /* Forward pipeline-only state. */
+                               if (vma_flags & XE_VMA_CPU_AUTORESET_ACTIVE)
+                                       op->map.vma_flags |= 
XE_VMA_CPU_AUTORESET_ACTIVE;
                                op->map.pat_index = default_pat;
                        }
                } else {
@@ -4749,7 +4778,7 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
                                xe_assert(vm->xe, !remap_op);
                                xe_assert(vm->xe, xe_vma_has_no_bo(vma));
                                remap_op = true;
-                               vma_flags = vma->gpuva.flags;
+                               vma_flags = xe_vma_effective_create_flags(vma);
                        }
 
                        if (__op->op == DRM_GPUVA_OP_MAP) {
@@ -4762,6 +4791,9 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
                                 * unmapping.
                                 */
                                op->map.vma_flags |= vma_flags & 
XE_VMA_CREATE_MASK;
+                               /* Forward pipeline-only state. */
+                               if (vma_flags & XE_VMA_CPU_AUTORESET_ACTIVE)
+                                       op->map.vma_flags |= 
XE_VMA_CPU_AUTORESET_ACTIVE;
                        }
                }
                print_op(vm->xe, __op);
-- 
2.43.0

Reply via email to