diff mbox series

[RFC,4/4] drm/xe: Keep module reference while there are active fences

Message ID 20250418164246.72426-5-tvrtko.ursulin@igalia.com (mailing list archive)
State New
Headers show
Series Some (drm_sched_|dma_)fence lifetime issues | expand

Commit Message

Tvrtko Ursulin April 18, 2025, 4:42 p.m. UTC
Continuing the theme from previous patches. This time round we deal with
the problem that it is possible to unbind the driver from the PCI device
with an active sync file fence.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <phasta@kernel.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 drivers/gpu/drm/xe/xe_hw_fence.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/xe/xe_hw_fence.c b/drivers/gpu/drm/xe/xe_hw_fence.c
index 0b4f12be3692..209ed6ca78d9 100644
--- a/drivers/gpu/drm/xe/xe_hw_fence.c
+++ b/drivers/gpu/drm/xe/xe_hw_fence.c
@@ -37,7 +37,16 @@  void xe_hw_fence_module_exit(void)
 
 static struct xe_hw_fence *fence_alloc(void)
 {
-	return kmem_cache_zalloc(xe_hw_fence_slab, GFP_KERNEL);
+	struct xe_hw_fence *fence;
+
+	if (!try_module_get(THIS_MODULE))
+		return NULL;
+
+	fence = kmem_cache_zalloc(xe_hw_fence_slab, GFP_KERNEL);
+	if (!fence)
+		module_put(THIS_MODULE);
+
+	return fence;
 }
 
 static void fence_free(struct rcu_head *rcu)
@@ -189,6 +198,7 @@  static void xe_hw_fence_release(struct dma_fence *dma_fence)
 
 	XE_WARN_ON(!list_empty(&fence->irq_link));
 	call_rcu(&dma_fence->rcu, fence_free);
+	module_put(THIS_MODULE);
 }
 
 static const struct dma_fence_ops xe_hw_fence_ops = {
@@ -235,6 +245,7 @@  struct dma_fence *xe_hw_fence_alloc(void)
 void xe_hw_fence_free(struct dma_fence *fence)
 {
 	fence_free(&fence->rcu);
+	module_put(THIS_MODULE);
 }
 
 /**