Skip to contentSkip to conversation

Fix a data race with goflag in rcutorture test

PATCH Superseded Vitalii Mordan 2 participants 2 messages Jan 22, 2025 – Jan 23, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix a data race with goflag in rcutorture test

This patch addresses a potential data race involving the global variable goflag in the rcutorture test. The issue is resolved by adding the atomic qualifier to ensure proper synchronization.

Fixes 8fda74a52b ("rcu: add rcutorture")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2750

---
 tests/unit/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/unit/rcutorture.c +1 -1
index 7662081683..c4971632f8 100644
@@ -70,7 +70,7 @@ int nthreadsrunning;
 #define GOFLAG_RUN  1
 #define GOFLAG_STOP 2
 
-static volatile int goflag = GOFLAG_INIT;
+static _Atomic int goflag = GOFLAG_INIT;
 
 #define RCU_READ_RUN 1000
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Vitalii Mordan

This patch addresses a potential data race involving the global variable goflag in the rcutorture test. The issue is resolved by adding the atomic qualifier to ensure proper synchronization.

Hello!

QEMU does not use _Atomic; in general, the C11 committee decision to default to sequentially consistent atomics is a bad idea and we prefer to annotate _accesses_ rather than _variables_ (yes, I'm aware that volatile has the same issue!).

Can you redo the patch to access goflag with qatomic_read and qatomic_set?

Paolo

Quoted 23 lines
Fixes 8fda74a52b ("rcu: add rcutorture")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2750

---
 tests/unit/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/unit/rcutorture.c +1 -2
index 7662081683..c4971632f8 100644
@@ -70,7 +70,7 @@ int nthreadsrunning;
 #define GOFLAG_RUN  1
 #define GOFLAG_STOP 2
 
-static volatile int goflag = GOFLAG_INIT;
+static _Atomic int goflag = GOFLAG_INIT;
 
 #define RCU_READ_RUN 1000
 
--

2.34.1