evtchn: address races with evtchn_reset()
authorJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2020 14:15:14 +0000 (16:15 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2020 14:15:14 +0000 (16:15 +0200)
commitecc6428b7ea63a24e244f747e8568c0ccc03a6f8
treea9d56bdc16bf4701fee353a9095bb4052f28d17a
parent2ee270e126458471b178ca1e5d7d8d0afc48be39
evtchn: address races with evtchn_reset()

Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
lock-less manner, as both may change by a racing evtchn_reset(). In the
common case, at least one of the domain's event lock or the per-channel
lock needs to be held. In the specific case of the inter-domain sending
by evtchn_send() and notify_via_xen_event_channel() holding the other
side's per-channel lock is sufficient, as the channel can't change state
without both per-channel locks held. Without such a channel changing
state, evtchn_reset() can't complete successfully.

Lock-free accesses continue to be permitted for the shim (calling some
otherwise internal event channel functions), as this happens while the
domain is in effectively single-threaded mode. Special care also needs
taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
use of such ports in the shim case is okay because switching into and
hence also out of FIFO mode is impossihble there).

As a side effect, certain operations on Xen bound event channels which
were mistakenly permitted so far (e.g. unmask or poll) will be refused
now.

This is part of XSA-343.

Reported-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/arch/x86/irq.c
xen/arch/x86/pv/shim.c
xen/common/event_2l.c
xen/common/event_channel.c
xen/common/event_fifo.c
xen/include/asm-x86/event.h
xen/include/xen/event.h