From 5b3ca78daca43bb386999a09365d0c5a07043a4d Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 18 Sep 2019 15:36:14 +0100 Subject: [PATCH] vmm: Use the full host physical address range Probe for the size of the host physical address range and use that to establish the address range for the VM. This removes the limitation on the size of the VM RAM and gives more space for the devices. Signed-off-by: Rob Bradford --- vmm/src/vm.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index d600c4fd1..c6d30228f 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -518,6 +518,20 @@ pub struct Vm<'a> { signals: Option, } +fn get_host_cpu_phys_bits() -> u8 { + use core::arch::x86_64; + unsafe { + let leaf = x86_64::__cpuid(0x8000_0000); + + if leaf.eax >= 0x8000_0008 { + let leaf = x86_64::__cpuid(0x8000_0008); + (leaf.eax & 0xff) as u8 + } else { + 36 + } + } +} + impl<'a> Vm<'a> { pub fn new(kvm: &Kvm, config: &'a VmConfig<'a>) -> Result { let kernel = File::open(&config.kernel.path).map_err(Error::KernelFile)?; @@ -676,7 +690,7 @@ impl<'a> Vm<'a> { GuestAddress(0), 1 << 16 as GuestUsize, GuestAddress(0), - 1 << 36 as GuestUsize, + 1 << get_host_cpu_phys_bits(), mem_hole.0, mem_hole.1 as GuestUsize, vec![ioapic], @@ -787,7 +801,7 @@ impl<'a> Vm<'a> { .map_err(|_| Error::CmdLine)?; let vcpu_count = u8::from(&self.config.cpus); - let end_of_range = GuestAddress((1 << 36) - 1); + let end_of_range = GuestAddress((1 << get_host_cpu_phys_bits()) - 1); match entry_addr.setup_header { Some(hdr) => { arch::configure_system(