All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, cota@braap.org
Subject: Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables
Date: Wed, 12 Oct 2016 09:44:17 +0100	[thread overview]
Message-ID: <87zimanehq.fsf@linaro.org> (raw)
In-Reply-To: <1476107947-31430-3-git-send-email-pbonzini@redhat.com>


Paolo Bonzini <pbonzini@redhat.com> writes:

> There is a data race if the variable is written concurrently to the
> read.  In C11 this has undefined behavior.  Use atomic_read.  The
> write side does not need atomic_set, because it is protected by a
> mutex.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  cpus.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index b2fbe33..3fc2f6e 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -170,7 +170,8 @@ int64_t cpu_get_icount_raw(void)
>  static int64_t cpu_get_icount_locked(void)
>  {
>      int64_t icount = cpu_get_icount_raw();
> -    return timers_state.qemu_icount_bias + cpu_icount_to_ns(icount);
> +    int64_t ns = cpu_icount_to_ns(icount);
> +    return atomic_read(&timers_state.qemu_icount_bias) + ns;
>  }
>
>  int64_t cpu_get_icount(void)
> @@ -206,7 +207,7 @@ int64_t cpu_get_ticks(void)
>      }
>
>      ticks = timers_state.cpu_ticks_offset;
> -    if (timers_state.cpu_ticks_enabled) {
> +    if (atomic_read(&timers_state.cpu_ticks_enabled)) {
>          ticks += cpu_get_host_ticks();
>      }
>
> @@ -225,8 +226,8 @@ static int64_t cpu_get_clock_locked(void)
>  {
>      int64_t time;
>
> -    time = timers_state.cpu_clock_offset;
> -    if (timers_state.cpu_ticks_enabled) {
> +    time = atomic_read(&timers_state.cpu_clock_offset);
> +    if (atomic_read(&timers_state.cpu_ticks_enabled)) {
>          time += get_clock();
>      }


--
Alex Bennée

  reply	other threads:[~2016-10-12  8:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 13:59 [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 1/5] atomic: introduce smp_mb_acquire and smp_mb_release Paolo Bonzini
2016-10-10 15:29   ` Eric Blake
2016-10-10 16:38     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables Paolo Bonzini
2016-10-12  8:44   ` Alex Bennée [this message]
2016-10-13 19:20   ` Emilio G. Cota
2016-10-13 20:45     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 3/5] qemu-thread: use acquire/release to clarify semantics of QemuEvent Paolo Bonzini
2016-10-12  9:21   ` Alex Bennée
2016-10-12  9:31     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 4/5] rcu: simplify memory barriers Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release Paolo Bonzini
2016-10-12  9:28   ` Alex Bennée
2016-10-12  9:30     ` Paolo Bonzini
2016-10-20 18:36   ` Pranith Kumar
2016-10-10 16:53 ` [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements no-reply
2016-10-11 19:21 ` no-reply
2016-10-12 11:32 ` Alex Bennée
2016-10-12 11:34   ` Paolo Bonzini
2016-10-12 22:45 ` Emilio G. Cota
2016-10-13  7:39   ` Paolo Bonzini
2016-10-13 19:29     ` Emilio G. Cota
2016-10-14  9:55       ` Paolo Bonzini
2016-10-21 17:38 ` Alex Bennée
2016-10-22  9:10   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zimanehq.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=cota@braap.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.