devices:vfio-pci: Add close() for vfio pci device

When vfio pci device is hotplug out from the guest machine, vfio device's
resource should be returned to system, so vfio pci device's close() is
needed.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: I4686d737e93ae6db6078851e2add3275b9faaa84
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955574
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Xiong Zhang 2021-06-08 14:00:53 +08:00 committed by Commit Bot
parent 436fa1b807
commit 22dc9f80c4

View file

@ -868,11 +868,15 @@ impl VfioPciDevice {
}
}
fn enable_bars_mmap(&mut self) {
fn disable_bars_mmap(&mut self) {
for mmap_info in self.mmap_info.iter() {
self.remove_bar_mmap(mmap_info);
}
self.mmap_info.clear();
}
fn enable_bars_mmap(&mut self) {
self.disable_bars_mmap();
for mmio_info in self.mmio_regions.iter() {
let mut mmap_info =
@ -882,6 +886,12 @@ impl VfioPciDevice {
self.remap = false;
}
#[allow(dead_code)]
fn close(&mut self) {
self.disable_bars_mmap();
self.device.close();
}
}
impl PciDevice for VfioPciDevice {