Skip to content

Commit ad2fd73

Browse files
committed
refactor(vmm/aarch64): removed Result redefinition
- Removed redefinition of `Result` - Removed unnecessary imports Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 44b595a commit ad2fd73

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/vmm/src/arch/aarch64/regs.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// found in the THIRD-PARTY file.
77

88
use std::path::PathBuf;
9-
use std::{fs, mem, result, u32};
109

1110
use kvm_bindings::*;
1211
use kvm_ioctls::VcpuFd;
@@ -19,7 +18,7 @@ use super::get_fdt_addr;
1918
/// Struct describing a saved aarch64 register.
2019
///
2120
/// Used for interacting with `KVM_GET/SET_ONE_REG`.
22-
#[derive(Debug, Clone, Versionize, PartialEq, Eq)]
21+
#[derive(Debug, Clone, PartialEq, Eq, Versionize)]
2322
pub struct Aarch64Register {
2423
/// The KVM register ID.
2524
///
@@ -58,7 +57,6 @@ pub enum Error {
5857
#[error("{0}")]
5958
GetMidrEl1(String),
6059
}
61-
type Result<T> = result::Result<T, Error>;
6260

6361
#[allow(non_upper_case_globals)]
6462
// PSR (Processor State Register) bits.
@@ -123,7 +121,7 @@ macro_rules! arm64_core_reg_id {
123121
KVM_REG_ARM64 as u64
124122
| u64::from(KVM_REG_ARM_CORE)
125123
| $size
126-
| (($offset / mem::size_of::<u32>()) as u64)
124+
| (($offset / std::mem::size_of::<u32>()) as u64)
127125
};
128126
}
129127

@@ -171,7 +169,7 @@ arm64_sys_reg!(KVM_REG_ARM_TIMER_CNT, 3, 3, 14, 3, 2);
171169
///
172170
/// * `state` - Array slice of [`Aarch64Register`] structures, representing the registers of a VCPU
173171
/// state.
174-
pub fn get_manufacturer_id_from_state(state: &[Aarch64Register]) -> Result<u32> {
172+
pub fn get_manufacturer_id_from_state(state: &[Aarch64Register]) -> Result<u32, Error> {
175173
let midr_el1 = state.iter().find(|reg| reg.id == MIDR_EL1);
176174
match midr_el1 {
177175
Some(register) => Ok(register.value as u32 >> 24),
@@ -183,11 +181,11 @@ pub fn get_manufacturer_id_from_state(state: &[Aarch64Register]) -> Result<u32>
183181

184182
/// Extract the Manufacturer ID from the host.
185183
/// The ID is found between bits 24-31 of MIDR_EL1 register.
186-
pub fn get_manufacturer_id_from_host() -> Result<u32> {
184+
pub fn get_manufacturer_id_from_host() -> Result<u32, Error> {
187185
let midr_el1_path =
188186
&PathBuf::from("/sys/devices/system/cpu/cpu0/regs/identification/midr_el1".to_string());
189187

190-
let midr_el1 = fs::read_to_string(midr_el1_path).map_err(|err| {
188+
let midr_el1 = std::fs::read_to_string(midr_el1_path).map_err(|err| {
191189
Error::GetMidrEl1(format!("Failed to get MIDR_EL1 from host path: {err}"))
192190
})?;
193191
let midr_el1_trimmed = midr_el1.trim_end().trim_start_matches("0x");
@@ -210,7 +208,7 @@ pub fn setup_boot_regs(
210208
cpu_id: u8,
211209
boot_ip: u64,
212210
mem: &GuestMemoryMmap,
213-
) -> Result<()> {
211+
) -> Result<(), Error> {
214212
let kreg_off = offset__of!(kvm_regs, regs);
215213

216214
// Get the register index of the PSTATE (Processor State) register.
@@ -244,7 +242,7 @@ pub fn setup_boot_regs(
244242
/// # Arguments
245243
///
246244
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
247-
pub fn read_mpidr(vcpu: &VcpuFd) -> Result<u64> {
245+
pub fn read_mpidr(vcpu: &VcpuFd) -> Result<u64, Error> {
248246
match vcpu.get_one_reg(MPIDR_EL1) {
249247
Err(err) => Err(Error::GetOneReg(MPIDR_EL1, err)),
250248
// MPIDR register is 64 bit wide on aarch64, this expect cannot fail
@@ -301,7 +299,7 @@ pub fn get_core_registers_ids() -> Vec<u64> {
301299
let mut off = offset__of!(kvm_regs, fp_regs) + offset__of!(user_fpsimd_state, vregs);
302300
for _ in 0..NR_FP_VREGS {
303301
ids.push(arm64_core_reg_id!(KVM_REG_SIZE_U128, off));
304-
off += mem::size_of::<u128>();
302+
off += std::mem::size_of::<u128>();
305303
}
306304

307305
// Floating-point Status Register.
@@ -321,7 +319,7 @@ pub fn get_core_registers_ids() -> Vec<u64> {
321319
///
322320
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
323321
/// * `state` - Input/Output vector of registers states.
324-
pub fn save_core_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> Result<()> {
322+
pub fn save_core_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> Result<(), Error> {
325323
save_registers(vcpu, &get_core_registers_ids(), state)
326324
}
327325

@@ -331,7 +329,7 @@ pub fn save_core_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> R
331329
///
332330
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
333331
/// * `state` - Input/Output vector of registers states.
334-
pub fn save_all_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> Result<()> {
332+
pub fn save_all_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> Result<(), Error> {
335333
// Call KVM_GET_REG_LIST to get all registers available to the guest. For ArmV8 there are
336334
// less than 500 registers.
337335
let mut reg_list = RegList::new(500).map_err(Error::Fam)?;
@@ -350,7 +348,11 @@ pub fn save_all_registers(vcpu: &VcpuFd, state: &mut Vec<Aarch64Register>) -> Re
350348
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
351349
/// * `ids` - Slice of registers ids to save.
352350
/// * `state` - Input/Output vector of registers states.
353-
pub fn save_registers(vcpu: &VcpuFd, ids: &[u64], state: &mut Vec<Aarch64Register>) -> Result<()> {
351+
pub fn save_registers(
352+
vcpu: &VcpuFd,
353+
ids: &[u64],
354+
state: &mut Vec<Aarch64Register>,
355+
) -> Result<(), Error> {
354356
for id in ids.iter() {
355357
state.push(Aarch64Register {
356358
id: *id,
@@ -369,7 +371,7 @@ pub fn save_registers(vcpu: &VcpuFd, ids: &[u64], state: &mut Vec<Aarch64Registe
369371
///
370372
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
371373
/// * `state` - Structure containing the state of the system registers.
372-
pub fn restore_registers(vcpu: &VcpuFd, state: &[Aarch64Register]) -> Result<()> {
374+
pub fn restore_registers(vcpu: &VcpuFd, state: &[Aarch64Register]) -> Result<(), Error> {
373375
for reg in state {
374376
vcpu.set_one_reg(reg.id, reg.value)
375377
.map_err(|e| Error::SetOneReg(reg.id, e))?;
@@ -382,7 +384,7 @@ pub fn restore_registers(vcpu: &VcpuFd, state: &[Aarch64Register]) -> Result<()>
382384
/// # Arguments
383385
///
384386
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
385-
pub fn get_mpstate(vcpu: &VcpuFd) -> Result<kvm_mp_state> {
387+
pub fn get_mpstate(vcpu: &VcpuFd) -> Result<kvm_mp_state, Error> {
386388
vcpu.get_mp_state().map_err(Error::GetMp)
387389
}
388390

@@ -392,7 +394,7 @@ pub fn get_mpstate(vcpu: &VcpuFd) -> Result<kvm_mp_state> {
392394
///
393395
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
394396
/// * `state` - Structure for returning the state of the system registers.
395-
pub fn set_mpstate(vcpu: &VcpuFd, state: kvm_mp_state) -> Result<()> {
397+
pub fn set_mpstate(vcpu: &VcpuFd, state: kvm_mp_state) -> Result<(), Error> {
396398
vcpu.set_mp_state(state).map_err(Error::SetMp)
397399
}
398400

0 commit comments

Comments
 (0)