This series implements automatic reset of MADVISE-managed GPU memory
attributes when userspace unmaps memory. Non-default attributes are
reset when CPU mappings are removed, preventing them from persisting
across later mmap() operations.

MMU interval notifiers detect munmap on CPU-only VMAs (not yet
GPU-faulted) and queue a worker to reset attributes. GPU-touched
VMAs continue using the existing SVM path.

Key aspects:
 - cpu_autoreset_active tracks CPU-only vs GPU-touched state.
 - MMU notifier callbacks do not allocate. work_struct is embedded in
   xe_madvise_notifier and initialized at ioctl time.
 - Unmap events are coalesced in the callback and processed by a worker.
 - teardown_rwsem serializes VM teardown against notifier callbacks.
 - maple_tree tracks notifier ranges and supports deduplication.
 - MMU notifier registration is performed outside vm->lock.

Patch organization:
 1. Track cpu_autoreset_active in xe_vma.
 2. Preserve state across GPUVA operations.
 3. Clear state on first GPU fault.
 4. Add MMU notifier and worker infrastructure.
 5. Disable madvise notifier after GPU touch.
 6. Wire notifiers into VM lifecycle.
 7. Fix partial unmap attribute reset.

Changes in v2:
 - Move runtime state to xe_vma bool cpu_autoreset_active. (Matt)
 - Embed work_struct in xe_madvise_notifier. (Thomas)
 - Coalesce overlapping munmap events.
 - Replace closing state with teardown_rwsem. (Matt)
 - Use maple_tree for notifier tracking. (Matt)
 - Register notifiers outside vm->lock.
 - Add xe_vma_effective_create_flags() and fix REMAP split handling.
 - Move GPU-touch handling to the successful pagefault path. (Matt)
 - Use plain bool active in notifier. (Matt)
 - Add lockdep assertions for vm->lock.

Changes in v3:
 - Add kernel-doc and lockdep_assert_held to
   xe_vma_has_cpu_autoreset_active(). (Matt)
 - Guard cpu_autoreset_active assignment to CPU_ADDR_MIRROR VMAs only. (Matt)
 - Drop lockdep_assert_held_write from xe_svm_handle_pagefault. (Matt)
 - Rework GPU-touch handling after page faults. (Matt)
 - Rework notifier lifetime handling and teardown.
 - Keep exact-match notifier deactivation for split VMA handling.
 - Move notifier_ranges allocation before VMA mutation.
 - Keep a VM-owned notifier list for teardown.
 - Coalesce pending unmap ranges and reset only CPU holes in the worker.
 - Clear MADV_AUTORESET on notifier registration failure.
 - Coalesce partial_unmap range via min/max instead of blind overwrite. (Matt)
 - Restore range_debug() in xe_svm_garbage_collector_add_range(). (Matt)
 - Update partial_unmap under garbage_collector.lock.
 - Continue processing queued ranges on non-fatal set_default_attr failures.
 - Annotate lockless notifier->active access with READ_ONCE/WRITE_ONCE.

Arvind Yadav (6):
  drm/xe/vm: Track CPU_AUTORESET state in xe_vma
  drm/xe/vm: Preserve cpu_autoreset_active across GPUVA operations
  drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault
  drm/xe/vm: Add madvise autoreset notifier worker
  drm/xe/vm: Disable madvise notifier on GPU touch
  drm/xe/vm: Wire MADVISE_AUTORESET notifiers into VM lifecycle

Himal Prasad Ghimiray (1):
  drm/xe/svm: Correct memory attribute reset for partial unmap

 drivers/gpu/drm/xe/xe_pagefault.c  |  13 +-
 drivers/gpu/drm/xe/xe_svm.c        | 102 ++++-
 drivers/gpu/drm/xe/xe_svm.h        |  10 +
 drivers/gpu/drm/xe/xe_vm.c         |  58 ++-
 drivers/gpu/drm/xe/xe_vm.h         |  28 ++
 drivers/gpu/drm/xe/xe_vm_madvise.c | 651 ++++++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_vm_madvise.h |   9 +
 drivers/gpu/drm/xe/xe_vm_types.h   |  82 ++++
 8 files changed, 928 insertions(+), 25 deletions(-)

-- 
2.43.0

Reply via email to