Skip to content

Commit bc16266

Browse files
committed
vmm: additional x86_64 necessary labeling
* labeled x86_64 specific code * conditonal compilation for cpuid Signed-off-by: Diana Popa <[email protected]>
1 parent 0d23c87 commit bc16266

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

vmm/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ serde_json = ">=1.0.9"
1414
time = ">=0.1.39"
1515
timerfd = ">=1.0"
1616

17-
cpuid = { path = "../cpuid" }
1817
devices = { path = "../devices" }
1918
fc_util = { path = "../fc_util" }
2019
kernel = { path = "../kernel" }
@@ -28,9 +27,11 @@ seccomp = { path = "../seccomp" }
2827
sys_util = { path = "../sys_util" }
2928
arch = { path = "../arch" }
3029

30+
[target.'cfg(target_arch = "x86_64")'.dependencies]
31+
cpuid = { path = "../cpuid" }
32+
3133
[dev-dependencies]
3234
tempfile = ">=3.0.2"
3335

3436
[features]
3537
vsock = ["devices/vsock"]
36-

vmm/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern crate serde_derive;
1919
extern crate time;
2020
extern crate timerfd;
2121

22+
#[cfg(target_arch = "x86_64")]
2223
extern crate cpuid;
2324
extern crate devices;
2425
extern crate fc_util;
@@ -825,6 +826,7 @@ impl Vmm {
825826
&self.legacy_device_manager.com_evt_1_3,
826827
&self.legacy_device_manager.com_evt_2_4,
827828
).map_err(|e| StartMicrovmError::ConfigureVm(e))?;
829+
#[cfg(target_arch = "x86_64")]
828830
self.vm
829831
.create_pit()
830832
.map_err(|e| StartMicrovmError::ConfigureVm(e))?;

vmm/src/vstate.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ extern crate sys_util;
1212
use std::result;
1313

1414
use super::KvmContext;
15+
#[cfg(target_arch = "x86_64")]
1516
use cpuid::{c3_template, filter_cpuid, t2_template};
1617
use kvm::*;
1718
use memory_model::{GuestAddress, GuestMemory, GuestMemoryError};
1819
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;
2023

24+
#[cfg(target_arch = "x86_64")]
2125
pub const KVM_TSS_ADDRESS: usize = 0xfffbd000;
2226
// Initial stack for the boot CPU.
2327
const BOOT_STACK_POINTER: usize = 0x8ff0;
2428

2529
/// Errors associated with the wrappers over KVM ioctls.
2630
#[derive(Debug)]
2731
pub enum Error {
32+
#[cfg(target_arch = "x86_64")]
2833
/// A call to cpuid instruction failed.
2934
CpuId(cpuid::Error),
3035
/// Invalid guest memory configuration.
@@ -45,6 +50,7 @@ pub enum Error {
4550
SetSupportedCpusFailed(sys_util::Error),
4651
/// The number of configured slots is bigger than the maximum reported by KVM.
4752
NotEnoughMemorySlots,
53+
#[cfg(target_arch = "x86_64")]
4854
/// Cannot set the local interruption due to bad configuration.
4955
LocalIntConfiguration(arch::interrupts::Error),
5056
/// Cannot set the memory regions.
@@ -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);
@@ -109,9 +114,9 @@ impl Vm {
109114
})?;
110115
self.guest_mem = Some(guest_mem);
111116

112-
let tss_addr = GuestAddress(KVM_TSS_ADDRESS);
117+
#[cfg(target_arch = "x86_64")]
113118
self.fd
114-
.set_tss_address(tss_addr.offset())
119+
.set_tss_address(GuestAddress(KVM_TSS_ADDRESS).offset())
115120
.map_err(Error::VmSetup)?;
116121

117122
Ok(())
@@ -127,6 +132,7 @@ impl Vm {
127132
Ok(())
128133
}
129134

135+
#[cfg(target_arch = "x86_64")]
130136
/// Creates an in-kernel device model for the PIT.
131137
pub fn create_pit(&self) -> Result<()> {
132138
self.fd.create_pit2().map_err(Error::VmSetup)?;
@@ -150,6 +156,7 @@ impl Vm {
150156

151157
/// A wrapper around creating and using a kvm-based VCPU.
152158
pub struct Vcpu {
159+
#[cfg(target_arch = "x86_64")]
153160
cpuid: CpuId,
154161
fd: VcpuFd,
155162
id: u8,
@@ -158,24 +165,29 @@ pub struct Vcpu {
158165
impl Vcpu {
159166
/// Constructs a new VCPU for `vm`.
160167
///
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.
162172
pub fn new(id: u8, vm: &Vm) -> Result<Self> {
163173
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.
165175
Ok(Vcpu {
166-
fd: kvm_vcpu,
176+
#[cfg(target_arch = "x86_64")]
167177
cpuid: vm.fd.get_supported_cpuid(),
178+
fd: kvm_vcpu,
168179
id,
169180
})
170181
}
171182

172183
#[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.
174185
///
175186
/// # Arguments
176187
///
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.
179191
pub fn configure(
180192
&mut self,
181193
machine_config: &VmConfig,
@@ -288,7 +300,7 @@ mod tests {
288300
assert_eq!(read_val, 67u8);
289301
}
290302

291-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
303+
#[cfg(target_arch = "x86_64")]
292304
#[test]
293305
fn test_configure_vcpu() {
294306
let kvm_fd = Kvm::new().unwrap();

0 commit comments

Comments
 (0)