Skip to content

Commit 7c85370

Browse files
committed
refactor(aarch64/vcpu): set one register at a time
Replace `set_registers` with `set_register` in order to have more control over each register restoration process. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent c910e44 commit 7c85370

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/vmm/src/arch/aarch64/vcpu.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,15 @@ pub fn get_all_registers_ids(vcpufd: &VcpuFd) -> Result<Vec<u64>, VcpuError> {
179179
}
180180
}
181181

182-
/// Set the state of the system registers.
182+
/// Set the state of one system register.
183183
///
184184
/// # Arguments
185185
///
186-
/// * `regs` - Slice of registers to be set.
187-
pub fn set_registers(vcpufd: &VcpuFd, regs: &Aarch64RegisterVec) -> Result<(), VcpuError> {
188-
for reg in regs.iter() {
189-
vcpufd
190-
.set_one_reg(reg.id, reg.as_slice())
191-
.map_err(|e| VcpuError::SetOneReg(reg.id, e))?;
192-
}
186+
/// * `reg` - Register to be set.
187+
pub fn set_register(vcpufd: &VcpuFd, reg: Aarch64RegisterRef) -> Result<(), VcpuError> {
188+
vcpufd
189+
.set_one_reg(reg.id, reg.as_slice())
190+
.map_err(|e| VcpuError::SetOneReg(reg.id, e))?;
193191
Ok(())
194192
}
195193

@@ -277,7 +275,9 @@ mod tests {
277275

278276
vcpu.vcpu_init(&kvi).unwrap();
279277
get_all_registers(&vcpu, &mut regs).unwrap();
280-
set_registers(&vcpu, &regs).unwrap();
278+
for reg in regs.iter() {
279+
set_register(&vcpu, reg).unwrap();
280+
}
281281
}
282282

283283
#[test]

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::arch::aarch64::regs::{
1616
};
1717
use crate::arch::aarch64::vcpu::{
1818
get_all_registers, get_all_registers_ids, get_mpidr, get_mpstate, get_registers, set_mpstate,
19-
set_registers, setup_boot_regs, VcpuError as ArchError,
19+
set_register, setup_boot_regs, VcpuError as ArchError,
2020
};
2121
use crate::cpu_config::aarch64::custom_cpu_template::VcpuFeatures;
2222
use crate::cpu_config::templates::CpuConfiguration;
@@ -191,9 +191,11 @@ impl KvmVcpu {
191191
};
192192

193193
self.init_vcpu_fd(&kvi)?;
194-
195194
self.kvi = state.kvi;
196-
set_registers(&self.fd, &state.regs).map_err(KvmVcpuError::RestoreState)?;
195+
196+
for reg in state.regs.iter() {
197+
set_register(&self.fd, reg).map_err(KvmVcpuError::RestoreState)?;
198+
}
197199
set_mpstate(&self.fd, state.mp_state).map_err(KvmVcpuError::RestoreState)?;
198200
Ok(())
199201
}

0 commit comments

Comments
 (0)