summary refs log tree commit diff stats
path: root/include/qemu/seqlock.h
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-09-30 22:30:56 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2016-10-04 10:00:26 +0200
commitf96a8cc3c633b25d9269337408ae2417ebbbad8e (patch)
tree8d2f8fc029d7d988529bc0a4a2049d46b98cc045 /include/qemu/seqlock.h
parent550276ae0a88851edda2cb7fcdd64256dbb8e314 (diff)
downloadfocaccia-qemu-f96a8cc3c633b25d9269337408ae2417ebbbad8e.tar.gz
focaccia-qemu-f96a8cc3c633b25d9269337408ae2417ebbbad8e.zip
seqlock: use atomic writes for the sequence
There is a data race if the sequence is written concurrently to the
read.  In C11 this has undefined behavior.  Use atomic_set; the
read side is already using atomic_read.

Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20160930213106.20186-6-alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qemu/seqlock.h')
-rw-r--r--include/qemu/seqlock.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h
index 2e2be4c4f0..8dee11d101 100644
--- a/include/qemu/seqlock.h
+++ b/include/qemu/seqlock.h
@@ -31,7 +31,7 @@ static inline void seqlock_init(QemuSeqLock *sl)
 /* Lock out other writers and update the count.  */
 static inline void seqlock_write_begin(QemuSeqLock *sl)
 {
-    ++sl->sequence;
+    atomic_set(&sl->sequence, sl->sequence + 1);
 
     /* Write sequence before updating other fields.  */
     smp_wmb();
@@ -42,7 +42,7 @@ static inline void seqlock_write_end(QemuSeqLock *sl)
     /* Write other fields before finalizing sequence.  */
     smp_wmb();
 
-    ++sl->sequence;
+    atomic_set(&sl->sequence, sl->sequence + 1);
 }
 
 static inline unsigned seqlock_read_begin(QemuSeqLock *sl)