[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18/x86/time: fix wc_version retry check


  • To: "xen-devel" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Jan Beulich" <JBeulich@xxxxxxxx>
  • Date: Mon, 20 Jan 2014 08:56:24 +0000
  • Delivery-date: Mon, 20 Jan 2014 08:56:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

When using | instead of || (attempting to make the compiler issue just
a single branch), both sides of the operator aren't separated by a
sequence point, and hence evaluation can happen in any order. In
particular the rightmost read of s->wc_version could get carried out
before the leftmost one. Use a local variable to prevent this. (In
reality the compiler is very likely to do only a single memory read
here anyway.)

Reported-by: Julian Stecklina <jsteckli@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/arch/i386/kernel/time-xen.c
+++ b/arch/i386/kernel/time-xen.c
@@ -257,6 +257,7 @@
 static void update_wallclock(void)
 {
        shared_info_t *s = HYPERVISOR_shared_info;
+       u32 version;
 
        do {
                shadow_tv_version = s->wc_version;
@@ -264,7 +265,8 @@
                shadow_tv.tv_sec  = s->wc_sec;
                shadow_tv.tv_nsec = s->wc_nsec;
                rmb();
-       } while ((s->wc_version & 1) | (shadow_tv_version ^ s->wc_version));
+               version = s->wc_version;
+       } while ((version & 1) | (shadow_tv_version ^ version));
 
        if (!independent_wallclock)
                __update_wallclock(shadow_tv.tv_sec, shadow_tv.tv_nsec);



Attachment: xenlinux-x86-update-wc-ordering.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.