Skip to contentSkip to conversation

dma-buf: Assign separate lockdep class to chain lock

PATCH Superseded Matthew Brost 3 participants 8 messages Feb 24 – Mar 3

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dma-buf: Assign separate lockdep class to chain lock

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the dma-fence-chain")
Cc Christian König <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/dma-buf/dma-fence-chain.c +17 -0
index a707792b6025..4c2a9f2ce126 100644
@@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 			  struct dma_fence *fence,
 			  uint64_t seqno)
 {
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
 	uint64_t context;
 
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 	dma_fence_init64(&chain->base, &dma_fence_chain_ops, NULL,
 			 context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while holding
+	 * chain->base.inline_lock and may call dma_fence_add_callback()
+	 * on the underlying fences, which takes their inline_lock.
+	 *
+	 * Since both locks share the same lockdep class, this legitimate
+	 * nesting confuses lockdep and triggers a recursive locking
+	 * warning. Assign a separate lockdep class to the chain lock
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock, &dma_fence_chain_lock_key);
+#endif
+
 	/*
 	 * Chaining dma_fence_chain container together is only allowed through
 	 * the prev fence and not through the contained fence.
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 dma-buf: Assign separate lockdep class to array lock

dma_fence_array_enable_signaling() runs while holding the array inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the array inline_lock so lockdep can correctly model the hierarchy.

Fixes 5943243914b9 ("dma-buf: use inline lock for the dma-fence-array")
Cc Christian König <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-array.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/dma-buf/dma-fence-array.c +18 -0
index cd970eceaefb..9cfac1ca68b5 100644
@@ -200,6 +200,10 @@ void dma_fence_array_init(struct dma_fence_array *array,
 			  u64 context, unsigned seqno,
 			  bool signal_on_any)
 {
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_array_lock_key;
+#endif
+
 	WARN_ON(!num_fences || !fences);
 
 	array->num_fences = num_fences;
@@ -208,6 +212,20 @@ void dma_fence_array_init(struct dma_fence_array *array,
 		       seqno);
 	init_irq_work(&array->work, irq_dma_fence_array_work);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_array_enable_signaling() is invoked while holding
+	 * array->base.inline_lock and may call dma_fence_add_callback()
+	 * on the underlying fences, which takes their inline_lock.
+	 *
+	 * Since both locks share the same lockdep class, this legitimate
+	 * nesting confuses lockdep and triggers a recursive locking
+	 * warning. Assign a separate lockdep class to the array lock
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&array->base.inline_lock, &dma_fence_array_lock_key);
+#endif
+
 	atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences);
 	array->fences = fences;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/2
#2 lore raw
In reply to Matthew Brost
Quoted 3 lines · Matthew Brost

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Just for the record, we have the same problem for dma_fence_chain_is_signaled().

Maybe mention that in the commit message as well for completeness.

Quoted 4 lines

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Thanks a lot! I was just about to figure out how to do this.

Quoted 7 lines
Fixes a408c0ca0c41 ("dma-buf: use inline lock for the dma-fence-chain")
Cc Christian König <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>

Regards,
Christian.

Quoted 39 lines
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/dma-buf/dma-fence-chain.c +17 -0
index a707792b6025..4c2a9f2ce126 100644
@@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 			  struct dma_fence *fence,
 			  uint64_t seqno)
 {
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
 	uint64_t context;
 
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 	dma_fence_init64(&chain->base, &dma_fence_chain_ops, NULL,
 			 context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while holding
+	 * chain->base.inline_lock and may call dma_fence_add_callback()
+	 * on the underlying fences, which takes their inline_lock.
+	 *
+	 * Since both locks share the same lockdep class, this legitimate
+	 * nesting confuses lockdep and triggers a recursive locking
+	 * warning. Assign a separate lockdep class to the chain lock
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock, &dma_fence_chain_lock_key);
+#endif
+
 	/*
 	 * Chaining dma_fence_chain container together is only allowed through
 	 * the prev fence and not through the contained fence.
#3 lore raw
In reply to Matthew Brost
Quoted 39 lines · On Tue, 24 Feb 2026 09:55:43 -0800 Matthew Brost <[email protected]>…

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the dma-fence-chain")
Cc Christian König <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/dma-buf/dma-fence-chain.c +6 -0
index a707792b6025..4c2a9f2ce126 100644
@@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 			  struct dma_fence *fence,
 			  uint64_t seqno)
 {
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
 	uint64_t context;
 
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 	dma_fence_init64(&chain->base, &dma_fence_chain_ops, NULL,
 			 context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while holding

drivers/dma-buf/dma-fence-chain.c void dma_fence_chain_init(struct dma_fence_chain *chain, · line 281

Quoted 10 lines
drivers/dma-buf/dma-fence-chain.c +10 -0
+	 * chain->base.inline_lock and may call dma_fence_add_callback()
+	 * on the underlying fences, which takes their inline_lock.
+	 *
+	 * Since both locks share the same lockdep class, this legitimate
+	 * nesting confuses lockdep and triggers a recursive locking
+	 * warning. Assign a separate lockdep class to the chain lock
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock, &dma_fence_chain_lock_key);
+#endif

If we're going to recommend the use of this inline_lock for all new dma_fence_ops implementers, as the commit message seems to imply

Quoted 6 lines

Shared spinlocks have the problem that implementations need to guarantee that the lock lives at least as long all fences referencing them.

Using a per-fence spinlock allows completely decoupling spinlock producer and consumer life times, simplifying the handling in most use cases.

maybe we should have the lock_class_key at the dma_buf_ops level and have this lockdep_set_class() automated in __dma_fence_init().

Quoted 4 lines
drivers/dma-buf/dma-fence-chain.c +1 -0
+
 	/*
 	 * Chaining dma_fence_chain container together is only allowed through
 	 * the prev fence and not through the contained fence.
maintainer
#4 lore raw
Quoted 59 lines · Boris Brezillon
Quoted 39 lines · On Tue, 24 Feb 2026 09:55:43 -0800 Matthew Brost <[email protected]>…

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the dma-fence-chain")
Cc Christian König <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/dma-buf/dma-fence-chain.c +6 -0
index a707792b6025..4c2a9f2ce126 100644
@@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 			  struct dma_fence *fence,
 			  uint64_t seqno)
 {
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
 	uint64_t context;
 
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 	dma_fence_init64(&chain->base, &dma_fence_chain_ops, NULL,
 			 context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while holding

drivers/dma-buf/dma-fence-chain.c void dma_fence_chain_init(struct dma_fence_chain *chain, · line 281

Quoted 10 lines
drivers/dma-buf/dma-fence-chain.c +10 -0
+	 * chain->base.inline_lock and may call dma_fence_add_callback()
+	 * on the underlying fences, which takes their inline_lock.
+	 *
+	 * Since both locks share the same lockdep class, this legitimate
+	 * nesting confuses lockdep and triggers a recursive locking
+	 * warning. Assign a separate lockdep class to the chain lock
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock, &dma_fence_chain_lock_key);
+#endif

If we're going to recommend the use of this inline_lock for all new dma_fence_ops implementers, as the commit message seems to imply

Quoted 3 lines

Shared spinlocks have the problem that implementations need to guarantee that the lock lives at least as long all fences referencing them.

Quoted 6 lines
Quoted 3 lines

Using a per-fence spinlock allows completely decoupling spinlock producer and consumer life times, simplifying the handling in most use cases.

maybe we should have the lock_class_key at the dma_buf_ops level and have this lockdep_set_class() automated in __dma_fence_init().

The dma_fence_chain() and dma_fence_array() containers are the only ones who are allowed to nest the lock with other dma_fences. E.g. we have WARN_ON()s in place which fire when you try to stitch together something which won't work.

So everybody else should get a lockdep warning when they try to do nasty things like this because you really can't guarantee lock order between different dma_fence implementations.

Regards,
Christian.

Quoted 6 lines
Quoted 5 lines
drivers/dma-buf/dma-fence-chain.c +1 -0
+
 	/*
 	 * Chaining dma_fence_chain container together is only allowed through
 	 * the prev fence and not through the contained fence.
#5 lore raw
Quoted 75 lines · On Mon, 2 Mar 2026 16:42:28 +0100 Christian König <[email protected]>…
Quoted 67 lines · Boris Brezillon
Quoted 55 lines · On Tue, 24 Feb 2026 09:55:43 -0800 Matthew Brost <[email protected]>…

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the

dma-fence-chain") Cc: Christian König <[email protected]>

Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
(quoted diff) +0 -0

b/drivers/dma-buf/dma-fence-chain.c index a707792b6025..4c2a9f2ce126 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, struct dma_fence *fence, uint64_t seqno)
{

drivers/dma-buf/dma-fence-chain.c +3 -0
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain =

to_dma_fence_chain(prev); uint64_t context;

drivers/dma-buf/dma-fence-chain.c +3 -0
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct
 dma_fence_chain *chain, dma_fence_init64(&chain->base,
 &dma_fence_chain_ops, NULL, context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while

holding

(quoted diff) +1 -0
+	 * chain->base.inline_lock and may call

dma_fence_add_callback()

(quoted diff) +1 -0
+	 * on the underlying fences, which takes their

inline_lock.

(quoted diff) +2 -0
+	 *
+	 * Since both locks share the same lockdep class, this

legitimate

(quoted diff) +1 -0
+	 * nesting confuses lockdep and triggers a recursive

locking

(quoted diff) +1 -0
+	 * warning. Assign a separate lockdep class to the chain

lock

drivers/dma-buf/dma-fence-chain.c +3 -0
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock,
Quoted 1 line

&dma_fence_chain_lock_key); +#endif

If we're going to recommend the use of this inline_lock for all new dma_fence_ops implementers, as the commit message seems to imply

Quoted 4 lines

Shared spinlocks have the problem that implementations need to guarantee that the lock lives at least as long all fences referencing them.

Quoted 6 lines
Quoted 3 lines

Using a per-fence spinlock allows completely decoupling spinlock producer and consumer life times, simplifying the handling in most use cases.

maybe we should have the lock_class_key at the dma_buf_ops level and have this lockdep_set_class() automated in __dma_fence_init().

Quoted 8 lines

The dma_fence_chain() and dma_fence_array() containers are the only ones who are allowed to nest the lock with other dma_fences. E.g. we have WARN_ON()s in place which fire when you try to stitch together something which won't work.

So everybody else should get a lockdep warning when they try to do nasty things like this because you really can't guarantee lock order between different dma_fence implementations.

Okay, that makes sense.

#6 lore raw
Quoted 83 lines · Boris Brezillon
Quoted 80 lines · On Mon, 2 Mar 2026 16:42:28 +0100 Christian König <[email protected]>…
Quoted 67 lines · Boris Brezillon
Quoted 55 lines · On Tue, 24 Feb 2026 09:55:43 -0800 Matthew Brost <[email protected]>…

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the

dma-fence-chain") Cc: Christian König <[email protected]>

Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
(quoted diff) +0 -0

b/drivers/dma-buf/dma-fence-chain.c index a707792b6025..4c2a9f2ce126 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, struct dma_fence *fence, uint64_t seqno)
{

drivers/dma-buf/dma-fence-chain.c +3 -0
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain =

to_dma_fence_chain(prev); uint64_t context;

drivers/dma-buf/dma-fence-chain.c +3 -0
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct
 dma_fence_chain *chain, dma_fence_init64(&chain->base,
 &dma_fence_chain_ops, NULL, context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while

holding

(quoted diff) +1 -0
+	 * chain->base.inline_lock and may call

dma_fence_add_callback()

(quoted diff) +1 -0
+	 * on the underlying fences, which takes their

inline_lock.

(quoted diff) +2 -0
+	 *
+	 * Since both locks share the same lockdep class, this

legitimate

(quoted diff) +1 -0
+	 * nesting confuses lockdep and triggers a recursive

locking

(quoted diff) +1 -0
+	 * warning. Assign a separate lockdep class to the chain

lock

drivers/dma-buf/dma-fence-chain.c +3 -0
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock,
Quoted 1 line

&dma_fence_chain_lock_key); +#endif

If we're going to recommend the use of this inline_lock for all new dma_fence_ops implementers, as the commit message seems to imply

Quoted 4 lines

Shared spinlocks have the problem that implementations need to guarantee that the lock lives at least as long all fences referencing them.

Quoted 6 lines
Quoted 3 lines

Using a per-fence spinlock allows completely decoupling spinlock producer and consumer life times, simplifying the handling in most use cases.

maybe we should have the lock_class_key at the dma_buf_ops level and have this lockdep_set_class() automated in __dma_fence_init().

The dma_fence_chain() and dma_fence_array() containers are the only ones who are allowed to nest the lock with other dma_fences. E.g. we have WARN_ON()s in place which fire when you try to stitch together something which won't work.

Quoted 5 lines
Quoted 3 lines

So everybody else should get a lockdep warning when they try to do nasty things like this because you really can't guarantee lock order between different dma_fence implementations.

Okay, that makes sense.

Yes, I agree with Christian's reasoning - chains / arrays is the only case where nesting should be allowed. Also if we assigned a key for every inline lock we'd quickly exhaust the number of lockdep keys.

Matt

#7 lore raw
Quoted 88 lines · On Mon, 2 Mar 2026 12:05:46 -0800 Matthew Brost <[email protected]> wrote:
Quoted 87 lines · Boris Brezillon
Quoted 83 lines · On Mon, 2 Mar 2026 16:42:28 +0100 Christian König <[email protected]>…
Quoted 67 lines · Boris Brezillon
Quoted 55 lines · On Tue, 24 Feb 2026 09:55:43 -0800 Matthew Brost <[email protected]>…

dma_fence_chain_enable_signaling() runs while holding the chain inline_lock and may add callbacks to underlying fences, which takes their inline_lock.

Since both locks share the same lockdep class, this valid nesting triggers a recursive locking warning. Assign a distinct lockdep class to the chain inline_lock so lockdep can correctly model the hierarchy.

Fixes a408c0ca0c41 ("dma-buf: use inline lock for the

dma-fence-chain") Cc: Christian König <[email protected]>

Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/dma-buf/dma-fence-chain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
(quoted diff) +0 -0

b/drivers/dma-buf/dma-fence-chain.c index a707792b6025..4c2a9f2ce126 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -242,6 +242,9 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, struct dma_fence *fence, uint64_t seqno)
{

drivers/dma-buf/dma-fence-chain.c +3 -0
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	static struct lock_class_key dma_fence_chain_lock_key;
+#endif
 	struct dma_fence_chain *prev_chain =

to_dma_fence_chain(prev); uint64_t context;

drivers/dma-buf/dma-fence-chain.c +3 -0
@@ -263,6 +266,20 @@ void dma_fence_chain_init(struct
 dma_fence_chain *chain, dma_fence_init64(&chain->base,
 &dma_fence_chain_ops, NULL, context, seqno);
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	/*
+	 * dma_fence_chain_enable_signaling() is invoked while

holding

(quoted diff) +1 -0
+	 * chain->base.inline_lock and may call

dma_fence_add_callback()

(quoted diff) +1 -0
+	 * on the underlying fences, which takes their

inline_lock.

(quoted diff) +2 -0
+	 *
+	 * Since both locks share the same lockdep class, this

legitimate

(quoted diff) +1 -0
+	 * nesting confuses lockdep and triggers a recursive

locking

(quoted diff) +1 -0
+	 * warning. Assign a separate lockdep class to the chain

lock

drivers/dma-buf/dma-fence-chain.c +3 -0
+	 * to model this hierarchy correctly.
+	 */
+	lockdep_set_class(&chain->base.inline_lock,
Quoted 1 line

&dma_fence_chain_lock_key); +#endif

If we're going to recommend the use of this inline_lock for all new dma_fence_ops implementers, as the commit message seems to imply

Quoted 4 lines

Shared spinlocks have the problem that implementations need to guarantee that the lock lives at least as long all fences referencing them.

Quoted 6 lines
Quoted 3 lines

Using a per-fence spinlock allows completely decoupling spinlock producer and consumer life times, simplifying the handling in most use cases.

maybe we should have the lock_class_key at the dma_buf_ops level and have this lockdep_set_class() automated in __dma_fence_init().

The dma_fence_chain() and dma_fence_array() containers are the only ones who are allowed to nest the lock with other dma_fences. E.g. we have WARN_ON()s in place which fire when you try to stitch together something which won't work.

So everybody else should get a lockdep warning when they try to do nasty things like this because you really can't guarantee lock order between different dma_fence implementations.

Quoted 5 lines
Quoted 1 line

Okay, that makes sense.

Yes, I agree with Christian's reasoning - chains / arrays is the only case where nesting should be allowed. Also if we assigned a key for every inline lock we'd quickly exhaust the number of lockdep keys.

The suggestion was to have a key per-dma_buf_ops implementation, not per-lock ;-). Anyway, Christian's argument already convinced me, so this is moot.