mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-23 06:05:21 +00:00
device_manager: Simplify the passthrough internal API
We store the device passthrough handler, so we should use it through our internal API and only carry the passed through device configuration. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
f57d970451
commit
be51ea250d
@ -2392,11 +2392,10 @@ impl DeviceManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pci: &mut PciBus,
|
pci: &mut PciBus,
|
||||||
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||||
device: &Arc<dyn hypervisor::Device>,
|
|
||||||
device_cfg: &mut DeviceConfig,
|
device_cfg: &mut DeviceConfig,
|
||||||
) -> DeviceManagerResult<(u32, String)> {
|
) -> DeviceManagerResult<(u32, String)> {
|
||||||
#[cfg(feature = "kvm")]
|
#[cfg(feature = "kvm")]
|
||||||
return self.add_vfio_device(pci, interrupt_manager, device, device_cfg);
|
return self.add_vfio_device(pci, interrupt_manager, device_cfg);
|
||||||
|
|
||||||
#[cfg(not(feature = "kvm"))]
|
#[cfg(not(feature = "kvm"))]
|
||||||
Err(DeviceManagerError::NoDevicePassthroughSupport)
|
Err(DeviceManagerError::NoDevicePassthroughSupport)
|
||||||
@ -2407,9 +2406,13 @@ impl DeviceManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pci: &mut PciBus,
|
pci: &mut PciBus,
|
||||||
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||||
device: &Arc<dyn hypervisor::Device>,
|
|
||||||
device_cfg: &mut DeviceConfig,
|
device_cfg: &mut DeviceConfig,
|
||||||
) -> DeviceManagerResult<(u32, String)> {
|
) -> DeviceManagerResult<(u32, String)> {
|
||||||
|
let passthrough_device = self
|
||||||
|
.passthrough_device
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(DeviceManagerError::NoDevicePassthroughSupport)?;
|
||||||
|
|
||||||
// We need to shift the device id since the 3 first bits
|
// We need to shift the device id since the 3 first bits
|
||||||
// are dedicated to the PCI function, and we know we don't
|
// are dedicated to the PCI function, and we know we don't
|
||||||
// do multifunction. Also, because we only support one PCI
|
// do multifunction. Also, because we only support one PCI
|
||||||
@ -2423,7 +2426,7 @@ impl DeviceManager {
|
|||||||
let memory = self.memory_manager.lock().unwrap().guest_memory();
|
let memory = self.memory_manager.lock().unwrap().guest_memory();
|
||||||
let vfio_container = Arc::new(
|
let vfio_container = Arc::new(
|
||||||
VfioContainer::new(Arc::new(unsafe {
|
VfioContainer::new(Arc::new(unsafe {
|
||||||
DeviceFd::from_raw_fd(device.as_raw_fd())
|
DeviceFd::from_raw_fd(passthrough_device.as_raw_fd())
|
||||||
}))
|
}))
|
||||||
.map_err(DeviceManagerError::VfioCreate)?,
|
.map_err(DeviceManagerError::VfioCreate)?,
|
||||||
);
|
);
|
||||||
@ -2515,17 +2518,19 @@ impl DeviceManager {
|
|||||||
let mut devices = self.config.lock().unwrap().devices.clone();
|
let mut devices = self.config.lock().unwrap().devices.clone();
|
||||||
|
|
||||||
if let Some(device_list_cfg) = &mut devices {
|
if let Some(device_list_cfg) = &mut devices {
|
||||||
// Create the passthrough device handle
|
if self.passthrough_device.is_none() {
|
||||||
let device = self
|
// Create the passthrough device.
|
||||||
.address_manager
|
self.passthrough_device = Some(
|
||||||
.vm
|
self.address_manager
|
||||||
.create_passthrough_device()
|
.vm
|
||||||
.map_err(|e| DeviceManagerError::CreatePassthroughDevice(e.into()))?;
|
.create_passthrough_device()
|
||||||
self.passthrough_device = Some(Arc::clone(&device));
|
.map_err(|e| DeviceManagerError::CreatePassthroughDevice(e.into()))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for device_cfg in device_list_cfg.iter_mut() {
|
for device_cfg in device_list_cfg.iter_mut() {
|
||||||
let (device_id, _) =
|
let (device_id, _) =
|
||||||
self.add_passthrough_device(pci, interrupt_manager, &device, device_cfg)?;
|
self.add_passthrough_device(pci, interrupt_manager, device_cfg)?;
|
||||||
if device_cfg.iommu && self.iommu_device.is_some() {
|
if device_cfg.iommu && self.iommu_device.is_some() {
|
||||||
iommu_attached_device_ids.push(device_id);
|
iommu_attached_device_ids.push(device_id);
|
||||||
}
|
}
|
||||||
@ -2940,27 +2945,19 @@ impl DeviceManager {
|
|||||||
|
|
||||||
let interrupt_manager = Arc::clone(&self.msi_interrupt_manager);
|
let interrupt_manager = Arc::clone(&self.msi_interrupt_manager);
|
||||||
|
|
||||||
let device = if let Some(device) = &self.passthrough_device {
|
if self.passthrough_device.is_none() {
|
||||||
Arc::clone(&device)
|
// If the passthrough device has not been created yet, it is created
|
||||||
} else {
|
// here and stored in the DeviceManager structure for future needs.
|
||||||
// If the passthrough device file descriptor has not been created yet,
|
self.passthrough_device = Some(
|
||||||
// it is created here and stored in the DeviceManager structure for
|
self.address_manager
|
||||||
// future needs.
|
.vm
|
||||||
let device = self
|
.create_passthrough_device()
|
||||||
.address_manager
|
.map_err(|e| DeviceManagerError::CreatePassthroughDevice(e.into()))?,
|
||||||
.vm
|
);
|
||||||
.create_passthrough_device()
|
}
|
||||||
.map_err(|e| DeviceManagerError::CreatePassthroughDevice(e.into()))?;
|
|
||||||
self.passthrough_device = Some(Arc::clone(&device));
|
|
||||||
device
|
|
||||||
};
|
|
||||||
|
|
||||||
let (device_id, device_name) = self.add_passthrough_device(
|
let (device_id, device_name) =
|
||||||
&mut pci.lock().unwrap(),
|
self.add_passthrough_device(&mut pci.lock().unwrap(), &interrupt_manager, device_cfg)?;
|
||||||
&interrupt_manager,
|
|
||||||
&device,
|
|
||||||
device_cfg,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Update the PCIU bitmap
|
// Update the PCIU bitmap
|
||||||
self.pci_devices_up |= 1 << (device_id >> 3);
|
self.pci_devices_up |= 1 << (device_id >> 3);
|
||||||
|
Loading…
Reference in New Issue
Block a user