vmm: Validate the PCI segment ID without platform configuration

Validate that the PCI segment specified is a valid PCI segment ID (less
than the number of segments specified) defaulting to default if no
segments are specified because no there is no platform configuration.

See: #8376

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-06-12 11:48:54 +01:00
parent e94bb6bce6
commit bf3bc325e2
+16 -10
View File
@@ -1365,17 +1365,23 @@ impl PciDeviceCommonConfig {
} }
pub fn validate(&self, vm_config: &VmConfig) -> ValidationResult<()> { pub fn validate(&self, vm_config: &VmConfig) -> ValidationResult<()> {
if let Some(platform_config) = vm_config.platform.as_ref() { let num_pci_segments = vm_config
if self.pci_segment >= platform_config.num_pci_segments { .platform
return Err(ValidationError::InvalidPciSegment(self.pci_segment)); .as_ref()
} .map_or(DEFAULT_NUM_PCI_SEGMENTS, |platform_config| {
platform_config.num_pci_segments
});
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() if self.pci_segment >= num_pci_segments {
&& iommu_segments.contains(&self.pci_segment) return Err(ValidationError::InvalidPciSegment(self.pci_segment));
&& !self.iommu }
{
return Err(ValidationError::OnIommuSegment(self.pci_segment)); if let Some(platform_config) = vm_config.platform.as_ref()
} && 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));
} }
if let Some(device_id) = self.pci_device_id { if let Some(device_id) = self.pci_device_id {