From: Matthew Brost <matthew.brost@intel.com>
To: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH 1/2][CI-ONLY] drm/xe/bo: Fix self-flush deadlock in async BO free
Date: Wed, 25 Nov 2026 09:10:29 -0800 [thread overview]
Message-ID: <awcWheuLWdYTdXtT@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20261122125605.3508411-5-sanjay.kumar.yadav@intel.com>
On Sun, Nov 22, 2026 at 06:26:07PM +0530, Sanjay Yadav wrote:
> The async BO free worker can drop the last reference to a page-table
> BO, which puts the VM and, via drm_gpuvm_free(), possibly the last
> drm_device reference. Device teardown then runs from the worker and
> xe_bo_dev_fini() calls flush_work() on the running work, deadlocking.
>
What if anytime we added a BO to &bo_device->async_list, we call
drm_dev_get and then drop in when we remove it from the list?
Then just delete flush_work in xe_bo_dev_fini and convert it to an
assert &bo_device->async_list is empty.
Matt
> Hold a device reference across xe_bo_put_commit() so that the final
> put happens only after the list is processed, and when
> xe_bo_dev_fini() is called from the worker itself, cancel any requeued
> instance and free the pending BOs inline instead of flushing.
>
> Fixes: 0e33330f1238 ("drm/xe: Add struct xe_pt_job_ops")
> Signed-off-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
> ---
> drivers/gpu/drm/xe/xe_bo.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 42a6aa1a2e4a..dc78f5f49e35 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -4157,8 +4157,20 @@ 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 VM reference, and with it the last
> + * device reference. Hold a device reference while freeing so that
> + * the final put, if any, happens only after the whole list has been
> + * processed. The refcount is already zero if xe_bo_dev_fini() is
> + * flushing this work from another context.
> + */
> + 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);
> }
>
> /**
> @@ -4176,7 +4188,17 @@ 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);
> + /*
> + * The final device put may come from xe_bo_dev_work_func() itself,
> + * where flushing would wait on ourselves. The work may have been
> + * requeued meanwhile, so cancel it and free the pending BOs here.
> + */
> + 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);
> + }
> }
>
> void xe_bo_put(struct xe_bo *bo)
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-11-25 18:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 12:56 [PATCH 0/2][CI-ONLY] drm/xe/bo: Fix async BO free teardown deadlock Sanjay Yadav
2026-11-22 12:56 ` [PATCH 1/2][CI-ONLY] drm/xe/bo: Fix self-flush deadlock in async BO free Sanjay Yadav
2026-11-25 17:10 ` Matthew Brost [this message]
2026-11-22 12:56 ` [PATCH 2/2][CI-ONLY] drm/xe/bo: Queue async BO free on the module-lifetime destroy wq Sanjay Yadav
2026-11-22 13:14 ` ✓ CI.KUnit: success for drm/xe/bo: Fix async BO free teardown deadlock Patchwork
2026-11-22 13:49 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-23 8:19 ` ✓ Xe.CI.FULL: " 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=awcWheuLWdYTdXtT@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=sanjay.kumar.yadav@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.