Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/imagination: avoid deadlock on fence release

Do scheduler queue fence release processing on a workqueue, rather
than in the release function itself.

Fixes deadlock issues such as the following:

[ 607.400437] ============================================
[ 607.405755] WARNING: possible recursive locking detected
[ 607.415500] --------------------------------------------
[ 607.420817] weston:zfq0/24149 is trying to acquire lock:
[ 607.426131] ffff000017d041a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: pvr_gem_object_vunmap+0x40/0xc0 [powervr]
[ 607.436728]
but task is already holding lock:
[ 607.442554] ffff000017d105a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: dma_buf_ioctl+0x250/0x554
[ 607.451727]
other info that might help us debug this:
[ 607.458245] Possible unsafe locking scenario:

[ 607.464155] CPU0
[ 607.466601] ----
[ 607.469044] lock(reservation_ww_class_mutex);
[ 607.473584] lock(reservation_ww_class_mutex);
[ 607.478114]
*** DEADLOCK ***

Cc: stable@vger.kernel.org
Fixes: eaf01ee5ba28 ("drm/imagination: Implement job submission and scheduling")
Signed-off-by: Brendan King <brendan.king@imgtec.com>
Reviewed-by: Matt Coster <matt.coster@imgtec.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250226-fence-release-deadlock-v2-1-6fed2fc1fe88@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>

authored by

Brendan King and committed by
Matt Coster
df1a1ed5 6b481ab0

+15 -2
+11 -2
drivers/gpu/drm/imagination/pvr_queue.c
··· 109 109 return PVR_DRIVER_NAME; 110 110 } 111 111 112 + static void pvr_queue_fence_release_work(struct work_struct *w) 113 + { 114 + struct pvr_queue_fence *fence = container_of(w, struct pvr_queue_fence, release_work); 115 + 116 + pvr_context_put(fence->queue->ctx); 117 + dma_fence_free(&fence->base); 118 + } 119 + 112 120 static void pvr_queue_fence_release(struct dma_fence *f) 113 121 { 114 122 struct pvr_queue_fence *fence = container_of(f, struct pvr_queue_fence, base); 123 + struct pvr_device *pvr_dev = fence->queue->ctx->pvr_dev; 115 124 116 - pvr_context_put(fence->queue->ctx); 117 - dma_fence_free(f); 125 + queue_work(pvr_dev->sched_wq, &fence->release_work); 118 126 } 119 127 120 128 static const char * ··· 276 268 277 269 pvr_context_get(queue->ctx); 278 270 fence->queue = queue; 271 + INIT_WORK(&fence->release_work, pvr_queue_fence_release_work); 279 272 dma_fence_init(&fence->base, fence_ops, 280 273 &fence_ctx->lock, fence_ctx->id, 281 274 atomic_inc_return(&fence_ctx->seqno));
+4
drivers/gpu/drm/imagination/pvr_queue.h
··· 5 5 #define PVR_QUEUE_H 6 6 7 7 #include <drm/gpu_scheduler.h> 8 + #include <linux/workqueue.h> 8 9 9 10 #include "pvr_cccb.h" 10 11 #include "pvr_device.h" ··· 64 63 65 64 /** @queue: Queue that created this fence. */ 66 65 struct pvr_queue *queue; 66 + 67 + /** @release_work: Fence release work structure. */ 68 + struct work_struct release_work; 67 69 }; 68 70 69 71 /**