@@ -4,10 +4,10 @@ use x86_64::registers::control::{Cr0, Cr4, Cr4Flags};
44use alloc:: format;
55use memory_addr:: PAGE_SIZE_4K as PAGE_SIZE ;
66
7- use crate :: { Hal , Result , VmxError } ;
87use crate :: msr:: Msr ;
98use crate :: vmx:: has_hardware_support;
109use 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 ) ?;
0 commit comments