Received: from eggs.gnu.org ([2001:4830:134:3::10]:34317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTe-00042z-GL for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTc-00085x-U4 for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTc-00085s-Nt for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:28 -0400 From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:37 +0200 Message-Id: <1475859483-32234-14-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 13/39] seqlock: use atomic writes for the sequence List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= 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=C3=A9e Signed-off-by: Paolo Bonzini Signed-off-by: Alex Benn=C3=A9e Message-Id: <20160930213106.20186-6-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/seqlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); =20 /* 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(); =20 - ++sl->sequence; + atomic_set(&sl->sequence, sl->sequence + 1); } =20 static inline unsigned seqlock_read_begin(QemuSeqLock *sl) --=20 2.7.4