Received: from eggs.gnu.org ([2001:4830:134:3::10]:59144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn650-0006ns-AU for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:38:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn64v-0005mb-Bq for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:38:29 -0400 Received: from mail-yw0-x241.google.com ([2607:f8b0:4002:c05::241]:34514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn64v-0005mS-68 for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:38:25 -0400 Received: by mail-yw0-x241.google.com with SMTP id t67so4869963ywg.1 for ; Thu, 22 Sep 2016 08:38:25 -0700 (PDT) Sender: Richard Henderson References: <20160922101316.13064-1-alex.bennee@linaro.org> <20160922101316.13064-5-alex.bennee@linaro.org> From: Richard Henderson Message-ID: Date: Thu, 22 Sep 2016 08:38:21 -0700 MIME-Version: 1.0 In-Reply-To: <20160922101316.13064-5-alex.bennee@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2 4/9] seqlock: use atomic writes for the sequence List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , qemu-devel@nongnu.org, pbonzini@redhat.com, cota@braap.org, stefanha@redhat.com, kwolf@redhat.com Cc: mttcg@greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com, mark.burton@greensocs.com, jan.kiszka@siemens.com, serge.fdrv@gmail.com, peter.maydell@linaro.org, claudio.fontana@huawei.com On 09/22/2016 03:13 AM, Alex Bennée wrote: > From: Paolo Bonzini > > 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 > --- > 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); The read side isn't using a atomic_read right here. This appears to be tsan silliness to me. r~