Skip to contentSkip to conversation

dma-fence: Remove 64-bit flag

RFC PATCH In review Philipp Stanner 4 participants 5 messages Oct 17, 2025 – Oct 27, 2025

Subsystems (3)
lore
Share & tools
lore

Philipp Stanner

author maintainer
#0 lore raw

RFC PATCH 1/1 dma-fence: Remove 64-bit flag

It seems that DMA_FENCE_FLAG_SEQNO64_BIT has no real effects anymore, since seqno is a u64 everywhere.

Remove the unneeded flag.

---
Seems to me that this flag doesn't really do anything anymore?

I *suspect* that it could be that some drivers pass a u32 to dma_fence_init()? I guess they could be ported, couldn't they.

P.

---
 drivers/dma-buf/dma-fence.c |  3 +--
 include/linux/dma-fence.h   | 10 +---------
 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-fence.c +1 -2
index 3f78c56b58dc..24794c027813 100644
@@ -1078,8 +1078,7 @@ void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
 		 spinlock_t *lock, u64 context, u64 seqno)
 {
-	__dma_fence_init(fence, ops, lock, context, seqno,
-			 BIT(DMA_FENCE_FLAG_SEQNO64_BIT));
+	__dma_fence_init(fence, ops, lock, context, seqno, 0);
 }
 EXPORT_SYMBOL(dma_fence_init64);
 
include/linux/dma-fence.h +1 -9
index 64639e104110..4eca2db28625 100644
@@ -98,7 +98,6 @@ struct dma_fence {
 };
 
 enum dma_fence_flag_bits {
-	DMA_FENCE_FLAG_SEQNO64_BIT,
 	DMA_FENCE_FLAG_SIGNALED_BIT,
 	DMA_FENCE_FLAG_TIMESTAMP_BIT,
 	DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
@@ -470,14 +469,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
  */
 static inline bool __dma_fence_is_later(struct dma_fence *fence, u64 f1, u64 f2)
 {
-	/* This is for backward compatibility with drivers which can only handle
-	 * 32bit sequence numbers. Use a 64bit compare when the driver says to
-	 * do so.
-	 */
-	if (test_bit(DMA_FENCE_FLAG_SEQNO64_BIT, &fence->flags))
-		return f1 > f2;
-
-	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
+	return f1 > f2;
 }
 
 /**
Signature · 1 line
2.49.0
#1 lore raw
Quoted 12 lines · Philipp Stanner

It seems that DMA_FENCE_FLAG_SEQNO64_BIT has no real effects anymore, since seqno is a u64 everywhere.

Remove the unneeded flag.

---
Seems to me that this flag doesn't really do anything anymore?

I *suspect* that it could be that some drivers pass a u32 to dma_fence_init()? I guess they could be ported, couldn't they.

Xe uses 32-bit hardware fence sequence numbers—see [1] and [2]. We could switch to 64-bit hardware fence sequence numbers, but that would require changes on the driver side. If you sent this to our CI, I’m fairly certain we’d see a bunch of failures. I suspect this would also break several other drivers.

As I mentioned, all Xe-supported platforms could be updated since their rings support 64-bit store instructions. However, I suspect that very old i915 platforms don’t support such instructions in the ring. I agree this is a legacy issue, and we should probably use 64-bit sequence numbers in Xe. But again, platforms and drivers that are decades old might break as a result.

Matt

[1] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence.c#L264
[2] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence_types.h#L51

Quoted 51 lines

P.

---
 drivers/dma-buf/dma-fence.c |  3 +--
 include/linux/dma-fence.h   | 10 +---------
 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-fence.c +1 -2
index 3f78c56b58dc..24794c027813 100644
@@ -1078,8 +1078,7 @@ void
 dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
 		 spinlock_t *lock, u64 context, u64 seqno)
 {
-	__dma_fence_init(fence, ops, lock, context, seqno,
-			 BIT(DMA_FENCE_FLAG_SEQNO64_BIT));
+	__dma_fence_init(fence, ops, lock, context, seqno, 0);
 }
 EXPORT_SYMBOL(dma_fence_init64);
 
include/linux/dma-fence.h +1 -9
index 64639e104110..4eca2db28625 100644
@@ -98,7 +98,6 @@ struct dma_fence {
 };
 
 enum dma_fence_flag_bits {
-	DMA_FENCE_FLAG_SEQNO64_BIT,
 	DMA_FENCE_FLAG_SIGNALED_BIT,
 	DMA_FENCE_FLAG_TIMESTAMP_BIT,
 	DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
@@ -470,14 +469,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
  */
 static inline bool __dma_fence_is_later(struct dma_fence *fence, u64 f1, u64 f2)
 {
-	/* This is for backward compatibility with drivers which can only handle
-	 * 32bit sequence numbers. Use a 64bit compare when the driver says to
-	 * do so.
-	 */
-	if (test_bit(DMA_FENCE_FLAG_SEQNO64_BIT, &fence->flags))
-		return f1 > f2;
-
-	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
+	return f1 > f2;
 }
 
 /**
Signature · 1 line
2.49.0
#2 lore raw
Quoted 14 lines · Matthew Brost
Quoted 12 lines · Philipp Stanner

It seems that DMA_FENCE_FLAG_SEQNO64_BIT has no real effects anymore, since seqno is a u64 everywhere.

Remove the unneeded flag.

---
Seems to me that this flag doesn't really do anything anymore?

I *suspect* that it could be that some drivers pass a u32 to dma_fence_init()? I guess they could be ported, couldn't they.

Quoted 5 lines

Xe uses 32-bit hardware fence sequence numbers—see [1] and [2]. We could switch to 64-bit hardware fence sequence numbers, but that would require changes on the driver side. If you sent this to our CI, I’m fairly certain we’d see a bunch of failures. I suspect this would also break several other drivers.

What exactly breaks? Help me out here; if you pass a u32 for a u64, doesn't the C standard guarantee that the higher, unused 32 bits will be 0?

Because the only thing the flag still does is do this lower_32 check in fence_is_later.

P.

Quoted 64 lines

As I mentioned, all Xe-supported platforms could be updated since their rings support 64-bit store instructions. However, I suspect that very old i915 platforms don’t support such instructions in the ring. I agree this is a legacy issue, and we should probably use 64-bit sequence numbers in Xe. But again, platforms and drivers that are decades old might break as a result.

Matt

[1] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence.c#L264
[2] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence_types.h#L51

Quoted 51 lines

P.
---
 drivers/dma-buf/dma-fence.c |  3 +--
 include/linux/dma-fence.h   | 10 +---------

 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-fence.c +1 -2
index 3f78c56b58dc..24794c027813 100644
@@ -1078,8 +1078,7 @@ void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
  		 spinlock_t *lock, u64 context, u64 seqno)
  {
-	__dma_fence_init(fence, ops, lock, context, seqno,
-			 BIT(DMA_FENCE_FLAG_SEQNO64_BIT));
+	__dma_fence_init(fence, ops, lock, context, seqno, 0);
  }
  EXPORT_SYMBOL(dma_fence_init64);

include/linux/dma-fence.h +0 -0
index 64639e104110..4eca2db28625 100644
@@ -98,7 +98,6 @@ struct dma_fence {
  };


 enum dma_fence_flag_bits {

include/linux/dma-fence.h +0 -1
-	DMA_FENCE_FLAG_SEQNO64_BIT,

  DMA_FENCE_FLAG_SIGNALED_BIT,
  DMA_FENCE_FLAG_TIMESTAMP_BIT,
  DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,

include/linux/dma-fence.h +1 -8
@@ -470,14 +469,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
   */
  static inline bool __dma_fence_is_later(struct dma_fence *fence, u64 f1, u64 f2)
  {
-	/* This is for backward compatibility with drivers which can only handle
-	 * 32bit sequence numbers. Use a 64bit compare when the driver says to
-	 * do so.
-	 */
-	if (test_bit(DMA_FENCE_FLAG_SEQNO64_BIT, &fence->flags))
-		return f1 > f2;
-
-	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
+	return f1 > f2;
  }


 /**

Signature · 1 line
2.49.0
#3 lore raw
Quoted 15 lines · Philipp Stanner
Quoted 14 lines · Matthew Brost
Quoted 12 lines · Philipp Stanner

It seems that DMA_FENCE_FLAG_SEQNO64_BIT has no real effects anymore, since seqno is a u64 everywhere.

Remove the unneeded flag.

---
Seems to me that this flag doesn't really do anything anymore?

I *suspect* that it could be that some drivers pass a u32 to dma_fence_init()? I guess they could be ported, couldn't they.

Quoted 7 lines
Quoted 5 lines

Xe uses 32-bit hardware fence sequence numbers—see [1] and [2]. We could switch to 64-bit hardware fence sequence numbers, but that would require changes on the driver side. If you sent this to our CI, I’m fairly certain we’d see a bunch of failures. I suspect this would also break several other drivers.

What exactly breaks? Help me out here; if you pass a u32 for a u64,

Seqno wraps.

Quoted 2 lines

doesn't the C standard guarantee that the higher, unused 32 bits will be 0?

	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;

Look at the above logic.

f1 = 0x0;
f2 = 0xffffffff; /* -1 */

The above statement will correctly return true.

Compared to the below statement which returns false.

	return f1 > f2;

We test seqno wraps in Xe by setting our initial seqno to -127, again if you send this patch to our CI any test which sends more than 127 job on queue will likely fail.

Matt

Quoted 71 lines

Because the only thing the flag still does is do this lower_32 check in fence_is_later.

P.

Quoted 64 lines

As I mentioned, all Xe-supported platforms could be updated since their rings support 64-bit store instructions. However, I suspect that very old i915 platforms don’t support such instructions in the ring. I agree this is a legacy issue, and we should probably use 64-bit sequence numbers in Xe. But again, platforms and drivers that are decades old might break as a result.

Matt

[1] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence.c#L264
[2] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence_types.h#L51

Quoted 51 lines

P.
---
 drivers/dma-buf/dma-fence.c |  3 +--
 include/linux/dma-fence.h   | 10 +---------

 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-fence.c +1 -2
index 3f78c56b58dc..24794c027813 100644
@@ -1078,8 +1078,7 @@ void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
  		 spinlock_t *lock, u64 context, u64 seqno)
  {
-	__dma_fence_init(fence, ops, lock, context, seqno,
-			 BIT(DMA_FENCE_FLAG_SEQNO64_BIT));
+	__dma_fence_init(fence, ops, lock, context, seqno, 0);
  }
  EXPORT_SYMBOL(dma_fence_init64);

include/linux/dma-fence.h +0 -0
index 64639e104110..4eca2db28625 100644
@@ -98,7 +98,6 @@ struct dma_fence {
  };


 enum dma_fence_flag_bits {

include/linux/dma-fence.h +0 -1
-	DMA_FENCE_FLAG_SEQNO64_BIT,

  DMA_FENCE_FLAG_SIGNALED_BIT,
  DMA_FENCE_FLAG_TIMESTAMP_BIT,
  DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,

include/linux/dma-fence.h +1 -8
@@ -470,14 +469,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
   */
  static inline bool __dma_fence_is_later(struct dma_fence *fence, u64 f1, u64 f2)
  {
-	/* This is for backward compatibility with drivers which can only handle
-	 * 32bit sequence numbers. Use a 64bit compare when the driver says to
-	 * do so.
-	 */
-	if (test_bit(DMA_FENCE_FLAG_SEQNO64_BIT, &fence->flags))
-		return f1 > f2;
-
-	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
+	return f1 > f2;
  }


 /**

Signature · 1 line
2.49.0
maintainer
#4 lore raw
Quoted 38 lines · Matthew Brost
Quoted 15 lines · Philipp Stanner
Quoted 14 lines · Matthew Brost
Quoted 12 lines · Philipp Stanner

It seems that DMA_FENCE_FLAG_SEQNO64_BIT has no real effects anymore, since seqno is a u64 everywhere.

Remove the unneeded flag.

---
Seems to me that this flag doesn't really do anything anymore?

I *suspect* that it could be that some drivers pass a u32 to dma_fence_init()? I guess they could be ported, couldn't they.

Quoted 7 lines
Quoted 5 lines

Xe uses 32-bit hardware fence sequence numbers—see [1] and [2]. We could switch to 64-bit hardware fence sequence numbers, but that would require changes on the driver side. If you sent this to our CI, I’m fairly certain we’d see a bunch of failures. I suspect this would also break several other drivers.

What exactly breaks? Help me out here; if you pass a u32 for a u64,

Seqno wraps.

Quoted 2 lines

doesn't the C standard guarantee that the higher, unused 32 bits will be 0?

	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;

Look at the above logic.

f1 = 0x0;
f2 = 0xffffffff; /* -1 */

The above statement will correctly return true.

Quoted 7 lines

Compared to the below statement which returns false.

	return f1 > f2;

We test seqno wraps in Xe by setting our initial seqno to -127, again if you send this patch to our CI any test which sends more than 127 job on queue will likely fail.

Yeah, exactly that's why this flag is needed for quite a lot of things.

Question is what is missing in the documentation to make that clear?

Regards,
Christian.

Quoted 74 lines

Matt

Quoted 71 lines

Because the only thing the flag still does is do this lower_32 check in fence_is_later.

P.

Quoted 64 lines

As I mentioned, all Xe-supported platforms could be updated since their rings support 64-bit store instructions. However, I suspect that very old i915 platforms don’t support such instructions in the ring. I agree this is a legacy issue, and we should probably use 64-bit sequence numbers in Xe. But again, platforms and drivers that are decades old might break as a result.

Matt

[1] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence.c#L264
[2] https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/xe/xe_hw_fence_types.h#L51

Quoted 51 lines

P.
---
 drivers/dma-buf/dma-fence.c |  3 +--
 include/linux/dma-fence.h   | 10 +---------

 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-fence.c +1 -2
index 3f78c56b58dc..24794c027813 100644
@@ -1078,8 +1078,7 @@ void
  dma_fence_init64(struct dma_fence *fence, const struct dma_fence_ops *ops,
  		 spinlock_t *lock, u64 context, u64 seqno)
  {
-	__dma_fence_init(fence, ops, lock, context, seqno,
-			 BIT(DMA_FENCE_FLAG_SEQNO64_BIT));
+	__dma_fence_init(fence, ops, lock, context, seqno, 0);
  }
  EXPORT_SYMBOL(dma_fence_init64);

include/linux/dma-fence.h +0 -0
index 64639e104110..4eca2db28625 100644
@@ -98,7 +98,6 @@ struct dma_fence {
  };


 enum dma_fence_flag_bits {

include/linux/dma-fence.h +0 -1
-	DMA_FENCE_FLAG_SEQNO64_BIT,

  DMA_FENCE_FLAG_SIGNALED_BIT,
  DMA_FENCE_FLAG_TIMESTAMP_BIT,
  DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,

include/linux/dma-fence.h +1 -8
@@ -470,14 +469,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
   */
  static inline bool __dma_fence_is_later(struct dma_fence *fence, u64 f1, u64 f2)
  {
-	/* This is for backward compatibility with drivers which can only handle
-	 * 32bit sequence numbers. Use a 64bit compare when the driver says to
-	 * do so.
-	 */
-	if (test_bit(DMA_FENCE_FLAG_SEQNO64_BIT, &fence->flags))
-		return f1 > f2;
-
-	return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
+	return f1 > f2;
  }


 /**

Signature · 1 line
2.49.0