vmm: pci: Move creation of vfio_user::Client to DeviceManager

By moving this from the VfioUserPciDevice to DeviceManager the client
can be reused for handling DMA mapping behind an IOMMU.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2021-08-11 10:19:33 +00:00
parent fd4f32fa69
commit e9d67dc405
4 changed files with 19 additions and 9 deletions
Generated
+1
View File
@@ -1398,6 +1398,7 @@ dependencies = [
"versionize", "versionize",
"versionize_derive", "versionize_derive",
"vfio-ioctls", "vfio-ioctls",
"vfio_user",
"vhdx", "vhdx",
"virtio-devices", "virtio-devices",
"vm-allocator", "vm-allocator",
+8 -8
View File
@@ -11,7 +11,6 @@ use crate::{
use hypervisor::HypervisorVmError; use hypervisor::HypervisorVmError;
use std::any::Any; use std::any::Any;
use std::os::unix::prelude::AsRawFd; use std::os::unix::prelude::AsRawFd;
use std::path::Path;
use std::ptr::null_mut; use std::ptr::null_mut;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::u32; use std::u32;
@@ -61,12 +60,10 @@ impl PciSubclass for PciVfioUserSubclass {
impl VfioUserPciDevice { impl VfioUserPciDevice {
pub fn new( pub fn new(
vm: &Arc<dyn hypervisor::Vm>, vm: &Arc<dyn hypervisor::Vm>,
path: &Path, client: Arc<Mutex<Client>>,
msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>, msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>, legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>,
) -> Result<Self, VfioUserPciDeviceError> { ) -> Result<Self, VfioUserPciDeviceError> {
let mut client = Client::new(path).map_err(VfioUserPciDeviceError::Client)?;
// This is used for the BAR and capabilities only // This is used for the BAR and capabilities only
let configuration = PciConfiguration::new( let configuration = PciConfiguration::new(
0, 0,
@@ -80,12 +77,15 @@ impl VfioUserPciDevice {
0, 0,
None, None,
); );
if client.resettable() { let resettable = client.lock().unwrap().resettable();
client.reset().map_err(VfioUserPciDeviceError::Client)?; if resettable {
client
.lock()
.unwrap()
.reset()
.map_err(VfioUserPciDeviceError::Client)?;
} }
let client = Arc::new(Mutex::new(client));
let vfio_wrapper = VfioUserClientWrapper { let vfio_wrapper = VfioUserClientWrapper {
client: client.clone(), client: client.clone(),
}; };
+1
View File
@@ -45,6 +45,7 @@ uuid = "0.8.2"
versionize = "0.1.6" versionize = "0.1.6"
versionize_derive = "0.1.4" versionize_derive = "0.1.4"
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "main", default-features = false } vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "main", default-features = false }
vfio_user = { path = "../vfio_user" }
vhdx = { path = "../vhdx" } vhdx = { path = "../vhdx" }
virtio-devices = { path = "../virtio-devices" } virtio-devices = { path = "../virtio-devices" }
vm-allocator = { path = "../vm-allocator" } vm-allocator = { path = "../vm-allocator" }
+9 -1
View File
@@ -442,6 +442,9 @@ pub enum DeviceManagerError {
/// Failed removing DMA mapping handler from virtio-mem device. /// Failed removing DMA mapping handler from virtio-mem device.
RemoveDmaMappingHandlerVirtioMem(virtio_devices::mem::Error), RemoveDmaMappingHandlerVirtioMem(virtio_devices::mem::Error),
/// Failed to create vfio-user client
VfioUserCreateClient(vfio_user::Error),
/// Failed to create VFIO user device /// Failed to create VFIO user device
VfioUserCreate(VfioUserPciDeviceError), VfioUserCreate(VfioUserPciDeviceError),
@@ -3105,9 +3108,14 @@ impl DeviceManager {
None None
}; };
let client = Arc::new(Mutex::new(
vfio_user::Client::new(&device_cfg.socket)
.map_err(DeviceManagerError::VfioUserCreateClient)?,
));
let mut vfio_user_pci_device = VfioUserPciDevice::new( let mut vfio_user_pci_device = VfioUserPciDevice::new(
&self.address_manager.vm, &self.address_manager.vm,
&device_cfg.socket, client,
&self.msi_interrupt_manager, &self.msi_interrupt_manager,
legacy_interrupt_group, legacy_interrupt_group,
) )