Commit f96a8cc3 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

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: default avatarAlex Bennée <alex.bennee@linaro.org>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarAlex Bennée <alex.bennee@linaro.org>
Message-Id: <20160930213106.20186-6-alex.bennee@linaro.org>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 550276ae
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)