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 the scheduler's manual timestamp evaluation until we found a
more suitable solution for mainline linux.

Cc: [email protected]
Fixes: f7fe64ad0f22 ("drm/sched: Split free_job into own work item")
Signed-off-by: Philipp Stanner <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c
index 99252674e266..3d26a48ff1c3 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -928,8 +928,16 @@ drm_sched_get_finished_job(struct drm_gpu_scheduler *sched)
                next = list_first_entry_or_null(&sched->pending_list,
                                                typeof(*next), list);
                if (next) {
-                       /* make the scheduled timestamp more accurate */
-                       if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
+                       /* Make the scheduled timestamp more accurate.
+                        *
+                        * TODO
+                        * The test_bit_acquire() is a hotfix against timestamp
+                        * misordering. Replace it with something better.
+                        *
+                        * The counter-part of the barrier is located in
+                        * dma_fence_signal_timestamp_locked().
+                        */
+                       if (test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT,
                                     &next->s_fence->scheduled.flags))
                                next->s_fence->scheduled.timestamp =
                                        
dma_fence_timestamp(&job->s_fence->finished);
-- 
2.56.0

Reply via email to