Intel-XE Archive on 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 2/2] drm/xe/bo: Queue async BO free on the module-lifetime destroy wq
Date: Mon, 23 Nov 2026 10:26:55 +0530	[thread overview]
Message-ID: <20261123045652.3575516-6-sanjay.kumar.yadav@intel.com> (raw)
In-Reply-To: <20261123045652.3575516-4-sanjay.kumar.yadav@intel.com>

The async BO free work may run device teardown and still execute xe
code after xe_device_count drops to zero. Since it runs on system_wq,
which module unload does not drain, rmmod can free the module text
under the running worker.

Queue it on xe_destroy_wq instead, which is drained after
xe_device_exit() at module unload.

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.h     | 3 ++-
 drivers/gpu/drm/xe/xe_module.c | 5 +++--
 drivers/gpu/drm/xe/xe_pt.c     | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 77b3a02e9b8e..a4c4fa6f183b 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -14,6 +14,7 @@
 #include "xe_bo_types.h"
 #include "xe_ggtt.h"
 #include "xe_macros.h"
+#include "xe_module.h"
 #include "xe_validation.h"
 #include "xe_vm_types.h"
 #include "xe_vm.h"
@@ -550,7 +551,7 @@ xe_bo_put_async(struct xe_bo *bo)
 	struct xe_bo_dev *bo_device = &xe_bo_device(bo)->bo_device;
 
 	if (xe_bo_put_deferred(bo, &bo_device->async_list, NULL))
-		schedule_work(&bo_device->async_free);
+		xe_destroy_wq_queue(&bo_device->async_free);
 }
 
 void xe_bo_dev_init(struct xe_bo_dev *bo_device);
diff --git a/drivers/gpu/drm/xe/xe_module.c b/drivers/gpu/drm/xe/xe_module.c
index 897724cb5cfb..c7323d59b747 100644
--- a/drivers/gpu/drm/xe/xe_module.c
+++ b/drivers/gpu/drm/xe/xe_module.c
@@ -116,8 +116,9 @@ static void xe_destroy_wq_module_exit(void)
  *
  * The destroy workqueue has module lifetime, and is guaranteed to outlive
  * any xe_device, and to be drained before the module is unloaded. It is used
- * for GuC exec queue and xe_vm/xe_vma teardown that can be deferred past the
- * lifetime of the xe_device that triggered it. SVM pagemap destroy uses the
+ * for GuC exec queue, xe_vm/xe_vma teardown and async BO freeing that can be
+ * deferred past the lifetime of the xe_device that triggered it, or that can
+ * drop the last xe_device reference. SVM pagemap destroy uses the
  * per-device xe->destroy_wq instead.
  *
  * Return: %true if @work was queued, %false if it was already pending.
diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
index 81e3c2e2011b..bceead2938a4 100644
--- a/drivers/gpu/drm/xe/xe_pt.c
+++ b/drivers/gpu/drm/xe/xe_pt.c
@@ -3072,7 +3072,7 @@ static void xe_pt_job_ops_destroy(struct kref *ref)
 			 * put.
 			 */
 			if (llist_add(&bo->freed, &bo_device->async_list))
-				schedule_work(&bo_device->async_free);
+				xe_destroy_wq_queue(&bo_device->async_free);
 		}
 	}
 
-- 
2.52.0


  parent reply	other threads:[~2026-11-23  5:06 UTC|newest]

Thread overview: 5+ 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
2026-11-23  4:56 ` Sanjay Yadav [this message]
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-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox