Skip to content

Commit 809d720

Browse files
committed
fmt
1 parent 41f8326 commit 809d720

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

src/mem.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::marker::PhantomData;
22

3-
use memory_addr::PAGE_SIZE_4K as PAGE_SIZE;
43
use crate::{Hal, HostPhysAddr, Result, VmxError};
4+
use memory_addr::PAGE_SIZE_4K as PAGE_SIZE;
55

66
/// A physical frame which will be automatically deallocated when dropped.
77
///
@@ -16,8 +16,7 @@ pub struct PhysFrame<H: Hal> {
1616
impl<H: Hal> PhysFrame<H> {
1717
/// Allocate a [`PhysFrame`].
1818
pub fn alloc() -> Result<Self> {
19-
let start_paddr = H::alloc_frame()
20-
.ok_or_else(|| VmxError::MemoryAllocationFailed)?;
19+
let start_paddr = H::alloc_frame().ok_or_else(|| VmxError::MemoryAllocationFailed)?;
2120
assert_ne!(start_paddr, 0);
2221
Ok(Self {
2322
start_paddr: Some(start_paddr),

src/vmx/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use self::vcpu::VmxVcpu as VmxArchVCpu;
1313
pub use self::vmcs::{VmxExitInfo, VmxInterruptInfo, VmxIoExitInfo};
1414

1515
// 导出自定义错误类型
16-
pub use crate::{VmxError, Result};
16+
pub use crate::{Result, VmxError};
1717

1818
/// Return if current platform support virtualization extension.
1919
pub fn has_hardware_support() -> bool {
@@ -31,9 +31,9 @@ pub fn read_vmcs_revision_id() -> u32 {
3131
fn as_axerr(err: x86::vmx::VmFail) -> VmxError {
3232
use x86::vmx::VmFail;
3333
match err {
34-
VmFail::VmFailValid => {
35-
VmxError::VmxInstructionError(alloc::string::String::from(vmcs::instruction_error().as_str()))
36-
}
34+
VmFail::VmFailValid => VmxError::VmxInstructionError(alloc::string::String::from(
35+
vmcs::instruction_error().as_str(),
36+
)),
3737
VmFail::VmFailInvalid => VmxError::InvalidVmcsPtr,
3838
}
3939
}

src/vmx/percpu.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use x86_64::registers::control::{Cr0, Cr4, Cr4Flags};
44
use alloc::format;
55
use memory_addr::PAGE_SIZE_4K as PAGE_SIZE;
66

7-
use crate::{Hal, Result, VmxError};
87
use crate::msr::Msr;
98
use crate::vmx::has_hardware_support;
109
use crate::vmx::structs::{FeatureControl, FeatureControlFlags, VmxBasic, VmxRegion};
10+
use crate::{Hal, Result, VmxError};
1111

1212
/// Represents the per-CPU state for Virtual Machine Extensions (VMX).
1313
///
@@ -43,7 +43,9 @@ impl<H: Hal> VmxPerCpuState<H> {
4343

4444
pub fn hardware_enable(&mut self) -> Result<()> {
4545
if !has_hardware_support() {
46-
return Err(VmxError::UnsupportedFeature("CPU does not support feature VMX".into()));
46+
return Err(VmxError::UnsupportedFeature(
47+
"CPU does not support feature VMX".into(),
48+
));
4749
}
4850
if self.is_enabled() {
4951
return Err(VmxError::VmxAlreadyEnabled);
@@ -77,28 +79,42 @@ impl<H: Hal> VmxPerCpuState<H> {
7779
}};
7880
}
7981
if !cr_is_valid!(Cr0::read().bits(), CR0) {
80-
return Err(VmxError::InvalidVmcsConfig("host CR0 is not valid in VMX operation".into()));
82+
return Err(VmxError::InvalidVmcsConfig(
83+
"host CR0 is not valid in VMX operation".into(),
84+
));
8185
}
8286
if !cr_is_valid!(Cr4::read().bits(), CR4) {
83-
return Err(VmxError::InvalidVmcsConfig("host CR4 is not valid in VMX operation".into()));
87+
return Err(VmxError::InvalidVmcsConfig(
88+
"host CR4 is not valid in VMX operation".into(),
89+
));
8490
}
8591

8692
// Get VMCS revision identifier in IA32_VMX_BASIC MSR.
8793
let vmx_basic = VmxBasic::read();
8894
if vmx_basic.region_size as usize != PAGE_SIZE {
89-
return Err(VmxError::UnsupportedFeature("VMX region size is not 4K".into()));
95+
return Err(VmxError::UnsupportedFeature(
96+
"VMX region size is not 4K".into(),
97+
));
9098
}
9199
if vmx_basic.mem_type != VmxBasic::VMX_MEMORY_TYPE_WRITE_BACK {
92-
return Err(VmxError::UnsupportedFeature("VMX memory type is not write-back".into()));
100+
return Err(VmxError::UnsupportedFeature(
101+
"VMX memory type is not write-back".into(),
102+
));
93103
}
94104
if vmx_basic.is_32bit_address {
95-
return Err(VmxError::UnsupportedFeature("32-bit VMX not supported".into()));
105+
return Err(VmxError::UnsupportedFeature(
106+
"32-bit VMX not supported".into(),
107+
));
96108
}
97109
if !vmx_basic.io_exit_info {
98-
return Err(VmxError::UnsupportedFeature("IO exit info not supported".into()));
110+
return Err(VmxError::UnsupportedFeature(
111+
"IO exit info not supported".into(),
112+
));
99113
}
100114
if !vmx_basic.vmx_flex_controls {
101-
return Err(VmxError::UnsupportedFeature("VMX flex controls not supported".into()));
115+
return Err(VmxError::UnsupportedFeature(
116+
"VMX flex controls not supported".into(),
117+
));
102118
}
103119
self.vmcs_revision_id = vmx_basic.revision_id;
104120
self.vmx_region = VmxRegion::new(self.vmcs_revision_id, false)?;

src/vmx/vmcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use axaddrspace::{GuestPhysAddr, HostPhysAddr, NestedPageFaultInfo};
1111
use page_table_entry::MappingFlags;
1212

1313
use super::as_axerr;
14-
use super::definitions::{VmxRawExitReason, VmxInstructionError, VmxInterruptionType};
15-
use crate::{Result, VmxError};
14+
use super::definitions::{VmxInstructionError, VmxInterruptionType, VmxRawExitReason};
1615
use crate::msr::Msr;
16+
use crate::{Result, VmxError};
1717

1818
// HYGIENE: These macros are only used in this file, so we can use `as_axerr` directly.
1919

0 commit comments

Comments
 (0)