Skip to content

Commit 9fc4073

Browse files
roypatbchalios
authored andcommitted
refactor: move get_manufacturer_id_from_host() to regs.rs
Just make this a method on `Aarch64RegisterVec`, and make it return `Option`, because there was only a single error case, and the error message was additionall never displayed because the only call site ignores errors beyond acknowledging that they happened. Signed-off-by: Patrick Roy <[email protected]>
1 parent 3e4d837 commit 9fc4073

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ impl Aarch64RegisterVec {
260260
data: &mut self.data,
261261
}
262262
}
263+
264+
/// Extract the Manufacturer ID from a VCPU state's registers.
265+
/// The ID is found between bits 24-31 of MIDR_EL1 register.
266+
pub fn manifacturer_id(&self) -> Option<u32> {
267+
self.iter()
268+
.find(|reg| reg.id == MIDR_EL1)
269+
.map(|reg| ((reg.value::<u64, 8>() >> 24) & 0xFF) as u32)
270+
}
263271
}
264272

265273
impl Serialize for Aarch64RegisterVec {

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ pub enum VcpuArchError {
4545
GetMidrEl1(String),
4646
}
4747

48-
/// Extract the Manufacturer ID from a VCPU state's registers.
49-
/// The ID is found between bits 24-31 of MIDR_EL1 register.
50-
///
51-
/// # Arguments
52-
///
53-
/// * `regs` - reference [`Aarch64RegisterVec`] structure with all registers of a VCPU.
54-
pub fn get_manufacturer_id_from_state(regs: &Aarch64RegisterVec) -> Result<u32, VcpuArchError> {
55-
let midr_el1 = regs.iter().find(|reg| reg.id == MIDR_EL1);
56-
match midr_el1 {
57-
Some(register) => Ok(((register.value::<u64, 8>() >> 24) & 0xFF) as u32),
58-
None => Err(VcpuArchError::GetMidrEl1(
59-
"Failed to find MIDR_EL1 in vCPU state!".to_string(),
60-
)),
61-
}
62-
}
63-
6448
/// Extract the Manufacturer ID from the host.
6549
/// The ID is found between bits 24-31 of MIDR_EL1 register.
6650
pub fn get_manufacturer_id_from_host() -> Result<u32, VcpuArchError> {

src/vmm/src/persist.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use userfaultfd::{FeatureFlags, Uffd, UffdBuilder};
1717
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
1818

1919
#[cfg(target_arch = "aarch64")]
20-
use crate::arch::aarch64::vcpu::{get_manufacturer_id_from_host, get_manufacturer_id_from_state};
20+
use crate::arch::aarch64::vcpu::get_manufacturer_id_from_host;
2121
use crate::builder::{self, BuildMicrovmFromSnapshotError};
2222
use crate::cpu_config::templates::StaticCpuTemplate;
2323
#[cfg(target_arch = "x86_64")]
@@ -331,24 +331,24 @@ pub fn validate_cpu_vendor(microvm_state: &MicrovmState) {
331331
#[cfg(target_arch = "aarch64")]
332332
pub fn validate_cpu_manufacturer_id(microvm_state: &MicrovmState) {
333333
let host_cpu_id = get_manufacturer_id_from_host();
334-
let snapshot_cpu_id = get_manufacturer_id_from_state(&microvm_state.vcpu_states[0].regs);
334+
let snapshot_cpu_id = microvm_state.vcpu_states[0].regs.manifacturer_id();
335335
match (host_cpu_id, snapshot_cpu_id) {
336-
(Ok(host_id), Ok(snapshot_id)) => {
336+
(Ok(host_id), Some(snapshot_id)) => {
337337
info!("Host CPU manufacturer ID: {host_id:?}");
338338
info!("Snapshot CPU manufacturer ID: {snapshot_id:?}");
339339
if host_id != snapshot_id {
340340
warn!("Host CPU manufacturer ID differs from the snapshotted one",);
341341
}
342342
}
343-
(Ok(host_id), Err(_)) => {
343+
(Ok(host_id), None) => {
344344
info!("Host CPU manufacturer ID: {host_id:?}");
345345
warn!("Snapshot CPU manufacturer ID: couldn't get from the snapshot");
346346
}
347-
(Err(_), Ok(snapshot_id)) => {
347+
(Err(_), Some(snapshot_id)) => {
348348
warn!("Host CPU manufacturer ID: couldn't get from the host");
349349
info!("Snapshot CPU manufacturer ID: {snapshot_id:?}");
350350
}
351-
(Err(_), Err(_)) => {
351+
(Err(_), None) => {
352352
warn!("Host CPU manufacturer ID: couldn't get from the host");
353353
warn!("Snapshot CPU manufacturer ID: couldn't get from the snapshot");
354354
}

0 commit comments

Comments
 (0)