* [RFC PATCH 1/8] dma-buf: dma-fence: Hot-fix timestamp misordering
[not found] <20261127101812.2706432-2-phasta@kernel.org>
@ 2026-11-27 10:18 ` Philipp Stanner
2026-11-27 10:18 ` [RFC PATCH 2/8] drm/sched: " Philipp Stanner
1 sibling, 0 replies; 2+ messages in thread
From: Philipp Stanner @ 2026-11-27 10:18 UTC (permalink / raw)
To: Sumit Semwal, Christian König, Philipp Stanner, Alex Deucher,
David Airlie, Simona Vetter, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, Matthew Brost, Danilo Krummrich,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Mario Limonciello (AMD), Ruslan Vagner, Gustavo Padovan,
Chris Wilson
Cc: linux-media, dri-devel, linux-kernel, amd-gfx, intel-gfx, stable
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@vger.kernel.org
Fixes: 76250f2b743b ("dma-buf/fence: Avoid use of uninitialised timestamp")
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
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 ab02afdb0f18..c947aec1bf91 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 513d9dbbff47..29c4332c8662 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -686,10 +686,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();
- 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;
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [RFC PATCH 2/8] drm/sched: Hot-fix timestamp misordering
[not found] <20261127101812.2706432-2-phasta@kernel.org>
2026-11-27 10:18 ` [RFC PATCH 1/8] dma-buf: dma-fence: Hot-fix timestamp misordering Philipp Stanner
@ 2026-11-27 10:18 ` Philipp Stanner
1 sibling, 0 replies; 2+ messages in thread
From: Philipp Stanner @ 2026-11-27 10:18 UTC (permalink / raw)
To: Sumit Semwal, Christian König, Philipp Stanner, Alex Deucher,
David Airlie, Simona Vetter, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, Matthew Brost, Danilo Krummrich,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Mario Limonciello (AMD), Ruslan Vagner, Gustavo Padovan,
Chris Wilson
Cc: linux-media, dri-devel, linux-kernel, amd-gfx, intel-gfx, stable
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: stable@vger.kernel.org
Fixes: f7fe64ad0f22 ("drm/sched: Split free_job into own work item")
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
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 85a49e219837..44553db9b04c 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 10:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261127101812.2706432-2-phasta@kernel.org>
2026-11-27 10:18 ` [RFC PATCH 1/8] dma-buf: dma-fence: Hot-fix timestamp misordering Philipp Stanner
2026-11-27 10:18 ` [RFC PATCH 2/8] drm/sched: " Philipp Stanner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox