Re: [PATCH 1/3] dma-buf: dma-fence: Hot-fix timestamp misordering
From: Tvrtko Ursulin
Date: Fri Nov 27 2026 - 04:44:20 EST
On 26/11/2026 17:20, Philipp Stanner wrote:
fence timestamps can be written and read without any memory ordering
since, presumably, forever. This can cause real bugs, other than false
accounting, for parties whose algorithms depend on the timestamp.
Hot-fix the problem for now so that it can be backported until we found
a suitable way forward for mainline.
Cc: stable@xxxxxxxxxxxxxxx
Fixes: 76250f2b743b ("dma-buf/fence: Avoid use of uninitialised timestamp")
Signed-off-by: Philipp Stanner <phasta@xxxxxxxxxx>
---
drivers/dma-buf/dma-fence.c | 9 +++++++++
include/linux/dma-fence.h | 8 ++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index bd58688b81a7..8a842fc8168f 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -378,6 +378,15 @@ void dma_fence_signal_timestamp_locked(struct dma_fence *fence,
list_replace(&fence->cb_list, &cb_list);
fence->timestamp = timestamp;
+ /*
+ * TODO:
+ * This is a temporary hotfix to prevent misordering until we
+ * can completely remove the TIMESTAMP bit.
+ *
+ * The counterpart of this barrier are the test_bit_acquire()s in
+ * dma_fence_timestamp().
+ */
+ smp_mb__before_atomic();
set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
list_for_each_entry_safe(cur, tmp, &cb_list, node) {
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 64330bf52561..6b16095e8521 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -715,10 +715,14 @@ static inline void dma_fence_set_error(struct dma_fence *fence,
*/
static inline ktime_t dma_fence_timestamp(struct dma_fence *fence)
{
- if (WARN_ON(!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)))
+ /*
+ * The test_bit_acquire() calls order against the
+ * smp_mb__before_atomic() in dma_fence_signal_timestamp_locked().
+ */
+ if (WARN_ON(!test_bit_acquire(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)))
return ktime_get();
This one I think could stay as is since there is no point to have two barriers in sequence.
- while (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags))
+ while (!test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags))
cpu_relax();
return fence->timestamp;
The rest looks good to me.
I would also probably expand the commit message to actually explain what practical bugs and races the patch on its own fixes. Which would be all callers of dma_fence_timestamp, right? AFAIU they are all vulnerable to observing missing/torn timestamp on weakly ordered architectures.
Regards,
Tvrtko