Skip to contentSkip to conversation

dma-fence: Clarify external lock use case in dma_fence_init() docs

PATCH Superseded Maíra Canal 3 participants 9 messages Apr 19 – May 18

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dma-fence: Clarify external lock use case in dma_fence_init() docs

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.

---
 drivers/dma-buf/dma-fence.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +7 -6
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
  * context and seqno are used for easy comparison between fences, allowing
  * to check which fence is later by simply using dma_fence_later().
  *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
  */
 void
 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
  * Context and seqno are used for easy comparison between fences, allowing
  * to check which fence is later by simply using dma_fence_later().
  *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
  */
 void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

Quoted 7 lines

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

Quoted 43 lines

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
 drivers/dma-buf/dma-fence.c | 13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +5 -3
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
   * context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
   */

 void
 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +2 -3
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
   * Context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */

 void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,

#2 lore raw

Hi Christian,

When possible, could you take a look at this patch? If you are okay with it, I can apply it to drm-misc-next.

Best regards,
- Maíra

Quoted 62 lines · Philipp Stanner
Quoted 7 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

Quoted 7 lines

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

Quoted 43 lines

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.

---
  drivers/dma-buf/dma-fence.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +7 -6
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
   * context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
   */
  void
  dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
   * Context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */
  void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
#3 lore raw

+cc Christian's AMD e-mail

Quoted 4 lines · Maíra Canal

Hi Christian,

When possible, could you take a look at this patch? If you are okay with it, I can apply it to drm-misc-next.

Gentle ping.

Best regards,
- Maíra

Quoted 78 lines

Best regards,
- Maíra

Quoted 72 lines · Philipp Stanner
Quoted 7 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

Quoted 7 lines

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

Quoted 53 lines

---

v1 -> v2: https://lore.kernel.org/dri-devel/20260411185756.1887119-4- [email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
  drivers/dma-buf/dma-fence.c | 13 +++++++------

  1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +0 -1
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, 
 const struct dma_fence_ops *ops,
    * context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because 

this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
   */
  void
  dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +0 -1
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
    * Context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because 

this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */
  void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,

#4 lore raw
In reply to Maíra Canal

+cc Christian's AMD e-mail

Quoted 4 lines · Maíra Canal

Hi Christian,

When possible, could you take a look at this patch? If you are okay with it, I can apply it to drm-misc-next.

Gentle ping.

Best regards,
- Maíra

Quoted 78 lines

Best regards,
- Maíra

Quoted 72 lines · Philipp Stanner
Quoted 7 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

Quoted 7 lines

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

Quoted 53 lines

---

v1 -> v2: https://lore.kernel.org/dri-devel/20260411185756.1887119-4- [email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
  drivers/dma-buf/dma-fence.c | 13 +++++++------

  1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +0 -1
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, 
 const struct dma_fence_ops *ops,
    * context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because 

this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
   */
  void
  dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +0 -1
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
    * Context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because 

this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */
  void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,

maintainer
#5 lore raw
Quoted 9 lines · Maíra Canal

+cc Christian's AMD e-mail

Quoted 4 lines · Maíra Canal

Hi Christian,

When possible, could you take a look at this patch? If you are okay with it, I can apply it to drm-misc-next.

Gentle ping.

Sorry for the delay, please always CC my AMD email address as well.

Regards,
Christian.

Quoted 73 lines

Best regards,
- Maíra

Quoted 68 lines

Best regards,
- Maíra

Quoted 62 lines · Philipp Stanner
Quoted 7 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

Quoted 7 lines

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

Quoted 43 lines

---

v1 -> v2: https://lore.kernel.org/dri-devel/20260411185756.1887119-4- [email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
  drivers/dma-buf/dma-fence.c | 13 +++++++------

  1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +5 -3
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
    * context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.
    */

  void
  dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +2 -3
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
    * Context and seqno are used for easy comparison between fences, allowing
    * to check which fence is later by simply using dma_fence_later().
    *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
    */

  void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,

maintainer
#6 lore raw
In reply to Maíra Canal
Quoted 32 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.

---
 drivers/dma-buf/dma-fence.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +0 -0
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
  * context and seqno are used for easy comparison between fences, allowing

drivers/dma-buf/dma-fence.c __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, · line 1109

Quoted 10 lines
drivers/dma-buf/dma-fence.c +5 -3
  * to check which fence is later by simply using dma_fence_later().
  *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.

No that's not correct. The use of the external lock was indeed to prevent signaling out of order.

It is perfectly possible to observe the fence as signaled even without taking the lock because of the unlocked test_bit() operation we use, so the new wording is clearly misleading and not explaining properly what is going on here.

Regards,
Christian.

Quoted 15 lines
drivers/dma-buf/dma-fence.c +2 -3
  */
 void
 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
  * Context and seqno are used for easy comparison between fences, allowing
  * to check which fence is later by simply using dma_fence_later().
  *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
  */
 void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
#7 lore raw
Quoted 46 lines · Christian König
Quoted 32 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
 drivers/dma-buf/dma-fence.c | 13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +0 -0
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
   * context and seqno are used for easy comparison between fences, allowing

drivers/dma-buf/dma-fence.c __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, · line 1109

Quoted 10 lines
drivers/dma-buf/dma-fence.c +5 -3
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.

No that's not correct. The use of the external lock was indeed to prevent signaling out of order.

Quoted 2 lines

It is perfectly possible to observe the fence as signaled even without taking the lock because of the unlocked test_bit() operation we use, so the new wording is clearly misleading and not explaining properly what is going on here.

I think the point Maíra / we tried to make with that statement is that an external lock is effectively useless for ensuring correct signaling order. Afair you agree with that in general.

Do you have a suggestion for a better formulation?

Regards
P.

Quoted 20 lines

Regards,
Christian.

Quoted 15 lines
drivers/dma-buf/dma-fence.c +0 -0
   */

 void
 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +2 -3
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
   * Context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */

 void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,

maintainer
#8 lore raw
Quoted 47 lines · Philipp Stanner
Quoted 46 lines · Christian König
Quoted 32 lines · Maíra Canal

The kerneldoc comment on dma_fence_init() and dma_fence_init64() describe the legacy reason to pass an external lock as a need to prevent multiple fences "from signaling out of order". However, this wording is a bit
misleading: a shared spinlock does not (and cannot) prevent the signaler from signaling out of order. Signaling order is the driver's responsibility regardless of whether the lock is shared or per-fence.

What a shared lock actually provides is serialization of signaling and observation across fences in a given context, so that observers never see a later fence signaled while an earlier one is not.

Reword both comments to describe this more accurately.

---

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/

- Be more explicit about not allowing new users to use an external lock.
- De-duplicate the explanation in dma_fence_init64() by pointing to the dma_fence_init() documentation.
---
 drivers/dma-buf/dma-fence.c | 13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dma-buf/dma-fence.c +0 -0
index 1c1eaecaf1b0..63b349ba9a34 100644
@@ -1102,9 +1102,11 @@ __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
   * context and seqno are used for easy comparison between fences, allowing

drivers/dma-buf/dma-fence.c __dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, · line 1109

Quoted 10 lines
drivers/dma-buf/dma-fence.c +5 -3
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * External locks are a relic from legacy use cases that needed a shared lock
+ * to serialize signaling and observation of fences within a context, so that
+ * observers never see a later fence signaled while an earlier one isn't. New
+ * users MUST NOT use external locks, as they force the issuer to outlive all
+ * fences that reference the lock.

No that's not correct. The use of the external lock was indeed to prevent signaling out of order.

Quoted 6 lines
Quoted 2 lines

It is perfectly possible to observe the fence as signaled even without taking the lock because of the unlocked test_bit() operation we use, so the new wording is clearly misleading and not explaining properly what is going on here.

I think the point Maíra / we tried to make with that statement is that an external lock is effectively useless for ensuring correct signaling order.

Well yeah it's just historically.

The point is *if* you use one lock for all your fences *and not* have an is_signaled callback then all fences signal in order.

It's just that as far as I know all drivers sooner or later implemented the is_signaled callback because of the performance benefits and so abandoned the signaling order approach.

So we could in theory fix all drivers to not use the external lock, but that's tons of extra work which nobody wants to do for a radeon, nouveau or QXL driver.

Quoted 3 lines

Afair you agree with that in general.

Do you have a suggestion for a better formulation?

Yeah I really liked the "relic" and "MUST NOT" wording, that is pretty much exactly what we need here.

Maybe something like that here:

* External locks are a relic from legacy use cases that needed a shared lock
* to serialize signaling when no out of order signaling through the is_signaled
* callback was possible. We have long abandoned that concept, but the external
* lock is still around. New users MUST NOT use external locks, as they force the
* issuer to outlive all fences that reference the lock.

Regards,
Christian.

Quoted 25 lines

Regards
P.

Quoted 20 lines

Regards,
Christian.

Quoted 15 lines
drivers/dma-buf/dma-fence.c +0 -0
   */

 void
 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,

drivers/dma-buf/dma-fence.c +2 -3
@@ -1129,9 +1131,8 @@ EXPORT_SYMBOL(dma_fence_init);
   * Context and seqno are used for easy comparison between fences, allowing
   * to check which fence is later by simply using dma_fence_later().
   *
- * It is strongly discouraged to provide an external lock because this couples
- * lock and fence life time. This is only allowed for legacy use cases when
- * multiple fences need to be prevented from signaling out of order.
+ * New users MUST NOT use external locks. Check the documentation in
+ * dma_fence_init() to understand the motives behind the legacy use cases.
   */

 void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,