diff --git a/Cargo.lock b/Cargo.lock index cad65f236..69631d092 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1420,7 +1420,6 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "vfio-ioctls", "vhost", "virtio-bindings", "vm-allocator", diff --git a/virtio-devices/Cargo.toml b/virtio-devices/Cargo.toml index dd76cee89..0636feb42 100644 --- a/virtio-devices/Cargo.toml +++ b/virtio-devices/Cargo.toml @@ -25,7 +25,6 @@ seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v serde = ">=1.0.27" serde_derive = ">=1.0.27" serde_json = ">=1.0.9" -vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" } vhost_rs = { git = "https://github.com/rust-vmm/vhost", branch = "master", package = "vhost", features = ["vhost-user-master", "vhost-user-slave"] } virtio-bindings = { version = "0.1", features = ["virtio-v5_0_0"]} vm-allocator = { path = "../vm-allocator" } diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index 6a36fa0a6..631e26120 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -22,7 +22,7 @@ use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, RwLock}; use std::thread; -use vfio_ioctls::ExternalDmaMapping; +use vm_device::dma_mapping::ExternalDmaMapping; use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError, GuestMemoryMmap, diff --git a/virtio-devices/src/lib.rs b/virtio-devices/src/lib.rs index 26fed217e..fa1892478 100644 --- a/virtio-devices/src/lib.rs +++ b/virtio-devices/src/lib.rs @@ -59,6 +59,7 @@ pub use self::pmem::*; pub use self::rng::*; pub use self::vsock::*; pub use self::watchdog::*; +use vm_memory::{GuestAddress, GuestMemory}; use vm_virtio::{queue::*, VirtioDeviceType}; const DEVICE_INIT: u32 = 0x00; @@ -125,3 +126,19 @@ pub enum Error { NetQueuePair(::net_util::NetQueuePairError), ApplySeccompFilter(seccomp::Error), } + +/// Convert an absolute address into an address space (GuestMemory) +/// to a host pointer and verify that the provided size define a valid +/// range within a single memory region. +/// Return None if it is out of bounds or if addr+size overlaps a single region. +pub fn get_host_address_range( + mem: &M, + addr: GuestAddress, + size: usize, +) -> Option<*mut u8> { + if mem.check_range(addr, size) { + Some(mem.get_host_address(addr).unwrap()) + } else { + None + } +} diff --git a/virtio-devices/src/vhost_user/vu_common_ctrl.rs b/virtio-devices/src/vhost_user/vu_common_ctrl.rs index 752671ed7..791122717 100644 --- a/virtio-devices/src/vhost_user/vu_common_ctrl.rs +++ b/virtio-devices/src/vhost_user/vu_common_ctrl.rs @@ -3,13 +3,12 @@ use super::super::{Descriptor, Queue}; use super::{Error, Result}; -use crate::{VirtioInterrupt, VirtioInterruptType}; +use crate::{get_host_address_range, VirtioInterrupt, VirtioInterruptType}; use libc::EFD_NONBLOCK; use std::convert::TryInto; use std::os::unix::io::AsRawFd; use std::sync::Arc; use std::vec::Vec; -use vfio_ioctls::get_host_address_range; use vhost_rs::vhost_user::{Master, VhostUserMaster}; use vhost_rs::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; use vm_memory::{Address, Error as MmapError, GuestMemory, GuestMemoryMmap, GuestMemoryRegion}; diff --git a/virtio-devices/src/vsock/packet.rs b/virtio-devices/src/vsock/packet.rs index 7edcc5abe..7be31923e 100644 --- a/virtio-devices/src/vsock/packet.rs +++ b/virtio-devices/src/vsock/packet.rs @@ -17,10 +17,9 @@ /// use byteorder::{ByteOrder, LittleEndian}; -use super::super::DescriptorChain; use super::defs; use super::{Result, VsockError}; -use vfio_ioctls::get_host_address_range; +use crate::{get_host_address_range, DescriptorChain}; // The vsock packet header is defined by the C struct: // diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index c9d7de044..75f7c27d8 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -79,13 +79,15 @@ use std::path::PathBuf; use std::result; use std::sync::{Arc, Barrier, Mutex}; #[cfg(feature = "kvm")] -use vfio_ioctls::{VfioContainer, VfioDevice, VfioDmaMapping}; +use vfio_ioctls::{VfioContainer, VfioDevice}; use virtio_devices::transport::VirtioPciDevice; use virtio_devices::transport::VirtioTransport; use virtio_devices::vhost_user::VhostUserConfig; use virtio_devices::{DmaRemapping, IommuMapping}; use virtio_devices::{VirtioSharedMemory, VirtioSharedMemoryList}; use vm_allocator::SystemAllocator; +#[cfg(feature = "kvm")] +use vm_device::dma_mapping::vfio::VfioDmaMapping; use vm_device::interrupt::{ InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig, };