@@ -12,19 +12,24 @@ extern crate sys_util;
12
12
use std:: result;
13
13
14
14
use super :: KvmContext ;
15
+ #[ cfg( target_arch = "x86_64" ) ]
15
16
use cpuid:: { c3_template, filter_cpuid, t2_template} ;
16
17
use kvm:: * ;
17
18
use memory_model:: { GuestAddress , GuestMemory , GuestMemoryError } ;
18
19
use sys_util:: EventFd ;
19
- use vmm_config:: machine_config:: { CpuFeaturesTemplate , VmConfig } ;
20
+ #[ cfg( target_arch = "x86_64" ) ]
21
+ use vmm_config:: machine_config:: CpuFeaturesTemplate ;
22
+ use vmm_config:: machine_config:: VmConfig ;
20
23
24
+ #[ cfg( target_arch = "x86_64" ) ]
21
25
pub const KVM_TSS_ADDRESS : usize = 0xfffbd000 ;
22
26
// Initial stack for the boot CPU.
23
27
const BOOT_STACK_POINTER : usize = 0x8ff0 ;
24
28
25
29
/// Errors associated with the wrappers over KVM ioctls.
26
30
#[ derive( Debug ) ]
27
31
pub enum Error {
32
+ #[ cfg( target_arch = "x86_64" ) ]
28
33
/// A call to cpuid instruction failed.
29
34
CpuId ( cpuid:: Error ) ,
30
35
/// Invalid guest memory configuration.
@@ -45,6 +50,7 @@ pub enum Error {
45
50
SetSupportedCpusFailed ( sys_util:: Error ) ,
46
51
/// The number of configured slots is bigger than the maximum reported by KVM.
47
52
NotEnoughMemorySlots ,
53
+ #[ cfg( target_arch = "x86_64" ) ]
48
54
/// Cannot set the local interruption due to bad configuration.
49
55
LocalIntConfiguration ( arch:: interrupts:: Error ) ,
50
56
/// Cannot set the memory regions.
@@ -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 ) ;
@@ -109,9 +114,9 @@ impl Vm {
109
114
} ) ?;
110
115
self . guest_mem = Some ( guest_mem) ;
111
116
112
- let tss_addr = GuestAddress ( KVM_TSS_ADDRESS ) ;
117
+ # [ cfg ( target_arch = "x86_64" ) ]
113
118
self . fd
114
- . set_tss_address ( tss_addr . offset ( ) )
119
+ . set_tss_address ( GuestAddress ( KVM_TSS_ADDRESS ) . offset ( ) )
115
120
. map_err ( Error :: VmSetup ) ?;
116
121
117
122
Ok ( ( ) )
@@ -127,6 +132,7 @@ impl Vm {
127
132
Ok ( ( ) )
128
133
}
129
134
135
+ #[ cfg( target_arch = "x86_64" ) ]
130
136
/// Creates an in-kernel device model for the PIT.
131
137
pub fn create_pit ( & self ) -> Result < ( ) > {
132
138
self . fd . create_pit2 ( ) . map_err ( Error :: VmSetup ) ?;
@@ -150,6 +156,7 @@ impl Vm {
150
156
151
157
/// A wrapper around creating and using a kvm-based VCPU.
152
158
pub struct Vcpu {
159
+ #[ cfg( target_arch = "x86_64" ) ]
153
160
cpuid : CpuId ,
154
161
fd : VcpuFd ,
155
162
id : u8 ,
@@ -158,24 +165,29 @@ pub struct Vcpu {
158
165
impl Vcpu {
159
166
/// Constructs a new VCPU for `vm`.
160
167
///
161
- /// The `id` argument is the CPU number between [0, max vcpus).
168
+ /// # Arguments
169
+ ///
170
+ /// * `id` - Represents the CPU number between [0, max vcpus).
171
+ /// * `vm` - The virtual machine this vcpu will get attached to.
162
172
pub fn new ( id : u8 , vm : & Vm ) -> Result < Self > {
163
173
let kvm_vcpu = vm. fd . create_vcpu ( id) . map_err ( Error :: VcpuFd ) ?;
164
- // Initially the cpuid per vCPU is the one supported by this VM
174
+ // Initially the cpuid per vCPU is the one supported by this VM.
165
175
Ok ( Vcpu {
166
- fd : kvm_vcpu ,
176
+ # [ cfg ( target_arch = "x86_64" ) ]
167
177
cpuid : vm. fd . get_supported_cpuid ( ) ,
178
+ fd : kvm_vcpu,
168
179
id,
169
180
} )
170
181
}
171
182
172
183
#[ cfg( target_arch = "x86_64" ) ]
173
- /// Configures the vcpu and should be called once per vcpu from the vcpu's thread.
184
+ /// Configures a x86_64 specifc vcpu and should be called once per vcpu from the vcpu's thread.
174
185
///
175
186
/// # Arguments
176
187
///
177
- /// * `kernel_load_offset` - Offset from `guest_mem` at which the kernel starts.
178
- /// nr cpus is required for checking populating the kvm_cpuid2 entry for ebx and edx registers
188
+ /// * `machine_config` - Specifies necessary info used for the CPUID configuration.
189
+ /// * `kernel_start_addr` - Offset from `guest_mem` at which the kernel starts.
190
+ /// * `vm` - The virtual machine this vcpu will get attached to.
179
191
pub fn configure (
180
192
& mut self ,
181
193
machine_config : & VmConfig ,
@@ -288,7 +300,7 @@ mod tests {
288
300
assert_eq ! ( read_val, 67u8 ) ;
289
301
}
290
302
291
- #[ cfg( any ( target_arch = "x86" , target_arch = " x86_64") ) ]
303
+ #[ cfg( target_arch = "x86_64" ) ]
292
304
#[ test]
293
305
fn test_configure_vcpu ( ) {
294
306
let kvm_fd = Kvm :: new ( ) . unwrap ( ) ;
0 commit comments