From: Peter Zijlstra <peterz@infradead.org>
To: Minfei Huang <mnghuan@gmail.com>
Cc: bp@suse.de, pbonzini@redhat.com, luto@kernel.org, hpa@zytor.com,
mingo@redhat.com, tglx@linutronix.de, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3 V2] pvclock: Get rid of __pvclock_read_cycles in function pvclock_read_flags
Date: Thu, 9 Jun 2016 14:24:04 +0200 [thread overview]
Message-ID: <20160609122404.GB30927@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20160609121603.GB30935@twins.programming.kicks-ass.net>
On Thu, Jun 09, 2016 at 02:16:03PM +0200, Peter Zijlstra wrote:
> What's wrong with:
>
> u8 flags = READ_ONCE(src->flags);
>
> ?
>
> (and have the flags store be done using WRITE_ONCE() of course).
>
> Sure, if your total state is larger than one word you need the
> seqcount for integrity, but reading _one_ byte, shees.
Something like so; although given that I've never seen this code before
I can easily have missed an update site.
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index 99bfc025111d..7a4bf59aa929 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -60,15 +60,7 @@ void pvclock_resume(void)
u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
{
- unsigned version;
- cycle_t ret;
- u8 flags;
-
- do {
- version = __pvclock_read_cycles(src, &ret, &flags);
- } while ((src->version & 1) || version != src->version);
-
- return flags & valid_flags;
+ return READ_ONCE(src->flags) & valid_flags;
}
cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
@@ -83,7 +75,8 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
} while ((src->version & 1) || version != src->version);
if (unlikely((flags & PVCLOCK_GUEST_STOPPED) != 0)) {
- src->flags &= ~PVCLOCK_GUEST_STOPPED;
+ flags &= ~PVCLOCK_GUEST_STOPPED;
+ WRITE_ONCE(src->flags, flags);
pvclock_touch_watchdogs();
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1ba3b7d3cae9..54458acce4f5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1832,7 +1832,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
if (use_master_clock)
pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
- vcpu->hv_clock.flags = pvclock_flags;
+ WRITE_ONCE(vcpu->hv_clock.flags, pvclock_flags);
trace_kvm_pvclock_update(v->vcpu_id, &vcpu->hv_clock);
next prev parent reply other threads:[~2016-06-09 12:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-27 6:17 [PATCH 1/3] pvclock: Add CPU barries to get correct version value Minfei Huang
2016-05-27 6:17 ` [PATCH 2/3] pvclock: Cleanup to remove function pvclock_get_nsec_offset Minfei Huang
2016-05-27 15:40 ` Andy Lutomirski
2016-05-27 6:17 ` [PATCH 3/3] pvclock: Add a new wrapper function to only get variable flags Minfei Huang
2016-05-27 15:40 ` Andy Lutomirski
2016-05-27 16:06 ` Paolo Bonzini
2016-05-28 12:02 ` Minfei Huang
2016-05-28 12:27 ` [PATCH 3/3 V2] pvclock: Get rid of __pvclock_read_cycles in function pvclock_read_flags Minfei Huang
2016-06-07 13:16 ` Minfei Huang
2016-06-09 11:17 ` Paolo Bonzini
2016-06-08 8:17 ` Borislav Petkov
2016-06-09 11:21 ` Paolo Bonzini
2016-06-09 11:28 ` Borislav Petkov
2016-06-09 12:31 ` Paolo Bonzini
2016-06-12 11:46 ` Minfei Huang
2016-06-09 12:16 ` Peter Zijlstra
2016-06-09 12:24 ` Peter Zijlstra [this message]
2016-06-09 12:26 ` Paolo Bonzini
2016-06-09 12:35 ` Peter Zijlstra
2016-05-27 15:39 ` [PATCH 1/3] pvclock: Add CPU barries to get correct version value Andy Lutomirski
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=20160609122404.GB30927@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=mnghuan@gmail.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®