hypervisor: trim qualified paths

Import the modules used in the crate instead of spelling the full paths
at every use site, and drop the now-unnecessary crate-level
generated msr_index.rs was trimmed separately.

Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com>
Assisted-by: Claude:Opus-4.8
This commit is contained in:
Henry Hrvoje Tonkovac
2026-06-22 11:20:58 +02:00
committed by Sebastien Boeuf
parent bb81c6650b
commit 01de980615
11 changed files with 105 additions and 88 deletions

View File

@@ -3,13 +3,17 @@
// SPDX-License-Identifier: Apache-2.0
use std::any::Any;
use std::result;
use std::{mem, result};
use serde::de::Error as SerdeError;
use serde::{Deserialize, Serialize};
use serde_json;
use thiserror::Error;
#[cfg(feature = "kvm")]
use crate::kvm::aarch64::gic::Gicv3ItsState;
#[cfg(feature = "mshv")]
use crate::mshv::aarch64::gic::MshvGicV2MState;
use crate::{CpuState, HypervisorDeviceError, HypervisorVmError};
/// Errors thrown while setting up the VGIC.
@@ -42,13 +46,13 @@ pub struct VgicConfig {
#[derive(Clone, Serialize)]
pub enum GicState {
#[cfg(feature = "kvm")]
Kvm(crate::kvm::aarch64::gic::Gicv3ItsState),
Kvm(Gicv3ItsState),
#[cfg(feature = "mshv")]
MshvGicV2M(crate::mshv::aarch64::gic::MshvGicV2MState),
MshvGicV2M(MshvGicV2MState),
}
impl<'de> Deserialize<'de> for GicState {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
@@ -57,24 +61,19 @@ impl<'de> Deserialize<'de> for GicState {
#[derive(Deserialize)]
pub enum GicStateDefaultDeserialize {
#[cfg(feature = "kvm")]
Kvm(crate::kvm::aarch64::gic::Gicv3ItsState),
Kvm(Gicv3ItsState),
#[cfg(feature = "mshv")]
MshvGicV2M(crate::mshv::aarch64::gic::MshvGicV2MState),
MshvGicV2M(MshvGicV2MState),
}
const {
assert!(
std::mem::size_of::<GicStateDefaultDeserialize>()
== std::mem::size_of::<GicState>()
);
assert!(mem::size_of::<GicStateDefaultDeserialize>() == mem::size_of::<GicState>());
};
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
#[cfg(feature = "kvm")]
if let Ok(gicv3_its_state) =
crate::kvm::aarch64::gic::Gicv3ItsState::deserialize(value.clone())
{
if let Ok(gicv3_its_state) = Gicv3ItsState::deserialize(value.clone()) {
return Ok(GicState::Kvm(gicv3_its_state));
}

View File

@@ -6,6 +6,7 @@
use core::fmt::Debug;
use std::fmt::{self, Display};
use std::result;
use thiserror::Error;
@@ -147,4 +148,4 @@ pub trait PlatformEmulator {
fn fetch(&self, ip: u64, instruction_bytes: &mut [u8]) -> Result<(), PlatformError>;
}
pub type EmulationResult<S, E> = std::result::Result<S, EmulationError<E>>;
pub type EmulationResult<S, E> = result::Result<S, EmulationError<E>>;

View File

@@ -12,6 +12,8 @@
//
use core::fmt;
use std::mem;
use std::os::raw;
use thiserror::Error;
@@ -246,7 +248,7 @@ pub struct CpuIdEntry {
}
impl fmt::Display for CpuIdEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"function = 0x{:08x} \
@@ -280,13 +282,13 @@ pub struct FpuState {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct LapicState {
#[serde_as(as = "[_; 1024usize]")]
pub(crate) regs: [::std::os::raw::c_char; 1024usize],
pub(crate) regs: [raw::c_char; 1024usize],
}
impl Default for LapicState {
fn default() -> Self {
// SAFETY: this is plain old data structure
unsafe { ::std::mem::zeroed() }
unsafe { mem::zeroed() }
}
}
@@ -353,7 +355,7 @@ impl Default for XsaveState {
fn default() -> Self {
Self {
// SAFETY: this is plain old data structure
region: unsafe { std::mem::zeroed() },
region: unsafe { mem::zeroed() },
extra: Vec::new(),
}
}