Skip to content

Commit c8a5d5e

Browse files
committed
nouveau: fix client work fence deletion race
This seems to have existed for ever but is now more apparant after commit 9bff18d ("drm/ttm: use per BO cleanup workers") My analysis: two threads are running, one in the irq signalling the fence, in dma_fence_signal_timestamp_locked, it has done the DMA_FENCE_FLAG_SIGNALLED_BIT setting, but hasn't yet reached the callbacks. The second thread in nouveau_cli_work_ready, where it sees the fence is signalled, so then puts the fence, cleanups the object and frees the work item, which contains the callback. Thread one goes again and tries to call the callback and causes the use-after-free. Proposed fix: lock the fence signalled check in nouveau_cli_work_ready, so either the callbacks are done or the memory is freed. Reviewed-by: Karol Herbst <[email protected]> Fixes: 11e451e ("drm/nouveau: remove fence wait code from deferred client work handler") Cc: [email protected] Signed-off-by: Dave Airlie <[email protected]> Link: https://lore.kernel.org/dri-devel/[email protected]/
1 parent c8ac109 commit c8a5d5e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/gpu/drm/nouveau/nouveau_drm.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,16 @@ nouveau_name(struct drm_device *dev)
137137
static inline bool
138138
nouveau_cli_work_ready(struct dma_fence *fence)
139139
{
140-
if (!dma_fence_is_signaled(fence))
141-
return false;
142-
dma_fence_put(fence);
143-
return true;
140+
bool ret = true;
141+
142+
spin_lock_irq(fence->lock);
143+
if (!dma_fence_is_signaled_locked(fence))
144+
ret = false;
145+
spin_unlock_irq(fence->lock);
146+
147+
if (ret == true)
148+
dma_fence_put(fence);
149+
return ret;
144150
}
145151

146152
static void

0 commit comments

Comments
 (0)