Skip to content

Commit 59e6520

Browse files
committed
fix: power off vcpus only during startup
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. To do this we stop applying the `KVM_ARM_VCPU_POWER_OFF` to the `kvi` during restore. Also if we need to store `kvi` in the state, do this before adding `KVM_ARM_VCPU_POWER_OFF` to it, so that during restore `kvi` will not have `KVM_ARM_VCPU_POWER_OFF` set. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 8859726 commit 59e6520

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/vmm/src/vstate/vcpu/aarch64.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,32 @@ impl KvmVcpu {
129129
vm_fd: &VmFd,
130130
vcpu_features: &[VcpuFeatures],
131131
) -> Result<(), KvmVcpuError> {
132-
let mut kvi = Self::default_kvi(vm_fd, self.index)?;
132+
let mut kvi = Self::default_kvi(vm_fd)?;
133133

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

139-
self.init_vcpu(&kvi)?;
140-
self.finalize_vcpu(&kvi)?;
141-
142139
self.kvi = if !vcpu_features.is_empty() {
143140
Some(kvi)
144141
} else {
145142
None
146143
};
147144

145+
// Non-boot cpus are powered off initially.
146+
if 0 < self.index {
147+
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;
148+
}
149+
150+
self.init_vcpu(&kvi)?;
151+
self.finalize_vcpu(&kvi)?;
152+
148153
Ok(())
149154
}
150155

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

164-
// Non-boot cpus are powered off initially.
165-
if index > 0 {
166-
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;
167-
}
168-
169166
Ok(kvi)
170167
}
171168

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

0 commit comments

Comments
 (0)