Skip to content

Commit e0b1257

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 cea9cf5 commit e0b1257

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

vmm/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ time = ">=0.1.39"
1515
timerfd = ">=1.0"
1616

1717
arch = { path = "../arch" }
18-
cpuid = { path = "../cpuid" }
1918
devices = { path = "../devices" }
2019
fc_util = { path = "../fc_util" }
2120
kernel = { path = "../kernel" }
@@ -28,6 +27,9 @@ rate_limiter = { path = "../rate_limiter" }
2827
seccomp = { path = "../seccomp" }
2928
sys_util = { path = "../sys_util" }
3029

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

vmm/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate serde_json;
2020
extern crate time;
2121
extern crate timerfd;
2222

23+
#[cfg(target_arch = "x86_64")]
2324
extern crate cpuid;
2425
extern crate devices;
2526
extern crate fc_util;
@@ -873,6 +874,7 @@ impl Vmm {
873874
&self.legacy_device_manager.com_evt_2_4,
874875
)
875876
.map_err(|e| StartMicrovmError::ConfigureVm(e))?;
877+
#[cfg(target_arch = "x86_64")]
876878
self.vm
877879
.create_pit()
878880
.map_err(|e| StartMicrovmError::ConfigureVm(e))?;

vmm/src/vstate.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ extern crate sys_util;
1313
use std::result;
1414

1515
use super::KvmContext;
16+
#[cfg(target_arch = "x86_64")]
1617
use cpuid::{c3_template, filter_cpuid, t2_template};
1718
use kvm::*;
1819
use logger::{LogOption, LOGGER};
1920
use logger::{Metric, METRICS};
2021
use memory_model::{GuestAddress, GuestMemory, GuestMemoryError};
2122
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;
2326

2427
const KVM_MEM_LOG_DIRTY_PAGES: u32 = 0x1;
2528

2629
/// Errors associated with the wrappers over KVM ioctls.
2730
#[derive(Debug)]
2831
pub 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.
158164
pub struct Vcpu {
165+
#[cfg(target_arch = "x86_64")]
159166
cpuid: CpuId,
160167
fd: VcpuFd,
161168
id: u8,
@@ -164,24 +171,29 @@ pub struct Vcpu {
164171
impl 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

Comments
 (0)