From: MaoXiaoyun Subject: RE: VM hung after running sometime Date: Sun, 19 Sep 2010 18:37:31 +0800 Message-ID: References: , , Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0520194607==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: keir.fraser@eu.citrix.com Cc: xen devel List-Id: xen-devel@lists.xenproject.org --===============0520194607== Content-Type: multipart/alternative; boundary="_02cd3de8-0eb8-48f1-97a6-c5711dc4703a_" --_02cd3de8-0eb8-48f1-97a6-c5711dc4703a_ Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi Keir: =20 Regards to HVM hang , according to our recent test, it turns out t= his issue still exists. When I go through the code, I obseved something abnormal and need = your help. =20 We've noticed when VM hang, its VCPU flags is always 4, which indic= ates _VPF_blocked_in_xen, and it is invoked in prepare_wait_on_xen_event_channel. I've notice= d that Domain U has setup a event channel with domain 0 for each VCPU and qemu-dm select on = the event fd. =20 =20 notify_via_xen_event_channel is called when Domain U issue a reques= t. And in qemu-dm it will=20 get the event, and invoke cpu_handle_ioreq(/xen-4.0.0/tools/ioemu-= qemu-xen/i386-dm/helper2.c) ->cpu_get_ioreq()->xc_evtchn_unmask(). In evtchn_unmask it will has = operation on evtchn_pending,=20 evtchn_mask, or evtchn_pending_sel. =20 My confusion is on notify_via_xen_event_channel()->evtchn_set_pendi= ng, the **evtchn_set_pending here in not locked**, while inside it also have operation on evtchn_pend= ing, evtchn_mask, or evtchn_pending_sel. =20 I'm afried this access competition might cause event undeliverd fro= m dom U to qemu-dm, but I am not sure,=20 since I still not fully understand where event_mask and is set, and= where event_pending is cleared.=20 =20 -------------------------notify_via_xen_event_channel--------------------= ----------------- 989 void notify_via_xen_event_channel(int lport) 990 { 991 struct evtchn *lchn, *rchn; 992 struct domain *ld =3D current->domain, *rd; 993 int rport; 994=20 995 spin_lock(&ld->event_lock); 996=20 997 ASSERT(port_is_valid(ld, lport)); 998 lchn =3D evtchn_from_port(ld, lport); 999 ASSERT(lchn->consumer_is_xen); 1000=20 1001 if ( likely(lchn->state =3D=3D ECS_INTERDOMAIN) ) 1002 { 1003 rd =3D lchn->u.interdomain.remote_dom; 1004 rport =3D lchn->u.interdomain.remote_port; 1005 rchn =3D evtchn_from_port(rd, rport); 1006 evtchn_set_pending(rd->vcpu[rchn->notify_vcpu_id], rport); 1007 } 1008=20 1009 spin_unlock(&ld->event_lock); 1010 } =20 ----------------------------evtchn_set_pending---------------------- 535 static int evtchn_set_pending(struct vcpu *v, int port) 536 { 537 struct domain *d =3D v->domain; 538 int vcpuid; 539=20 540 /* 541 * The following bit operations must happen in strict order. 542 * NB. On x86, the atomic bit operations also act as memory barr= iers. 543 * There is therefore sufficiently strict ordering for this arch= itecture -- 544 * others may require explicit memory barriers. 545 */ 546=20 547 if ( test_and_set_bit(port, &shared_info(d, evtchn_pending)) ) 548 return 1; 549=20 550 if ( !test_bit (port, &shared_info(d, evtchn_mask)) && 551 !test_and_set_bit(port / BITS_PER_EVTCHN_WORD(d), 552 &vcpu_info(v, evtchn_pending_sel)) ) 553 { 554 vcpu_mark_events_pending(v); 555 } 556=20 557 /* Check if some VCPU might be polling for this event. */ 558 if ( likely(bitmap_empty(d->poll_mask, d->max_vcpus)) ) 559 return 0; 560=20 561 /* Wake any interested (or potentially interested) pollers. */ 562 for ( vcpuid =3D find_first_bit(d->poll_mask, d->max_vcpus); 563 vcpuid < d->max_vcpus; 564 vcpuid =3D find_next_bit(d->poll_mask, d->max_vcpus, vcpui= d+1) ) 565 { 566 v =3D d->vcpu[vcpuid]; 567 if ( ((v->poll_evtchn <=3D 0) || (v->poll_evtchn =3D=3D port= )) && 568 test_and_clear_bit(vcpuid, d->poll_mask) ) 569 { 570 v->poll_evtchn =3D 0; 571 vcpu_unblock(v); =20 --------------------------------------evtchn_unmask----------------------= -------- 764=20 765 int evtchn_unmask(unsigned int port) 766 { 767 struct domain *d =3D current->domain; 768 struct vcpu *v; 769=20 770 spin_lock(&d->event_lock); 771=20 772 if ( unlikely(!port_is_valid(d, port)) ) 773 { 774 spin_unlock(&d->event_lock); 775 return -EINVAL; 776 } 777=20 778 v =3D d->vcpu[evtchn_from_port(d, port)->notify_vcpu_id]; 779=20 780 /* 781 * These operations must happen in strict order. Based on 782 * include/xen/event.h:evtchn_set_pending().=20 783 */ 784 if ( test_and_clear_bit(port, &shared_info(d, evtchn_mask)) && 785 test_bit (port, &shared_info(d, evtchn_pending)) &= & 786 !test_and_set_bit (port / BITS_PER_EVTCHN_WORD(d), 787 &vcpu_info(v, evtchn_pending_sel)) ) 788 { 789 vcpu_mark_events_pending(v); 790 } 791=20 792 spin_unlock(&d->event_lock); 793=20 794 return 0; 795 } =20 ----------------------------cpu_get_ioreq------------------------- 260 static ioreq_t *cpu_get_ioreq(void) 261 { 262 int i; 263 evtchn_port_t port; 264=20 265 port =3D xc_evtchn_pending(xce_handle); 266 if (port !=3D -1) { 267 for ( i =3D 0; i < vcpus; i++ ) 268 if ( ioreq_local_port[i] =3D=3D port ) 269 break; 270=20 271 if ( i =3D=3D vcpus ) { 272 fprintf(logfile, "Fatal error while trying to get io even= t!\n"); 273 exit(1); 274 } 275=20 276 // unmask the wanted port again 277 xc_evtchn_unmask(xce_handle, port); 278=20 279 //get the io packet from shared memory 280 send_vcpu =3D i; 281 return __cpu_get_ioreq(i); 282 } 283=20 284 //read error or read nothing 285 return NULL; 286 } 287=20 =20 =20 --_02cd3de8-0eb8-48f1-97a6-c5711dc4703a_ Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi Keir:
 
       Regards to HVM hang , according to o= ur recent test, it turns out this issue still exists.
       When I go through the code, I o= bseved something abnormal and need your help.
 
      We've noticed when VM hang, its VCPU flags= is always 4, which indicates _VPF_blocked_in_xen,
      and it is invoked in prepare_wait_on_= xen_event_channel. I've noticed that Domain U has setup
      a event channel  with domain 0 for ea= ch VCPU and qemu-dm select on the event fd.  
 
      notify_via_xen_event_channel is = called when Domain U issue a request. And in qemu-dm it will        get the event,  and invoke cpu_handle= _ioreq(/xen-4.0.0/tools/ioemu-qemu-xen/i386-dm/helper2.c)
     ->cpu_get_ioreq()->xc_evtchn_unmask()= . In evtchn_unmask it will has operation on evtchn_pending, 
      evtchn_mask, or evtchn_pending_sel.  
      My confusion is on notify_via_xen_event_ch= annel()->evtchn_set_pending, the **evtchn_set_pending here
      in not locked**, while inside it also have= operation on evtchn_pending, evtchn_mask, or evtchn_pending_se= l.
 
      I'm afried this access competition might c= ause event undeliverd from dom U to qemu-dm, but I am not sure,
     since  I still not fully understand wh= ere event_mask and is set, and where event_pending is cleared.
 
-------------------------notify_via_xen_event_channel--------------------= -----------------
 989 void notify_via_xen_event_channel(int lport)
 990 {
=  991     struct evtchn *lchn, *rchn;
 99= 2     struct domain *ld =3D current->domain, *rd;<= BR> 993     int     &nb= sp;      rport;
 994
 995 =     spin_lock(&ld->event_lock);
 996
&n= bsp;997     ASSERT(port_is_valid(ld, lport));
&nbs= p;998     lchn =3D evtchn_from_port(ld, lport);
&n= bsp;999     ASSERT(lchn->consumer_is_xen);
1000=
1001     if ( likely(lchn->state =3D=3D ECS_I= NTERDOMAIN) )
1002     {
1003   =       rd    =3D lchn->u.interd= omain.remote_dom;
1004        = rport =3D lchn->u.interdomain.remote_port;
100 5         rchn  =3D evtchn_= from_port(rd, rport);
1006       &n= bsp; evtchn_set_pending(rd->vcpu[rchn->notify_vcpu_id], rport);
= 1007     }
1008
1009     s= pin_unlock(&ld->event_lock);
1010 }
     
----------------------------evtchn_set_pending----------------------
535 static int evtchn_set_pending(struct vcpu *v, int port)
 536 = {
 537     struct domain *d =3D v->domain;=
 538     int vcpuid;
 539
 = 540     /*
 541     = * The following bit operations must happen in strict order.
 542=       * NB. On x86, the atomic bit operations al= so act as memory barriers.
 543      * T= here is therefore sufficiently strict ordering for this architecture -- 544      * others may require explicit m= emory barriers.
 545      */
 54= 6
 547     if ( test_and_set_bit(port, &= shared_info(d, evtchn_pending)) )
 548    &nb= sp;    return 1;
 549
 550  &nb= sp;  if ( !test_bit   & nbsp;    (port, &shared_info(d, evtchn_mask)) &&a= mp;
 551          !t= est_and_set_bit(port / BITS_PER_EVTCHN_WORD(d),
 552  &= nbsp;           &n= bsp;           &nb= sp; &vcpu_info(v, evtchn_pending_sel)) )
 553  &nbs= p;  {
 554         v= cpu_mark_events_pending(v);
 555     }
&nb= sp;556
 557     /* Check if some VCPU might = be polling for this event. */
 558     if ( l= ikely(bitmap_empty(d->poll_mask, d->max_vcpus)) )
 559 = ;        return 0;
 560
&n= bsp;561     /* Wake any interested (or potentially in= terested) pollers. */
 562 &n bsp;   for ( vcpuid =3D find_first_bit(d->poll_mask, d->= max_vcpus);
 563        &= nbsp;  vcpuid < d->max_vcpus;
 564   &n= bsp;       vcpuid =3D find_next_bit(d->p= oll_mask, d->max_vcpus, vcpuid+1) )
 565   &nbs= p; {
 566         v =3D d= ->vcpu[vcpuid];
 567       =   if ( ((v->poll_evtchn <=3D 0) || (v->poll_evtchn =3D=3D p= ort)) &&
 568       &n= bsp;      test_and_clear_bit(vcpuid, d->poll_= mask) )
 569         { 570          &nb= sp;  v->poll_evtchn =3D 0;
 571    &n= bsp;        vcpu_unbl ock(v);
   
--------------------------------------evtchn_unmask----------------------= --------
 764
 765 int evtchn_unmask(unsigned int port)
 766= {
 767     struct domain *d =3D current->= domain;
 768     struct vcpu   *v;<= BR> 769
 770     spin_lock(&d->e= vent_lock);
 771
 772     if ( unlik= ely(!port_is_valid(d, port)) )
 773     {
=  774         spin_unlock(&am= p;d->event_lock);
 775      &nbs= p;  return -EINVAL;
 776     }
 = 777
 778     v =3D d->vcpu[evtchn_from_po= rt(d, port)->notify_vcpu_id];
 779
 780  &n= bsp;  /*
 781      * These operatio= ns must happen in strict order. Based on
 782   &n= bsp;  * include/xen/event.h:evtchn_set_p ending().
 783      */
 784&nb= sp;    if ( test_and_clear_bit(port, &shared_info(d, e= vtchn_mask)) &&
 785      &= nbsp;   test_bit        = ;  (port, &shared_info(d, evtchn_pending)) &&
 7= 86          !test_and_set_bi= t (port / BITS_PER_EVTCHN_WORD(d),
 787    &n= bsp;           &nb= sp;            &am= p;vcpu_info(v, evtchn_pending_sel)) )
 788    = ; {
 789         vcpu_mar= k_events_pending(v);
 790     }
 791 =
 792     spin_unlock(&d->event_lock);=
 793
 794  &nb sp;  return 0;
 795 }      &n= bsp;           &nb= sp;       
 ----------------------------cpu_get_ioreq-------------------------<= BR> 260 static ioreq_t *cpu_get_ioreq(void)
261 {
262   =   int i;
263     evtchn_port_t port;
264 <= BR>265     port =3D xc_evtchn_pending(xce_handle);266     if (port !=3D -1) {
267   =       for ( i =3D 0; i < vcpus; i++ )
268&= nbsp;            i= f ( ioreq_local_port[i] =3D=3D port )
269     = ;            break= ;
270
271         if ( i =3D= =3D vcpus ) {
272         = ;    fprintf(logfile, "Fatal error while trying to get io = event!\n");
273         &= nbsp;   exit(1);
274      &nbs= p;  }
275
276    &nbs p;    // unmask the wanted port again
277  &= nbsp;      xc_evtchn_unmask(xce_handle, port);278
279         //get the i= o packet from shared memory
280      &nb= sp;  send_vcpu =3D i;
281      &nbs= p;  return __cpu_get_ioreq(i);
282     }
2= 83
284     //read error or read nothing
285&nb= sp;    return NULL;
286 }
287
      
--_02cd3de8-0eb8-48f1-97a6-c5711dc4703a_-- --===============0520194607== 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 --===============0520194607==--