From: sashiko-bot@kernel.org
To: "Sanjay Yadav" <sanjay.kumar.yadav@intel.com>,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/xe/bo: Fix self-flush deadlock in async BO free
Date: Mon, 23 Nov 2026 05:41:48 +0000 [thread overview]
Message-ID: <sashiko-outbox-228726@kernel.org> (raw)
In-Reply-To: <20261123045652.3575516-5-sanjay.kumar.yadav@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/xe/bo: device ref in xe_bo_dev_work_func() misses delayed
TTM delete
- [High] drm/xe/bo: use-after-free in xe_bo_dev_fini() due to drmm
teardown order
--
commit 5fbac2ccb59bdff95da98ffe9fb0729223881834
Author: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
drm/xe/bo: Fix self-flush deadlock in async BO free
This commit holds a temporary drm_device reference across xe_bo_put_commit()
in the async BO free worker and skips flush_work() in xe_bo_dev_fini() when
called from the worker itself.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 42a6aa1a2e4a0..b8c6d6a643d3a 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -4157,8 +4157,17 @@ void xe_bo_put_commit(struct llist_head *deferred)
> static void xe_bo_dev_work_func(struct work_struct *work)
> {
> struct xe_bo_dev *bo_dev = container_of(work, typeof(*bo_dev), async_free);
> + struct xe_device *xe = container_of(bo_dev, struct xe_device, bo_device);
> + /*
> + * Freeing a BO may drop the last device ref, so hold one until the
> + * list is processed. Zero if xe_bo_dev_fini() is already flushing us.
> + */
> + bool dev_ref = kref_get_unless_zero(&xe->drm.ref);
>
> xe_bo_put_commit(&bo_dev->async_list);
> +
> + if (dev_ref)
> + drm_dev_put(&xe->drm);
> }
[Severity: High]
Does holding xe->drm.ref only across xe_bo_put_commit() protect against the
same deadlock when TTM defers freeing the BO to bo->delayed_delete?
When xe_bo_put_commit() reaches ttm_bo_release(), TTM queues
ttm_bo_delayed_delete() onto bdev->wq (xe->ttm.wq) instead of calling
xe_ttm_bo_destroy() synchronously whenever bookkeep fences on the BO are not
yet signaled or want_init_on_free() is active with a non-NULL bo->ttm.
Because xe_ttm_bo_destroy() has not run yet, bo->vm still holds its xe_vm and
drm_device references when xe_bo_dev_work_func() drops dev_ref and exits.
When ttm_bo_delayed_delete() later runs on xe->ttm.wq with no outer
drm_device reference held, xe_ttm_bo_destroy() calls xe_vm_put(bo->vm) ->
drm_gpuvm_free() -> drm_dev_put(), dropping the final drm_device reference
from inside xe->ttm.wq:
drivers/gpu/drm/xe/xe_bo.c:xe_ttm_bo_destroy() {
...
if (bo->vm && (xe_bo_is_user(bo) || bo->flags & XE_BO_FLAG_PAGETABLE))
xe_vm_put(bo->vm);
if (bo->parent_obj)
xe_bo_put(bo->parent_obj);
mutex_lock(&xe->mem_access.vram_userfault.lock);
...
}
That triggers xe_device_destroy() -> ttm_device_fini(), which calls
drain_workqueue(bdev->wq) from a worker running on bdev->wq and deadlocks;
even apart from the workqueue drain, dropping the last drm_device reference
in xe_vm_put(bo->vm) frees struct xe_device before the following
mutex_lock(&xe->mem_access.vram_userfault.lock).
> /**
> @@ -4176,7 +4185,16 @@ void xe_bo_dev_init(struct xe_bo_dev *bo_dev)
> */
> void xe_bo_dev_fini(struct xe_bo_dev *bo_dev)
> {
> - flush_work(&bo_dev->async_free);
> + /*
> + * Final device put from the worker itself: flushing would deadlock,
> + * so cancel any requeue and free the pending BOs inline.
> + */
> + if (current_work() == &bo_dev->async_free) {
> + cancel_work(&bo_dev->async_free);
> + xe_bo_put_commit(&bo_dev->async_list);
> + } else {
> + flush_work(&bo_dev->async_free);
> + }
> }
[Severity: High]
Can freeing pending BOs in xe_bo_dev_fini() access BO resources that
drm_managed_release() has already destroyed?
In xe_device_init_early(), xe_device_destroy() is the first drmm action
registered, before xe_shrinker_create(), drmm_mutex_init() for
xe->mem_access.vram_userfault.lock, and the TTM resource managers. Because
drm_managed_release() runs actions in reverse registration order, those
resources are already destroyed and freed by the time xe_device_destroy()
calls xe_bo_dev_fini().
If a BO that does not pin a drm_device reference while queued (such as an SVM
devmem BO with bo->vm == NULL queued via xe_svm_devmem_release() ->
xe_bo_put_async()) is added to bo_dev->async_list while xe_bo_put_commit() is
sleeping in xe_bo_dev_work_func(), drm_dev_put(&xe->drm) starts
drm_managed_release() with that BO still on bo_dev->async_list. When
xe_bo_dev_fini() then runs xe_bo_put_commit(&bo_dev->async_list) (or flushes
the worker), xe_ttm_bo_destroy() locks the destroyed
xe->mem_access.vram_userfault.lock and xe_ttm_tt_unpopulate() accesses the
freed xe->mem.shrinker.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123045652.3575516-4-sanjay.kumar.yadav@intel.com?part=1
next prev parent reply other threads:[~2026-11-23 5:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:56 [PATCH 0/2] drm/xe/bo: Fix async BO free teardown deadlock Sanjay Yadav
2026-11-23 4:56 ` [PATCH 1/2] drm/xe/bo: Fix self-flush deadlock in async BO free Sanjay Yadav
2026-11-23 5:41 ` sashiko-bot [this message]
2026-11-23 4:56 ` [PATCH 2/2] drm/xe/bo: Queue async BO free on the module-lifetime destroy wq Sanjay Yadav
2026-11-25 16:53 ` Matthew Brost
2026-11-23 5:20 ` ✗ CI.KUnit: failure for drm/xe/bo: Fix async BO free teardown deadlock (rev2) 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=sashiko-outbox-228726@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sanjay.kumar.yadav@intel.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.