On 02.02.2022 15:45, Roger Pau Monne wrote:
> One of the boxes where I was attempting to boot Xen in PVH dom0 mode
> has quirky firmware, as it will handover with a PCI 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 any
> memory region defined in the memory map, 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 defined in the
> memory map. If overlaps are detected just disable the memory decoding
> bit for the device and expect the hardware domain to properly position
> the BAR.
>
> Note apply_quirks must be called before check_pdev so that ignore_bars
> is set when calling the later. PCI_HEADER_{NORMAL,BRIDGE}_NR_BARS
> needs to be moved into pci_regs.h so it's defined even in the absence
> of vPCI.
>
> Signed-off-by: Roger Pau Monné <[email protected]>
Reviewed-by: Jan Beulich <[email protected]>