mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: platform: add structured SMBIOS config
Extend SMBIOS System Information with manufacturer, product, version, family, sku, serial, and uuid fields, add a chassis asset tag, and pass a structured SMBIOS config from --platform into arch setup. Keep OEM strings and legacy serial_number/uuid options working for compatibility. The platform option naming follows `dmidecode -s <field>`. Fields: - system_manufacturer - system_product_name - system_version - system_family - system_serial_number - system_uuid - chassis_asset_tag On-behalf-of: SAP leander.kohler@sap.com Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
e097d7d495
commit
063caca4a8
@@ -786,14 +786,30 @@ components:
|
||||
iommu_address_width_bits:
|
||||
type: integer
|
||||
format: uint8
|
||||
system_serial_number:
|
||||
type: string
|
||||
serial_number:
|
||||
type: string
|
||||
system_uuid:
|
||||
type: string
|
||||
uuid:
|
||||
type: string
|
||||
oem_strings:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
system_manufacturer:
|
||||
type: string
|
||||
system_product_name:
|
||||
type: string
|
||||
system_version:
|
||||
type: string
|
||||
system_family:
|
||||
type: string
|
||||
system_sku_number:
|
||||
type: string
|
||||
chassis_asset_tag:
|
||||
type: string
|
||||
tdx:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
@@ -847,9 +847,11 @@ impl PlatformConfig {
|
||||
static SYNTAX: LazyLock<String> = LazyLock::new(|| {
|
||||
let mut syntax = "Platform configuration parameters \
|
||||
\"num_pci_segments=<num_pci_segments>,iommu_segments=<list_of_segments>,\
|
||||
iommu_address_width=<bits>,serial_number=<dmi_device_serial_number>,\
|
||||
uuid=<dmi_device_uuid>,oem_strings=<list_of_strings>,iommufd=on|off,\
|
||||
vfio_p2p_dma=on|off"
|
||||
iommu_address_width=<bits>,iommufd=on|off,vfio_p2p_dma=on|off,system_manufacturer=<dmi_system_manufacturer>,\
|
||||
system_product_name=<dmi_system_product_name>,system_version=<dmi_system_version>,\
|
||||
system_serial_number=<dmi_system_serial_number>,system_uuid=<dmi_system_uuid>,\
|
||||
system_sku_number=<dmi_system_sku_number>,system_family=<dmi_system_family>,\
|
||||
oem_strings=<list_of_strings>,chassis_asset_tag=<dmi_chassis_asset_tag>"
|
||||
.to_string();
|
||||
|
||||
if cfg!(feature = "tdx") {
|
||||
@@ -869,6 +871,46 @@ impl PlatformConfig {
|
||||
}
|
||||
|
||||
pub fn parse(platform: &str) -> Result<Self> {
|
||||
struct StringField {
|
||||
key: &'static str,
|
||||
apply: fn(&mut PlatformConfig, String),
|
||||
}
|
||||
|
||||
const SMBIOS_STRING_FIELDS: &[StringField] = &[
|
||||
StringField {
|
||||
key: "system_manufacturer",
|
||||
apply: |config, value| config.system_manufacturer = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_product_name",
|
||||
apply: |config, value| config.system_product_name = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_version",
|
||||
apply: |config, value| config.system_version = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_serial_number",
|
||||
apply: |config, value| config.system_serial_number = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_uuid",
|
||||
apply: |config, value| config.system_uuid = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_sku_number",
|
||||
apply: |config, value| config.system_sku_number = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "system_family",
|
||||
apply: |config, value| config.system_family = Some(value),
|
||||
},
|
||||
StringField {
|
||||
key: "chassis_asset_tag",
|
||||
apply: |config, value| config.chassis_asset_tag = Some(value),
|
||||
},
|
||||
];
|
||||
|
||||
let mut parser = OptionParser::new();
|
||||
parser
|
||||
.add("num_pci_segments")
|
||||
@@ -879,6 +921,9 @@ impl PlatformConfig {
|
||||
.add("oem_strings")
|
||||
.add("iommufd")
|
||||
.add("vfio_p2p_dma");
|
||||
for field in SMBIOS_STRING_FIELDS {
|
||||
parser.add(field.key);
|
||||
}
|
||||
#[cfg(feature = "tdx")]
|
||||
parser.add("tdx");
|
||||
#[cfg(feature = "sev_snp")]
|
||||
@@ -897,10 +942,6 @@ impl PlatformConfig {
|
||||
.convert("iommu_address_width")
|
||||
.map_err(Error::ParsePlatform)?
|
||||
.unwrap_or(MAX_IOMMU_ADDRESS_WIDTH_BITS);
|
||||
let serial_number = parser
|
||||
.convert("serial_number")
|
||||
.map_err(Error::ParsePlatform)?;
|
||||
let uuid = parser.convert("uuid").map_err(Error::ParsePlatform)?;
|
||||
let oem_strings = parser
|
||||
.convert::<StringList>("oem_strings")
|
||||
.map_err(Error::ParsePlatform)?
|
||||
@@ -927,20 +968,50 @@ impl PlatformConfig {
|
||||
.map_err(Error::ParsePlatform)?
|
||||
.unwrap_or(Toggle(false))
|
||||
.0;
|
||||
Ok(PlatformConfig {
|
||||
|
||||
let mut platform_config = PlatformConfig {
|
||||
num_pci_segments,
|
||||
iommu_segments,
|
||||
iommu_address_width_bits,
|
||||
serial_number,
|
||||
uuid,
|
||||
system_serial_number: None,
|
||||
system_uuid: None,
|
||||
oem_strings,
|
||||
system_manufacturer: None,
|
||||
system_product_name: None,
|
||||
system_version: None,
|
||||
system_family: None,
|
||||
system_sku_number: None,
|
||||
chassis_asset_tag: None,
|
||||
iommufd,
|
||||
vfio_p2p_dma,
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
sev_snp,
|
||||
})
|
||||
vfio_p2p_dma,
|
||||
};
|
||||
|
||||
for field in SMBIOS_STRING_FIELDS {
|
||||
if let Some(value) = parser
|
||||
.convert::<String>(field.key)
|
||||
.map_err(Error::ParsePlatform)?
|
||||
{
|
||||
(field.apply)(&mut platform_config, value);
|
||||
}
|
||||
}
|
||||
|
||||
let legacy_serial_number = parser
|
||||
.convert::<String>("serial_number")
|
||||
.map_err(Error::ParsePlatform)?;
|
||||
platform_config.system_serial_number = platform_config
|
||||
.system_serial_number
|
||||
.or(legacy_serial_number);
|
||||
|
||||
let legacy_uuid = parser
|
||||
.convert::<String>("uuid")
|
||||
.map_err(Error::ParsePlatform)?;
|
||||
platform_config.system_uuid = platform_config.system_uuid.or(legacy_uuid);
|
||||
|
||||
Ok(platform_config)
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> ValidationResult<()> {
|
||||
@@ -5027,11 +5098,17 @@ id=\"{id}\",pci_segment={pci_segment},queue_sizes={queue_sizes}"
|
||||
num_pci_segments: MAX_NUM_PCI_SEGMENTS,
|
||||
iommu_segments: None,
|
||||
iommu_address_width_bits: MAX_IOMMU_ADDRESS_WIDTH_BITS,
|
||||
serial_number: None,
|
||||
uuid: None,
|
||||
system_serial_number: None,
|
||||
system_uuid: None,
|
||||
oem_strings: None,
|
||||
iommufd: false,
|
||||
vfio_p2p_dma: default_platformconfig_vfio_p2p_dma(),
|
||||
system_manufacturer: None,
|
||||
system_product_name: None,
|
||||
system_version: None,
|
||||
system_family: None,
|
||||
system_sku_number: None,
|
||||
chassis_asset_tag: None,
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx: false,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
|
||||
@@ -131,12 +131,24 @@ pub struct PlatformConfig {
|
||||
pub iommu_segments: Option<Box<[u16]>>,
|
||||
#[serde(default = "default_platformconfig_iommu_address_width_bits")]
|
||||
pub iommu_address_width_bits: u8,
|
||||
#[serde(default)]
|
||||
pub serial_number: Option<String>,
|
||||
#[serde(default)]
|
||||
pub uuid: Option<String>,
|
||||
#[serde(default, alias = "serial_number")]
|
||||
pub system_serial_number: Option<String>,
|
||||
#[serde(default, alias = "uuid")]
|
||||
pub system_uuid: Option<String>,
|
||||
#[serde(default)]
|
||||
pub oem_strings: Option<Box<[String]>>,
|
||||
#[serde(default)]
|
||||
pub system_manufacturer: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_product_name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_version: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_family: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_sku_number: Option<String>,
|
||||
#[serde(default)]
|
||||
pub chassis_asset_tag: Option<String>,
|
||||
#[cfg(feature = "tdx")]
|
||||
#[serde(default)]
|
||||
pub tdx: bool,
|
||||
@@ -154,9 +166,38 @@ impl PlatformConfig {
|
||||
/// Returns `None` if no SMBIOS-relevant platform fields are set, otherwise
|
||||
/// `Some` with a [`SmbiosConfig`] built from the populated fields.
|
||||
pub fn smbios_config(&self) -> Option<arch::x86_64::SmbiosConfig> {
|
||||
let has_system = [
|
||||
&self.system_serial_number,
|
||||
&self.system_uuid,
|
||||
&self.system_manufacturer,
|
||||
&self.system_product_name,
|
||||
&self.system_version,
|
||||
&self.system_family,
|
||||
&self.system_sku_number,
|
||||
]
|
||||
.iter()
|
||||
.any(|v| v.is_some());
|
||||
|
||||
let system = has_system.then_some(arch::x86_64::SmbiosSystem {
|
||||
manufacturer: self.system_manufacturer.clone(),
|
||||
product_name: self.system_product_name.clone(),
|
||||
version: self.system_version.clone(),
|
||||
serial_number: self.system_serial_number.clone(),
|
||||
uuid: self.system_uuid.clone(),
|
||||
sku_number: self.system_sku_number.clone(),
|
||||
family: self.system_family.clone(),
|
||||
});
|
||||
|
||||
let chassis =
|
||||
self.chassis_asset_tag
|
||||
.clone()
|
||||
.map(|asset_tag| arch::x86_64::SmbiosChassisConfig {
|
||||
asset_tag: Some(asset_tag),
|
||||
});
|
||||
|
||||
let smbios = arch::x86_64::SmbiosConfig {
|
||||
serial_number: self.serial_number.clone(),
|
||||
uuid: self.uuid.clone(),
|
||||
system,
|
||||
chassis,
|
||||
oem_strings: self.oem_strings.clone().unwrap_or_default(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user