xen/arm: allocate_bank_memory: don't create memory banks of size zero
authorStefano Stabellini <stefano.stabellini@xilinx.com>
Wed, 10 Nov 2021 20:55:55 +0000 (12:55 -0800)
committerStefano Stabellini <stefano.stabellini@xilinx.com>
Thu, 11 Nov 2021 18:35:13 +0000 (10:35 -0800)
commitd8e1ed865ac4804c2ba98fc9ef1b53bfa8357f43
tree7d9bb82ddc5a96886295781b5faeb53ff65f23c5
parent9aaf437cd3612fea26d5a645da83b8f21cf34a79
xen/arm: allocate_bank_memory: don't create memory banks of size zero

allocate_bank_memory can be called with a tot_size of zero, as an
example see the implementation of allocate_memory which can call
allocate_bank_memory with a tot_size of zero for the second memory bank.

If tot_size == 0, don't create an empty memory bank, just return
immediately without error. Otherwise a zero-size memory bank will be
added to the domain device tree.

Note that Linux is known to be able to cope with zero-size memory banks,
and Xen more recently gained the ability to do so as well (5a37207df520
"xen/arm: bootfdt: Ignore empty memory bank"). However, there might be
other non-Linux OSes that are not able to cope with empty memory banks
as well as Linux (and now Xen). It would be more robust to avoid
zero-size memory banks unless required.

Moreover, the code to find empty address regions in make_hypervisor_node
in Xen is not able to cope with empty memory banks today and would
result in a Xen crash. This is only a latent bug because
make_hypervisor_node is only called for Dom0 at present and
allocate_memory is only called for DomU at the moment. (But if
make_hypervisor_node was to be called for a DomU, then the Xen crash
would become manifest.)

Fixes: f2931b4233ec ("xen/arm: introduce allocate_memory")
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
xen/arch/arm/domain_build.c