Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Matthew Auld <matthew.auld@intel.com>,
	Matthew Brost	 <matthew.brost@intel.com>,
	Himal Prasad Ghimiray	 <himal.prasad.ghimiray@intel.com>,
	Stuart Summers <stuart.summers@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 1/5] drm/xe/vm: restore userptr invalidations on VMA op unwind
Date: Thu, 19 Nov 2026 13:48:42 +0100	[thread overview]
Message-ID: <905fc2549d7a7354d9486c8dafe092a2166ca4bd.camel@linux.intel.com> (raw)
In-Reply-To: <20261119-userptr-repin-v1-1-af2e327833a9@intel.com>

On Thu, 2026-11-19 at 11:14 +0000, Matthew Auld wrote:
> When xe_vma_op_commit() commits DRM_GPUVA_OP_UNMAP or
> DRM_GPUVA_OP_REMAP, prep_vma_destroy() sets XE_VMA_DESTROYED while
> the
> old VMA's GPU page tables remain live. If a subsequent step fails and
> unwinds (for example splitting a userptr VMA where new_vma() fails,
> or a
> later op in an array of binds failing), a concurrent MMU notifier
> invalidation is lost on non-fault-mode VMs:
> 
>   CPU0 (VM_BIND / MADVISE)            CPU1 (MMU notifier)
>   ------------------------            -------------------
>   down_write(&vm->lock)
>   xe_vma_op_commit()
>     prep_vma_destroy(vma)
>       flags |= XE_VMA_DESTROYED
>   ...
>   /* later step fails */
>                                      
> xe_vma_userptr_invalidate_start()
>                                         down_write(&notifier_lock)
>                                         mmu_interval_set_seq()
>                                         /* XE_VMA_DESTROYED set:
> skips
>                                          * vm->userptr.invalidated
>                                          */
>                                         drm_gpusvm_unmap_pages()
>                                         up_write(&notifier_lock)
>   xe_vma_op_unwind()
>     flags &= ~XE_VMA_DESTROYED
>     xe_vm_insert_vma(vm, vma)
>   up_write(&vm->lock)
> 
> Once vm->lock is dropped, the VMA remains in the VM with live GPU
> PTEs
> pointing at unmapped pages, while neither exec nor the rebind worker
> knows to repin and rebind it.
> 
> Add unprep_vma_destroy() to check xe_vma_userptr_check_repin() while
> clearing XE_VMA_DESTROYED under the notifier lock and queue
> invalidated
> non-fault-mode userptr VMAs onto vm->userptr.invalidated.
> 
> Fixes: b06d47be7c83 ("drm/xe: Port Xe to GPUVA")
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: <stable@vger.kernel.org> # v6.12+

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>



> ---
>  drivers/gpu/drm/xe/xe_vm.c | 35 ++++++++++++++++++++++++-----------
>  1 file changed, 24 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index dd855876f571..75be5e5329bd 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -44,6 +44,7 @@
>  #include "xe_tile.h"
>  #include "xe_tlb_inval.h"
>  #include "xe_trace_bo.h"
> +#include "xe_userptr.h"
>  #include "xe_vm_madvise.h"
>  #include "xe_wa.h"
>  
> @@ -2401,6 +2402,26 @@ static void prep_vma_destroy(struct xe_vm *vm,
> struct xe_vma *vma,
>  		xe_vm_remove_vma(vm, vma);
>  }
>  
> +static void unprep_vma_destroy(struct xe_vm *vm, struct xe_vma *vma,
> +			       bool post_commit)
> +{
> +	xe_svm_notifier_lock(vm);
> +	vma->gpuva.flags &= ~XE_VMA_DESTROYED;
> +	if (IS_ENABLED(CONFIG_DRM_GPUSVM) &&
> !xe_vm_in_fault_mode(vm) &&
> +	    xe_vma_is_userptr(vma) &&
> +	    xe_vma_userptr_check_repin(to_userptr_vma(vma))) {
> +		struct xe_userptr_vma *uvma = to_userptr_vma(vma);
> +
> +		spin_lock(&vm->userptr.invalidated_lock);
> +		list_move_tail(&uvma->userptr.invalidate_link,
> +			       &vm->userptr.invalidated);
> +		spin_unlock(&vm->userptr.invalidated_lock);
> +	}
> +	xe_svm_notifier_unlock(vm);
> +	if (post_commit)
> +		xe_vm_insert_vma(vm, vma);
> +}
> +
>  #undef ULL
>  #define ULL	unsigned long long
>  
> @@ -3093,13 +3114,8 @@ static void xe_vma_op_unwind(struct xe_vm *vm,
> struct xe_vma_op *op,
>  
>  		xe_vm_assert_write_mode_or_garbage_collector(vm);
>  
> -		if (vma) {
> -			xe_svm_notifier_lock(vm);
> -			vma->gpuva.flags &= ~XE_VMA_DESTROYED;
> -			xe_svm_notifier_unlock(vm);
> -			if (post_commit)
> -				xe_vm_insert_vma(vm, vma);
> -		}
> +		if (vma)
> +			unprep_vma_destroy(vm, vma, post_commit);
>  		break;
>  	}
>  	case DRM_GPUVA_OP_REMAP:
> @@ -3117,9 +3133,6 @@ static void xe_vma_op_unwind(struct xe_vm *vm,
> struct xe_vma_op *op,
>  			xe_vma_destroy_unlocked(op->remap.next);
>  		}
>  		if (vma) {
> -			xe_svm_notifier_lock(vm);
> -			vma->gpuva.flags &= ~XE_VMA_DESTROYED;
> -			xe_svm_notifier_unlock(vm);
>  			if (post_commit) {
>  				/*
>  				 * Restore the old va range, in case
> of the
> @@ -3131,8 +3144,8 @@ static void xe_vma_op_unwind(struct xe_vm *vm,
> struct xe_vma_op *op,
>  					op->remap.old_start;
>  				op->base.remap.unmap->va->va.range =
>  					op->remap.old_range;
> -				xe_vm_insert_vma(vm, vma);
>  			}
> +			unprep_vma_destroy(vm, vma, post_commit);
>  		}
>  		break;
>  	}

  reply	other threads:[~2026-11-19 12:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 11:14 [PATCH 0/5] Non-fatal repin retries and NUMA-local rebind worker Matthew Auld
2026-11-19 11:14 ` [PATCH 1/5] drm/xe/vm: restore userptr invalidations on VMA op unwind Matthew Auld
2026-11-19 12:48   ` Thomas Hellström [this message]
2026-11-19 16:35   ` Himal prasad Ghimiray
2026-11-19 11:14 ` [PATCH 2/5] drm/xe: Requeue the rebind worker instead of retrying in-line on -EAGAIN Matthew Auld
2026-11-19 12:51   ` Thomas Hellström
2026-11-19 16:29     ` Matthew Auld
2026-11-19 17:26       ` Thomas Hellström
2026-11-19 17:38         ` Matthew Auld
2026-11-19 16:36   ` Himal prasad Ghimiray
2026-11-19 11:14 ` [PATCH 3/5] drm/xe: Add a userptr repin timeout sysfs attribute Matthew Auld
2026-11-19 16:38   ` Himal prasad Ghimiray
2026-11-19 11:14 ` [PATCH 4/5] drm/xe/userptr: Make the repin retry loop non-fatal Matthew Auld
2026-11-19 13:03   ` Thomas Hellström
2026-11-19 17:10   ` Himal prasad Ghimiray
2026-11-19 11:14 ` [PATCH 5/5] drm/xe: run compute rebind worker on device NUMA node Matthew Auld
2026-11-19 13:11   ` Thomas Hellström
2026-11-19 13:38     ` Matthew Auld
2026-11-19 13:16 ` ✓ CI.KUnit: success for Non-fatal repin retries and NUMA-local rebind worker Patchwork
2026-11-19 13:54 ` ✓ Xe.CI.BAT: " 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=905fc2549d7a7354d9486c8dafe092a2166ca4bd.camel@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=stuart.summers@intel.com \
    /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