Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1407837 > unrolled thread

[PATCH 1/3] pvclock: Add CPU barries to get correct version value

Started byMinfei Huang <mnghuan@gmail.com>
First post2016-05-27 08:20 +0200
Last post2016-05-27 17:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/3] pvclock: Add CPU barries to get correct version value Minfei Huang <mnghuan@gmail.com> - 2016-05-27 08:20 +0200
    Re: [PATCH 1/3] pvclock: Add CPU barries to get correct version value Andy Lutomirski <luto@amacapital.net> - 2016-05-27 17:50 +0200

#1407837 — [PATCH 1/3] pvclock: Add CPU barries to get correct version value

FromMinfei Huang <mnghuan@gmail.com>
Date2016-05-27 08:20 +0200
Subject[PATCH 1/3] pvclock: Add CPU barries to get correct version value
Message-ID<rDjhL-8fO-5@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1408149

FromAndy Lutomirski <luto@amacapital.net>
Date2016-05-27 17:50 +0200
Message-ID<rDsbo-5gf-15@gated-at.bofh.it>
In reply to#1407837
On Thu, May 26, 2016 at 11:17 PM, Minfei Huang <mnghuan@gmail.com> wrote:
> 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.

LGTM.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web