pci, vmm: Move to upstream vfio-ioctls crate

This commit moves both pci and vmm code from the internal vfio-ioctls
crate to the upstream one from the rust-vmm project.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-02-23 15:01:31 +01:00 committed by Samuel Ortiz
parent aee1155870
commit a0a89b1346
7 changed files with 42 additions and 24 deletions

2
Cargo.lock generated
View File

@ -1324,7 +1324,7 @@ dependencies = [
[[package]]
name = "vfio-ioctls"
version = "0.1.0"
source = "git+https://github.com/cloud-hypervisor/vfio-ioctls?branch=ch#6ea1b934bbff9102bbdc80c23a357a48645cd722"
source = "git+https://github.com/rust-vmm/vfio-ioctls?branch=master#95e70655e34ad942f5ca8d3bc450d7dec4964514"
dependencies = [
"byteorder",
"kvm-bindings",

View File

@ -37,6 +37,10 @@ clap = { version = "2.33.3", features = ["wrap_help"] }
[patch.'https://github.com/rust-vmm/vhost']
vhost_rs = { git = "https://github.com/cloud-hypervisor/vhost", branch = "ch", package = "vhost", features = ["vhost-user-master", "vhost-user-slave"] }
[patch.crates-io]
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch", features = ["with-serde", "fam-wrappers"] }
kvm-ioctls = { git = "https://github.com/cloud-hypervisor/kvm-ioctls", branch = "ch" }
[dev-dependencies]
credibility = "0.1.3"
dirs = "3.0.1"

View File

@ -8,7 +8,7 @@ edition = "2018"
anyhow = "1.0"
byteorder = "1.3.4"
hypervisor = { path = "../hypervisor" }
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "master" }
vmm-sys-util = ">=0.3.1"
libc = "0.2.86"
log = "0.4.14"

View File

@ -18,15 +18,15 @@ use std::ptr::null_mut;
use std::sync::{Arc, Barrier};
use std::{fmt, io, result};
use vfio_bindings::bindings::vfio::*;
use vfio_ioctls::{VfioDevice, VfioError};
use vfio_ioctls::{VfioContainer, VfioDevice, VfioError};
use vm_allocator::SystemAllocator;
use vm_device::interrupt::{
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
};
use vm_device::BusDevice;
use vm_memory::{
Address, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap, GuestRegionMmap,
GuestUsize,
Address, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
GuestMemoryRegion, GuestRegionMmap, GuestUsize,
};
use vmm_sys_util::eventfd::EventFd;
@ -298,11 +298,13 @@ impl VfioPciConfig {
pub struct VfioPciDevice {
vm: Arc<dyn hypervisor::Vm>,
device: Arc<VfioDevice>,
container: Arc<VfioContainer>,
vfio_pci_configuration: VfioPciConfig,
configuration: PciConfiguration,
mmio_regions: Vec<MmioRegion>,
interrupt: Interrupt,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
iommu_attached: bool,
}
impl VfioPciDevice {
@ -310,9 +312,11 @@ impl VfioPciDevice {
pub fn new(
vm: &Arc<dyn hypervisor::Vm>,
device: VfioDevice,
container: Arc<VfioContainer>,
msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
legacy_interrupt_group: Option<Arc<Box<dyn InterruptSourceGroup>>>,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
iommu_attached: bool,
) -> Result<Self> {
let device = Arc::new(device);
device.reset();
@ -335,6 +339,7 @@ impl VfioPciDevice {
let mut vfio_pci_device = VfioPciDevice {
vm: vm.clone(),
device,
container,
configuration,
vfio_pci_configuration,
mmio_regions: Vec::new(),
@ -344,6 +349,7 @@ impl VfioPciDevice {
msix: None,
},
mem,
iommu_attached,
};
vfio_pci_device.parse_capabilities(msi_interrupt_manager);
@ -723,9 +729,17 @@ impl VfioPciDevice {
}
pub fn update_memory(&self, new_region: &Arc<GuestRegionMmap>) -> Result<()> {
self.device
.extend_dma_map(new_region)
.map_err(VfioPciError::UpdateMemory)
if !self.iommu_attached {
self.container
.vfio_dma_map(
new_region.start_addr().raw_value(),
new_region.len() as u64,
new_region.as_ptr() as u64,
)
.map_err(VfioPciError::UpdateMemory)?;
}
Ok(())
}
pub fn mmio_regions(&self) -> Vec<MmioRegion> {
@ -753,10 +767,11 @@ impl Drop for VfioPciDevice {
self.disable_intx();
}
if self
.device
.unset_dma_map(self.mem.memory().deref())
.is_err()
if !self.iommu_attached
&& self
.container
.vfio_unmap_guest_memory(self.mem.memory().deref())
.is_err()
{
error!("failed to remove all guest memory regions from iommu table");
}
@ -963,10 +978,11 @@ impl PciDevice for VfioPciDevice {
}
}
if self
.device
.setup_dma_map(self.mem.memory().deref())
.is_err()
if !self.iommu_attached
&& self
.container
.vfio_map_guest_memory(self.mem.memory().deref())
.is_err()
{
error!("failed to add all guest memory regions into iommu table");
}

View File

@ -10,7 +10,7 @@ thiserror = "1.0"
serde = {version = ">=1.0.27", features = ["rc"] }
serde_derive = ">=1.0.27"
serde_json = ">=1.0.9"
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "master" }
vm-memory = { version = "0.5.0", features = ["backend-mmap"] }
vmm-sys-util = ">=0.3.1"

View File

@ -40,7 +40,7 @@ serde_json = ">=1.0.9"
signal-hook = "0.3.6"
thiserror = "1.0"
url = "2.2.1"
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "master" }
virtio-devices = { path = "../virtio-devices" }
vm-allocator = { path = "../vm-allocator" }
vm-device = { path = "../vm-device" }

View File

@ -2691,12 +2691,8 @@ impl DeviceManager {
.map_err(DeviceManagerError::VfioCreate)?,
);
let vfio_device = VfioDevice::new(
&device_cfg.path,
Arc::clone(&vfio_container),
device_cfg.iommu,
)
.map_err(DeviceManagerError::VfioCreate)?;
let vfio_device = VfioDevice::new(&device_cfg.path, Arc::clone(&vfio_container))
.map_err(DeviceManagerError::VfioCreate)?;
if device_cfg.iommu {
if let Some(iommu) = &self.iommu_device {
@ -2731,9 +2727,11 @@ impl DeviceManager {
let mut vfio_pci_device = VfioPciDevice::new(
&self.address_manager.vm,
vfio_device,
vfio_container,
&self.msi_interrupt_manager,
legacy_interrupt_group,
memory,
device_cfg.iommu,
)
.map_err(DeviceManagerError::VfioPciCreate)?;