From: Philipp Stanner <phasta@kernel.org>
To: "Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Matthew Brost" <matthew.brost@intel.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
"Mario Limonciello (AMD)" <superm1@kernel.org>,
"Aurabindo Pillai" <aurabindo.pillai@amd.com>,
"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
"Gustavo Padovan" <gustavo.padovan@collabora.com>,
"Chris Wilson" <chris@chris-wilson.co.uk>,
"Luben Tuikov" <ltuikov89@gmail.com>,
"Shashank Sharma" <shashank.sharma@amd.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
"Gary Guo" <gary@garyguo.net>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org,
stable@vger.kernel.org
Subject: [PATCH 1/3] dma-buf: dma-fence: Hot-fix timestamp misordering
Date: Thu, 26 Nov 2026 18:20:45 +0100 [thread overview]
Message-ID: <20261126172046.2473303-3-phasta@kernel.org> (raw)
In-Reply-To: <20261126172046.2473303-2-phasta@kernel.org>
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 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();
- 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
next prev parent reply other threads:[~2026-11-26 17:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 17:20 [PATCH 0/3] dma-fence: Properly order timestamps Philipp Stanner
2026-11-26 17:20 ` Philipp Stanner [this message]
2026-11-26 17:20 ` [PATCH 2/3] drm/sched: Hot-fix timestamp misordering Philipp Stanner
2026-11-26 17:20 ` [PATCH 3/3] drm/amdgpu: " Philipp Stanner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126172046.2473303-3-phasta@kernel.org \
--to=phasta@kernel.org \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=aurabindo.pillai@amd.com \
--cc=chris@chris-wilson.co.uk \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=gustavo.padovan@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=ltuikov89@gmail.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=paulmck@kernel.org \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=shashank.sharma@amd.com \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=superm1@kernel.org \
--cc=tvrtko.ursulin@igalia.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox