mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor: Optional vCPU MSR configuration update in vcpu constructor
When applying a CPU profile we need a way to change the configuration of each vCPU to respect the requirements of the CPU profile. This means that we need to set the feature MSRs in accordance with the CPU profile upon configuring the vCPU and also ensuring that we do not attempt to restore any MSRs that are not compatible with the profile upon snapshot/restore. The first step is to update `Vm::create_vcpu` to take an extra parameter describing the necessary update. In the case of KVM we modify the internal MSR state buffer when constructing the vCPU whenever a VcpuMsrConfigUpdate is present. The feature MSRs contained in the configuration will be treated in follow up commits. The changes to the vmm crate that are part of this commit are just the minimum necessary to make the crate compile. We will update the vmm crate to take CPU profiles into account in a follow up commit. 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
2aff169533
commit
6ea8e8e20e
@@ -95,7 +95,7 @@ use crate::ClockData;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use crate::arch::x86::{
|
||||
CpuIdEntry, FpuState, LapicState, MTRR_MSR_INDICES, MsrEntry, NUM_IOAPIC_PINS,
|
||||
SpecialRegisters, XsaveState,
|
||||
SpecialRegisters, VcpuMsrConfigUpdate, XsaveState,
|
||||
};
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
|
||||
use crate::{ClockRestoreMode, ClockState};
|
||||
@@ -886,6 +886,7 @@ impl vm::Vm for KvmVm {
|
||||
&self,
|
||||
id: u32,
|
||||
vm_ops: Option<Arc<dyn VmOps>>,
|
||||
#[cfg(target_arch = "x86_64")] msr_config_update: Option<VcpuMsrConfigUpdate>,
|
||||
) -> vm::Result<Box<dyn cpu::Vcpu>> {
|
||||
let fd = self
|
||||
.fd
|
||||
@@ -911,6 +912,21 @@ impl vm::Vm for KvmVm {
|
||||
})?;
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
let (feature_msrs, msrs) = msr_config_update.map_or_else(
|
||||
|| (Vec::new(), self.msrs.clone()),
|
||||
|update| {
|
||||
(
|
||||
update.feature_msrs,
|
||||
update
|
||||
.snapshottable_msr_indices
|
||||
.into_iter()
|
||||
.map(|index| MsrEntry { index, data: 0 })
|
||||
.collect(),
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
// Safety: `xsave_size` will not change after vcpu creation because:
|
||||
// 1. `xsave_size` depends on cpuid
|
||||
@@ -924,7 +940,9 @@ impl vm::Vm for KvmVm {
|
||||
let vcpu = KvmVcpu {
|
||||
fd,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
msrs: self.msrs.clone(),
|
||||
msrs,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
feature_msrs,
|
||||
vm_ops,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
hyperv_synic: AtomicBool::new(false),
|
||||
@@ -1921,6 +1939,8 @@ pub struct KvmVcpu {
|
||||
fd: VcpuFd,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
msrs: Vec<MsrEntry>,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
feature_msrs: Vec<MsrEntry>,
|
||||
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
hyperv_synic: AtomicBool,
|
||||
@@ -2011,7 +2031,7 @@ impl KvmVcpu {
|
||||
/// let kvm = KvmHypervisor::new().unwrap();
|
||||
/// let hypervisor = Arc::new(kvm);
|
||||
/// let vm = hypervisor.create_vm(HypervisorVmConfig::default()).expect("new VM fd creation failed");
|
||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
/// let vcpu = vm.create_vcpu(0, None, #[cfg(target_arch = "x86_64")] Default::default()).unwrap();
|
||||
/// ```
|
||||
impl cpu::Vcpu for KvmVcpu {
|
||||
///
|
||||
@@ -3068,7 +3088,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
/// let hv = Arc::new(kvm);
|
||||
/// let vm = hv.create_vm(HypervisorVmConfig::default()).expect("new VM fd creation failed");
|
||||
/// vm.enable_split_irq().unwrap();
|
||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
/// let vcpu = vm.create_vcpu(0, None, Default::default()).unwrap();
|
||||
/// let state = vcpu.state().unwrap();
|
||||
/// ```
|
||||
fn state(&self) -> cpu::Result<CpuState> {
|
||||
@@ -3333,7 +3353,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
/// let hv = Arc::new(kvm);
|
||||
/// let vm = hv.create_vm(HypervisorVmConfig::default()).expect("new VM fd creation failed");
|
||||
/// vm.enable_split_irq().unwrap();
|
||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
/// let vcpu = vm.create_vcpu(0, None, Default::default()).unwrap();
|
||||
/// let state = vcpu.state().unwrap();
|
||||
/// vcpu.set_state(&state).unwrap();
|
||||
/// ```
|
||||
|
||||
Reference in New Issue
Block a user