From 5109f914ebe597332ab6c1b0de4432fa0558cda2 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 5 May 2020 09:59:49 +0100 Subject: [PATCH] vmm: config: Reject attempts to use VFIO or IOMMU without PCI Generate an error during validation if an attempt it made to place a device behind an IOMMU or using a VFIO device when not using PCI. Fixes: #751 Signed-off-by: Rob Bradford --- vmm/src/config.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index e9c0a7854..f612f8ffb 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -84,6 +84,10 @@ pub enum ValidationError { DiskSocketAndPath, /// Using vhost user requires shared memory VhostUserRequiresSharedMemory, + /// Trying to use IOMMU without PCI + IommuUnsupported, + /// Trying to use VFIO without PCI + VfioUnsupported, } type ValidationResult = std::result::Result; @@ -100,6 +104,8 @@ impl fmt::Display for ValidationError { VhostUserRequiresSharedMemory => { write!(f, "Using vhost-user requires using shared memory") } + IommuUnsupported => write!(f, "Using an IOMMU without PCI support is unsupported"), + VfioUnsupported => write!(f, "Using VFIO without PCI support is unsupported"), } } } @@ -1293,6 +1299,15 @@ impl VmConfig { } } + if cfg!(not(feature = "pci_support")) { + if self.iommu { + return Err(ValidationError::IommuUnsupported); + } + if self.devices.is_some() { + return Err(ValidationError::VfioUnsupported); + } + } + Ok(()) }