diff --git a/devicemodel/hw/pci/core.c b/devicemodel/hw/pci/core.c index 4f15bf6c8..3dcad83c9 100644 --- a/devicemodel/hw/pci/core.c +++ b/devicemodel/hw/pci/core.c @@ -26,6 +26,7 @@ * $FreeBSD$ */ +#include #include #include #include @@ -564,6 +565,13 @@ pci_emul_alloc_resource(uint64_t *baseptr, uint64_t limit, uint64_t size, return -1; } + /* PCI spec said that BAR base should be naturally aligned. On ACRN + * if the bar size < PAGE_SIZE, BAR base should be aligned with + * PAGE_SIZE. This is because the minimal size that EPT can map/unmap + * is PAGE_SIZE. + */ + if (size < PAGE_SIZE) + size = PAGE_SIZE; base = roundup2(*baseptr, size); /* TODO:Currently, we only reserve gvt mmio regions,