xen/memory: Fix mapping grant tables with XENMEM_acquire_resource
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 27 Jul 2020 16:24:11 +0000 (17:24 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 5 Feb 2021 17:37:27 +0000 (17:37 +0000)
commit34cc2e5f8dba6906da82fe8d76e839f9ab20f153
tree6edc5e79782cd8e97dd75b77a468f7344137ed00
parentf4318db940c39cc656128fcf72df3e79d2e55bc1
xen/memory: Fix mapping grant tables with XENMEM_acquire_resource

A guest's default number of grant frames is 64, and XENMEM_acquire_resource
will reject an attempt to map more than 32 frames.  This limit is caused by
the size of mfn_list[] on the stack.

Fix mapping of arbitrary size requests by looping over batches of 32 in
acquire_resource(), and using hypercall continuations when necessary.

To start with, break _acquire_resource() out of acquire_resource() to cope
with type-specific dispatching, and update the return semantics to indicate
the number of mfns returned.  Update gnttab_acquire_resource() and x86's
arch_acquire_resource() to match these new semantics.

Have do_memory_op() pass start_extent into acquire_resource() so it can pick
up where it left off after a continuation, and loop over batches of 32 until
all the work is done, or a continuation needs to occur.

compat_memory_op() is a bit more complicated, because it also has to marshal
frame_list in the XLAT buffer.  Have it account for continuation information
itself and hide details from the upper layer, so it can marshal the buffer in
chunks if necessary.

With these fixes in place, it is now possible to map the whole grant table for
a guest.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
xen/common/compat/memory.c
xen/common/grant_table.c
xen/common/memory.c