When allocating MMIO space for the MSI-X table, kvmtool rounds the allocation to the host's page size to make it as easy as possible for the guest to map the table to a page, if it wants to (and doesn't do BAR reassignment, like the x86 architecture for example). However, the host's page size can differ from the guest's, for example, if the host is compiled with 4k pages and the guest is using 64k pages. To make sure the allocation is always aligned to a guest's page size, round it up to the maximum page size, which is 64k. Do the same for the pending bit array if it lives in its own BAR. Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx> --- vfio/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vfio/pci.c b/vfio/pci.c index a6d0408..7e258a4 100644 --- a/vfio/pci.c +++ b/vfio/pci.c @@ -1,3 +1,5 @@ +#include "linux/sizes.h" + #include "kvm/irq.h" #include "kvm/kvm.h" #include "kvm/kvm-cpu.h" @@ -929,7 +931,7 @@ static int vfio_pci_create_msix_table(struct kvm *kvm, struct vfio_device *vdev) if (!info.size) return -EINVAL; - map_size = ALIGN(info.size, PAGE_SIZE); + map_size = ALIGN(info.size, SZ_64K); table->guest_phys_addr = pci_get_mmio_block(map_size); if (!table->guest_phys_addr) { pr_err("cannot allocate MMIO space"); @@ -960,7 +962,7 @@ static int vfio_pci_create_msix_table(struct kvm *kvm, struct vfio_device *vdev) if (!info.size) return -EINVAL; - map_size = ALIGN(info.size, PAGE_SIZE); + map_size = ALIGN(info.size, SZ_64K); pba->guest_phys_addr = pci_get_mmio_block(map_size); if (!pba->guest_phys_addr) { pr_err("cannot allocate MMIO space"); -- 2.20.1