[PATCH] lib/xe/spin: Use READ_ONCE, WRITE_ONCE macros in Xe spin library

Matthew Brost matthew.brost at intel.com
Wed Apr 16 16:10:25 UTC 2025


Without the READ_ONCE macro is xe_spin_started(), a compiler may choose
to read the value of spin->start exactly once rather than every call of
xe_spin_started(). If the initial read is before the GPU batch execution
flips spin->start to a non-zero value, the test will hang forever. This
was shown on Chrome.

For uniformity, update xe_spin_end to use WRITE_ONCE too.

Signed-off-by: Matthew Brost <matthew.brost at intel.com>
---
 lib/xe/xe_spin.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c
index 0de0b1f2e9..65c29284aa 100644
--- a/lib/xe/xe_spin.c
+++ b/lib/xe/xe_spin.c
@@ -145,7 +145,7 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
  */
 bool xe_spin_started(struct xe_spin *spin)
 {
-	return spin->start != 0;
+	return READ_ONCE(spin->start) != 0;
 }
 
 /**
@@ -162,7 +162,7 @@ void xe_spin_wait_started(struct xe_spin *spin)
 
 void xe_spin_end(struct xe_spin *spin)
 {
-	spin->end = 0;
+	WRITE_ONCE(spin->end, 0);
 }
 
 /**
-- 
2.34.1



More information about the igt-dev mailing list