mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor: hypervisor_type method on Vcpu trait
Although it is already possible to obtain the hypervisor type from the hypervisor trait object, there is currently no way for functions that only have a vCPU object to work with to know what the hypervisor backend is. In the rare case where there is significant divergence between the supported hypervisor backends when working with vCPU objects the caller must necessarily branch on the hypervisor type. We thus introduce a hypervisor_type method on the Vcpu trait. This will be utilized in a follow up commit where we need special handling when configuring MSRs of vCPUs. Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de> On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
6ea8e8e20e
commit
d2d13beb28
@@ -30,7 +30,7 @@ use crate::arch::aarch64::ExtendedReg;
|
||||
use crate::arch::x86::{CpuIdEntry, FpuState, LapicState, MsrEntry, SpecialRegisters};
|
||||
#[cfg(feature = "tdx")]
|
||||
use crate::kvm::{TdxExitDetails, TdxExitStatus};
|
||||
use crate::{CpuState, MpState, StandardRegisters};
|
||||
use crate::{CpuState, HypervisorType, MpState, StandardRegisters};
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
@@ -679,4 +679,9 @@ pub trait Vcpu: Send + Sync {
|
||||
/// Trigger NMI interrupt
|
||||
///
|
||||
fn nmi(&self) -> Result<()>;
|
||||
|
||||
///
|
||||
/// The type of the hypervisor backing this vCPU
|
||||
///
|
||||
fn hypervisor_type(&self) -> HypervisorType;
|
||||
}
|
||||
|
||||
@@ -3765,6 +3765,10 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hypervisor_type(&self) -> HypervisorType {
|
||||
HypervisorType::Kvm
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
|
||||
@@ -1626,6 +1626,10 @@ impl cpu::Vcpu for MshvVcpu {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hypervisor_type(&self) -> HypervisorType {
|
||||
HypervisorType::Mshv
|
||||
}
|
||||
}
|
||||
|
||||
impl MshvVcpu {
|
||||
|
||||
Reference in New Issue
Block a user