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 26, 2024
1 parent 36a8d56 commit 83a0471
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/vmm/src/vstate/vcpu/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,32 @@ 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]);
}

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

self.kvi = if !vcpu_features.is_empty() {
Some(kvi)
} else {
None
};

// 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)?;

Ok(())
}

/// 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 83a0471

Please sign in to comment.