vmm: Check for required capabilities

We now require CAP_SIGNAL_MSI, CAP_TSC_DEADLINE_TIMER and
CAP_SPLIT_IRQCHIP.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2019-12-05 15:24:26 +00:00 committed by Samuel Ortiz
parent 904b1ea599
commit 72fb687e3f

View File

@ -145,6 +145,9 @@ pub enum Error {
/// Error from CPU handling /// Error from CPU handling
CpuManager(cpu::Error), CpuManager(cpu::Error),
/// Capability missing
CapabilityMissing(Cap),
} }
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;
@ -243,6 +246,20 @@ impl Vm {
reset_evt: EventFd, reset_evt: EventFd,
) -> Result<Self> { ) -> Result<Self> {
let kvm = Kvm::new().map_err(Error::KvmNew)?; let kvm = Kvm::new().map_err(Error::KvmNew)?;
// Check required capabilities:
if !kvm.check_extension(Cap::SignalMsi) {
return Err(Error::CapabilityMissing(Cap::SignalMsi));
}
if !kvm.check_extension(Cap::TscDeadlineTimer) {
return Err(Error::CapabilityMissing(Cap::TscDeadlineTimer));
}
if !kvm.check_extension(Cap::SplitIrqchip) {
return Err(Error::CapabilityMissing(Cap::SplitIrqchip));
}
let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path) let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path)
.map_err(Error::KernelFile)?; .map_err(Error::KernelFile)?;
let fd = kvm.create_vm().map_err(Error::VmCreate)?; let fd = kvm.create_vm().map_err(Error::VmCreate)?;