@@ -13,19 +13,25 @@ extern crate sys_util;
13
13
use std:: result;
14
14
15
15
use super :: KvmContext ;
16
+ #[ cfg( target_arch = "x86_64" ) ]
16
17
use cpuid:: { c3_template, filter_cpuid, t2_template} ;
17
18
use kvm:: * ;
18
19
use logger:: { LogOption , LOGGER } ;
19
20
use logger:: { Metric , METRICS } ;
20
21
use memory_model:: { GuestAddress , GuestMemory , GuestMemoryError } ;
21
22
use 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 ;
23
26
24
27
const KVM_MEM_LOG_DIRTY_PAGES : u32 = 0x1 ;
25
28
26
29
/// Errors associated with the wrappers over KVM ioctls.
27
30
#[ derive( Debug ) ]
28
31
pub enum Error {
32
+ #[ cfg( target_arch = "x86_64" ) ]
33
+ /// A call to cpuid instruction failed.
34
+ CpuId ( cpuid:: Error ) ,
29
35
/// Invalid guest memory configuration.
30
36
GuestMemory ( GuestMemoryError ) ,
31
37
/// Hyperthreading flag is not initialized.
@@ -90,8 +96,7 @@ impl Vm {
90
96
} )
91
97
}
92
98
93
- /// Initializes the guest memory. Currently this is x86 specific
94
- /// because of the TSS address setup.
99
+ /// Initializes the guest memory.
95
100
pub fn memory_init ( & mut self , guest_mem : GuestMemory , kvm_context : & KvmContext ) -> Result < ( ) > {
96
101
if guest_mem. num_regions ( ) > kvm_context. max_memslots ( ) {
97
102
return Err ( Error :: NotEnoughMemorySlots ) ;
@@ -133,6 +138,7 @@ impl Vm {
133
138
Ok ( ( ) )
134
139
}
135
140
141
+ #[ cfg( target_arch = "x86_64" ) ]
136
142
/// Creates an in-kernel device model for the PIT.
137
143
pub fn create_pit ( & self ) -> Result < ( ) > {
138
144
self . fd . create_pit2 ( ) . map_err ( Error :: VmSetup ) ?;
@@ -156,6 +162,7 @@ impl Vm {
156
162
157
163
/// A wrapper around creating and using a kvm-based VCPU.
158
164
pub struct Vcpu {
165
+ #[ cfg( target_arch = "x86_64" ) ]
159
166
cpuid : CpuId ,
160
167
fd : VcpuFd ,
161
168
id : u8 ,
@@ -164,24 +171,29 @@ pub struct Vcpu {
164
171
impl Vcpu {
165
172
/// Constructs a new VCPU for `vm`.
166
173
///
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.
168
178
pub fn new ( id : u8 , vm : & Vm ) -> Result < Self > {
169
179
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.
171
181
Ok ( Vcpu {
172
- fd : kvm_vcpu ,
182
+ # [ cfg ( target_arch = "x86_64" ) ]
173
183
cpuid : vm. fd . get_supported_cpuid ( ) ,
184
+ fd : kvm_vcpu,
174
185
id,
175
186
} )
176
187
}
177
188
178
189
#[ 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.
180
191
///
181
192
/// # Arguments
182
193
///
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.
185
197
pub fn configure (
186
198
& mut self ,
187
199
machine_config : & VmConfig ,
@@ -285,7 +297,7 @@ mod tests {
285
297
assert_eq ! ( read_val, 67u8 ) ;
286
298
}
287
299
288
- #[ cfg( any ( target_arch = "x86" , target_arch = " x86_64") ) ]
300
+ #[ cfg( target_arch = "x86_64" ) ]
289
301
#[ test]
290
302
fn test_configure_vcpu ( ) {
291
303
let kvm_fd = Kvm :: new ( ) . unwrap ( ) ;
0 commit comments