From: "Yadav, Sanjay Kumar" <sanjay.kumar.yadav@intel.com>
To: Arvind Yadav <arvind.yadav@intel.com>,
<intel-xe@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>
Cc: <rodrigo.vivi@intel.com>, <matthew.brost@intel.com>,
<himal.prasad.ghimiray@intel.com>,
<thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH v2 3/4] drm/xe: Mark VMs as closing before queue cleanup
Date: Wed, 28 Oct 2026 19:30:49 +0530 [thread overview]
Message-ID: <6d36e1fd-362b-49fe-acb5-954daaf415bc@intel.com> (raw)
In-Reply-To: <20261028122125.3772832-4-arvind.yadav@intel.com>
On 28-10-2026 17:51, Arvind Yadav wrote:
> Queue cleanup is asynchronous. New VM work can therefore race with file
> close or VM destroy while cleanup is starting.
>
> Add a closing state and set it before starting queue cleanup. Treat a
> closing VM as unavailable for new exec, bind, rebind and page-fault work.
>
> Keep vm->size valid while the VM is closing so SVM invalidation can still
> drain existing mappings.
>
> Also reject page faults on banned VMs, which cannot resume execution.
>
> 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>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Assisted-by: LLM
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
Tested-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
> ---
> drivers/gpu/drm/xe/xe_device.c | 4 ++++
> drivers/gpu/drm/xe/xe_pagefault.c | 2 +-
> drivers/gpu/drm/xe/xe_svm.c | 3 ++-
> drivers/gpu/drm/xe/xe_vm.c | 18 +++++++++++++++++-
> drivers/gpu/drm/xe/xe_vm.h | 9 ++++++++-
> drivers/gpu/drm/xe/xe_vm_types.h | 1 +
> 6 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index d3bb42e4d0d7..7b4913d7665d 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -181,6 +181,10 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
>
> guard(xe_pm_runtime)(xe);
>
> + /* Block new VM work before starting asynchronous queue teardown. */
> + xa_for_each(&xef->vm.xa, idx, vm)
> + xe_vm_close_start(vm);
> +
> /*
> * No need for exec_queue.lock here as there is no contention for it
> * when FD is closing as IOCTLs presumably can't be modifying the
> diff --git a/drivers/gpu/drm/xe/xe_pagefault.c b/drivers/gpu/drm/xe/xe_pagefault.c
> index 5247321c805e..e1363bfbfbd9 100644
> --- a/drivers/gpu/drm/xe/xe_pagefault.c
> +++ b/drivers/gpu/drm/xe/xe_pagefault.c
> @@ -291,7 +291,7 @@ static int xe_pagefault_service(struct xe_pagefault *pf)
>
> down_read(&vm->lock);
>
> - if (xe_vm_is_closed(vm)) {
> + if (xe_vm_is_closed_or_banned(vm)) {
> err = -ENOENT;
> xe_pagefault_set_error(pf, XE_PAGEFAULT_ERROR_VM_CLOSED);
> goto unlock_vm;
> diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> index 909a602d091e..3b71d9636296 100644
> --- a/drivers/gpu/drm/xe/xe_svm.c
> +++ b/drivers/gpu/drm/xe/xe_svm.c
> @@ -219,7 +219,8 @@ xe_svm_range_notifier_event_end(struct xe_vm *vm, struct drm_gpusvm_range *r,
>
> drm_gpusvm_unmap_pages(&vm->svm.gpusvm, &(to_xe_range(r)->pages),
> drm_gpusvm_range_size(r) >> PAGE_SHIFT, &ctx);
> - if (!xe_vm_is_closed(vm) && mmu_range->event == MMU_NOTIFY_UNMAP)
> + if (!xe_vm_is_closed(vm) && !xe_vm_is_closing(vm) &&
> + mmu_range->event == MMU_NOTIFY_UNMAP)
> xe_svm_garbage_collector_add_range(vm, to_xe_range(r),
> mmu_range);
> }
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index a1a4eaf3165f..6e548fd8a809 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -1975,6 +1975,20 @@ static void xe_vm_close(struct xe_vm *vm)
> drm_dev_exit(idx);
> }
>
> +void xe_vm_close_start(struct xe_vm *vm)
> +{
> + down_write(&vm->lock);
> + if (xe_vm_in_fault_mode(vm))
> + xe_svm_notifier_lock(vm);
> +
> + /* Keep size valid so SVM invalidation still performs its full drain. */
> + vm->flags |= XE_VM_FLAG_CLOSING;
> +
> + if (xe_vm_in_fault_mode(vm))
> + xe_svm_notifier_unlock(vm);
> + up_write(&vm->lock);
> +}
> +
> void xe_vm_close_and_put(struct xe_vm *vm)
> {
> LIST_HEAD(contested);
> @@ -2268,8 +2282,10 @@ int xe_vm_destroy_ioctl(struct drm_device *dev, void *data,
> xa_erase(&xef->vm.xa, args->vm_id);
> mutex_unlock(&xef->vm.lock);
>
> - if (!err)
> + if (!err) {
> + xe_vm_close_start(vm);
> xe_vm_close_and_put(vm);
> + }
>
> return err;
> }
> diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
> index 351d08b3b378..a8b33cb2b559 100644
> --- a/drivers/gpu/drm/xe/xe_vm.h
> +++ b/drivers/gpu/drm/xe/xe_vm.h
> @@ -59,6 +59,11 @@ static inline bool xe_vm_is_closed(struct xe_vm *vm)
> return !vm->size;
> }
>
> +static inline bool xe_vm_is_closing(struct xe_vm *vm)
> +{
> + return vm->flags & XE_VM_FLAG_CLOSING;
> +}
> +
> static inline bool xe_vm_is_banned(struct xe_vm *vm)
> {
> return vm->flags & XE_VM_FLAG_BANNED;
> @@ -67,7 +72,8 @@ static inline bool xe_vm_is_banned(struct xe_vm *vm)
> static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm)
> {
> lockdep_assert_held(&vm->lock);
> - return xe_vm_is_closed(vm) || xe_vm_is_banned(vm);
> + return xe_vm_is_closed(vm) || xe_vm_is_banned(vm) ||
> + xe_vm_is_closing(vm);
> }
>
> struct xe_vma *
> @@ -214,6 +220,7 @@ int xe_vm_get_property_ioctl(struct drm_device *dev, void *data,
> struct drm_file *file);
>
> void xe_vm_close_and_put(struct xe_vm *vm);
> +void xe_vm_close_start(struct xe_vm *vm);
>
> static inline bool xe_vm_in_fault_mode(struct xe_vm *vm)
> {
> diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
> index fb9305124679..6ca9ef9d0c0b 100644
> --- a/drivers/gpu/drm/xe/xe_vm_types.h
> +++ b/drivers/gpu/drm/xe/xe_vm_types.h
> @@ -286,6 +286,7 @@ struct xe_vm {
> #define XE_VM_FLAG_SET_TILE_ID(tile) FIELD_PREP(GENMASK(7, 6), (tile)->id)
> #define XE_VM_FLAG_GSC BIT(8)
> #define XE_VM_FLAG_NO_VM_OVERCOMMIT BIT(9)
> +#define XE_VM_FLAG_CLOSING BIT(10)
> unsigned long flags;
>
> /**
next prev parent reply other threads:[~2026-10-28 14:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 12:21 [PATCH v2 0/4] drm/xe: Fix VM teardown and migration queue recovery Arvind Yadav
2026-10-28 12:21 ` [PATCH v2 1/4] drm/xe: Hold a device reference across deferred VM destruction Arvind Yadav
2026-10-28 13:59 ` Yadav, Sanjay Kumar
2026-10-28 12:21 ` [PATCH v2 2/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Arvind Yadav
2026-10-28 12:21 ` [PATCH v2 3/4] drm/xe: Mark VMs as closing before queue cleanup Arvind Yadav
2026-10-28 14:00 ` Yadav, Sanjay Kumar [this message]
2026-10-28 12:21 ` [PATCH v2 4/4] drm/xe: Defer VM teardown until exec queue cleanup completes Arvind Yadav
2026-10-28 14:01 ` Yadav, Sanjay Kumar
2026-10-28 12:30 ` ✓ CI.KUnit: success for drm/xe: Fix VM teardown and migration queue recovery (rev2) Patchwork
2026-10-28 13:07 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-28 22:09 ` ✗ Xe.CI.FULL: failure " 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=6d36e1fd-362b-49fe-acb5-954daaf415bc@intel.com \
--to=sanjay.kumar.yadav@intel.com \
--cc=arvind.yadav@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=thomas.hellstrom@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.