mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio, vmm, vfio: Store GuestMemoryMmap in an Arc<ArcSwap<T>>
This allows us to change the memory map that is being used by the devices via an atomic swap (by replacing the map with another one). The ArcSwap provides the mechanism for atomically swapping from to another whilst still giving good read performace. It is inside an Arc so that we can use a single ArcSwap for all users. Not covered by this change is replacing the GuestMemoryMmap itself. This change also removes some vertical whitespace from use blocks in the files that this commit also changed. Vertical whitespace was being used inconsistently and broke rustfmt's behaviour of ordering the imports as it would only do it within the block. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -8,27 +8,23 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
//
|
||||
|
||||
use std::cmp;
|
||||
use std::os::unix::thread::JoinHandleExt;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Barrier, Mutex, RwLock, Weak};
|
||||
use std::thread;
|
||||
use std::{fmt, io, result};
|
||||
|
||||
use libc::{c_void, siginfo_t};
|
||||
|
||||
use crate::device_manager::DeviceManager;
|
||||
#[cfg(feature = "acpi")]
|
||||
use acpi_tables::{aml, aml::Aml, sdt::SDT};
|
||||
use arc_swap::ArcSwap;
|
||||
use arch::layout;
|
||||
use devices::{ioapic, BusDevice};
|
||||
use kvm_bindings::CpuId;
|
||||
use kvm_ioctls::*;
|
||||
|
||||
use libc::{c_void, siginfo_t};
|
||||
use std::cmp;
|
||||
use std::os::unix::thread::JoinHandleExt;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Barrier, Mutex, Weak};
|
||||
use std::thread;
|
||||
use std::{fmt, io, result};
|
||||
use vm_device::{Migratable, MigratableError, Pausable, Snapshotable};
|
||||
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
|
||||
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
use vmm_sys_util::signal::{register_signal_handler, SIGRTMIN};
|
||||
|
||||
@@ -279,7 +275,7 @@ impl Vcpu {
|
||||
pub fn configure(
|
||||
&mut self,
|
||||
kernel_start_addr: Option<GuestAddress>,
|
||||
vm_memory: &Arc<RwLock<GuestMemoryMmap>>,
|
||||
vm_memory: &Arc<ArcSwap<GuestMemoryMmap>>,
|
||||
cpuid: CpuId,
|
||||
) -> Result<()> {
|
||||
let mut cpuid = cpuid;
|
||||
@@ -299,7 +295,7 @@ impl Vcpu {
|
||||
)
|
||||
.map_err(Error::REGSConfiguration)?;
|
||||
arch::x86_64::regs::setup_fpu(&self.fd).map_err(Error::FPUConfiguration)?;
|
||||
arch::x86_64::regs::setup_sregs(&vm_memory.read().unwrap(), &self.fd)
|
||||
arch::x86_64::regs::setup_sregs(&vm_memory.load(), &self.fd)
|
||||
.map_err(Error::SREGSConfiguration)?;
|
||||
}
|
||||
arch::x86_64::interrupts::set_lint(&self.fd).map_err(Error::LocalIntConfiguration)?;
|
||||
@@ -378,7 +374,7 @@ pub struct CpuManager {
|
||||
io_bus: Weak<devices::Bus>,
|
||||
mmio_bus: Arc<devices::Bus>,
|
||||
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
||||
vm_memory: Arc<RwLock<GuestMemoryMmap>>,
|
||||
vm_memory: Arc<ArcSwap<GuestMemoryMmap>>,
|
||||
cpuid: CpuId,
|
||||
fd: Arc<VmFd>,
|
||||
vcpus_kill_signalled: Arc<AtomicBool>,
|
||||
@@ -498,7 +494,7 @@ impl CpuManager {
|
||||
boot_vcpus: u8,
|
||||
max_vcpus: u8,
|
||||
device_manager: &DeviceManager,
|
||||
guest_memory: Arc<RwLock<GuestMemoryMmap>>,
|
||||
guest_memory: Arc<ArcSwap<GuestMemoryMmap>>,
|
||||
fd: Arc<VmFd>,
|
||||
cpuid: CpuId,
|
||||
reset_evt: EventFd,
|
||||
|
||||
Reference in New Issue
Block a user