diff --git a/hypervisor/src/hypervisor.rs b/hypervisor/src/hypervisor.rs index 055a3db64..4fcceae71 100644 --- a/hypervisor/src/hypervisor.rs +++ b/hypervisor/src/hypervisor.rs @@ -55,6 +55,11 @@ pub enum HypervisorError { /// #[error("Failed to get the list of supported MSRs: {0}")] GetMsrList(#[source] anyhow::Error), + /// + /// API version is not compatible + /// + #[error("Incompatible API version")] + IncompatibleApiVersion, } /// diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index f06a5046b..2efc75402 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -345,6 +345,12 @@ impl KvmHypervisor { /// Create a hypervisor based on Kvm pub fn new() -> hypervisor::Result { let kvm_obj = Kvm::new().map_err(|e| hypervisor::HypervisorError::VmCreate(e.into()))?; + let api_version = kvm_obj.get_api_version(); + + if api_version != kvm_bindings::KVM_API_VERSION as i32 { + return Err(hypervisor::HypervisorError::IncompatibleApiVersion); + } + Ok(KvmHypervisor { kvm: kvm_obj }) } }