On 12/1/26 10:17, Philipp Stanner wrote: > 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. > > The current misordering allows for the bit DMA_FENCE_FLAG_TIMESTAMP_BIT > to be read as true before the union containing the timestamp actually > gets the timestamp set. Thus, amdgpu could interpret the list-head > pointer in the union as a timestamp value by accident. > > Fix amdgpu's manual timestamp evaluation with test_bit_acquire(). > > Cc: [email protected] > Fixes: af0b54167009 ("drm/amdgpu: Convert to common fdinfo format v5") > Signed-off-by: Philipp Stanner <[email protected]> > Reviewed-by: Tvrtko Ursulin <[email protected]> > --- > 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))
That one looks unnecessary to me because we don't really care about the timestamp value. Christian. > 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,
