Skip to content

Commit 069f2b7

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 065ef95 commit 069f2b7

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

vmm/Cargo.toml

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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;
@@ -865,6 +866,7 @@ impl Vmm {
865866
&self.legacy_device_manager.com_evt_2_4,
866867
)
867868
.map_err(|e| StartMicrovmError::ConfigureVm(e))?;
869+
#[cfg(target_arch = "x86_64")]
868870
self.vm
869871
.create_pit()
870872
.map_err(|e| StartMicrovmError::ConfigureVm(e))?;

vmm/src/vstate.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ 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

27+
#[cfg(target_arch = "x86_64")]
2428
pub const KVM_TSS_ADDRESS: usize = 0xfffbd000;
2529

2630
// Initial stack for the boot CPU.
@@ -30,6 +34,9 @@ const KVM_MEM_LOG_DIRTY_PAGES: u32 = 0x1;
3034
/// Errors associated with the wrappers over KVM ioctls.
3135
#[derive(Debug)]
3236
pub enum Error {
37+
#[cfg(target_arch = "x86_64")]
38+
/// A call to cpuid instruction failed.
39+
CpuId(cpuid::Error),
3340
/// Invalid guest memory configuration.
3441
GuestMemory(GuestMemoryError),
3542
/// Hyperthreading flag is not initialized.
@@ -48,6 +55,7 @@ pub enum Error {
4855
SetSupportedCpusFailed(sys_util::Error),
4956
/// The number of configured slots is bigger than the maximum reported by KVM.
5057
NotEnoughMemorySlots,
58+
#[cfg(target_arch = "x86_64")]
5159
/// Cannot set the local interruption due to bad configuration.
5260
LocalIntConfiguration(arch::interrupts::Error),
5361
/// Cannot set the memory regions.
@@ -93,8 +101,7 @@ impl Vm {
93101
})
94102
}
95103

96-
/// Initializes the guest memory. Currently this is x86 specific
97-
/// because of the TSS address setup.
104+
/// Initializes the guest memory.
98105
pub fn memory_init(&mut self, guest_mem: GuestMemory, kvm_context: &KvmContext) -> Result<()> {
99106
if guest_mem.num_regions() > kvm_context.max_memslots() {
100107
return Err(Error::NotEnoughMemorySlots);
@@ -118,9 +125,9 @@ impl Vm {
118125
})?;
119126
self.guest_mem = Some(guest_mem);
120127

121-
let tss_addr = GuestAddress(KVM_TSS_ADDRESS);
128+
#[cfg(target_arch = "x86_64")]
122129
self.fd
123-
.set_tss_address(tss_addr.offset())
130+
.set_tss_address(GuestAddress(KVM_TSS_ADDRESS).offset())
124131
.map_err(Error::VmSetup)?;
125132

126133
Ok(())
@@ -136,6 +143,7 @@ impl Vm {
136143
Ok(())
137144
}
138145

146+
#[cfg(target_arch = "x86_64")]
139147
/// Creates an in-kernel device model for the PIT.
140148
pub fn create_pit(&self) -> Result<()> {
141149
self.fd.create_pit2().map_err(Error::VmSetup)?;
@@ -159,6 +167,7 @@ impl Vm {
159167

160168
/// A wrapper around creating and using a kvm-based VCPU.
161169
pub struct Vcpu {
170+
#[cfg(target_arch = "x86_64")]
162171
cpuid: CpuId,
163172
fd: VcpuFd,
164173
id: u8,
@@ -167,24 +176,29 @@ pub struct Vcpu {
167176
impl Vcpu {
168177
/// Constructs a new VCPU for `vm`.
169178
///
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.
171183
pub fn new(id: u8, vm: &Vm) -> Result<Self> {
172184
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.
174186
Ok(Vcpu {
175-
fd: kvm_vcpu,
187+
#[cfg(target_arch = "x86_64")]
176188
cpuid: vm.fd.get_supported_cpuid(),
189+
fd: kvm_vcpu,
177190
id,
178191
})
179192
}
180193

181194
#[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.
183196
///
184197
/// # Arguments
185198
///
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.
188202
pub fn configure(
189203
&mut self,
190204
machine_config: &VmConfig,
@@ -288,7 +302,7 @@ mod tests {
288302
assert_eq!(read_val, 67u8);
289303
}
290304

291-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
305+
#[cfg(target_arch = "x86_64")]
292306
#[test]
293307
fn test_configure_vcpu() {
294308
let kvm_fd = Kvm::new().unwrap();

0 commit comments

Comments
 (0)