vm-virtio: Add IOMMU support to virtio-vsock

Adding virtio feature VIRTIO_F_IOMMU_PLATFORM when explicitly asked by
the user. The need for this feature is to be able to attach the virtio
device to a virtual IOMMU.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-10-04 10:47:13 -07:00 committed by Samuel Ortiz
parent 9ab00dcb75
commit 6566c739e1
3 changed files with 9 additions and 5 deletions

View File

@ -41,7 +41,7 @@ use crate::Error as DeviceError;
use crate::VirtioInterrupt;
use crate::{
ActivateError, ActivateResult, DeviceEventT, Queue, VirtioDevice, VirtioDeviceType,
VirtioInterruptType, VIRTIO_F_IN_ORDER, VIRTIO_F_VERSION_1,
VirtioInterruptType, VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
};
use byteorder::{ByteOrder, LittleEndian};
use vm_memory::GuestMemoryMmap;
@ -366,8 +366,12 @@ where
{
/// Create a new virtio-vsock device with the given VM CID and vsock
/// backend.
pub fn new(cid: u64, backend: B) -> io::Result<Vsock<B>> {
let avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
pub fn new(cid: u64, backend: B, iommu: bool) -> io::Result<Vsock<B>> {
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
if iommu {
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
}
Ok(Vsock {
cid,

View File

@ -256,7 +256,7 @@ mod tests {
cid: CID,
mem: GuestMemoryMmap::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap(),
mem_size: MEM_SIZE,
device: Vsock::new(CID, TestBackend::new()).unwrap(),
device: Vsock::new(CID, TestBackend::new(), false).unwrap(),
}
}

View File

@ -860,7 +860,7 @@ impl DeviceManager {
vm_virtio::vsock::VsockUnixBackend::new(vsock_cfg.cid, socket_path.to_string())
.map_err(DeviceManagerError::CreateVsockBackend)?;
let vsock_device = vm_virtio::Vsock::new(vsock_cfg.cid, backend)
let vsock_device = vm_virtio::Vsock::new(vsock_cfg.cid, backend, false)
.map_err(DeviceManagerError::CreateVirtioVsock)?;
devices.push(Box::new(vsock_device) as Box<dyn vm_virtio::VirtioDevice>);