@@ -13,14 +13,18 @@ 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
27
+ #[ cfg( target_arch = "x86_64" ) ]
24
28
pub const KVM_TSS_ADDRESS : usize = 0xfffbd000 ;
25
29
26
30
// Initial stack for the boot CPU.
@@ -30,6 +34,9 @@ const KVM_MEM_LOG_DIRTY_PAGES: u32 = 0x1;
30
34
/// Errors associated with the wrappers over KVM ioctls.
31
35
#[ derive( Debug ) ]
32
36
pub enum Error {
37
+ #[ cfg( target_arch = "x86_64" ) ]
38
+ /// A call to cpuid instruction failed.
39
+ CpuId ( cpuid:: Error ) ,
33
40
/// Invalid guest memory configuration.
34
41
GuestMemory ( GuestMemoryError ) ,
35
42
/// Hyperthreading flag is not initialized.
@@ -48,6 +55,7 @@ pub enum Error {
48
55
SetSupportedCpusFailed ( sys_util:: Error ) ,
49
56
/// The number of configured slots is bigger than the maximum reported by KVM.
50
57
NotEnoughMemorySlots ,
58
+ #[ cfg( target_arch = "x86_64" ) ]
51
59
/// Cannot set the local interruption due to bad configuration.
52
60
LocalIntConfiguration ( arch:: interrupts:: Error ) ,
53
61
/// Cannot set the memory regions.
@@ -93,8 +101,7 @@ impl Vm {
93
101
} )
94
102
}
95
103
96
- /// Initializes the guest memory. Currently this is x86 specific
97
- /// because of the TSS address setup.
104
+ /// Initializes the guest memory.
98
105
pub fn memory_init ( & mut self , guest_mem : GuestMemory , kvm_context : & KvmContext ) -> Result < ( ) > {
99
106
if guest_mem. num_regions ( ) > kvm_context. max_memslots ( ) {
100
107
return Err ( Error :: NotEnoughMemorySlots ) ;
@@ -118,9 +125,9 @@ impl Vm {
118
125
} ) ?;
119
126
self . guest_mem = Some ( guest_mem) ;
120
127
121
- let tss_addr = GuestAddress ( KVM_TSS_ADDRESS ) ;
128
+ # [ cfg ( target_arch = "x86_64" ) ]
122
129
self . fd
123
- . set_tss_address ( tss_addr . offset ( ) )
130
+ . set_tss_address ( GuestAddress ( KVM_TSS_ADDRESS ) . offset ( ) )
124
131
. map_err ( Error :: VmSetup ) ?;
125
132
126
133
Ok ( ( ) )
@@ -136,6 +143,7 @@ impl Vm {
136
143
Ok ( ( ) )
137
144
}
138
145
146
+ #[ cfg( target_arch = "x86_64" ) ]
139
147
/// Creates an in-kernel device model for the PIT.
140
148
pub fn create_pit ( & self ) -> Result < ( ) > {
141
149
self . fd . create_pit2 ( ) . map_err ( Error :: VmSetup ) ?;
@@ -159,6 +167,7 @@ impl Vm {
159
167
160
168
/// A wrapper around creating and using a kvm-based VCPU.
161
169
pub struct Vcpu {
170
+ #[ cfg( target_arch = "x86_64" ) ]
162
171
cpuid : CpuId ,
163
172
fd : VcpuFd ,
164
173
id : u8 ,
@@ -167,24 +176,29 @@ pub struct Vcpu {
167
176
impl Vcpu {
168
177
/// Constructs a new VCPU for `vm`.
169
178
///
170
- /// The `id` argument is the CPU number between [0, max vcpus).
179
+ /// # Arguments
180
+ ///
181
+ /// * `id` - Represents the CPU number between [0, max vcpus).
182
+ /// * `vm` - The virtual machine this vcpu will get attached to.
171
183
pub fn new ( id : u8 , vm : & Vm ) -> Result < Self > {
172
184
let kvm_vcpu = vm. fd . create_vcpu ( id) . map_err ( Error :: VcpuFd ) ?;
173
- // Initially the cpuid per vCPU is the one supported by this VM
185
+ // Initially the cpuid per vCPU is the one supported by this VM.
174
186
Ok ( Vcpu {
175
- fd : kvm_vcpu ,
187
+ # [ cfg ( target_arch = "x86_64" ) ]
176
188
cpuid : vm. fd . get_supported_cpuid ( ) ,
189
+ fd : kvm_vcpu,
177
190
id,
178
191
} )
179
192
}
180
193
181
194
#[ cfg( target_arch = "x86_64" ) ]
182
- /// Configures the vcpu and should be called once per vcpu from the vcpu's thread.
195
+ /// Configures a x86_64 specific vcpu and should be called once per vcpu from the vcpu's thread.
183
196
///
184
197
/// # Arguments
185
198
///
186
- /// * `kernel_load_offset` - Offset from `guest_mem` at which the kernel starts.
187
- /// nr cpus is required for checking populating the kvm_cpuid2 entry for ebx and edx registers
199
+ /// * `machine_config` - Specifies necessary info used for the CPUID configuration.
200
+ /// * `kernel_start_addr` - Offset from `guest_mem` at which the kernel starts.
201
+ /// * `vm` - The virtual machine this vcpu will get attached to.
188
202
pub fn configure (
189
203
& mut self ,
190
204
machine_config : & VmConfig ,
@@ -288,7 +302,7 @@ mod tests {
288
302
assert_eq ! ( read_val, 67u8 ) ;
289
303
}
290
304
291
- #[ cfg( any ( target_arch = "x86" , target_arch = " x86_64") ) ]
305
+ #[ cfg( target_arch = "x86_64" ) ]
292
306
#[ test]
293
307
fn test_configure_vcpu ( ) {
294
308
let kvm_fd = Kvm :: new ( ) . unwrap ( ) ;
0 commit comments