mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
pci: Use a weak reference to the AddressManager
Storing a strong reference to the AddressManager behind the DeviceRelocation trait results in a cyclic reference count. Use a weak reference to break that dependency. Signed-off-by: Rob Bradford <robert.bradford@intel.com> Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
149b61b213
commit
3e819ac797
@ -10,8 +10,7 @@ use byteorder::{ByteOrder, LittleEndian};
|
|||||||
use devices::BusDevice;
|
use devices::BusDevice;
|
||||||
use std;
|
use std;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex, Weak};
|
||||||
use std::sync::Mutex;
|
|
||||||
use vm_memory::{Address, GuestAddress, GuestUsize};
|
use vm_memory::{Address, GuestAddress, GuestUsize};
|
||||||
|
|
||||||
const VENDOR_ID_INTEL: u16 = 0x8086;
|
const VENDOR_ID_INTEL: u16 = 0x8086;
|
||||||
@ -76,11 +75,11 @@ pub struct PciBus {
|
|||||||
/// Devices attached to this bus.
|
/// Devices attached to this bus.
|
||||||
/// Device 0 is host bridge.
|
/// Device 0 is host bridge.
|
||||||
devices: Vec<Arc<Mutex<dyn PciDevice>>>,
|
devices: Vec<Arc<Mutex<dyn PciDevice>>>,
|
||||||
device_reloc: Arc<dyn DeviceRelocation>,
|
device_reloc: Weak<dyn DeviceRelocation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PciBus {
|
impl PciBus {
|
||||||
pub fn new(pci_root: PciRoot, device_reloc: Arc<dyn DeviceRelocation>) -> Self {
|
pub fn new(pci_root: PciRoot, device_reloc: Weak<dyn DeviceRelocation>) -> Self {
|
||||||
let mut devices: Vec<Arc<Mutex<dyn PciDevice>>> = Vec::new();
|
let mut devices: Vec<Arc<Mutex<dyn PciDevice>>> = Vec::new();
|
||||||
|
|
||||||
devices.push(Arc::new(Mutex::new(pci_root)));
|
devices.push(Arc::new(Mutex::new(pci_root)));
|
||||||
@ -198,7 +197,7 @@ impl PciConfigIo {
|
|||||||
|
|
||||||
// Reprogram the BAR if needed
|
// Reprogram the BAR if needed
|
||||||
if let Some(params) = bar_reprog_params {
|
if let Some(params) = bar_reprog_params {
|
||||||
pci_bus.device_reloc.move_bar(
|
pci_bus.device_reloc.upgrade().unwrap().move_bar(
|
||||||
params.old_base,
|
params.old_base,
|
||||||
params.new_base,
|
params.new_base,
|
||||||
params.len,
|
params.len,
|
||||||
@ -314,7 +313,7 @@ impl PciConfigMmio {
|
|||||||
|
|
||||||
// Reprogram the BAR if needed
|
// Reprogram the BAR if needed
|
||||||
if let Some(params) = bar_reprog_params {
|
if let Some(params) = bar_reprog_params {
|
||||||
pci_bus.device_reloc.move_bar(
|
pci_bus.device_reloc.upgrade().unwrap().move_bar(
|
||||||
params.old_base,
|
params.old_base,
|
||||||
params.new_base,
|
params.new_base,
|
||||||
params.len,
|
params.len,
|
||||||
|
@ -34,6 +34,8 @@ use std::os::unix::fs::OpenOptionsExt;
|
|||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::result;
|
use std::result;
|
||||||
|
#[cfg(feature = "pci_support")]
|
||||||
|
use std::sync::Weak;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
use vfio::{VfioDevice, VfioDmaMapping, VfioPciDevice, VfioPciError};
|
use vfio::{VfioDevice, VfioDmaMapping, VfioPciDevice, VfioPciError};
|
||||||
@ -536,7 +538,10 @@ impl DeviceManager {
|
|||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
{
|
{
|
||||||
let pci_root = PciRoot::new(None);
|
let pci_root = PciRoot::new(None);
|
||||||
let mut pci_bus = PciBus::new(pci_root, address_manager.clone());
|
let mut pci_bus = PciBus::new(
|
||||||
|
pci_root,
|
||||||
|
Arc::downgrade(&address_manager) as Weak<dyn DeviceRelocation>,
|
||||||
|
);
|
||||||
|
|
||||||
let (mut iommu_device, iommu_mapping) = if vm_info.vm_cfg.iommu {
|
let (mut iommu_device, iommu_mapping) = if vm_info.vm_cfg.iommu {
|
||||||
let (device, mapping) =
|
let (device, mapping) =
|
||||||
|
Loading…
Reference in New Issue
Block a user