The evtchn device frees its per-port state after xen_intr_unbind(), but
it's possible the event channel has more references (like from gntdev) so
the handler stayed registered and later ran on freed memory.
Just like we have a handle to pick up an extra reference on an event
channel (xen_intr_get_evtchn_from_port()), there's also a need to have a
way to drop such reference that's not xen_intr_unbind().
The logic in xen_intr_unbind() should only be used by the owner of the
event channel, so that the interrupt handler is unhooked and the event
channel masked. Callers that take extra references on the event channel
should not control the life cycle of the event handler. Introduce a new
helper to be the counterpart of the existing
xen_intr_get_evtchn_from_port(), so that extra references to event channels
can be safely dropped. Also adjust xen_intr_unbind() to unhook and mask
the event channel unconditionally: it's not safe to execute the handler after
the owner has requested to unbind it.
Fixes: 0f4d7d9fd78b ("xen/intr: add reference counts to event channels")
PR: 300890
Reported by: Scott Blomenkamp
Sponsored by: Advanced Micro Devices, Inc.
MFC after: 1 week