From: sashiko-bot@kernel.org
To: "Tejas Upadhyay" <tejas.upadhyay@intel.com>,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/xe: Hold VM reference in preempt rebind worker
Date: Mon, 30 Nov 2026 10:45:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-240882@kernel.org> (raw)
In-Reply-To: <20261130102837.4056493-2-tejas.upadhyay@intel.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/xe: race in xe_vm_queue_rebind_worker() taking VM ref after
queuing work
- [Medium] drm/xe: self-flush deadlock in preempt_rebind_work_func() via
xe_vm_put()
- [Low] drm/xe: missing Fixes trailer for vm_destroy_work_func() flush
warning fix
--
commit a7801ac2662678d368acc3e11b0b5eed7a84e910
Author: Tejas Upadhyay <tejas.upadhyay@intel.com>
> drm/xe: Hold VM reference in preempt rebind worker
>
> vm_destroy_work_func() runs on a WQ_MEM_RECLAIM workqueue and currently
> flushes vm->preempt.rebind_work, which is queued on the non-reclaim
> rebind_wq. This triggers a workqueue flush dependency warning:
>
> workqueue: WQ_MEM_RECLAIM xe-destroy-wq:vm_destroy_work_func [xe] is flushing !WQ_MEM_RECLAIM xe-ordered-wq:preempt_rebind_work_func [xe]
> WARNING: kernel/workqueue.c:3921 at check_flush_dependency.part.0+0xd9/0x110
>
> Take a VM reference when queuing vm->preempt.rebind_work and drop it
> when preempt_rebind_work_func() exits. Since the VM cannot be destroyed
> while rebind_work is pending or running, drop the redundant flush_work()
> from vm_destroy_work_func().
>
> Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
[Severity: Low]
This fixes the workqueue flush dependency warning introduced when deferred
VM teardown was moved to the reclaim-marked destroy_wq. Should it include a
Fixes: tag?
Fixes: 61e18525023a ("drm/xe: Route deferred xe_vma/xe_vm teardown off system_dfl_wq")
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index ab138d495f3f8..547d2c2980a76 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -586,14 +586,14 @@ static void preempt_rebind_work_func(struct work_struct *w)
> if (xe_vm_is_closed_or_banned(vm)) {
> up_write(&vm->lock);
> trace_xe_vm_rebind_worker_exit(vm);
> - return;
> + goto out_put_vm;
> }
>
> if (!try_wait_for_completion(&vm->xe->pm_block) && vm_suspend_rebind_worker(vm)) {
> up_write(&vm->lock);
> /* We don't actually block but don't make progress. */
> xe_pm_might_block_on_suspend();
> - return;
> + goto out_put_vm;
> }
>
> if (xe_vm_userptr_check_repin(vm)) {
> @@ -669,7 +669,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
> free_preempt_fences(&preempt_fences);
> xe_vm_queue_rebind_worker(vm);
> trace_xe_vm_rebind_worker_exit(vm);
> - return;
> + goto out_put_vm;
> }
>
> xe_vm_rebind_worker_reset_inject(vm);
> @@ -683,6 +683,8 @@ static void preempt_rebind_work_func(struct work_struct *w)
> free_preempt_fences(&preempt_fences);
>
> trace_xe_vm_rebind_worker_exit(vm);
> +out_put_vm:
> + xe_vm_put(vm);
> }
[Severity: Medium]
Can calling xe_vm_put(vm) from preempt_rebind_work_func() deadlock on
xe->rebind_wq when it drops the last VM reference after device unplug?
preempt_rebind_work_func() runs on the per-device xe->rebind_wq. When
xe_vm_put() drops the final reference on vm->gpuvm, drm_gpuvm_free() calls
xe_vm_free() (which queues vm->destroy_work without holding a drm_device
reference) and then synchronously calls drm_dev_put() in the caller's
context.
If the device was unplugged and the DRM file closed while rebind_work was
still pending or re-queued (for example via preempt_fence_work_func() or the
-EAGAIN retry path), that drm_dev_put() is the final device reference and
runs:
preempt_rebind_work_func() [on xe->rebind_wq]
xe_vm_put(vm)
drm_gpuvm_put(&vm->gpuvm)
drm_gpuvm_free()
drm_dev_put()
drm_managed_release()
xe_device_destroy()
destroy_workqueue(xe->rebind_wq) <-- self-flush deadlock
As noted in vma_destroy_cb(), work items that put a VM reference cannot do
so from a per-device workqueue destroyed in xe_device_destroy().
[ ... ]
> diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
> index ed590bad892cd..1917deca4679d 100644
> --- a/drivers/gpu/drm/xe/xe_vm.h
> +++ b/drivers/gpu/drm/xe/xe_vm.h
> @@ -262,8 +262,9 @@ int xe_vm_validate_protected(struct xe_vm *vm);
> static inline void xe_vm_queue_rebind_worker(struct xe_vm *vm)
> {
> xe_assert(vm->xe, xe_vm_in_preempt_fence_mode(vm));
> - queue_work_node(dev_to_node(vm->xe->drm.dev), vm->xe->rebind_wq,
> - &vm->preempt.rebind_work);
> + if (queue_work_node(dev_to_node(vm->xe->drm.dev), vm->xe->rebind_wq,
> + &vm->preempt.rebind_work))
> + xe_vm_get(vm);
> }
[Severity: High]
Can preempt_rebind_work_func() start on another CPU and call xe_vm_put(vm)
before xe_vm_queue_rebind_worker() calls xe_vm_get(vm)?
vm->xe->rebind_wq is an unbound workqueue. If a caller queues rebind_work
when the VM is already closed and only one reference remains (for example
preempt_fence_work_func() running after xe_vm_close_and_put(), where q->vm
holds the last VM reference):
CPU0 CPU1 (rebind_wq)
preempt_fence_work_func()
xe_vm_queue_rebind_worker(q->vm)
queue_work_node(..., rebind_work)
preempt_rebind_work_func()
xe_vm_is_closed_or_banned(vm)
goto out_put_vm;
xe_vm_put(vm) <-- kref 1 -> 0
xe_vm_get(vm) <-- refcount_inc on 0 / UAF
xe_exec_queue_put(q)
...
xe_vm_put(vm) <-- second drop to 0
Taking the reference with xe_vm_get(vm) before queue_work_node() and
dropping it with xe_vm_put(vm) if queue_work_node() returns false avoids the
race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130102837.4056493-2-tejas.upadhyay@intel.com?part=1
next prev parent reply other threads:[~2026-11-30 10:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:28 [PATCH] drm/xe: Hold VM reference in preempt rebind worker Tejas Upadhyay
2026-11-30 10:36 ` ✗ CI.checkpatch: warning for " Patchwork
2026-11-30 10:38 ` ✓ CI.KUnit: success " Patchwork
2026-11-30 10:45 ` sashiko-bot [this message]
2026-11-30 11:26 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-11-30 15:45 ` ✗ Xe.CI.FULL: " Patchwork
2026-11-30 22:37 ` [PATCH] " Matthew Brost
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=sashiko-outbox-240882@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tejas.upadhyay@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.