From: Minfei Huang <mnghuan@gmail.com>
To: bp@suse.de, pbonzini@redhat.com, luto@kernel.org, hpa@zytor.com,
mingo@redhat.com, tglx@linutronix.de
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Minfei Huang <mnghuan@gmail.com>
Subject: [PATCH 1/3] pvclock: Add CPU barries to get correct version value
Date: Fri, 27 May 2016 14:17:10 +0800 [thread overview]
Message-ID: <1464329832-4638-1-git-send-email-mnghuan@gmail.com> (raw)
Protocol for the "version" fields is: hypervisor raises it (making it
uneven) before it starts updating the fields and raises it again (making
it even) when it is done. Thus the guest can make sure the time values
it got are consistent by checking the version before and after reading
them.
Add CPU barries after getting version value just like what function
vread_pvclock does, because all of callees in this function is inline.
Signed-off-by: Minfei Huang <mnghuan@gmail.com>
---
arch/x86/include/asm/pvclock.h | 2 ++
arch/x86/kernel/pvclock.c | 4 ++++
2 files changed, 6 insertions(+)
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index fdcc040..538ae94 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -85,6 +85,8 @@ unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src,
u8 ret_flags;
version = src->version;
+ /* Make the latest version visible */
+ smp_rmb();
offset = pvclock_get_nsec_offset(src);
ret = src->system_time + offset;
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index 99bfc02..7f82fe0 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -66,6 +66,8 @@ u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
do {
version = __pvclock_read_cycles(src, &ret, &flags);
+ /* Make sure that the version double-check is last. */
+ smp_rmb();
} while ((src->version & 1) || version != src->version);
return flags & valid_flags;
@@ -80,6 +82,8 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
do {
version = __pvclock_read_cycles(src, &ret, &flags);
+ /* Make sure that the version double-check is last. */
+ smp_rmb();
} while ((src->version & 1) || version != src->version);
if (unlikely((flags & PVCLOCK_GUEST_STOPPED) != 0)) {
--
2.6.3
next reply other threads:[~2016-05-27 6:17 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-27 6:17 Minfei Huang [this message]
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
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=1464329832-4638-1-git-send-email-mnghuan@gmail.com \
--to=mnghuan@gmail.com \
--cc=bp@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.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;
as well as URLs for NNTP newsgroup(s).