[RFC 4/4] drm/xe: Keep module reference while there are active fences
Tvrtko Ursulin
tvrtko.ursulin at igalia.com
Fri Apr 18 16:42:46 UTC 2025
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 at igalia.com>
Cc: Christian König <christian.koenig at amd.com>
Cc: Danilo Krummrich <dakr at kernel.org>
Cc: Lucas De Marchi <lucas.demarchi at intel.com>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: Philipp Stanner <phasta at kernel.org>
Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
---
drivers/gpu/drm/xe/xe_hw_fence.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
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);
}
/**
--
2.48.0
More information about the dri-devel
mailing list