From mboxrd@z Thu Jan 1 00:00:00 1970 From: "James Song" Subject: when timer go back in dom0 save and restore or migrate, PV domain hung Date: Tue, 25 Nov 2008 01:01:42 -0700 Message-ID: <492C4B970200002000007D07@lucius.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0911432376==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --===============0911432376== Content-Type: multipart/alternative; boundary="=__Part4C6423F6.0__=" This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part4C6423F6.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi, I find PV domin hung, When we take those steps=20 1, save PV domain=20 2, change system time of PV domain back=20 3, restore a PV domain=20 or=20 1, migrate a PV domain from Machine A to Machine B 2, the system time of Machine B is slower than Machine A. the problem is wc_sec will be change when system-time chanaged in dom0 = or restore in a slower-system-time machine, but when restoring, xen don't = restore the wc_sec of share_info from xenstore and use native one. So = guest os will hang.=20 this patch will work for this issue. Thanks -- Song Wei diff -r a5ed0dbc829f tools/libxc/xc_domain_restore.c --- a/tools/libxc/xc_domain_restore.c Tue Nov 18 14:34:14 2008 +0800 +++ b/tools/libxc/xc_domain_restore.c Fri Nov 21 17:34:15 2008 +0800 @@ -328,6 +328,16 @@ =20 /* For info only */ nr_pfns =3D 0; + //jsong@novell.com, james song + memset(&domctl, 0, sizeof(domctl)); + domctl.domain =3D dom; + domctl.cmd =3D XEN_DOMCTL_restoredomain; + frc =3D do_domctl(xc_handle, &domctl); + if ( frc !=3D 0 ) + { + ERROR("Unable to set flag of restore."); + goto out; + } =20 if ( read_exact(io_fd, &p2m_size, sizeof(unsigned long)) ) { @@ -1120,6 +1130,8 @@ =20 /* restore saved vcpu_info and arch specific info */ MEMCPY_FIELD(new_shared_info, old_shared_info, vcpu_info); + MEMCPY_FIELD(new_shared_info, old_shared_info, wc_nsec); + MEMCPY_FIELD(new_shared_info, old_shared_info, wc_sec); MEMCPY_FIELD(new_shared_info, old_shared_info, arch); =20 /* clear any pending events and the selector */ diff -r a5ed0dbc829f xen/arch/x86/time.c --- a/xen/arch/x86/time.c Tue Nov 18 14:34:14 2008 +0800 +++ b/xen/arch/x86/time.c Fri Nov 21 17:34:15 2008 +0800 @@ -689,7 +689,6 @@ wmb(); (*version)++; } - void update_vcpu_system_time(struct vcpu *v) { struct cpu_time *t; @@ -703,7 +702,6 @@ =20 if ( u->tsc_timestamp =3D=3D t->local_tsc_stamp ) return; - version_update_begin(&u->version); =20 u->tsc_timestamp =3D t->local_tsc_stamp; @@ -713,14 +711,19 @@ =20 version_update_end(&u->version); } - void update_domain_wallclock_time(struct domain *d) { spin_lock(&wc_lock); + if(d->after_restore ) + { + d->after_restore =3D 0; + goto out; //jsong@novell.com + } version_update_begin(&shared_info(d, wc_version)); shared_info(d, wc_sec) =3D wc_sec + d->time_offset_seconds; shared_info(d, wc_nsec) =3D wc_nsec; version_update_end(&shared_info(d, wc_version)); +out: spin_unlock(&wc_lock); } =20 @@ -751,7 +754,6 @@ u64 x; u32 y, _wc_sec, _wc_nsec; struct domain *d; - x =3D (secs * 1000000000ULL) + (u64)nsecs - system_time_base; y =3D do_div(x, 1000000000); =20 @@ -1050,7 +1052,6 @@ struct tm wallclock_time(void) { uint64_t seconds; - if ( !wc_sec ) return (struct tm) { 0 }; =20 diff -r a5ed0dbc829f xen/common/domctl.c --- a/xen/common/domctl.c Tue Nov 18 14:34:14 2008 +0800 +++ b/xen/common/domctl.c Fri Nov 21 17:34:15 2008 +0800 @@ -24,7 +24,6 @@ #include #include #include - extern long arch_do_domctl( struct xen_domctl *op, XEN_GUEST_HANDLE(xen_domctl_t) u_domctl); =20 @@ -315,6 +314,16 @@ ret =3D 0; } break; + case XEN_DOMCTL_restoredomain: + { + struct domain *d; + if ( (d =3D rcu_lock_domain_by_id(op->domain)) =3D=3D NULL ) + break; + =20 + d->after_restore =3D 1; + rcu_unlock_domain(d); + break; + } =20 case XEN_DOMCTL_createdomain: { diff -r a5ed0dbc829f xen/include/public/domctl.h --- a/xen/include/public/domctl.h Tue Nov 18 14:34:14 2008 +0800 +++ b/xen/include/public/domctl.h Fri Nov 21 17:34:15 2008 +0800 @@ -61,6 +61,7 @@ #define XEN_DOMCTL_destroydomain 2 #define XEN_DOMCTL_pausedomain 3 #define XEN_DOMCTL_unpausedomain 4 +#define XEN_DOMCTL_restoredomain 51 #define XEN_DOMCTL_resumedomain 27 =20 #define XEN_DOMCTL_getdomaininfo 5 diff -r a5ed0dbc829f xen/include/xen/sched.h --- a/xen/include/xen/sched.h Tue Nov 18 14:34:14 2008 +0800 +++ b/xen/include/xen/sched.h Fri Nov 21 17:34:15 2008 +0800 @@ -231,6 +231,7 @@ * cause a deadlock. Acquirers don't spin waiting; they preempt. */ spinlock_t hypercall_deadlock_mutex; + int after_restore; //jsong@novell.com }; =20 struct domain_setup_info ---------------------------------------------------------------------------= ------------------ Thanks --Song wei --=__Part4C6423F6.0__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi,
   I find PV domin hung, When we take = those steps
         1, save = PV domain
         2, change = system time of PV domain back
       = ;  3, restore a PV domain
        or =
         1, migrate a PV = domain from Machine A to Machine B
         2, = the system time of Machine B is slower than Machine A.
   the = problem is wc_sec will be change when system-time chanaged in dom0 or = restore in a slower-system-time machine, but when restoring, xen don't = restore the wc_sec of share_info from xenstore and use native one. So = guest os will hang.
this patch will work for this issue.

 T= hanks
 -- Song Wei

diff -r a5ed0dbc829f tools/libxc/xc_domai= n_restore.c
--- a/tools/libxc/xc_domain_restore.c    Tue = Nov 18 14:34:14 2008 +0800
+++ b/tools/libxc/xc_domain_restore.c &n= bsp;  Fri Nov 21 17:34:15 2008 +0800
@@ -328,6 +328,16 @@
 =
     /* For info only */
    = ; nr_pfns =3D 0;
+    //jsong@novell.com, james = song
+    memset(&domctl, 0, sizeof(domctl));
+&nb= sp;   domctl.domain =3D dom;
+    domctl.cmd&nb= sp;   =3D XEN_DOMCTL_restoredomain;
+    frc = =3D do_domctl(xc_handle, &domctl);
+    if ( frc = !=3D 0 )
+    {
+      &= nbsp;     ERROR("Unable to set flag of restore.");
+=             goto = out;
+    }
 
     if ( = read_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
  &n= bsp;  {
@@ -1120,6 +1130,8 @@
 
    = /* restore saved vcpu_info and arch specific info */
   =   MEMCPY_FIELD(new_shared_info, old_shared_info, vcpu_info);
+ = ;   MEMCPY_FIELD(new_shared_info, old_shared_info, wc_nsec);
+=     MEMCPY_FIELD(new_shared_info, old_shared_info, = wc_sec);
     MEMCPY_FIELD(new_shared_info, = old_shared_info, arch);
 
     /* clear any = pending events and the selector */
diff -r a5ed0dbc829f xen/arch/x86/tim= e.c
--- a/xen/arch/x86/time.c    Tue Nov 18 14:34:14 = 2008 +0800
+++ b/xen/arch/x86/time.c    Fri Nov 21 = 17:34:15 2008 +0800
@@ -689,7 +689,6 @@
     = wmb();
     (*version)++;
 }
-
 v= oid update_vcpu_system_time(struct vcpu *v)
 {
   = ;  struct cpu_time       *t;
@@ = -703,7 +702,6 @@
 
     if ( u->tsc_times= tamp =3D=3D t->local_tsc_stamp )
      =    return;
-
     version_update_begin(= &u->version);
 
     u->tsc_timest= amp     =3D t->local_tsc_stamp;
@@ -713,14 = +711,19 @@
 
     version_update_end(&u-= >version);
 }
-
 void update_domain_wallclock_time(st= ruct domain *d)
 {
     spin_lock(&wc_lo= ck);
+    if(d->after_restore )
+   = {
+        d->after_restore =3D = 0;
+        goto out; //jsong@novell.= com
+    }
     version_update_beg= in(&shared_info(d, wc_version));
     shared_inf= o(d, wc_sec)  =3D wc_sec + d->time_offset_seconds;
  &= nbsp;  shared_info(d, wc_nsec) =3D wc_nsec;
    = ; version_update_end(&shared_info(d, wc_version));
+out:
 &n= bsp;   spin_unlock(&wc_lock);
 }
 
@@ = -751,7 +754,6 @@
     u64 x;
   &n= bsp; u32 y, _wc_sec, _wc_nsec;
     struct domain = *d;
-
     x =3D (secs * 1000000000ULL) + = (u64)nsecs - system_time_base;
     y =3D do_div(x, = 1000000000);
 
@@ -1050,7 +1052,6 @@
 struct tm = wallclock_time(void)
 {
     uint64_t = seconds;
-
     if ( !wc_sec )
  &nb= sp;      return (struct tm) { 0 };
 
di= ff -r a5ed0dbc829f xen/common/domctl.c
--- a/xen/common/domctl.c &n= bsp;  Tue Nov 18 14:34:14 2008 +0800
+++ b/xen/common/domctl.c = ;   Fri Nov 21 17:34:15 2008 +0800
@@ -24,7 +24,6 @@
 = #include <asm/current.h>
 #include <public/domctl.h> #include <xsm/xsm.h>
-
 extern long arch_do_domctl(=
     struct xen_domctl *op, XEN_GUEST_HANDLE(xen_do= mctl_t) u_domctl);
 
@@ -315,6 +314,16 @@
   &= nbsp;     ret =3D 0;
     = }
     break;
+   case XEN_DOMCTL_resto= redomain:
+   {
+       = struct domain *d;
+        if ( (d = =3D rcu_lock_domain_by_id(op->domain)) =3D=3D NULL )
+  &nb= sp;         break;
+  =      
+      &nb= sp; d->after_restore =3D 1;
+      &nbs= p; rcu_unlock_domain(d);
+        = break;
+   }
 
     case = XEN_DOMCTL_createdomain:
     {
diff -r = a5ed0dbc829f xen/include/public/domctl.h
--- a/xen/include/public/domctl= .h    Tue Nov 18 14:34:14 2008 +0800
+++ b/xen/include/pu= blic/domctl.h    Fri Nov 21 17:34:15 2008 +0800
@@ -61,6 = +61,7 @@
 #define XEN_DOMCTL_destroydomain    &= nbsp; 2
 #define XEN_DOMCTL_pausedomain    &nbs= p;   3
 #define XEN_DOMCTL_unpausedomain   = ;   4
+#define XEN_DOMCTL_restoredomain    = ;  51
 #define XEN_DOMCTL_resumedomain    =   27
 
 #define XEN_DOMCTL_getdomaininfo  &n= bsp;   5
diff -r a5ed0dbc829f xen/include/xen/sched.h
--- = a/xen/include/xen/sched.h    Tue Nov 18 14:34:14 2008 = +0800
+++ b/xen/include/xen/sched.h    Fri Nov 21 = 17:34:15 2008 +0800
@@ -231,6 +231,7 @@
     = ; * cause a deadlock. Acquirers don't spin waiting; they preempt.
 =      */
     spinlock_t = hypercall_deadlock_mutex;
+    int after_restore; = //jsong@novell.com
 };
 
 struct domain_setup_info<= br>------------------------------------------------------------------------= ---------------------
 Thanks
--Song wei

--=__Part4C6423F6.0__=-- --===============0911432376== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0911432376==--