mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
pci: vfio: Naturally align the PCI BAR allocation
The PCI bar should be naturally aligned i.e. aligned to the size of the bar itself. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
bfc65bff2a
commit
c82226fdae
@ -910,26 +910,14 @@ impl PciDevice for VfioPciDevice {
|
||||
let first_bit = region_size.trailing_zeros();
|
||||
region_size = 2u64.pow(first_bit);
|
||||
|
||||
// We need to allocate a guest MMIO address range for that BAR.
|
||||
// In case the BAR is mappable directly, this means it might be
|
||||
// set as user memory region, which expects to deal with 4K
|
||||
// pages. Therefore, the alignment has to be set accordingly.
|
||||
let bar_alignment = if (bar_id == VFIO_PCI_ROM_REGION_INDEX)
|
||||
|| (self.device.get_region_flags(bar_id) & VFIO_REGION_INFO_FLAG_MMAP != 0)
|
||||
{
|
||||
// 4K alignment
|
||||
0x1000
|
||||
} else {
|
||||
// Default 16 bytes alignment
|
||||
0x10
|
||||
};
|
||||
// BAR allocation needs to be naturally aligned
|
||||
if is_64bit_bar {
|
||||
bar_addr = allocator
|
||||
.allocate_mmio_addresses(None, region_size, Some(bar_alignment))
|
||||
.allocate_mmio_addresses(None, region_size, Some(region_size))
|
||||
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?;
|
||||
} else {
|
||||
bar_addr = allocator
|
||||
.allocate_mmio_hole_addresses(None, region_size, Some(bar_alignment))
|
||||
.allocate_mmio_hole_addresses(None, region_size, Some(region_size))
|
||||
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user