linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] pvclock: Add CPU barries to get correct version value
@ 2016-05-27  6:17 Minfei Huang
  2016-05-27  6:17 ` [PATCH 2/3] pvclock: Cleanup to remove function pvclock_get_nsec_offset Minfei Huang
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Minfei Huang @ 2016-05-27  6:17 UTC (permalink / raw)
  To: bp, pbonzini, luto, hpa, mingo, tglx; +Cc: x86, linux-kernel, Minfei Huang

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

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-06-12 11:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).