diff --git a/Cargo.toml b/Cargo.toml index 7b12e4e73..aee1a7ca0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,9 @@ tempdir= "0.3.7" lazy_static= "1.4.0" [features] -default = ["acpi"] +default = ["acpi", "pci"] acpi = ["vmm/acpi"] +pci = ["vmm/pci_support"] # Integration tests require a special environment to run in integration_tests = [] diff --git a/vm-virtio/Cargo.toml b/vm-virtio/Cargo.toml index 24e7148f0..b4f63302e 100644 --- a/vm-virtio/Cargo.toml +++ b/vm-virtio/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" authors = ["Samuel Ortiz "] edition = "2018" +[features] +default = [] +pci_support = ["pci"] + [dependencies] byteorder = "1.3.2" devices = { path = "../devices" } @@ -12,7 +16,7 @@ libc = "0.2.60" log = "0.4.8" net_gen = { path = "../net_gen" } net_util = { path = "../net_util" } -pci = { path = "../pci" } +pci = { path = "../pci", optional = true } tempfile = "3.1.0" virtio-bindings = { path = "../virtio-bindings" } vm-allocator = { path = "../vm-allocator" } diff --git a/vm-virtio/src/lib.rs b/vm-virtio/src/lib.rs index 88dd38ca5..e7278c0fa 100755 --- a/vm-virtio/src/lib.rs +++ b/vm-virtio/src/lib.rs @@ -12,6 +12,7 @@ extern crate epoll; #[macro_use] extern crate log; +#[cfg(feature = "pci_support")] extern crate pci; extern crate vhost_rs; extern crate virtio_bindings; diff --git a/vm-virtio/src/transport/mod.rs b/vm-virtio/src/transport/mod.rs index 0941be94a..ea6b69d58 100644 --- a/vm-virtio/src/transport/mod.rs +++ b/vm-virtio/src/transport/mod.rs @@ -2,8 +2,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#[cfg(feature = "pci_support")] mod pci_common_config; +#[cfg(feature = "pci_support")] mod pci_device; - +#[cfg(feature = "pci_support")] pub use pci_common_config::VirtioPciCommonConfig; +#[cfg(feature = "pci_support")] pub use pci_device::VirtioPciDevice; diff --git a/vm-virtio/src/transport/pci_device.rs b/vm-virtio/src/transport/pci_device.rs index 6638197ff..81155aae0 100755 --- a/vm-virtio/src/transport/pci_device.rs +++ b/vm-virtio/src/transport/pci_device.rs @@ -7,6 +7,7 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause extern crate devices; +#[cfg(feature = "pci_support")] extern crate pci; extern crate vm_allocator; extern crate vm_memory; diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 69ef0b082..32af1d5bb 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [features] default = [] acpi = ["acpi_tables","devices/acpi", "arch/acpi"] +pci_support = ["pci", "vfio", "vm-virtio/pci_support"] [dependencies] acpi_tables = { path = "../acpi_tables", optional = true } @@ -18,9 +19,9 @@ kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master" libc = "0.2.62" log = "0.4.8" net_util = { path = "../net_util" } -pci = {path = "../pci"} +pci = {path = "../pci", optional = true} qcow = { path = "../qcow" } -vfio = { path = "../vfio" } +vfio = { path = "../vfio", optional = true } vm-virtio = { path = "../vm-virtio" } vm-allocator = { path = "../vm-allocator" } vmm-sys-util = { git = "https://github.com/rust-vmm/vmm-sys-util" } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index ad7f3a6b3..cfbc5bdeb 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -19,6 +19,7 @@ use libc::O_TMPFILE; use libc::{EFD_NONBLOCK, TIOCGWINSZ}; use net_util::Tap; +#[cfg(feature = "pci_support")] use pci::{ InterruptDelivery, InterruptParameters, PciConfigIo, PciDevice, PciInterruptPin, PciRoot, }; @@ -32,9 +33,11 @@ use std::os::unix::io::AsRawFd; use std::ptr::null_mut; use std::result; use std::sync::{Arc, Mutex, RwLock}; +#[cfg(feature = "pci_support")] use vfio::{VfioDevice, VfioPciDevice, VfioPciError}; use vm_allocator::SystemAllocator; use vm_memory::{Address, GuestMemoryMmap, GuestUsize}; +#[cfg(feature = "pci_support")] use vm_virtio::transport::VirtioPciDevice; use vm_virtio::{VirtioSharedMemory, VirtioSharedMemoryList}; use vmm_sys_util::eventfd::EventFd; @@ -98,6 +101,7 @@ pub enum DeviceManagerError { Irq(io::Error), /// Cannot allocate PCI BARs + #[cfg(feature = "pci_support")] AllocateBars(pci::PciDeviceError), /// Cannot register ioevent. @@ -107,6 +111,7 @@ pub enum DeviceManagerError { VirtioDevice(vmm_sys_util::errno::Error), /// Cannot add PCI device + #[cfg(feature = "pci_support")] AddPciDevice(pci::PciRootError), /// Cannot open persistent memory file @@ -128,12 +133,15 @@ pub enum DeviceManagerError { ConsoleOutputFileOpen(io::Error), /// Cannot create a VFIO device + #[cfg(feature = "pci_support")] VfioCreate(vfio::VfioError), /// Cannot create a VFIO PCI device + #[cfg(feature = "pci_support")] VfioPciCreate(vfio::VfioPciError), /// Failed to map VFIO MMIO region. + #[cfg(feature = "pci_support")] VfioMapRegion(VfioPciError), /// Failed to create the KVM device. @@ -272,9 +280,6 @@ pub struct DeviceManager { // IOAPIC ioapic: Option>>, - // PCI root - pci: Arc>, - // mmap()ed region to unmap on drop mmap_regions: Vec<(*mut libc::c_void, usize)>, @@ -395,26 +400,33 @@ impl DeviceManager { &mut mmap_regions, )?); + #[allow(unused_mut)] let mut cmdline_additions = Vec::new(); - let pci_root = PciRoot::new(None); - let mut pci = PciConfigIo::new(pci_root); + #[cfg(feature = "pci_support")] + { + let pci_root = PciRoot::new(None); + let mut pci = PciConfigIo::new(pci_root); - for device in virtio_devices { - DeviceManager::add_virtio_pci_device( - device, - vm_info.memory, - allocator, - vm_info.vm_fd, - &mut pci, - &mut buses, - &interrupt_info, - )?; + for device in virtio_devices { + DeviceManager::add_virtio_pci_device( + device, + vm_info.memory, + allocator, + vm_info.vm_fd, + &mut pci, + &mut buses, + &interrupt_info, + )?; + } + + DeviceManager::add_vfio_devices(vm_info, allocator, &mut pci, &mut buses, mem_slots)?; + let pci = Arc::new(Mutex::new(pci)); + io_bus + .insert(pci, 0xcf8, 0x8) + .map_err(DeviceManagerError::BusError)?; } - DeviceManager::add_vfio_devices(vm_info, allocator, &mut pci, &mut buses, mem_slots)?; - - let pci = Arc::new(Mutex::new(pci)); let mut dm = DeviceManager { io_bus, @@ -424,7 +436,6 @@ impl DeviceManager { #[cfg(feature = "acpi")] acpi_device, ioapic, - pci, mmap_regions, cmdline_additions, }; @@ -767,6 +778,7 @@ impl DeviceManager { .map_err(DeviceManagerError::CreateKvmDevice) } + #[cfg(feature = "pci_support")] fn add_vfio_devices( vm_info: &VmInfo, allocator: &mut SystemAllocator, @@ -808,6 +820,7 @@ impl DeviceManager { Ok(()) } + #[cfg(feature = "pci_support")] fn add_virtio_pci_device( virtio_device: Box, memory: &Arc>, @@ -939,11 +952,6 @@ impl DeviceManager { .insert(self.acpi_device.clone(), 0x3c0, 0x4) .map_err(DeviceManagerError::BusError)?; - // Insert the PCI root configuration space. - self.io_bus - .insert(self.pci.clone(), 0xcf8, 0x8) - .map_err(DeviceManagerError::BusError)?; - if let Some(ioapic) = &self.ioapic { // Insert IOAPIC self.mmio_bus diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index c62336fbe..dfd58a826 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -17,6 +17,7 @@ extern crate libc; extern crate linux_loader; extern crate net_util; extern crate signal_hook; +#[cfg(feature = "pci_support")] extern crate vfio; extern crate vm_allocator; extern crate vm_memory;