This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


[Xen-devel] Re: [PATCH RFC] do_settime is backwards?!

To: Rik van Riel <riel@xxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH RFC] do_settime is backwards?!
From: Rik van Riel <riel@xxxxxxxxxx>
Date: Wed, 6 Aug 2008 17:47:05 -0400
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 06 Aug 2008 14:47:33 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20080806173723.73884c9b@xxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Red Hat, Inc
References: <20080806173723.73884c9b@xxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
This patch fixes an apparent bug in do_settime() that was found while
auditing the code to fix an unrelated bug.

Signed-off-by: Rik van Riel <riel@xxxxxxxxxx>
I still hope I am wrong :)

On Wed, 6 Aug 2008 17:37:23 -0400
Rik van Riel <riel@xxxxxxxxxx> wrote:

> I hope I've overlooked some detail, but just in case I am
> right here's a patch to reverse the assignments.
> How did this ever work?

Of course, that is still not enough.  A u32 has some
more bits than a billion, so the wc_nsec variable
could be off by as much as 3 seconds...

diff -up xen/arch/x86/time.c.backwards xen/arch/x86/time.c
--- xen/arch/x86/time.c.backwards       2008-08-06 17:33:26.000000000 -0400
+++ xen/arch/x86/time.c 2008-08-06 17:43:46.000000000 -0400
@@ -819,12 +819,16 @@ void do_settime(unsigned long secs, unsi
     u32 y, _wc_sec, _wc_nsec;
     struct domain *d;
+    /* Calculate nanoseconds */
     x = (secs * 1000000000ULL) + (u64)nsecs - system_time_base;
+    /* Calculate seconds. */
     y = do_div(x, 1000000000);
+    /* Leave the remainder for the nanosecond field. */
+    x -= (y * 1000000000);
-    wc_sec  = _wc_sec  = (u32)x;
-    wc_nsec = _wc_nsec = (u32)y;
+    wc_sec  = _wc_sec  = (u32)y;
+    wc_nsec = _wc_nsec = (u32)x;

Xen-devel mailing list

<Prev in Thread] Current Thread [Next in Thread>