Skip to content

Commit 309eb66

Browse files
committed
refactor: simplify get_manufacturer_id_from_host
Replaces never used error result type wit optional. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent f70d3bc commit 309eb66

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::arch::aarch64::kvm::OptionalCapabilities;
2020
use crate::arch::aarch64::regs::{Aarch64RegisterVec, KVM_REG_ARM64_SVE_VLS};
2121
use crate::cpu_config::aarch64::custom_cpu_template::VcpuFeatures;
2222
use crate::cpu_config::templates::CpuConfiguration;
23+
use crate::logger::warn;
2324
use crate::logger::{IncMetric, METRICS, error};
2425
use crate::vcpu::{VcpuConfig, VcpuError};
2526
use crate::vstate::memory::{Address, GuestMemoryMmap};
@@ -41,25 +42,18 @@ pub enum VcpuArchError {
4142
SetMp(kvm_ioctls::Error),
4243
/// Failed FamStructWrapper operation: {0}
4344
Fam(vmm_sys_util::fam::Error),
44-
/// {0}
45-
GetMidrEl1(String),
4645
/// Failed to set/get device attributes for vCPU: {0}
4746
DeviceAttribute(kvm_ioctls::Error),
4847
}
4948

5049
/// Extract the Manufacturer ID from the host.
5150
/// The ID is found between bits 24-31 of MIDR_EL1 register.
52-
pub fn get_manufacturer_id_from_host() -> Result<u32, VcpuArchError> {
51+
pub fn get_manufacturer_id_from_host() -> Option<u32> {
5352
let midr_el1_path = "/sys/devices/system/cpu/cpu0/regs/identification/midr_el1";
54-
let midr_el1 = std::fs::read_to_string(midr_el1_path).map_err(|err| {
55-
VcpuArchError::GetMidrEl1(format!("Failed to get MIDR_EL1 from host path: {err}"))
56-
})?;
53+
let midr_el1 = std::fs::read_to_string(midr_el1_path).ok()?;
5754
let midr_el1_trimmed = midr_el1.trim_end().trim_start_matches("0x");
58-
let manufacturer_id = u32::from_str_radix(midr_el1_trimmed, 16).map_err(|err| {
59-
VcpuArchError::GetMidrEl1(format!("Invalid MIDR_EL1 found on host: {err}",))
60-
})?;
61-
62-
Ok(manufacturer_id >> 24)
55+
let manufacturer_id = u32::from_str_radix(midr_el1_trimmed, 16).ok()?;
56+
Some(manufacturer_id >> 24)
6357
}
6458

6559
/// Saves states of registers into `state`.

src/vmm/src/persist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,22 @@ pub fn validate_cpu_manufacturer_id(microvm_state: &MicrovmState) {
255255
let host_cpu_id = get_manufacturer_id_from_host();
256256
let snapshot_cpu_id = microvm_state.vcpu_states[0].regs.manifacturer_id();
257257
match (host_cpu_id, snapshot_cpu_id) {
258-
(Ok(host_id), Some(snapshot_id)) => {
258+
(Some(host_id), Some(snapshot_id)) => {
259259
info!("Host CPU manufacturer ID: {host_id:?}");
260260
info!("Snapshot CPU manufacturer ID: {snapshot_id:?}");
261261
if host_id != snapshot_id {
262262
warn!("Host CPU manufacturer ID differs from the snapshotted one",);
263263
}
264264
}
265-
(Ok(host_id), None) => {
265+
(Some(host_id), None) => {
266266
info!("Host CPU manufacturer ID: {host_id:?}");
267267
warn!("Snapshot CPU manufacturer ID: couldn't get from the snapshot");
268268
}
269-
(Err(_), Some(snapshot_id)) => {
269+
(None, Some(snapshot_id)) => {
270270
warn!("Host CPU manufacturer ID: couldn't get from the host");
271271
info!("Snapshot CPU manufacturer ID: {snapshot_id:?}");
272272
}
273-
(Err(_), None) => {
273+
(None, None) => {
274274
warn!("Host CPU manufacturer ID: couldn't get from the host");
275275
warn!("Snapshot CPU manufacturer ID: couldn't get from the snapshot");
276276
}

0 commit comments

Comments
 (0)