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

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