mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
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:
parent
fd4f32fa69
commit
e9d67dc405
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1398,6 +1398,7 @@ dependencies = [
|
||||
"versionize",
|
||||
"versionize_derive",
|
||||
"vfio-ioctls",
|
||||
"vfio_user",
|
||||
"vhdx",
|
||||
"virtio-devices",
|
||||
"vm-allocator",
|
||||
|
@ -11,7 +11,6 @@ use crate::{
|
||||
use hypervisor::HypervisorVmError;
|
||||
use std::any::Any;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
use std::path::Path;
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::{Arc, Barrier, Mutex};
|
||||
use std::u32;
|
||||
@ -61,12 +60,10 @@ impl PciSubclass for PciVfioUserSubclass {
|
||||
impl VfioUserPciDevice {
|
||||
pub fn new(
|
||||
vm: &Arc<dyn hypervisor::Vm>,
|
||||
path: &Path,
|
||||
client: Arc<Mutex<Client>>,
|
||||
msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||
legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>,
|
||||
) -> Result<Self, VfioUserPciDeviceError> {
|
||||
let mut client = Client::new(path).map_err(VfioUserPciDeviceError::Client)?;
|
||||
|
||||
// This is used for the BAR and capabilities only
|
||||
let configuration = PciConfiguration::new(
|
||||
0,
|
||||
@ -80,12 +77,15 @@ impl VfioUserPciDevice {
|
||||
0,
|
||||
None,
|
||||
);
|
||||
if client.resettable() {
|
||||
client.reset().map_err(VfioUserPciDeviceError::Client)?;
|
||||
let resettable = client.lock().unwrap().resettable();
|
||||
if resettable {
|
||||
client
|
||||
.lock()
|
||||
.unwrap()
|
||||
.reset()
|
||||
.map_err(VfioUserPciDeviceError::Client)?;
|
||||
}
|
||||
|
||||
let client = Arc::new(Mutex::new(client));
|
||||
|
||||
let vfio_wrapper = VfioUserClientWrapper {
|
||||
client: client.clone(),
|
||||
};
|
||||
|
@ -45,6 +45,7 @@ uuid = "0.8.2"
|
||||
versionize = "0.1.6"
|
||||
versionize_derive = "0.1.4"
|
||||
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "main", default-features = false }
|
||||
vfio_user = { path = "../vfio_user" }
|
||||
vhdx = { path = "../vhdx" }
|
||||
virtio-devices = { path = "../virtio-devices" }
|
||||
vm-allocator = { path = "../vm-allocator" }
|
||||
|
@ -442,6 +442,9 @@ pub enum DeviceManagerError {
|
||||
/// Failed removing DMA mapping handler from virtio-mem device.
|
||||
RemoveDmaMappingHandlerVirtioMem(virtio_devices::mem::Error),
|
||||
|
||||
/// Failed to create vfio-user client
|
||||
VfioUserCreateClient(vfio_user::Error),
|
||||
|
||||
/// Failed to create VFIO user device
|
||||
VfioUserCreate(VfioUserPciDeviceError),
|
||||
|
||||
@ -3105,9 +3108,14 @@ impl DeviceManager {
|
||||
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(
|
||||
&self.address_manager.vm,
|
||||
&device_cfg.socket,
|
||||
client,
|
||||
&self.msi_interrupt_manager,
|
||||
legacy_interrupt_group,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user