mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
pci, devices, virtio-devices, vmm: Refactor allocate_bars
Refactor PciDevice::allocate_bars trait and all implementations to take &mut SystemAllocator instead of &Arc<Mutex<SystemAllocator>>, removing double indirection. The caller in device_manager.rs now acquires the lock before calling allocate_bars. Signed-off-by: Chinmoy <daschinmoyy21@gmail.com>
This commit is contained in:
@@ -217,7 +217,7 @@ impl BusDevice for IvshmemDevice {
|
|||||||
impl PciDevice for IvshmemDevice {
|
impl PciDevice for IvshmemDevice {
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
_allocator: &Arc<Mutex<SystemAllocator>>,
|
_allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
mmio64_allocator: &mut AddressAllocator,
|
mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::sync::{Arc, Barrier, Mutex, RwLock};
|
use std::sync::{Arc, Barrier, RwLock};
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
|
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
@@ -722,7 +722,7 @@ impl PciDevice for PvmemcontrolPciDevice {
|
|||||||
|
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
_allocator: &Arc<Mutex<SystemAllocator>>,
|
_allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
_mmio64_allocator: &mut AddressAllocator,
|
_mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier};
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use event_monitor::event;
|
use event_monitor::event;
|
||||||
@@ -174,7 +174,7 @@ impl PciDevice for PvPanicDevice {
|
|||||||
|
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
_allocator: &Arc<Mutex<SystemAllocator>>,
|
_allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
_mmio64_allocator: &mut AddressAllocator,
|
_mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier};
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -49,7 +49,7 @@ pub trait PciDevice: Send {
|
|||||||
/// returns an address. Returns a Vec of (GuestAddress, GuestUsize) tuples.
|
/// returns an address. Returns a Vec of (GuestAddress, GuestUsize) tuples.
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
_allocator: &Arc<Mutex<SystemAllocator>>,
|
_allocator: &mut SystemAllocator,
|
||||||
_mmio32_allocator: &mut AddressAllocator,
|
_mmio32_allocator: &mut AddressAllocator,
|
||||||
_mmio64_allocator: &mut AddressAllocator,
|
_mmio64_allocator: &mut AddressAllocator,
|
||||||
_resources: Option<Vec<Resource>>,
|
_resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -602,7 +602,7 @@ impl VfioCommon {
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub(crate) fn allocate_bars(
|
pub(crate) fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
allocator: &Arc<Mutex<SystemAllocator>>,
|
allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
mmio64_allocator: &mut AddressAllocator,
|
mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<&[Resource]>,
|
resources: Option<&[Resource]>,
|
||||||
@@ -741,8 +741,6 @@ impl VfioCommon {
|
|||||||
PciBarRegionType::IoRegion => {
|
PciBarRegionType::IoRegion => {
|
||||||
// The address needs to be 4 bytes aligned.
|
// The address needs to be 4 bytes aligned.
|
||||||
allocator
|
allocator
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.allocate_io_addresses(restored_bar_addr, region_size, Some(0x4))
|
.allocate_io_addresses(restored_bar_addr, region_size, Some(0x4))
|
||||||
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?
|
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?
|
||||||
}
|
}
|
||||||
@@ -1852,7 +1850,7 @@ const PCI_ROM_EXP_BAR_INDEX: usize = 12;
|
|||||||
impl PciDevice for VfioPciDevice {
|
impl PciDevice for VfioPciDevice {
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
allocator: &Arc<Mutex<SystemAllocator>>,
|
allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
mmio64_allocator: &mut AddressAllocator,
|
mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ impl Vfio for VfioUserClientWrapper {
|
|||||||
impl PciDevice for VfioUserPciDevice {
|
impl PciDevice for VfioUserPciDevice {
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
allocator: &Arc<Mutex<SystemAllocator>>,
|
allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
mmio64_allocator: &mut AddressAllocator,
|
mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -978,7 +978,7 @@ impl PciDevice for VirtioPciDevice {
|
|||||||
|
|
||||||
fn allocate_bars(
|
fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
_allocator: &Arc<Mutex<SystemAllocator>>,
|
_allocator: &mut SystemAllocator,
|
||||||
mmio32_allocator: &mut AddressAllocator,
|
mmio32_allocator: &mut AddressAllocator,
|
||||||
mmio64_allocator: &mut AddressAllocator,
|
mmio64_allocator: &mut AddressAllocator,
|
||||||
resources: Option<Vec<Resource>>,
|
resources: Option<Vec<Resource>>,
|
||||||
|
|||||||
@@ -3995,7 +3995,7 @@ impl DeviceManager {
|
|||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.allocate_bars(
|
.allocate_bars(
|
||||||
&self.address_manager.allocator,
|
&mut self.address_manager.allocator.lock().unwrap(),
|
||||||
&mut self.pci_segments[segment_id as usize]
|
&mut self.pci_segments[segment_id as usize]
|
||||||
.mem32_allocator
|
.mem32_allocator
|
||||||
.lock()
|
.lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user