Home | History | Annotate | Download | only in include
History log of /src/sys/arch/xen/include/evtchn.h
RevisionDateAuthorComments
 1.32  07-May-2020  bouyer Change event_set_handler() to take the target CPU parameter. If ci is NULL,
event_set_handler() will choose the CPU and bind the event.
If ci is not NULL the caller is responsible for binding the event.
Use a IPI xcall to register the handlers if needed.
pull in a hack from x86 to force pirq handlers to be mpsafe if registered at
a level != IPL_VM. This is for the com at isa interrupt handler, which
registers at IPL_HIGH and has to way to tell it's mpsafe (taking
KERNEL_LOCK at IPL_HIGH causes deadlocks on MP systems).
 1.31  04-May-2020  jdolecek add support for using MSI for XenPV Dom0

use PHYSDEVOP_map_pirq to get the pirq/gsi for MSI/MSI-X, switch also INTx
to use it instead of PHYSDEVOP_alloc_irq_vector

MSI confirmed working with single-vector MSI for wm(4), ahcisata(4), bge(4)

XXX added some provision for MSI-X, but it doesn't actually work (no interrupts
delivered), needs some further investigation; disable MSI-X for XENPV
via flag in x86/pci/pci_machdep.c
 1.30  25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.29  13-Apr-2020  bouyer By default, events are bound to CPU 0 (exept for IPIs and VTIMERs which
are bound to a different CPU at creation time).
Recent MI changes caused the scheduler to choose a different CPU when
probing and attaching xennet devices (I guess it's the xenbus thread which
runs on a different CPU). This cause the callback to be called on a different
CPU than the one expected by the kernel, and the event is ignored.
It is handled when the clock causes the callback to be called on the right
CPU, which is why xennet still run, but slowly.

Change event_set_handler() to do a EVTCHNOP_bind_vcpu if requested to,
and make sure we don't do it for IPIs and VIRQs (for theses, the op fails).
 1.28  06-Apr-2020  jdolecek branches: 1.28.2;
add known_mpsafe parameter also to pirq_establish(), and pass the parameter
to underlying event_set_handler()
 1.27  06-Apr-2020  jdolecek remove restriction on interrupt level for MP-safe interrupt handlers
 1.26  24-Jun-2018  jdolecek branches: 1.26.2;
add support for kern.intr.list aka intrctl(8) 'list' for xen

event_set_handler() and pirq_establish() now have extra intrname
parameter; shared intr_create_intrid() is used to provide the value

xen drivers were changed to pass the specific driver instance
name as the xname, e.g. 'vcpu0 clock' instead just 'clock', or
'xencons0' instead of 'xencons'

associated evcnt is now changed to use intrname - this matches native x86
 1.25  04-Nov-2017  cherry branches: 1.25.2;
Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

void *intr_establish_xname(...);
void *intr_establish(...);
void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

int event_set_handler(...);
int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.
 1.24  16-Jul-2017  cherry branches: 1.24.2;
Add a glue function to inspect event channel<->legacy IRQ mappings.
This is towards getting xen to use more x86/ "native" code.
 1.23  14-Mar-2015  bouyer Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.22  12-Jan-2013  bouyer branches: 1.22.12; 1.22.14;
Back out this commit:
http://mail-index.netbsd.org/source-changes/2012/12/28/msg039950.html
which cause a panic when running tests on amd64, as shown on:
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/
(i386 hangs for unrelated reasons).
 1.21  28-Dec-2012  cherry Simplify the xen event handler callback by:
- moving the interrupt handler callback traversal into a separate
function.
- using evt_iterate_bits() to scan through the pending bitfield
- removing cross-cpu pending actions - events recieved on the wrong
vcpu are re-routed via hypervisor_send_event().
- simplifying nested while() loops by encapsulating them in
equivalent functions.

Many thanks for multiple reviews by bouyer@ and jym@
 1.20  20-Sep-2011  jym branches: 1.20.8; 1.20.12;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.19  11-Aug-2011  cherry Make event/interrupt handling MP aware
 1.18  23-Oct-2009  snj branches: 1.18.10;
Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.17  24-Oct-2008  jym branches: 1.17.8;
- rename init_events() to events_init(), to better reflect netbsd semantics

- change unbind_[pv]irq_from_evtch() so that they now return the event
channel the [PV]IRQ was bound to. It reflects the opposite behaviour of the
bind_[pv]irq_to_evtch() functions.

- remove xenbus_suspend() and xenbus_resume() prototypes, as they are not
used anywhere else, and will conflict with the xenbus pmf(9) handlers.

- make start_info aligned on a page boundary, as Xen expects it to be so.

- mask event channel during xbd detach before removing its handler (can
avoid spurious events).

- add the "protocol" entry in xenstore during xbd initialization. Normally
created during domU's boot by xentools, it is under domU's responsibility
in all other cases (save/restore, hot plugging, etc.).

- modifications to xs_init(), so that it can properly return an error.

Reviewed by Christoph (cegger@).
 1.16  01-Jul-2008  bouyer branches: 1.16.2;
Raise ci_idepth (and switch to interrupt stack on i386) becore calling
xenevt_event().
 1.15  19-Feb-2008  bouyer branches: 1.15.6; 1.15.10; 1.15.12; 1.15.14;
Fix xenevt to not call softint_schedule() above IPL_HIGH:
Register a ipl callback for IPL_HIGH.
if the current ipl level is too high, just record the event in a bitmap,
and record IPL_HIGH as pending. The callback will process the pending events.
 1.14  12-Dec-2007  bouyer cleanup the debug event handler to not use the IPL system at all. Fix
debug event storm on XEN2.
 1.13  08-Dec-2006  yamt branches: 1.13.24; 1.13.32; 1.13.34; 1.13.36;
- pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.12  28-Sep-2006  bouyer Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.11  11-Dec-2005  christos branches: 1.11.20; 1.11.22;
merge ktrace-lwp.
 1.10  10-Sep-2005  bouyer The line number in the PCI interrupt register can be larger than 31 on
some hardware, depending on how Xen set things up. So bump NR_PIRQ from 32
to 256.
 1.9  28-Apr-2005  yamt branches: 1.9.2;
rename do_event to evtchan_do_event.
the former is too generic name and it actually hides a bug in xennetback.
 1.8  20-Apr-2005  bouyer Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.

Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.7  18-Apr-2005  yamt don't unmask an event channel until all interrupts for it are served.
fix problems with shared (physical) interrupts.
 1.6  17-Apr-2005  bouyer Allow to pass a more descriptive name to event_set_handler() (e.g. IRQ number
for physical IRQ, or device name for xen device drivers). This makes
systat and vmstat output more usable, especially as the channel numbers
change each time a guest reboots.
 1.5  16-Apr-2005  bouyer Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.4  11-Apr-2005  yamt fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.3  11-Apr-2005  yamt don't stamp soft interrupts.
 1.2  09-Mar-2005  bouyer branches: 1.2.2; 1.2.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1  13-Dec-2004  bouyer branches: 1.1.2; 1.1.4; 1.1.6;
file evtchn.h was initially added on branch bouyer-xen2.
 1.1.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.4.1  29-Apr-2005  kent sync with -current
 1.1.2.4  08-Mar-2005  bouyer Add infrastructure to unregsiter event callbacks.
 1.1.2.3  21-Jan-2005  bouyer - Add a centralised handler for physical interrupts, which will call the
real handler. This is not necessery but is usefull for debug.
- make irq_needs_unmask_notify[] per-IRQ, instead of per physical IRQ
- use a static physdev_op_t for PHYSDEVOP_IRQ_UNMASK_NOTIFY (it never changes,
so no need to allocate a new one each time)
- call pirq_notify() from hypervisor_enable_irq().
 1.1.2.2  18-Jan-2005  bouyer Implement physical IRQ mapping.
 1.1.2.1  13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.2.4.3  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.4.2  01-Apr-2005  skrll Sync with HEAD.
 1.2.4.1  09-Mar-2005  skrll file evtchn.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.2.8  14-Sep-2005  tron Pull up following revision(s) (requested by bouyer in ticket #777):
sys/arch/xen/include/evtchn.h: revision 1.10
The line number in the PCI interrupt register can be larger than 31 on
some hardware, depending on how Xen set things up. So bump NR_PIRQ from 32
to 256.
 1.2.2.7  01-May-2005  tron Pull up revision 1.9 (requested by yamt in ticket #238):
rename do_event to evtchan_do_event.
the former is too generic name and it actually hides a bug in xennetback.
 1.2.2.6  28-Apr-2005  tron Pull up revision 1.8 (requested by bouyer in ticket #192):
Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.
Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.2.2.5  28-Apr-2005  tron Pull up revision 1.7 (requested by bouyer in ticket #192):
don't unmask an event channel until all interrupts for it are served.
fix problems with shared (physical) interrupts.
 1.2.2.4  28-Apr-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #192):
Allow to pass a more descriptive name to event_set_handler() (e.g. IRQ number
for physical IRQ, or device name for xen device drivers). This makes
systat and vmstat output more usable, especially as the channel numbers
change each time a guest reboots.
 1.2.2.3  28-Apr-2005  tron Pull up revision 1.5 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2.2.2  13-Apr-2005  tron Pull up revision 1.4 (requested by yamt in ticket #146):
fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.2.2.1  13-Apr-2005  tron Pull up revision 1.3 (requested by yamt in ticket #143):
don't stamp soft interrupts.
 1.9.2.4  27-Feb-2008  yamt sync with head.
 1.9.2.3  21-Jan-2008  yamt sync with head
 1.9.2.2  30-Dec-2006  yamt sync with head.
 1.9.2.1  21-Jun-2006  yamt sync with head.
 1.11.22.2  10-Dec-2006  yamt sync with head.
 1.11.22.1  22-Oct-2006  yamt sync with head
 1.11.20.2  12-Jan-2007  ad Sync with head.
 1.11.20.1  18-Nov-2006  ad Sync with head.
 1.13.36.1  13-Dec-2007  bouyer cleanup the way debug event is handled: make it bypass the IPL system
completely, it's called by shortcuts in the normal path because we want it to
be always called, even if the IPL is high.
Fix debug even recursion on XEN2
 1.13.34.1  13-Dec-2007  yamt sync with head.
 1.13.32.1  26-Dec-2007  ad Sync with head.
 1.13.24.2  23-Mar-2008  matt sync with HEAD
 1.13.24.1  09-Jan-2008  matt sync with HEAD
 1.15.14.1  03-Jul-2008  simonb Sync with head.
 1.15.12.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.10.2  11-Mar-2010  yamt sync with head
 1.15.10.1  04-May-2009  yamt sync with head.
 1.15.6.2  17-Jan-2009  mjf Sync with HEAD.
 1.15.6.1  02-Jul-2008  mjf Sync with HEAD.
 1.16.2.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.17.8.4  27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.17.8.3  01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.17.8.2  01-Nov-2009  jym Sync with HEAD.
 1.17.8.1  09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.18.10.3  17-Aug-2011  cherry Pullup relevant changes from -current
 1.18.10.2  04-Aug-2011  cherry first cut at per-cpu event handling
 1.18.10.1  03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.20.12.1  03-Dec-2017  jdolecek update from HEAD
 1.20.8.1  14-Apr-2015  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1278):
sys/arch/xen/include/evtchn.h: revision 1.23
sys/arch/xen/xen/evtchn.c: revision 1.71
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.17
Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.22.14.2  28-Aug-2017  skrll Sync with HEAD
 1.22.14.1  06-Apr-2015  skrll Sync with HEAD
 1.22.12.1  18-Mar-2015  snj Pull up following revision(s) (requested by bouyer in ticket #618):
sys/arch/xen/include/evtchn.h: revision 1.23
sys/arch/xen/xen/evtchn.c: revision 1.71
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.17
Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.24.2.2  16-Jul-2017  cherry 2752365
 1.24.2.1  16-Jul-2017  cherry file evtchn.h was added on branch perseant-stdc-iso10646 on 2017-07-16 05:03:37 +0000
 1.25.2.1  25-Jun-2018  pgoyette Sync with HEAD
 1.26.2.3  21-Apr-2020  martin Sync with HEAD
 1.26.2.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.26.2.1  08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.2.3  20-Apr-2020  bouyer Misc fixes after merge
 1.28.2.2  20-Apr-2020  bouyer Sync with HEAD
 1.28.2.1  19-Apr-2020  bouyer Add a struct pic * member to struct intrhand.
This will be used for interrupt_get_count()
For Xen remplace pic_type with a pointer to the pic, and add a pointer
to intrhand, in struct pintrhand
Make event_set_handler return the pointer to struct intrhand.
Don't allocate a fake intrhand in xen_intr_establish_xname(), use the
one returned by event_set_handler().

RSS XML Feed