Skip to content

Commit aef8bb6

Browse files
committed
refactor(aarch64/vcpu): split vcpu initialization and finalization
Split `vcpu_init` and `vcpu_finalize` into separate methods for better flexibility. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 26a8e46 commit aef8bb6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ impl KvmVcpu {
139139
kvi.features[index] = feature.bitmap.apply(kvi.features[index]);
140140
}
141141

142-
self.init_vcpu_fd(&kvi)?;
142+
self.init_vcpu(&kvi)?;
143+
self.finalize_vcpu(&kvi)?;
143144

144145
self.kvi = if !vcpu_features.is_empty() {
145146
Some(kvi)
@@ -190,7 +191,8 @@ impl KvmVcpu {
190191
None => Self::default_kvi(vm_fd, self.index)?,
191192
};
192193

193-
self.init_vcpu_fd(&kvi)?;
194+
self.init_vcpu(&kvi)?;
195+
self.finalize_vcpu(&kvi)?;
194196
self.kvi = state.kvi;
195197

196198
for reg in state.regs.iter() {
@@ -237,10 +239,14 @@ impl KvmVcpu {
237239
}
238240

239241
/// Initializes internal vcpufd.
240-
/// Does additional check for SVE and calls `vcpu_finalize` if
241-
/// SVE is enabled.
242-
fn init_vcpu_fd(&self, kvi: &kvm_bindings::kvm_vcpu_init) -> Result<(), KvmVcpuError> {
242+
fn init_vcpu(&self, kvi: &kvm_bindings::kvm_vcpu_init) -> Result<(), KvmVcpuError> {
243243
self.fd.vcpu_init(kvi).map_err(KvmVcpuError::Init)?;
244+
Ok(())
245+
}
246+
247+
/// Checks for SVE feature and calls `vcpu_finalize` if
248+
/// it is enabled.
249+
fn finalize_vcpu(&self, kvi: &kvm_bindings::kvm_vcpu_init) -> Result<(), KvmVcpuError> {
244250
if (kvi.features[0] & (1 << kvm_bindings::KVM_ARM_VCPU_SVE)) != 0 {
245251
// KVM_ARM_VCPU_SVE has value 4 so casting to i32 is safe.
246252
#[allow(clippy::cast_possible_wrap)]

0 commit comments

Comments
 (0)