All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Matthew Brost <matthew.brost@intel.com>,
	Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>,
	Tejas Upadhyay <tejas.upadhyay@intel.com>
Subject: [PATCH 1/2] drm/xe/bo: Fix self-flush deadlock in async BO free
Date: Mon, 23 Nov 2026 10:26:54 +0530	[thread overview]
Message-ID: <20261123045652.3575516-5-sanjay.kumar.yadav@intel.com> (raw)
In-Reply-To: <20261123045652.3575516-4-sanjay.kumar.yadav@intel.com>

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.

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")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
Signed-off-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c | 20 +++++++++++++++++++-
 1 file changed, 19 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,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);
 }
 
 /**
@@ -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);
+	}
 }
 
 void xe_bo_put(struct xe_bo *bo)
-- 
2.52.0


  reply	other threads:[~2026-11-23  5:06 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 ` Sanjay Yadav [this message]
2026-11-23  5:41   ` [PATCH 1/2] drm/xe/bo: Fix self-flush deadlock in async BO free sashiko-bot
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=20261123045652.3575516-5-sanjay.kumar.yadav@intel.com \
    --to=sanjay.kumar.yadav@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --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.