Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: power off vcpus only during startup #4567

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

roypat marked this conversation as resolved.
Show resolved Hide resolved
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
Loading