]> xenbits.xensource.com Git - people/pauldu/xen.git/commit
xen/evtchn: rework per event channel lock
authorJuergen Gross <jgross@suse.com>
Tue, 10 Nov 2020 13:36:15 +0000 (14:36 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 10 Nov 2020 13:36:15 +0000 (14:36 +0100)
commit5f2df45ead7c1195142f68b7923047a1e9479d54
treec35036fd35787715412a14824c4342682a0b08f3
parent3059178798a23ba870ff86ff54d442a07e6651fc
xen/evtchn: rework per event channel lock

Currently the lock for a single event channel needs to be taken with
interrupts off, which causes deadlocks in some cases.

Rework the per event channel lock to be non-blocking for the case of
sending an event and removing the need for disabling interrupts for
taking the lock.

The lock is needed for avoiding races between event channel state
changes (creation, closing, binding) against normal operations (set
pending, [un]masking, priority changes).

Use a rwlock, but with some restrictions:

- Changing the state of an event channel (creation, closing, binding)
  needs to use write_lock(), with ASSERT()ing that the lock is taken as
  writer only when the state of the event channel is either before or
  after the locked region appropriate (either free or unbound).

- Sending an event needs to use read_trylock() mostly, in case of not
  obtaining the lock the operation is omitted. This is needed as
  sending an event can happen with interrupts off (at least in some
  cases).

- Dumping the event channel state for debug purposes is using
  read_trylock(), too, in order to avoid blocking in case the lock is
  taken as writer for a long time.

- All other cases can use read_lock().

Fixes: e045199c7c9c54 ("evtchn: address races with evtchn_reset()")
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-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_channel.c
xen/include/xen/event.h
xen/include/xen/sched.h