mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: pci: Expect an identifier upon device creation
This identifier is chosen from the DeviceManager so that it will manage all identifiers across the VM, which will ensure uniqueness. It is based off the name from the virtio device attached to this transport layer. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
eeb7e10d1f
commit
06487131f9
@@ -259,6 +259,8 @@ const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4;
|
|||||||
const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID.
|
const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID.
|
||||||
|
|
||||||
pub struct VirtioPciDevice {
|
pub struct VirtioPciDevice {
|
||||||
|
id: String,
|
||||||
|
|
||||||
// PCI configuration registers.
|
// PCI configuration registers.
|
||||||
configuration: PciConfiguration,
|
configuration: PciConfiguration,
|
||||||
|
|
||||||
@@ -308,6 +310,7 @@ pub struct VirtioPciDevice {
|
|||||||
impl VirtioPciDevice {
|
impl VirtioPciDevice {
|
||||||
/// Constructs a new PCI transport for the given virtio device.
|
/// Constructs a new PCI transport for the given virtio device.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
id: String,
|
||||||
memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
device: Arc<Mutex<dyn VirtioDevice>>,
|
device: Arc<Mutex<dyn VirtioDevice>>,
|
||||||
msix_num: u16,
|
msix_num: u16,
|
||||||
@@ -384,6 +387,7 @@ impl VirtioPciDevice {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut virtio_pci_device = VirtioPciDevice {
|
let mut virtio_pci_device = VirtioPciDevice {
|
||||||
|
id,
|
||||||
configuration,
|
configuration,
|
||||||
common_config: VirtioPciCommonConfig {
|
common_config: VirtioPciCommonConfig {
|
||||||
driver_status: 0,
|
driver_status: 0,
|
||||||
@@ -962,6 +966,10 @@ impl Pausable for VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Snapshottable for VirtioPciDevice {}
|
impl Snapshottable for VirtioPciDevice {
|
||||||
|
fn id(&self) -> String {
|
||||||
|
self.id.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Transportable for VirtioPciDevice {}
|
impl Transportable for VirtioPciDevice {}
|
||||||
impl Migratable for VirtioPciDevice {}
|
impl Migratable for VirtioPciDevice {}
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ const IOMMU_DEVICE_NAME: &str = "iommu";
|
|||||||
|
|
||||||
#[cfg(feature = "mmio_support")]
|
#[cfg(feature = "mmio_support")]
|
||||||
const VIRTIO_MMIO_DEVICE_NAME_PREFIX: &str = "virtio-mmio";
|
const VIRTIO_MMIO_DEVICE_NAME_PREFIX: &str = "virtio-mmio";
|
||||||
|
#[cfg(feature = "pci_support")]
|
||||||
|
const VIRTIO_PCI_DEVICE_NAME_PREFIX: &str = "virtio-pci";
|
||||||
|
|
||||||
/// Errors associated with device manager
|
/// Errors associated with device manager
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -1933,8 +1935,10 @@ impl DeviceManager {
|
|||||||
pci: &mut PciBus,
|
pci: &mut PciBus,
|
||||||
iommu_mapping: &Option<Arc<IommuMapping>>,
|
iommu_mapping: &Option<Arc<IommuMapping>>,
|
||||||
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||||
id: String,
|
virtio_device_id: String,
|
||||||
) -> DeviceManagerResult<u32> {
|
) -> DeviceManagerResult<u32> {
|
||||||
|
let id = format!("{}-{}", VIRTIO_PCI_DEVICE_NAME_PREFIX, virtio_device_id);
|
||||||
|
|
||||||
// Allows support for one MSI-X vector per queue. It also adds 1
|
// Allows support for one MSI-X vector per queue. It also adds 1
|
||||||
// as we need to take into account the dedicated vector to notify
|
// as we need to take into account the dedicated vector to notify
|
||||||
// about a virtio config change.
|
// about a virtio config change.
|
||||||
@@ -1972,6 +1976,7 @@ impl DeviceManager {
|
|||||||
|
|
||||||
let memory = self.memory_manager.lock().unwrap().guest_memory();
|
let memory = self.memory_manager.lock().unwrap().guest_memory();
|
||||||
let mut virtio_pci_device = VirtioPciDevice::new(
|
let mut virtio_pci_device = VirtioPciDevice::new(
|
||||||
|
id,
|
||||||
memory,
|
memory,
|
||||||
virtio_device,
|
virtio_device,
|
||||||
msix_num,
|
msix_num,
|
||||||
@@ -1980,7 +1985,8 @@ impl DeviceManager {
|
|||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::VirtioDevice)?;
|
.map_err(DeviceManagerError::VirtioDevice)?;
|
||||||
|
|
||||||
let mut allocator = self.address_manager.allocator.lock().unwrap();
|
let allocator = self.address_manager.allocator.clone();
|
||||||
|
let mut allocator = allocator.lock().unwrap();
|
||||||
let bars = virtio_pci_device
|
let bars = virtio_pci_device
|
||||||
.allocate_bars(&mut allocator)
|
.allocate_bars(&mut allocator)
|
||||||
.map_err(DeviceManagerError::AllocateBars)?;
|
.map_err(DeviceManagerError::AllocateBars)?;
|
||||||
@@ -2005,10 +2011,10 @@ impl DeviceManager {
|
|||||||
self.bus_devices
|
self.bus_devices
|
||||||
.push(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn BusDevice>>);
|
.push(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn BusDevice>>);
|
||||||
|
|
||||||
if self.pci_id_list.contains_key(&id) {
|
if self.pci_id_list.contains_key(&virtio_device_id) {
|
||||||
return Err(DeviceManagerError::DeviceIdAlreadyInUse);
|
return Err(DeviceManagerError::DeviceIdAlreadyInUse);
|
||||||
}
|
}
|
||||||
self.pci_id_list.insert(id, pci_device_bdf);
|
self.pci_id_list.insert(virtio_device_id, pci_device_bdf);
|
||||||
|
|
||||||
pci.register_mapping(
|
pci.register_mapping(
|
||||||
virtio_pci_device.clone(),
|
virtio_pci_device.clone(),
|
||||||
@@ -2018,9 +2024,7 @@ impl DeviceManager {
|
|||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||||
|
|
||||||
let migratable = Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn Migratable>>;
|
self.add_migratable_device(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn Migratable>>);
|
||||||
let id = migratable.lock().unwrap().id();
|
|
||||||
self.migratable_devices.push((id, migratable));
|
|
||||||
|
|
||||||
Ok(pci_device_bdf)
|
Ok(pci_device_bdf)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user