mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
vmm: Ensure uniqueness of generated identifiers
The device identifiers generated from the DeviceManager were not guaranteed to be unique since they were not taking the list of identifiers provided through the configuration. By returning the list of unique identifiers from the configuration, and by providing it to the DeviceManager, the generation of new identifiers can rely both on the DeviceTree and the list of IDs from the configuration. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
634c53ea50
commit
677c8831af
@ -2329,7 +2329,9 @@ pub struct VmConfig {
|
||||
|
||||
impl VmConfig {
|
||||
// Also enables virtio-iommu if the config needs it
|
||||
pub fn validate(&mut self) -> ValidationResult<()> {
|
||||
// Returns the list of unique identifiers provided through the
|
||||
// configuration.
|
||||
pub fn validate(&mut self) -> ValidationResult<BTreeSet<String>> {
|
||||
let mut id_list = BTreeSet::new();
|
||||
|
||||
#[cfg(not(feature = "tdx"))]
|
||||
@ -2578,7 +2580,7 @@ impl VmConfig {
|
||||
.map(|p| p.iommu_segments.is_some())
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(())
|
||||
Ok(id_list)
|
||||
}
|
||||
|
||||
pub fn parse(vm_params: VmParams) -> Result<Self> {
|
||||
|
@ -72,7 +72,7 @@ use pci::{
|
||||
VfioUserPciDevice, VfioUserPciDeviceError,
|
||||
};
|
||||
use seccompiler::SeccompAction;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::convert::TryInto;
|
||||
use std::fs::{read_link, File, OpenOptions};
|
||||
use std::io::{self, stdout, Seek, SeekFrom};
|
||||
@ -934,6 +934,9 @@ pub struct DeviceManager {
|
||||
|
||||
// io_uring availability if detected
|
||||
io_uring_supported: Option<bool>,
|
||||
|
||||
// List of unique identifiers provided at boot through the configuration.
|
||||
boot_id_list: BTreeSet<String>,
|
||||
}
|
||||
|
||||
impl DeviceManager {
|
||||
@ -949,6 +952,7 @@ impl DeviceManager {
|
||||
activate_evt: &EventFd,
|
||||
force_iommu: bool,
|
||||
restoring: bool,
|
||||
boot_id_list: BTreeSet<String>,
|
||||
) -> DeviceManagerResult<Arc<Mutex<Self>>> {
|
||||
let device_tree = Arc::new(Mutex::new(DeviceTree::new()));
|
||||
|
||||
@ -1071,6 +1075,7 @@ impl DeviceManager {
|
||||
force_iommu,
|
||||
restoring,
|
||||
io_uring_supported: None,
|
||||
boot_id_list,
|
||||
};
|
||||
|
||||
let device_manager = Arc::new(Mutex::new(device_manager));
|
||||
@ -3002,7 +3007,9 @@ impl DeviceManager {
|
||||
// Increment the counter.
|
||||
self.device_id_cnt += Wrapping(1);
|
||||
// Check if the name is already in use.
|
||||
if !self.device_tree.lock().unwrap().contains_key(&name) {
|
||||
if !self.boot_id_list.contains(&name)
|
||||
&& !self.device_tree.lock().unwrap().contains_key(&name)
|
||||
{
|
||||
return Ok(name);
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ impl Vm {
|
||||
None
|
||||
};
|
||||
|
||||
config
|
||||
let boot_id_list = config
|
||||
.lock()
|
||||
.unwrap()
|
||||
.validate()
|
||||
@ -603,6 +603,7 @@ impl Vm {
|
||||
&activate_evt,
|
||||
force_iommu,
|
||||
restoring,
|
||||
boot_id_list,
|
||||
)
|
||||
.map_err(Error::DeviceManager)?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user