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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-08-04 15:14:24 +00:00
parent b28063a7b4
commit 3efccd0fef

View File

@ -138,6 +138,8 @@ pub enum ValidationError {
TdxKernelSpecified,
// Insuffient vCPUs for queues
TooManyQueues,
// Need shared memory for vfio-user
UserDevicesRequireSharedMemory,
}
type ValidationResult<T> = std::result::Result<T, ValidationError>;
@ -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(())
}