@@ -178,8 +178,18 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
fence->error = PENDING_ERROR;
- if (signal_on_any)
+ set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags);
+
+ if (signal_on_any) {
dma_fence_enable_sw_signaling(fence);
+ } else {
+ int i;
+
+ for (i = 0; i < num_fences; i++, fences++)
+ if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT,
+ &(*fences)->flags))
+ dma_fence_enable_sw_signaling(*fences);
+ }
return array;
}
@@ -255,5 +255,14 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
dma_fence_init(&chain->base, &dma_fence_chain_ops,
&chain->lock, context, seqno);
+
+ set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &chain->base.flags);
+ if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags)) {
+ /*
+ * Disable further calls into @fence's enable_signaling
+ * To prohibit further recursive locking
+ */
+ dma_fence_enable_sw_signaling(fence);
+ }
}
EXPORT_SYMBOL(dma_fence_chain_init);
@@ -99,6 +99,7 @@ enum dma_fence_flag_bits {
DMA_FENCE_FLAG_SIGNALED_BIT,
DMA_FENCE_FLAG_TIMESTAMP_BIT,
DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
+ DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT,
DMA_FENCE_FLAG_USER_BITS, /* must always be last member */
};
Some dma-fence containers lock other fence's locks from their enable_signaling() callbacks. We allow one level of nesting from the dma_fence_add_callback_nested() function, but we would also like to allow for example dma_fence_chain to point to a dma_fence_array and vice versa, even though that would create additional levels of nesting. To do that we need to break longer recursive chains of fence locking and we can do that either by deferring dma_fence_add_callback_nested() to a worker for affected fences or to call enable_signaling() early on affected fences. Opt for the latter, and define a DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT for fence classes that takes fence locks recursively from within their enable_signaling() callback. Note that a user could of course also call enable_signaling() manually on these fences before publishing them, but this solution attempts to do that only when necessary. Cc: Christian König <christian.koenig@amd.com> Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> --- drivers/dma-buf/dma-fence-array.c | 12 +++++++++++- drivers/dma-buf/dma-fence-chain.c | 9 +++++++++ include/linux/dma-fence.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)