[RFC PATCH 2/2] dma-fence: Avoid excessive recursive fence locking from enable_signaling() callbacks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
Cc: linaro-mm-sig@xxxxxxxxxxxxxxxx
Signed-off-by: Thomas Hellström <thomas.hellstrom@xxxxxxxxxxxxxxx>
---
 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(-)

diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
index 0322b92909fe..63ae9909bcfa 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -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;
 }
diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
index 0518e53880f6..b4012dbef0c9 100644
--- a/drivers/dma-buf/dma-fence-chain.c
+++ b/drivers/dma-buf/dma-fence-chain.c
@@ -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);
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 405cd83936f6..48bf5e14636e 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -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 */
 };
 
-- 
2.31.1




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux