Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6949,6 +6949,7 @@ dependencies = [
"bitfield-struct",
"libc",
"nix 0.26.4",
"pal_event",
"tracing",
"vfio-bindings",
]
Expand Down
1 change: 1 addition & 0 deletions vm/devices/user_driver/vfio_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ libc.workspace = true
nix = { workspace = true, features = ["ioctl"] }
tracing.workspace = true
vfio-bindings.workspace = true
pal_event.workspace = true

[lints]
workspace = true
12 changes: 12 additions & 0 deletions vm/devices/user_driver/vfio_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fs;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::iter;
use std::os::unix::prelude::*;
use std::path::Path;
use vfio_bindings::bindings::vfio::vfio_device_info;
Expand Down Expand Up @@ -392,6 +393,17 @@ impl AsFd for Device {
}
}

impl Drop for Device {
fn drop(&mut self) {
match self.map_msix(0, iter::empty::<pal_event::Event>()) {
Ok(_) => (),
Err(e) => {
tracing::error!("vfio_sys::Device::drop error calling map_msix: {:?}", e);
}
}
}
}

/// Find the Linux irq number for the MSI-X `index` of the PCI device `pci_id`.
pub fn find_msix_irq(pci_id: &str, index: u32) -> anyhow::Result<u32> {
let buffered = BufReader::new(File::open("/proc/interrupts")?);
Expand Down