]> xenbits.xensource.com Git - people/royger/xen.git/commit
xen/pci: detect when BARs overlap RAM bar-toe gitlab/bar-toe
authorRoger Pau Monne <roger.pau@citrix.com>
Tue, 25 Jan 2022 15:19:24 +0000 (16:19 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Wed, 26 Jan 2022 11:53:23 +0000 (12:53 +0100)
commit6ce8960ee7bc6fe4a92b2e2999ddb918172b6560
tree4f5def8898b0dcbcb96f951eee1618ad5645f5e9
parentaedc224087fec4363b434f5ab97d544e96d1580f
xen/pci: detect when BARs overlap RAM

One of the boxes where I was attempting to boot Xen in PVH dom0 mode
has quirky firmware, as it will handover with a device with memory
decoding enabled and a BAR of size 4K at address 0. Such BAR overlaps
with a RAM range on the e820.

This interacts badly with the dom0 PVH build, as BARs will be setup on
the p2m before RAM, so if there's a BAR positioned over a RAM region
it will trigger a domain crash when the dom0 builder attempts to
populate that region with a regular RAM page.

It's in general a very bad idea to have a BAR overlapping with a RAM
region, so add some sanity checks for devices that are added with
memory decoding enabled in order to assure that BARs are not placed on
top of memory regions. If overlaps are detected just disable the
memory decoding bit for the device and expect the hardware domain to
properly position the BAR.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
RFC because:
 - Not sure the best way to implement is_iomem_range on Arm. BARs can
   be quite big, so iterating over every possible page is not ideal.
 - is_iomem_page cannot be used for this purpose on x86, because all
   the low 1MB will return true due to belonging to dom_io.
 - VF BARs are not checked. Should we also check them and disable VF
   if overlaps in a followup patch?
xen/arch/arm/mm.c
xen/arch/x86/mm.c
xen/drivers/passthrough/pci.c
xen/include/xen/mm.h