]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.6.6/pvclock-add-cpu-barriers-to-get-correct-version-value.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.6.6 / pvclock-add-cpu-barriers-to-get-correct-version-value.patch
1 From 749d088b8e7f4b9826ede02b9a043e417fa84aa1 Mon Sep 17 00:00:00 2001
2 From: Minfei Huang <mnghuan@gmail.com>
3 Date: Fri, 27 May 2016 14:17:10 +0800
4 Subject: pvclock: Add CPU barriers to get correct version value
5
6 From: Minfei Huang <mnghuan@gmail.com>
7
8 commit 749d088b8e7f4b9826ede02b9a043e417fa84aa1 upstream.
9
10 Protocol for the "version" fields is: hypervisor raises it (making it
11 uneven) before it starts updating the fields and raises it again (making
12 it even) when it is done. Thus the guest can make sure the time values
13 it got are consistent by checking the version before and after reading
14 them.
15
16 Add CPU barries after getting version value just like what function
17 vread_pvclock does, because all of callees in this function is inline.
18
19 Fixes: 502dfeff239e8313bfbe906ca0a1a6827ac8481b
20 Signed-off-by: Minfei Huang <mnghuan@gmail.com>
21 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 arch/x86/include/asm/pvclock.h | 2 ++
26 arch/x86/kernel/pvclock.c | 4 ++++
27 2 files changed, 6 insertions(+)
28
29 --- a/arch/x86/include/asm/pvclock.h
30 +++ b/arch/x86/include/asm/pvclock.h
31 @@ -85,6 +85,8 @@ unsigned __pvclock_read_cycles(const str
32 u8 ret_flags;
33
34 version = src->version;
35 + /* Make the latest version visible */
36 + smp_rmb();
37
38 offset = pvclock_get_nsec_offset(src);
39 ret = src->system_time + offset;
40 --- a/arch/x86/kernel/pvclock.c
41 +++ b/arch/x86/kernel/pvclock.c
42 @@ -66,6 +66,8 @@ u8 pvclock_read_flags(struct pvclock_vcp
43
44 do {
45 version = __pvclock_read_cycles(src, &ret, &flags);
46 + /* Make sure that the version double-check is last. */
47 + smp_rmb();
48 } while ((src->version & 1) || version != src->version);
49
50 return flags & valid_flags;
51 @@ -80,6 +82,8 @@ cycle_t pvclock_clocksource_read(struct
52
53 do {
54 version = __pvclock_read_cycles(src, &ret, &flags);
55 + /* Make sure that the version double-check is last. */
56 + smp_rmb();
57 } while ((src->version & 1) || version != src->version);
58
59 if (unlikely((flags & PVCLOCK_GUEST_STOPPED) != 0)) {