xen/memory: Fix acquire_resource size semantics
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 23 Jul 2020 14:18:33 +0000 (15:18 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 30 Jan 2021 03:21:33 +0000 (03:21 +0000)
commit9244528955ded99d0cc341f223a6579362c908bf
tree43e0fcc06f93e960512edf5428f6c0f902500b2e
parent52531c734ea1e696e60faf358ef735acb2b325da
xen/memory: Fix acquire_resource size semantics

Calling XENMEM_acquire_resource with a NULL frame_list is a request for the
size of the resource, but the returned 32 is bogus.

If someone tries to follow it for XENMEM_resource_ioreq_server, the acquire
call will fail as IOREQ servers currently top out at 2 frames, and it is only
half the size of the default grant table limit for guests.

Also, no users actually request a resource size, because it was never wired up
in the sole implementation of resource acquisition in Linux.

Introduce a new resource_max_frames() to calculate the size of a resource, and
implement it the IOREQ and grant subsystems.

It is impossible to guarantee that a mapping call following a successful size
call will succeed (e.g. The target IOREQ server gets destroyed, or the domain
switches from grant v2 to v1).  Document the restriction, and use the
flexibility to simplify the paths to be lockless.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/grant_table.c
xen/common/memory.c
xen/include/public/memory.h
xen/include/xen/grant_table.h