xen/gnttab: Reduce complexity when reading grant_entry_header_t
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 21 Nov 2018 18:38:41 +0000 (18:38 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 28 Jun 2019 12:17:53 +0000 (13:17 +0100)
commit8dc0b31dc471b6dd45b58a3df225c07b6c08da5f
tree6281398cc4af294be317fed1a1373d5e2ce8b59c
parent3af3c95b81625adf7e6ea71c94b641424741eded
xen/gnttab: Reduce complexity when reading grant_entry_header_t

_set_status_v{1,2}() and gnttab_prepare_for_transfer() read the shared header
by always casting to u32.  Despite grant_entry_header_t only having an
alignment of 2, this is actually safe because of the grant table ABI itself.

Switch to using an explicit uint32_t *, which removes all subsequent casting.

Furthermore, switch to using ACCESS_ONCE() for the read.  There is nothing in
the _set_status_v1() and gnttab_prepare_for_transfer() which prevents the
compiler from issuing multiple memory reads and creating a TOCTOU race around
the sanity checks, although the worst that can happen is Xen stamping a status
flag over a bad grant entry if the guest is misbehaving.

_set_status_v2() does use barrier() to try avoid multiple reads, but this is
overkill.  All that matters is that the shared header gets read in one go, and
this allows the compiler more room to optimise.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/grant_table.c