mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
msix: Add VmFd to MsixConfig
Because MsixConfig will be responsible for updating the KVM GSI routes at some point, it must have access to the VmFd to invoke the KVM ioctl KVM_SET_GSI_ROUTING. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
86c760a0d9
commit
9b60fcdc39
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1110,6 +1110,7 @@ dependencies = [
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"devices 0.1.0",
|
||||
"epoll 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvm-ioctls 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"net_gen 0.1.0",
|
||||
|
@ -11,6 +11,7 @@ use std::sync::Arc;
|
||||
use crate::device::InterruptParameters;
|
||||
use crate::{InterruptDelivery, InterruptRoute, PciCapability, PciCapabilityID};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use kvm_ioctls::VmFd;
|
||||
use vm_allocator::SystemAllocator;
|
||||
use vm_memory::ByteValued;
|
||||
|
||||
@ -53,13 +54,14 @@ pub struct MsixConfig {
|
||||
pub table_entries: Vec<MsixTableEntry>,
|
||||
pub pba_entries: Vec<u64>,
|
||||
pub irq_routes: Vec<InterruptRoute>,
|
||||
_vm_fd: Arc<VmFd>,
|
||||
interrupt_cb: Option<Arc<InterruptDelivery>>,
|
||||
masked: bool,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl MsixConfig {
|
||||
pub fn new(msix_vectors: u16, allocator: &mut SystemAllocator) -> Self {
|
||||
pub fn new(msix_vectors: u16, allocator: &mut SystemAllocator, vm_fd: Arc<VmFd>) -> Self {
|
||||
assert!(msix_vectors <= MAX_MSIX_VECTORS_PER_DEVICE);
|
||||
|
||||
let mut table_entries: Vec<MsixTableEntry> = Vec::new();
|
||||
@ -77,6 +79,7 @@ impl MsixConfig {
|
||||
table_entries,
|
||||
pba_entries,
|
||||
irq_routes,
|
||||
_vm_fd: vm_fd,
|
||||
interrupt_cb: None,
|
||||
masked: false,
|
||||
enabled: false,
|
||||
|
@ -412,7 +412,7 @@ impl VfioPciDevice {
|
||||
table,
|
||||
pba,
|
||||
};
|
||||
let msix_config = MsixConfig::new(msix_cap.table_size(), allocator);
|
||||
let msix_config = MsixConfig::new(msix_cap.table_size(), allocator, self.vm_fd.clone());
|
||||
|
||||
self.interrupt.msix = Some(VfioMsix {
|
||||
bar: msix_config,
|
||||
|
@ -14,6 +14,7 @@ arc-swap = ">=0.4.4"
|
||||
byteorder = "1.3.2"
|
||||
devices = { path = "../devices" }
|
||||
epoll = ">=4.0.1"
|
||||
kvm-ioctls = "0.4.0"
|
||||
libc = "0.2.60"
|
||||
log = "0.4.8"
|
||||
net_gen = { path = "../net_gen" }
|
||||
|
@ -15,6 +15,7 @@ extern crate vmm_sys_util;
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use devices::BusDevice;
|
||||
use kvm_ioctls::VmFd;
|
||||
use libc::EFD_NONBLOCK;
|
||||
use pci::{
|
||||
BarReprogrammingParams, InterruptDelivery, InterruptParameters, MsixCap, MsixConfig,
|
||||
@ -257,6 +258,7 @@ impl VirtioPciDevice {
|
||||
msix_num: u16,
|
||||
iommu_mapping_cb: Option<Arc<VirtioIommuRemapping>>,
|
||||
allocator: &mut SystemAllocator,
|
||||
vm_fd: &Arc<VmFd>,
|
||||
) -> Result<Self> {
|
||||
let device_clone = device.clone();
|
||||
let locked_device = device_clone.lock().unwrap();
|
||||
@ -277,7 +279,11 @@ impl VirtioPciDevice {
|
||||
let pci_device_id = VIRTIO_PCI_DEVICE_ID_BASE + locked_device.device_type() as u16;
|
||||
|
||||
let (msix_config, msix_config_clone) = if msix_num > 0 {
|
||||
let msix_config = Arc::new(Mutex::new(MsixConfig::new(msix_num, allocator)));
|
||||
let msix_config = Arc::new(Mutex::new(MsixConfig::new(
|
||||
msix_num,
|
||||
allocator,
|
||||
vm_fd.clone(),
|
||||
)));
|
||||
let msix_config_clone = msix_config.clone();
|
||||
(Some(msix_config), Some(msix_config_clone))
|
||||
} else {
|
||||
|
@ -1473,6 +1473,7 @@ impl DeviceManager {
|
||||
msix_num,
|
||||
iommu_mapping_cb,
|
||||
&mut allocator,
|
||||
vm_fd,
|
||||
)
|
||||
.map_err(DeviceManagerError::VirtioDevice)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user