From a96da9d4bc8e82f25a673439d5320ec0638c94ce Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 3 Apr 2026 11:16:24 -0700 Subject: [PATCH] vmm: Introduce PciDeviceCommonConfig::validate() Implement some common PCI segment validation. This can be used to reduce duplication across the different validation methods. Signed-off-by: Rob Bradford --- vmm/src/config.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 2cf80191d..6c399dbdd 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1226,6 +1226,23 @@ impl PciDeviceCommonConfig { pci_segment, }) } + + pub fn validate(&self, vm_config: &VmConfig) -> ValidationResult<()> { + if let Some(platform_config) = vm_config.platform.as_ref() { + if self.pci_segment >= platform_config.num_pci_segments { + return Err(ValidationError::InvalidPciSegment(self.pci_segment)); + } + + if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() + && iommu_segments.contains(&self.pci_segment) + && !self.iommu + { + return Err(ValidationError::OnIommuSegment(self.pci_segment)); + } + } + + Ok(()) + } } impl DiskConfig {