Skip to content

Commit 82c6346

Browse files
committed
vmm: extend last MMIO64 allocator to cover full range
The MMIO64 allocator size is computed with alignment truncation: size = (range / alignment) * alignment This loses up to one alignment unit (4 GiB) at the top of the address space. When a guest (Windows with virtio-win 0.1.285) programs a BAR near the top of the physical address space, the allocation fails because the address falls in the truncated gap. Give the last PCI segment allocator all remaining space up to the end of the device area, so no addresses are lost. Signed-off-by: CMGS <ilskdw@gmail.com>
1 parent 6b9e315 commit 82c6346

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

vmm/src/device_manager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,15 @@ fn create_mmio_allocators(
11441144
for segment_id in 0..num_pci_segments as u64 {
11451145
let weight = weights[segment_id as usize] as u64;
11461146
let mmio_start = start + i * pci_segment_mmio_size;
1147-
let mmio_size = pci_segment_mmio_size * weight;
1147+
let is_last = segment_id == num_pci_segments as u64 - 1;
1148+
// Give the last segment all remaining space so no addresses
1149+
// near the top of the physical address space are lost to
1150+
// alignment truncation.
1151+
let mmio_size = if is_last {
1152+
end - mmio_start + 1
1153+
} else {
1154+
pci_segment_mmio_size * weight
1155+
};
11481156
let allocator = Arc::new(Mutex::new(
11491157
AddressAllocator::new(GuestAddress(mmio_start), mmio_size).unwrap(),
11501158
));

0 commit comments

Comments
 (0)