Skip to content

Commit 9aaece0

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 acff0d2 commit 9aaece0

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
@@ -1145,7 +1145,15 @@ fn create_mmio_allocators(
11451145
for segment_id in 0..num_pci_segments as u64 {
11461146
let weight = weights[segment_id as usize] as u64;
11471147
let mmio_start = start + i * pci_segment_mmio_size;
1148-
let mmio_size = pci_segment_mmio_size * weight;
1148+
let is_last = segment_id == num_pci_segments as u64 - 1;
1149+
// Give the last segment all remaining space so no addresses
1150+
// near the top of the physical address space are lost to
1151+
// alignment truncation.
1152+
let mmio_size = if is_last {
1153+
end - mmio_start + 1
1154+
} else {
1155+
pci_segment_mmio_size * weight
1156+
};
11491157
let allocator = Arc::new(Mutex::new(
11501158
AddressAllocator::new(GuestAddress(mmio_start), mmio_size).unwrap(),
11511159
));

0 commit comments

Comments
 (0)