mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor, vmm: Avoid leaking hypervisor specific data structure
Currently a bunch of KVM specific interfaces are leaked into the vmm crate which should ideally does not contain any hypervisor specific data structures. Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
//
|
||||
//
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use std::sync::Arc;
|
||||
|
||||
use thiserror::Error;
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
use vm_memory::GuestAddress;
|
||||
@@ -449,7 +452,26 @@ pub trait Vcpu: Send + Sync {
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_finalize(&self, feature: i32) -> Result<()>;
|
||||
|
||||
///
|
||||
/// Gets the features that have been finalized for a given CPU.
|
||||
///
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_get_finalized_features(&self) -> i32;
|
||||
///
|
||||
/// Sets processor features for a given CPU.
|
||||
///
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_set_processor_features(
|
||||
&self,
|
||||
vm: &Arc<dyn crate::Vm>,
|
||||
kvi: &mut VcpuInit,
|
||||
id: u8,
|
||||
) -> Result<()>;
|
||||
///
|
||||
/// Returns VcpuInit with default value set
|
||||
///
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn create_vcpu_init(&self) -> VcpuInit;
|
||||
///
|
||||
/// Gets a list of the guest registers that are supported for the
|
||||
/// KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
|
||||
|
||||
@@ -2657,6 +2657,64 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
.map_err(|e| cpu::HypervisorCpuError::SetDebugRegs(e.into()))
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_get_finalized_features(&self) -> i32 {
|
||||
kvm_bindings::KVM_ARM_VCPU_SVE as i32
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_set_processor_features(
|
||||
&self,
|
||||
vm: &Arc<dyn crate::Vm>,
|
||||
kvi: &mut crate::VcpuInit,
|
||||
id: u8,
|
||||
) -> cpu::Result<()> {
|
||||
use std::arch::is_aarch64_feature_detected;
|
||||
#[allow(clippy::nonminimal_bool)]
|
||||
let sve_supported =
|
||||
is_aarch64_feature_detected!("sve") || is_aarch64_feature_detected!("sve2");
|
||||
|
||||
let mut kvm_kvi: kvm_bindings::kvm_vcpu_init = (*kvi).into();
|
||||
|
||||
// We already checked that the capability is supported.
|
||||
kvm_kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PSCI_0_2;
|
||||
if vm
|
||||
.as_any()
|
||||
.downcast_ref::<crate::kvm::KvmVm>()
|
||||
.unwrap()
|
||||
.check_extension(Cap::ArmPmuV3)
|
||||
{
|
||||
kvm_kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PMU_V3;
|
||||
}
|
||||
|
||||
if sve_supported
|
||||
&& vm
|
||||
.as_any()
|
||||
.downcast_ref::<crate::kvm::KvmVm>()
|
||||
.unwrap()
|
||||
.check_extension(Cap::ArmSve)
|
||||
{
|
||||
kvm_kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_SVE;
|
||||
}
|
||||
|
||||
// Non-boot cpus are powered off initially.
|
||||
if id > 0 {
|
||||
kvm_kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;
|
||||
}
|
||||
|
||||
*kvi = kvm_kvi.into();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Return VcpuInit with default value set
|
||||
///
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn create_vcpu_init(&self) -> crate::VcpuInit {
|
||||
kvm_bindings::kvm_vcpu_init::default().into()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_init(&self, kvi: &crate::VcpuInit) -> cpu::Result<()> {
|
||||
let kvm_kvi: kvm_bindings::kvm_vcpu_init = (*kvi).into();
|
||||
|
||||
@@ -1257,6 +1257,31 @@ impl cpu::Vcpu for MshvVcpu {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_finalize(&self, _feature: i32) -> cpu::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_get_finalized_features(&self) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn vcpu_set_processor_features(
|
||||
&self,
|
||||
_vm: &Arc<dyn crate::Vm>,
|
||||
_kvi: &mut crate::VcpuInit,
|
||||
_id: u8,
|
||||
) -> cpu::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn create_vcpu_init(&self) -> crate::VcpuInit {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
///
|
||||
/// X86 specific call to setup the CPUID registers.
|
||||
|
||||
Reference in New Issue
Block a user