Skip to content

Commit

Permalink
fix: power off vcpus only during startup
Browse files Browse the repository at this point in the history
Vcpus should be in power off state during kernel boot,
but during snapshot restore we do not need to power them off
even thought kvm does not complain.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
  • Loading branch information
ShadowCurse committed Apr 23, 2024
1 parent 8e05e3c commit f48b03c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/vmm/src/vstate/vcpu/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,18 @@ impl KvmVcpu {
vm_fd: &VmFd,
vcpu_features: &[VcpuFeatures],
) -> Result<(), KvmVcpuError> {
let mut kvi = Self::default_kvi(vm_fd, self.index)?;
let mut kvi = Self::default_kvi(vm_fd)?;

for feature in vcpu_features.iter() {
let index = feature.index as usize;
kvi.features[index] = feature.bitmap.apply(kvi.features[index]);
}

// Non-boot cpus are powered off initially.
if 0 < self.index {
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;
}

self.init_vcpu(&kvi)?;
self.finalize_vcpu(&kvi)?;

Expand All @@ -149,10 +154,7 @@ impl KvmVcpu {
}

/// Creates default kvi struct based on vcpu index.
pub fn default_kvi(
vm_fd: &VmFd,
index: u8,
) -> Result<kvm_bindings::kvm_vcpu_init, KvmVcpuError> {
pub fn default_kvi(vm_fd: &VmFd) -> Result<kvm_bindings::kvm_vcpu_init, KvmVcpuError> {
let mut kvi: kvm_bindings::kvm_vcpu_init = kvm_bindings::kvm_vcpu_init::default();
// This reads back the kernel's preferred target type.
vm_fd
Expand All @@ -161,11 +163,6 @@ impl KvmVcpu {
// We already checked that the capability is supported.
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PSCI_0_2;

// Non-boot cpus are powered off initially.
if index > 0 {
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;
}

Ok(kvi)
}

Expand All @@ -185,7 +182,7 @@ impl KvmVcpu {
pub fn restore_state(&mut self, vm_fd: &VmFd, state: &VcpuState) -> Result<(), KvmVcpuError> {
let kvi = match state.kvi {
Some(kvi) => kvi,
None => Self::default_kvi(vm_fd, self.index)?,
None => Self::default_kvi(vm_fd)?,
};
self.kvi = state.kvi;

Expand Down

0 comments on commit f48b03c

Please sign in to comment.