evtchn: avoid race in get_xen_consumer()
authorJan Beulich <jbeulich@suse.com>
Fri, 23 Oct 2020 08:07:56 +0000 (10:07 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 23 Oct 2020 08:07:56 +0000 (10:07 +0200)
commitdcbd1d8ae527f3632eb9a2804ad03e0451918b62
treedbb9eade8cc1895420a474cea47f638feda58d96
parent83432adeb82122e392a3bfc2a8818d25ca9e69ed
evtchn: avoid race in get_xen_consumer()

There's no global lock around the updating of this global piece of data.
Make use of cmpxchgptr() to avoid two entities racing with their
updates.

While touching the functionality, mark xen_consumers[] read-mostly (or
else the if() condition could use the result of cmpxchgptr(), writing to
the slot unconditionally).

The use of cmpxchgptr() here points out (by way of clang warning about
it) that its original use of const was slightly wrong. Adjust the
placement, or else undefined behavior of const qualifying a function
type will result.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/common/event_channel.c
xen/include/asm-x86/system.h
xen/include/xen/lib.h