[PATCH 3/3] drm/amdgpu: Hot-fix timestamp misordering

From: Philipp Stanner

Date: Thu Nov 26 2026 - 12:21:41 EST


dma_fence timestamps could so far be written and read without any memory
ordering, a bug that presumably got overlooked because x86 is strongly
ordered.

Hot-fix amdgpu's manual timestamp evaluation until we found a more
suitable solution for mainline linux.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: af0b54167009 ("drm/amdgpu: Convert to common fdinfo format v5")
Signed-off-by: Philipp Stanner <phasta@xxxxxxxxxx>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 2f0349233695..415f23aa08a0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -177,11 +177,11 @@ static ktime_t amdgpu_ctx_fence_time(struct dma_fence *fence)

/* When the fence is not even scheduled it can't have spend time */
s_fence = to_drm_sched_fence(fence);
- if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->scheduled.flags))
+ if (!test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->scheduled.flags))
return ns_to_ktime(0);

/* When it is still running account how much already spend */
- if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->finished.flags))
+ if (!test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->finished.flags))
return ktime_sub(ktime_get(), s_fence->scheduled.timestamp);

return ktime_sub(s_fence->finished.timestamp,
--
2.56.0