memory_manager: Make addressable space size 64k aligned

While the addressable space size reduction of 4k in necessary due to
the Linux bug, the 64k alignment of the addressable space size is
required by Windows. This patch satisfies both.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski 2020-11-14 15:34:18 +01:00 committed by Rob Bradford
parent c0827e01b1
commit b399287430
2 changed files with 12 additions and 6 deletions

View File

@ -5523,7 +5523,7 @@ mod tests {
osdisk_path.push("windows-server-2019.raw"); osdisk_path.push("windows-server-2019.raw");
let mut child = Command::new(clh_command("cloud-hypervisor")) let mut child = Command::new(clh_command("cloud-hypervisor"))
.args(&["--cpus", "boot=2,kvm_hyperv=on,max_phys_bits=39"]) .args(&["--cpus", "boot=2,kvm_hyperv=on"])
.args(&["--memory", "size=4G"]) .args(&["--memory", "size=4G"])
.args(&["--kernel", ovmf_path.to_str().unwrap()]) .args(&["--kernel", ovmf_path.to_str().unwrap()])
.args(&["--disk", &format!("path={}", osdisk_path.to_str().unwrap())]) .args(&["--disk", &format!("path={}", osdisk_path.to_str().unwrap())])
@ -5578,7 +5578,7 @@ mod tests {
let mut child = Command::new(clh_command("cloud-hypervisor")) let mut child = Command::new(clh_command("cloud-hypervisor"))
.args(&["--api-socket", &api_socket]) .args(&["--api-socket", &api_socket])
.args(&["--cpus", "boot=2,kvm_hyperv=on,max_phys_bits=39"]) .args(&["--cpus", "boot=2,kvm_hyperv=on"])
.args(&["--memory", "size=4G"]) .args(&["--memory", "size=4G"])
.args(&["--kernel", ovmf_path.to_str().unwrap()]) .args(&["--kernel", ovmf_path.to_str().unwrap()])
.args(&["--disk", &format!("path={}", osdisk_path.to_str().unwrap())]) .args(&["--disk", &format!("path={}", osdisk_path.to_str().unwrap())])

View File

@ -255,11 +255,13 @@ const LENGTH_OFFSET_HIGH: u64 = 0xC;
const STATUS_OFFSET: u64 = 0x14; const STATUS_OFFSET: u64 = 0x14;
const SELECTION_OFFSET: u64 = 0; const SELECTION_OFFSET: u64 = 0;
// The MMIO address space size is subtracted with the size of a 4k page. This // The MMIO address space size is subtracted with 64k. This is done for the
// is done on purpose to workaround a Linux bug when the VMM allocates devices // following reasons:
// at the end of the addressable space. // - Reduce the addressable space size by at least 4k to workaround a Linux
// bug when the VMM allocates devices at the end of the addressable space
// - Windows requires the addressable space size to be 64k aligned
fn mmio_address_space_size(phys_bits: u8) -> u64 { fn mmio_address_space_size(phys_bits: u8) -> u64 {
(1 << phys_bits) - 0x1000 (1 << phys_bits) - (1 << 16)
} }
impl BusDevice for MemoryManager { impl BusDevice for MemoryManager {
@ -609,6 +611,10 @@ impl MemoryManager {
let boot_guest_memory = guest_memory.clone(); let boot_guest_memory = guest_memory.clone();
let mmio_address_space_size = mmio_address_space_size(phys_bits); let mmio_address_space_size = mmio_address_space_size(phys_bits);
debug_assert_eq!(
(((mmio_address_space_size) >> 16) << 16),
mmio_address_space_size
);
let end_of_device_area = GuestAddress(mmio_address_space_size - 1); let end_of_device_area = GuestAddress(mmio_address_space_size - 1);
let mut start_of_device_area = let mut start_of_device_area =