[RFC 2/7] drm/xe/vm: Preserve CPU_AUTORESET_ACTIVE across GPUVA operations

Arvind Yadav
2026-02-19T09:13:30Z

GPUVA split/merge operations rebuild VMA flags from XE_VMA_CREATE_MASK.
While this preserves XE_VMA_MADV_AUTORESET, it drops runtime-only state
such as XE_VMA_CPU_AUTORESET_ACTIVE.

Preserve CPU_AUTORESET_ACTIVE when creating new VMAs during MAP/REMAP
so the CPU-only vs GPU-touched state survives VMA transformations.

Without this, split VMAs would lose their CPU-only state and be
incorrectly treated as GPU-touched.

Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
drivers/gpu/drm/xe/xe_vm.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 8fe54a998385..152ee355e5c3 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -2350,8 +2350,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.pat_index = pat_index;
op->map.invalidate_on_bind =
__xe_vm_needs_clear_scratch_pages(vm, flags);
@@ -2668,6 +2670,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;
+ /* Preserve CPU_AUTORESET_ACTIVE (runtime-only). */
+ 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);
@@ -2708,6 +2713,10 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
op->remap.range = xe_vma_size(old);

flags |= op->base.remap.unmap->va->flags & XE_VMA_CREATE_MASK;
+ /* Preserve CPU_AUTORESET_ACTIVE (runtime-only). */
+ if (op->base.remap.unmap->va->flags & XE_VMA_CPU_AUTORESET_ACTIVE)
+ flags |= XE_VMA_CPU_AUTORESET_ACTIVE;
+
if (op->base.remap.prev) {
vma = new_vma(vm, op->base.remap.prev,
&old->attr, flags);
@@ -4409,19 +4418,28 @@ 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));
+ /*
+ * For CPU_AUTORESET_ACTIVE VMAs, attributes may be mid-reset and
+ * thus temporarily non-default.
+ */
+ XE_WARN_ON(!xe_vma_has_default_mem_attrs(vma) &&
+ !(vma->gpuva.flags & XE_VMA_CPU_AUTORESET_ACTIVE));
default_pat = vma->attr.default_pat_index;
vma_flags = vma->gpuva.flags;
}

if (__op->op == DRM_GPUVA_OP_REMAP) {
vma = gpuva_to_vma(op->base.remap.unmap->va);
- default_pat = vma->attr.default_pat_index;
+ /* Preserve current PAT index, not default, for remap */
+ default_pat = vma->attr.pat_index;
vma_flags = vma->gpuva.flags;
}

if (__op->op == DRM_GPUVA_OP_MAP) {
op->map.vma_flags |= vma_flags & XE_VMA_CREATE_MASK;
+ /* Preserve CPU_AUTORESET_ACTIVE (runtime-only). */
+ if (vma_flags & XE_VMA_CPU_AUTORESET_ACTIVE)
+ op->map.vma_flags |= XE_VMA_CPU_AUTORESET_ACTIVE;
op->map.pat_index = default_pat;
}
} else {
@@ -4434,6 +4452,7 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
}

if (__op->op == DRM_GPUVA_OP_MAP) {
+ /* Madvise MAP follows REMAP (split/merge). */
xe_assert(vm->xe, remap_op);
remap_op = false;
/*
@@ -4443,6 +4462,9 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
* unmapping.
*/
op->map.vma_flags |= vma_flags & XE_VMA_CREATE_MASK;
+ /* Preserve CPU_AUTORESET_ACTIVE (not in CREATE_MASK). */
+ 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