mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 21:55:20 +00:00
vmm: Seperate the CPUID setup from the CpuManager::new()
This allows the decoupling of CpuManager and MemoryManager. See: #4761 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
c5eac2e822
commit
725e388684
@ -547,7 +547,7 @@ impl CpuidFeatureEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_common_cpuid(
|
pub fn generate_common_cpuid(
|
||||||
hypervisor: Arc<dyn hypervisor::Hypervisor>,
|
hypervisor: &Arc<dyn hypervisor::Hypervisor>,
|
||||||
topology: Option<(u8, u8, u8)>,
|
topology: Option<(u8, u8, u8)>,
|
||||||
sgx_epc_sections: Option<Vec<SgxEpcSection>>,
|
sgx_epc_sections: Option<Vec<SgxEpcSection>>,
|
||||||
phys_bits: u8,
|
phys_bits: u8,
|
||||||
|
@ -20,6 +20,7 @@ use crate::coredump::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "guest_debug")]
|
#[cfg(feature = "guest_debug")]
|
||||||
use crate::gdb::{get_raw_tid, Debuggable, DebuggableError};
|
use crate::gdb::{get_raw_tid, Debuggable, DebuggableError};
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
use crate::memory_manager::MemoryManager;
|
use crate::memory_manager::MemoryManager;
|
||||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
@ -576,12 +577,11 @@ impl CpuManager {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
config: &CpusConfig,
|
config: &CpusConfig,
|
||||||
memory_manager: &Arc<Mutex<MemoryManager>>,
|
|
||||||
vm: Arc<dyn hypervisor::Vm>,
|
vm: Arc<dyn hypervisor::Vm>,
|
||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
reset_evt: EventFd,
|
reset_evt: EventFd,
|
||||||
#[cfg(feature = "guest_debug")] vm_debug_evt: EventFd,
|
#[cfg(feature = "guest_debug")] vm_debug_evt: EventFd,
|
||||||
hypervisor: Arc<dyn hypervisor::Hypervisor>,
|
hypervisor: &Arc<dyn hypervisor::Hypervisor>,
|
||||||
seccomp_action: SeccompAction,
|
seccomp_action: SeccompAction,
|
||||||
vm_ops: Arc<dyn VmOps>,
|
vm_ops: Arc<dyn VmOps>,
|
||||||
#[cfg(feature = "tdx")] tdx_enabled: bool,
|
#[cfg(feature = "tdx")] tdx_enabled: bool,
|
||||||
@ -591,30 +591,6 @@ impl CpuManager {
|
|||||||
vcpu_states.resize_with(usize::from(config.max_vcpus), VcpuState::default);
|
vcpu_states.resize_with(usize::from(config.max_vcpus), VcpuState::default);
|
||||||
let hypervisor_type = hypervisor.hypervisor_type();
|
let hypervisor_type = hypervisor.hypervisor_type();
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
let sgx_epc_sections = memory_manager
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.sgx_epc_region()
|
|
||||||
.as_ref()
|
|
||||||
.map(|sgx_epc_region| sgx_epc_region.epc_sections().values().cloned().collect());
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
let cpuid = {
|
|
||||||
let phys_bits = physical_bits(config.max_phys_bits);
|
|
||||||
arch::generate_common_cpuid(
|
|
||||||
hypervisor,
|
|
||||||
config
|
|
||||||
.topology
|
|
||||||
.clone()
|
|
||||||
.map(|t| (t.threads_per_core, t.cores_per_die, t.dies_per_package)),
|
|
||||||
sgx_epc_sections,
|
|
||||||
phys_bits,
|
|
||||||
config.kvm_hyperv,
|
|
||||||
#[cfg(feature = "tdx")]
|
|
||||||
tdx_enabled,
|
|
||||||
)
|
|
||||||
.map_err(Error::CommonCpuId)?
|
|
||||||
};
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
if config.features.amx {
|
if config.features.amx {
|
||||||
const ARCH_GET_XCOMP_GUEST_PERM: usize = 0x1024;
|
const ARCH_GET_XCOMP_GUEST_PERM: usize = 0x1024;
|
||||||
@ -678,7 +654,7 @@ impl CpuManager {
|
|||||||
config: config.clone(),
|
config: config.clone(),
|
||||||
interrupt_controller: None,
|
interrupt_controller: None,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
cpuid,
|
cpuid: Vec::new(),
|
||||||
vm,
|
vm,
|
||||||
vcpus_kill_signalled: Arc::new(AtomicBool::new(false)),
|
vcpus_kill_signalled: Arc::new(AtomicBool::new(false)),
|
||||||
vcpus_pause_signalled: Arc::new(AtomicBool::new(false)),
|
vcpus_pause_signalled: Arc::new(AtomicBool::new(false)),
|
||||||
@ -698,6 +674,39 @@ impl CpuManager {
|
|||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
pub fn populate_cpuid(
|
||||||
|
&mut self,
|
||||||
|
memory_manager: &Arc<Mutex<MemoryManager>>,
|
||||||
|
hypervisor: &Arc<dyn hypervisor::Hypervisor>,
|
||||||
|
#[cfg(feature = "tdx")] tdx_enabled: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
let sgx_epc_sections = memory_manager
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.sgx_epc_region()
|
||||||
|
.as_ref()
|
||||||
|
.map(|sgx_epc_region| sgx_epc_region.epc_sections().values().cloned().collect());
|
||||||
|
self.cpuid = {
|
||||||
|
let phys_bits = physical_bits(self.config.max_phys_bits);
|
||||||
|
arch::generate_common_cpuid(
|
||||||
|
hypervisor,
|
||||||
|
self.config
|
||||||
|
.topology
|
||||||
|
.clone()
|
||||||
|
.map(|t| (t.threads_per_core, t.cores_per_die, t.dies_per_package)),
|
||||||
|
sgx_epc_sections,
|
||||||
|
phys_bits,
|
||||||
|
self.config.kvm_hyperv,
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
tdx_enabled,
|
||||||
|
)
|
||||||
|
.map_err(Error::CommonCpuId)?
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn create_vcpu(&mut self, cpu_id: u8, snapshot: Option<Snapshot>) -> Result<Arc<Mutex<Vcpu>>> {
|
fn create_vcpu(&mut self, cpu_id: u8, snapshot: Option<Snapshot>) -> Result<Arc<Mutex<Vcpu>>> {
|
||||||
info!("Creating vCPU: cpu_id = {}", cpu_id);
|
info!("Creating vCPU: cpu_id = {}", cpu_id);
|
||||||
|
|
||||||
@ -733,6 +742,9 @@ impl CpuManager {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut vcpu = vcpu.lock().unwrap();
|
let mut vcpu = vcpu.lock().unwrap();
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
assert!(!self.cpuid.is_empty());
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
vcpu.configure(boot_setup, self.cpuid.clone(), self.config.kvm_hyperv)
|
vcpu.configure(boot_setup, self.cpuid.clone(), self.config.kvm_hyperv)
|
||||||
.expect("Failed to configure vCPU");
|
.expect("Failed to configure vCPU");
|
||||||
@ -1200,6 +1212,7 @@ impl CpuManager {
|
|||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub fn common_cpuid(&self) -> Vec<CpuIdEntry> {
|
pub fn common_cpuid(&self) -> Vec<CpuIdEntry> {
|
||||||
|
assert!(!self.cpuid.is_empty());
|
||||||
self.cpuid.clone()
|
self.cpuid.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1505,7 +1505,7 @@ impl Vmm {
|
|||||||
let common_cpuid = {
|
let common_cpuid = {
|
||||||
let phys_bits = vm::physical_bits(vm_config.lock().unwrap().cpus.max_phys_bits);
|
let phys_bits = vm::physical_bits(vm_config.lock().unwrap().cpus.max_phys_bits);
|
||||||
arch::generate_common_cpuid(
|
arch::generate_common_cpuid(
|
||||||
hypervisor,
|
&hypervisor,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
phys_bits,
|
phys_bits,
|
||||||
@ -1695,7 +1695,7 @@ impl Vmm {
|
|||||||
|
|
||||||
let phys_bits = vm::physical_bits(vm_config.cpus.max_phys_bits);
|
let phys_bits = vm::physical_bits(vm_config.cpus.max_phys_bits);
|
||||||
arch::generate_common_cpuid(
|
arch::generate_common_cpuid(
|
||||||
self.hypervisor.clone(),
|
&self.hypervisor.clone(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
phys_bits,
|
phys_bits,
|
||||||
|
@ -525,13 +525,12 @@ impl Vm {
|
|||||||
let cpus_config = { &config.lock().unwrap().cpus.clone() };
|
let cpus_config = { &config.lock().unwrap().cpus.clone() };
|
||||||
let cpu_manager = cpu::CpuManager::new(
|
let cpu_manager = cpu::CpuManager::new(
|
||||||
cpus_config,
|
cpus_config,
|
||||||
&memory_manager,
|
|
||||||
vm.clone(),
|
vm.clone(),
|
||||||
exit_evt.try_clone().map_err(Error::EventFdClone)?,
|
exit_evt.try_clone().map_err(Error::EventFdClone)?,
|
||||||
reset_evt.try_clone().map_err(Error::EventFdClone)?,
|
reset_evt.try_clone().map_err(Error::EventFdClone)?,
|
||||||
#[cfg(feature = "guest_debug")]
|
#[cfg(feature = "guest_debug")]
|
||||||
vm_debug_evt,
|
vm_debug_evt,
|
||||||
hypervisor.clone(),
|
&hypervisor,
|
||||||
seccomp_action.clone(),
|
seccomp_action.clone(),
|
||||||
vm_ops,
|
vm_ops,
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
@ -540,6 +539,18 @@ impl Vm {
|
|||||||
)
|
)
|
||||||
.map_err(Error::CpuManager)?;
|
.map_err(Error::CpuManager)?;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
cpu_manager
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.populate_cpuid(
|
||||||
|
&memory_manager,
|
||||||
|
&hypervisor,
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
tdx_enabled,
|
||||||
|
)
|
||||||
|
.map_err(Error::CpuManager)?;
|
||||||
|
|
||||||
cpu_manager
|
cpu_manager
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -2487,7 +2498,7 @@ impl Snapshottable for Vm {
|
|||||||
let common_cpuid = {
|
let common_cpuid = {
|
||||||
let phys_bits = physical_bits(self.config.lock().unwrap().cpus.max_phys_bits);
|
let phys_bits = physical_bits(self.config.lock().unwrap().cpus.max_phys_bits);
|
||||||
arch::generate_common_cpuid(
|
arch::generate_common_cpuid(
|
||||||
self.hypervisor.clone(),
|
&self.hypervisor,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
phys_bits,
|
phys_bits,
|
||||||
|
Loading…
Reference in New Issue
Block a user