@@ -13,19 +13,25 @@ extern crate sys_util;
1313use std:: result;
1414
1515use super :: KvmContext ;
16+ #[ cfg( target_arch = "x86_64" ) ]
1617use cpuid:: { c3_template, filter_cpuid, t2_template} ;
1718use kvm:: * ;
1819use logger:: { LogOption , LOGGER } ;
1920use logger:: { Metric , METRICS } ;
2021use memory_model:: { GuestAddress , GuestMemory , GuestMemoryError } ;
2122use sys_util:: EventFd ;
22- use vmm_config:: machine_config:: { CpuFeaturesTemplate , VmConfig } ;
23+ #[ cfg( target_arch = "x86_64" ) ]
24+ use vmm_config:: machine_config:: CpuFeaturesTemplate ;
25+ use vmm_config:: machine_config:: VmConfig ;
2326
2427const KVM_MEM_LOG_DIRTY_PAGES : u32 = 0x1 ;
2528
2629/// Errors associated with the wrappers over KVM ioctls.
2730#[ derive( Debug ) ]
2831pub enum Error {
32+ #[ cfg( target_arch = "x86_64" ) ]
33+ /// A call to cpuid instruction failed.
34+ CpuId ( cpuid:: Error ) ,
2935 /// Invalid guest memory configuration.
3036 GuestMemory ( GuestMemoryError ) ,
3137 /// Hyperthreading flag is not initialized.
@@ -90,8 +96,7 @@ impl Vm {
9096 } )
9197 }
9298
93- /// Initializes the guest memory. Currently this is x86 specific
94- /// because of the TSS address setup.
99+ /// Initializes the guest memory.
95100 pub fn memory_init ( & mut self , guest_mem : GuestMemory , kvm_context : & KvmContext ) -> Result < ( ) > {
96101 if guest_mem. num_regions ( ) > kvm_context. max_memslots ( ) {
97102 return Err ( Error :: NotEnoughMemorySlots ) ;
@@ -133,6 +138,7 @@ impl Vm {
133138 Ok ( ( ) )
134139 }
135140
141+ #[ cfg( target_arch = "x86_64" ) ]
136142 /// Creates an in-kernel device model for the PIT.
137143 pub fn create_pit ( & self ) -> Result < ( ) > {
138144 self . fd . create_pit2 ( ) . map_err ( Error :: VmSetup ) ?;
@@ -156,6 +162,7 @@ impl Vm {
156162
157163/// A wrapper around creating and using a kvm-based VCPU.
158164pub struct Vcpu {
165+ #[ cfg( target_arch = "x86_64" ) ]
159166 cpuid : CpuId ,
160167 fd : VcpuFd ,
161168 id : u8 ,
@@ -164,24 +171,29 @@ pub struct Vcpu {
164171impl Vcpu {
165172 /// Constructs a new VCPU for `vm`.
166173 ///
167- /// The `id` argument is the CPU number between [0, max vcpus).
174+ /// # Arguments
175+ ///
176+ /// * `id` - Represents the CPU number between [0, max vcpus).
177+ /// * `vm` - The virtual machine this vcpu will get attached to.
168178 pub fn new ( id : u8 , vm : & Vm ) -> Result < Self > {
169179 let kvm_vcpu = vm. fd . create_vcpu ( id) . map_err ( Error :: VcpuFd ) ?;
170- // Initially the cpuid per vCPU is the one supported by this VM
180+ // Initially the cpuid per vCPU is the one supported by this VM.
171181 Ok ( Vcpu {
172- fd : kvm_vcpu ,
182+ # [ cfg ( target_arch = "x86_64" ) ]
173183 cpuid : vm. fd . get_supported_cpuid ( ) ,
184+ fd : kvm_vcpu,
174185 id,
175186 } )
176187 }
177188
178189 #[ cfg( target_arch = "x86_64" ) ]
179- /// Configures the vcpu and should be called once per vcpu from the vcpu's thread.
190+ /// Configures a x86_64 specific vcpu and should be called once per vcpu from the vcpu's thread.
180191 ///
181192 /// # Arguments
182193 ///
183- /// * `kernel_load_offset` - Offset from `guest_mem` at which the kernel starts.
184- /// nr cpus is required for checking populating the kvm_cpuid2 entry for ebx and edx registers
194+ /// * `machine_config` - Specifies necessary info used for the CPUID configuration.
195+ /// * `kernel_start_addr` - Offset from `guest_mem` at which the kernel starts.
196+ /// * `vm` - The virtual machine this vcpu will get attached to.
185197 pub fn configure (
186198 & mut self ,
187199 machine_config : & VmConfig ,
@@ -285,7 +297,7 @@ mod tests {
285297 assert_eq ! ( read_val, 67u8 ) ;
286298 }
287299
288- #[ cfg( any ( target_arch = "x86" , target_arch = " x86_64") ) ]
300+ #[ cfg( target_arch = "x86_64" ) ]
289301 #[ test]
290302 fn test_configure_vcpu ( ) {
291303 let kvm_fd = Kvm :: new ( ) . unwrap ( ) ;
0 commit comments