From 53ce5298750a150f873665d840d1847232a5747b Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Fri, 8 Nov 2019 15:50:39 +0100 Subject: [PATCH] vfio: Move the PCI implementation to the PCI crate There is a much stronger PCI dependency from vfio_pci.rs than a VFIO one from pci/src/vfio.rs. It seems more natural to have the PCI specific VFIO implementation in the PCI crate rather than the other way around. Signed-off-by: Samuel Ortiz --- Cargo.lock | 8 +++++--- pci/Cargo.toml | 8 ++++++++ pci/src/lib.rs | 2 ++ vfio/src/vfio_pci.rs => pci/src/vfio.rs | 7 +++---- vfio/Cargo.toml | 3 --- vfio/src/lib.rs | 5 ----- vmm/src/device_manager.rs | 9 +++++---- 7 files changed, 23 insertions(+), 19 deletions(-) rename vfio/src/vfio_pci.rs => pci/src/vfio.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index c6df9773b..9ab15008a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -683,15 +683,20 @@ dependencies = [ "anyhow", "byteorder", "devices", + "kvm-bindings", + "kvm-ioctls", "libc", "log 0.4.8", "serde", "serde_derive", "serde_json", + "vfio", + "vfio-bindings", "vm-allocator", "vm-device", "vm-memory", "vm-migration", + "vmm-sys-util", ] [[package]] @@ -1345,14 +1350,11 @@ version = "0.0.1" dependencies = [ "arc-swap", "byteorder", - "devices", "kvm-bindings", "kvm-ioctls", "libc", "log 0.4.8", - "pci", "vfio-bindings", - "vm-allocator", "vm-device", "vm-memory", "vmm-sys-util", diff --git a/pci/Cargo.toml b/pci/Cargo.toml index b93e6686a..0b7d39ab8 100644 --- a/pci/Cargo.toml +++ b/pci/Cargo.toml @@ -8,6 +8,10 @@ edition = "2018" anyhow = "1.0" byteorder = "1.3.4" devices = { path = "../devices" } +kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch" } +kvm-ioctls = { git = "https://github.com/cloud-hypervisor/kvm-ioctls", branch = "ch" } +vfio = { path = "../vfio" } +vmm-sys-util = ">=0.3.1" libc = "0.2.71" log = "0.4.8" serde = {version = ">=1.0.27", features = ["rc"] } @@ -17,3 +21,7 @@ vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } vm-memory = "0.2.1" vm-migration = { path = "../vm-migration" } + +[dependencies.vfio-bindings] +git = "https://github.com/rust-vmm/vfio-bindings" +features = ["fam-wrappers"] diff --git a/pci/src/lib.rs b/pci/src/lib.rs index 2658fea18..05725638b 100644 --- a/pci/src/lib.rs +++ b/pci/src/lib.rs @@ -17,6 +17,7 @@ mod configuration; mod device; mod msi; mod msix; +mod vfio; pub use self::bus::{PciBus, PciConfigIo, PciConfigMmio, PciRoot, PciRootError}; pub use self::configuration::{ @@ -29,6 +30,7 @@ pub use self::device::{ }; pub use self::msi::{msi_num_enabled_vectors, MsiCap, MsiConfig}; pub use self::msix::{MsixCap, MsixConfig, MsixTableEntry, MSIX_TABLE_ENTRY_SIZE}; +pub use self::vfio::{VfioPciDevice, VfioPciError}; /// PCI has four interrupt pins A->D. #[derive(Copy, Clone)] diff --git a/vfio/src/vfio_pci.rs b/pci/src/vfio.rs similarity index 99% rename from vfio/src/vfio_pci.rs rename to pci/src/vfio.rs index c3de37377..f7303901a 100644 --- a/vfio/src/vfio_pci.rs +++ b/pci/src/vfio.rs @@ -4,15 +4,13 @@ // extern crate devices; -extern crate pci; extern crate vm_allocator; -use crate::vfio_device::VfioDevice; use byteorder::{ByteOrder, LittleEndian}; use devices::BusDevice; use kvm_bindings::kvm_userspace_memory_region; use kvm_ioctls::*; -use pci::{ +use crate::{ msi_num_enabled_vectors, BarReprogrammingParams, MsiConfig, MsixCap, MsixConfig, PciBarConfiguration, PciBarRegionType, PciCapabilityID, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, MSIX_TABLE_ENTRY_SIZE, @@ -22,6 +20,7 @@ use std::os::unix::io::AsRawFd; use std::ptr::null_mut; use std::sync::Arc; use std::{fmt, io, result}; +use vfio::{VfioDevice, VfioError}; use vfio_bindings::bindings::vfio::*; use vm_allocator::SystemAllocator; use vm_device::interrupt::{ @@ -41,7 +40,7 @@ pub enum VfioPciError { SetGsiRouting(kvm_ioctls::Error), MsiNotConfigured, MsixNotConfigured, - UpdateMemory(crate::VfioError), + UpdateMemory(VfioError), UpdateMsiEventFd, UpdateMsixEventFd, } diff --git a/vfio/Cargo.toml b/vfio/Cargo.toml index bc2c83696..7eea2a7a0 100644 --- a/vfio/Cargo.toml +++ b/vfio/Cargo.toml @@ -6,13 +6,10 @@ authors = ["The Cloud Hypervisor Authors"] [dependencies] arc-swap = ">=0.4.4" byteorder = "1.3.4" -devices = { path = "../devices" } kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch" } kvm-ioctls = { git = "https://github.com/cloud-hypervisor/kvm-ioctls", branch = "ch" } libc = "0.2.71" log = "0.4.8" -pci = { path = "../pci" } -vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } vm-memory = { version = "0.2.1", features = ["backend-mmap"] } vmm-sys-util = ">=0.3.1" diff --git a/vfio/src/lib.rs b/vfio/src/lib.rs index 80988745a..74d9e6434 100644 --- a/vfio/src/lib.rs +++ b/vfio/src/lib.rs @@ -7,14 +7,11 @@ //! Virtual Function I/O (VFIO) API extern crate arc_swap; extern crate byteorder; -extern crate devices; extern crate kvm_bindings; extern crate kvm_ioctls; #[macro_use] extern crate log; -extern crate pci; extern crate vfio_bindings; -extern crate vm_allocator; extern crate vm_device; extern crate vm_memory; #[macro_use] @@ -22,12 +19,10 @@ extern crate vmm_sys_util; mod vfio_device; mod vfio_ioctls; -mod vfio_pci; use std::mem::size_of; pub use vfio_device::{VfioContainer, VfioDevice, VfioDmaMapping, VfioError}; -pub use vfio_pci::{VfioPciDevice, VfioPciError}; // Returns a `Vec` with a size in bytes at least as large as `size_in_bytes`. fn vec_with_size_in_bytes(size_in_bytes: usize) -> Vec { diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 3659545f2..3894221fe 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -40,6 +40,7 @@ use libc::{MAP_NORESERVE, MAP_PRIVATE, MAP_SHARED, O_TMPFILE, PROT_READ, PROT_WR #[cfg(feature = "pci_support")] use pci::{ DeviceRelocation, PciBarRegionType, PciBus, PciConfigIo, PciConfigMmio, PciDevice, PciRoot, + VfioPciDevice, }; use qcow::{self, ImageType, QcowFile}; #[cfg(feature = "pci_support")] @@ -54,7 +55,7 @@ use std::result; use std::sync::{Arc, Mutex}; use tempfile::NamedTempFile; #[cfg(feature = "pci_support")] -use vfio::{VfioDevice, VfioDmaMapping, VfioPciDevice, VfioPciError}; +use vfio::{VfioDevice, VfioDmaMapping}; use vm_allocator::SystemAllocator; use vm_device::interrupt::{ InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig, @@ -215,11 +216,11 @@ pub enum DeviceManagerError { /// Cannot create a VFIO PCI device #[cfg(feature = "pci_support")] - VfioPciCreate(vfio::VfioPciError), + VfioPciCreate(pci::VfioPciError), /// Failed to map VFIO MMIO region. #[cfg(feature = "pci_support")] - VfioMapRegion(VfioPciError), + VfioMapRegion(pci::VfioPciError), /// Failed to create the KVM device. CreateKvmDevice(kvm_ioctls::Error), @@ -326,7 +327,7 @@ pub enum DeviceManagerError { /// Failed updating guest memory for VFIO PCI device. #[cfg(feature = "pci_support")] - UpdateMemoryForVfioPciDevice(VfioPciError), + UpdateMemoryForVfioPciDevice(pci::VfioPciError), /// Trying to use a directory for pmem but no size specified PmemWithDirectorySizeMissing,