From: Pascal Bouchareine Subject: fix evtchn cpu affinity ? Date: Thu, 3 Apr 2008 02:10:55 +0200 Message-ID: <20080403001055.GA60005@bar.gandi.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Return-path: Content-Disposition: inline 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 --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, When rebinding user event channels to cpu in dom0, evtchn/evtchn.c calls rebind_evtchn_to_cpu that changes the cpu_evtchn[] struct to mask an event to a specific cpu and notifies xen about this using an EVTCHNOP_bind_vcpu. In core/evtchn.c:evtchn_do_upcall, the evtchn_pending array from the shared info page is checked against this cpu_evtchn mask, effectively preventing domU from handling events when "upcalled" on the wrong cpu. On an EVTCHNOP_close, xen rebinds the event channel to vcpu 0. This seems to mean that anyone calling EVTCHNOP_close on an event channel that was bound to a vcpu touching the vcpu_evtchn[] array, must rebind the event channel to cpu 0 too, or we are losing the events (they stay pending, unmasked, and never do it to do_IRQ). I'm currently seeing such "lost" events, and some debugging shows they're bound in cpu_evtchn[] to a vcpu xen does not agree with (seen with an EVTCHNOP_status call and status->vcpu). I think I tracked it down to EVTCHNOP_closes() in evtchn/evtchn.c, thought I might miss some other cases here ? If this the right cause, maybe a close() wrapper in core/evtchn.c should be used to avoid such deadlocks, or some other mechanism should ensure we don't get out of synch with xen ? Or maybe let xen publish this mask in the shared info page and rely only on hypercalls for masking/unmasking events ? The attached patch is an attempt to fix the above - Thanks, -- \o/ Pascal Bouchareine - Gandi g 0170393757 15, place de la Nation - 75011 Paris --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="evtchn_rebind_on_close.patch" diff -r de57c3f218fb drivers/xen/evtchn/evtchn.c --- a/drivers/xen/evtchn/evtchn.c Thu Mar 20 11:35:25 2008 +0000 +++ b/drivers/xen/evtchn/evtchn.c Wed Apr 02 21:59:29 2008 +0200 @@ -346,9 +346,12 @@ static long evtchn_ioctl(struct file *fi spin_unlock_irq(&port_user_lock); break; } + port_user[unbind.port] = NULL; + mask_evtchn(unbind.port); + rebind_evtchn_to_cpu(unbind.port, 0); spin_unlock_irq(&port_user_lock); @@ -457,7 +460,9 @@ static int evtchn_release(struct inode * continue; port_user[i] = NULL; + mask_evtchn(i); + rebind_evtchn_to_cpu(i, 0); close.port = i; ret = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close); --T4sUOijqQbZv57TR 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 --T4sUOijqQbZv57TR--