vmm: Set CPUID

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-03-01 16:22:26 +01:00
parent 0921cfb8f8
commit 044f664135

View File

@ -83,13 +83,14 @@ pub enum Error {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
/// Error configuring the floating point related registers /// Error configuring the floating point related registers
FPUConfiguration(arch::x86_64::regs::Error), FPUConfiguration(arch::x86_64::regs::Error),
/// The call to KVM_SET_CPUID2 failed.
SetSupportedCpusFailed(io::Error),
} }
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;
/// A wrapper around creating and using a kvm-based VCPU. /// A wrapper around creating and using a kvm-based VCPU.
pub struct Vcpu { pub struct Vcpu {
// #[cfg(target_arch = "x86_64")]
// cpuid: CpuId,
fd: VcpuFd, fd: VcpuFd,
id: u8, id: u8,
} }
@ -115,6 +116,10 @@ impl Vcpu {
/// * `kernel_start_addr` - Offset from `guest_mem` at which the kernel starts. /// * `kernel_start_addr` - Offset from `guest_mem` at which the kernel starts.
/// * `vm` - The virtual machine this vcpu will get attached to. /// * `vm` - The virtual machine this vcpu will get attached to.
pub fn configure(&mut self, kernel_start_addr: GuestAddress, vm: &Vm) -> Result<()> { pub fn configure(&mut self, kernel_start_addr: GuestAddress, vm: &Vm) -> Result<()> {
self.fd
.set_cpuid2(&vm.cpuid)
.map_err(Error::SetSupportedCpusFailed)?;
arch::x86_64::regs::setup_msrs(&self.fd).map_err(Error::MSRSConfiguration)?; arch::x86_64::regs::setup_msrs(&self.fd).map_err(Error::MSRSConfiguration)?;
// Safe to unwrap because this method is called after the VM is configured // Safe to unwrap because this method is called after the VM is configured
let vm_memory = vm.get_memory(); let vm_memory = vm.get_memory();
@ -170,6 +175,7 @@ pub struct Vm<'a> {
kernel: File, kernel: File,
memory: GuestMemoryMmap, memory: GuestMemoryMmap,
vcpus: Option<Vec<thread::JoinHandle<()>>>, vcpus: Option<Vec<thread::JoinHandle<()>>>,
cpuid: CpuId,
config: VmConfig<'a>, config: VmConfig<'a>,
} }
@ -214,11 +220,17 @@ impl<'a> Vm<'a> {
// Create IRQ chip // Create IRQ chip
fd.create_irq_chip().map_err(Error::VmSetup)?; fd.create_irq_chip().map_err(Error::VmSetup)?;
// Supported CPUID
let cpuid = kvm
.get_supported_cpuid(MAX_KVM_CPUID_ENTRIES)
.map_err(Error::VmSetup)?;
Ok(Vm { Ok(Vm {
fd, fd,
kernel, kernel,
memory: guest_memory, memory: guest_memory,
vcpus: None, vcpus: None,
cpuid,
config: vm_config, config: vm_config,
}) })
} }