lib/xe/spin: Use READ_ONCE, WRITE_ONCE macros in Xe spin library
PATCH 1/1 lib/xe/spin: Use READ_ONCE, WRITE_ONCE macros in Xe spin library
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.
--- lib/xe/xe_spin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/xe/xe_spin.c +2 -2
@@ -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 ); }/**
Signature · 1 line
2.34.1
Quoted 27 lines · Matthew Brost
Without the
READ_ONCEmacro isxe_spin_started(), a compiler may choose to read the value ofspin->startexactly once rather than every call ofxe_spin_started(). If the initial read is before the GPU batch execution flipsspin->startto a non-zero value, the test will hang forever. This was shown on Chrome.For uniformity, update
xe_spin_endto useWRITE_ONCEtoo.Signed-off-by Matthew Brost <[email protected]>--- lib/xe/xe_spin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/xe/xe_spin.c +1
-1@@ -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 ; }/**
lib/xe/xe_spin.c void xe_spin_wait_started(struct xe_spin *spin) · line 168
Quoted 8 lines
lib/xe/xe_spin.c +1
-1@@ -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 ); }/**
Patchwork
CI✗ Fi.CI.BAT: failure for lib/xe/spin: Use READ_ONCE, WRITE_ONCE macros in Xe spin library
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: lib/xe/spin: Use READ_ONCE, WRITE_ONCE macros in Xe spin library
URL : https://patchwork.freedesktop.org/series/147841/
State : failure
== Summary ==
Series 147841 revision 1 was fully merged or fully failed: no git log
Quoted 18 lines · Matthew Brost
Without the
READ_ONCEmacro isxe_spin_started(), a compiler may choose to read the value ofspin->startexactly once rather than every call ofxe_spin_started(). If the initial read is before the GPU batch execution flipsspin->startto a non-zero value, the test will hang forever. This was shown on Chrome.For uniformity, update
xe_spin_endto useWRITE_ONCEtoo.Signed-off-by Matthew Brost <[email protected]>--- lib/xe/xe_spin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/xe/xe_spin.c +0
-0
lib/xe/xe_spin.c void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts) · line 148
Quoted 5 lines
lib/xe/xe_spin.c +1
-1@@ -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 ;
For dynamic libries in userspace compiler won't optimize the read if function is extern. I had a discussion about it with Lucas some time ago.
Where's the case you observe invalid behavior of this?
--
Zbigniew
Quoted 15 lines
lib/xe/xe_spin.c +1
-1}/** @@ -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 ); }/** Signature · 1 line
2.34.1
Quoted 5 lines · Matthew Brost
Without the
READ_ONCEmacro isxe_spin_started(), a compiler may choose to read the value ofspin->startexactly once rather than every call ofxe_spin_started(). If the initial read is before the GPU batch execution flipsspin->startto a non-zero value, the test will hang forever. This was shown on Chrome.
I missed this explanation about Chrome. May you point out the affected code? I'm really curious about how it looks like.
--
Zbigniew
Quoted 33 lines
For uniformity, update
xe_spin_endto useWRITE_ONCEtoo.Signed-off-by Matthew Brost <[email protected]>--- lib/xe/xe_spin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/xe/xe_spin.c +2
-2@@ -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 ); }/** Signature · 1 line
2.34.1