virtio-devices, vmm: Move to ExternalDmaMapping from vm-device

Now that ExternalDmaMapping is defined in vm-device, let's use it from
there.

This commit also defines the function get_host_address_range() to move
away from the vfio-ioctls dependency.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-02-23 14:57:10 +01:00 committed by Samuel Ortiz
parent 5bd05b1af0
commit aee1155870
7 changed files with 23 additions and 8 deletions

1
Cargo.lock generated
View File

@ -1420,7 +1420,6 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"vfio-ioctls",
"vhost",
"virtio-bindings",
"vm-allocator",

View File

@ -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" }

View File

@ -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,

View File

@ -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<M: GuestMemory>(
mem: &M,
addr: GuestAddress,
size: usize,
) -> Option<*mut u8> {
if mem.check_range(addr, size) {
Some(mem.get_host_address(addr).unwrap())
} else {
None
}
}

View File

@ -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};

View File

@ -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:
//

View File

@ -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,
};