fix evtchn cpu affinity ?
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,
Signature · 2 lines
\o/ Pascal Bouchareine - Gandi g 0170393757 15, place de la Nation - 75011 Paris
drivers/xen/evtchn/evtchn.c +5 -0
@@ -346,9 +346,12 @@ static long evtchn_ioctl(struct file *fispin_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);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Pascal Bouchareine
If this the right cause, maybe a
close()wrapper incore/evtchn.cshould be used to avoid such deadlocks, or some other mechanism should ensure we don't get out of synch with xen ?
Your patch is perfectly adequate. I will check it in.
Thanks!
Keir