From: Paolo Bonzini Date: Fri, 30 Sep 2016 21:30:56 +0000 (+0100) Subject: seqlock: use atomic writes for the sequence X-Git-Tag: TizenStudio_2.0_p2.3.2~9^2~14^2~5^2~139^2~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f96a8cc3c633b25d9269337408ae2417ebbbad8e;p=sdk%2Femulator%2Fqemu.git 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 Signed-off-by: Paolo Bonzini Signed-off-by: Alex Bennée Message-Id: <20160930213106.20186-6-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h index 2e2be4c..8dee11d 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)