From 3efccd0fefb7557e4af072f4459e7ad2b56beda6 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 4 Aug 2021 15:14:24 +0000 Subject: [PATCH] vmm: config: Ensure shared memory is enabled if using user-devices Correct operation of user devices (vfio-user) requires shared memory so flag this to prevent it from failing in strange ways. Signed-off-by: Rob Bradford --- vmm/src/config.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 583ab63f5..5081c3755 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -138,6 +138,8 @@ pub enum ValidationError { TdxKernelSpecified, // Insuffient vCPUs for queues TooManyQueues, + // Need shared memory for vfio-user + UserDevicesRequireSharedMemory, } type ValidationResult = std::result::Result; @@ -185,6 +187,9 @@ impl fmt::Display for ValidationError { TooManyQueues => { write!(f, "Number of vCPUs is insufficient for number of queues") } + UserDevicesRequireSharedMemory => { + write!(f, "Using user devices requires using shared memory") + } } } } @@ -1905,6 +1910,11 @@ impl VmConfig { } } + if let Some(user_devices) = &self.user_devices { + if !user_devices.is_empty() && !self.memory.shared { + return Err(ValidationError::UserDevicesRequireSharedMemory); + } + } Ok(()) }