mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-15 21:57:15 +00:00
vfio-pci: unmap regions when dropping VfioGroup
Introduce method unmap_mmio_regions to unmap all regions mapped to host. This patch eliminate the error message "Could not unset container". Signed-off-by: Wu Zongyong <wuzongyong@linux.alibaba.com>
This commit is contained in:
parent
62fa595ac6
commit
4de04e84b5
@ -258,6 +258,7 @@ struct MmioRegion {
|
|||||||
index: u32,
|
index: u32,
|
||||||
mem_slot: Option<u32>,
|
mem_slot: Option<u32>,
|
||||||
host_addr: Option<u64>,
|
host_addr: Option<u64>,
|
||||||
|
mmap_size: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VfioPciConfig {
|
struct VfioPciConfig {
|
||||||
@ -665,6 +666,7 @@ impl VfioPciDevice {
|
|||||||
// Update the region with memory mapped info.
|
// Update the region with memory mapped info.
|
||||||
region.mem_slot = Some(new_mem_slot);
|
region.mem_slot = Some(new_mem_slot);
|
||||||
region.host_addr = Some(host_addr as u64);
|
region.host_addr = Some(host_addr as u64);
|
||||||
|
region.mmap_size = Some(mmap_size as usize);
|
||||||
|
|
||||||
new_mem_slot += 1;
|
new_mem_slot += 1;
|
||||||
}
|
}
|
||||||
@ -672,10 +674,26 @@ impl VfioPciDevice {
|
|||||||
|
|
||||||
Ok(new_mem_slot)
|
Ok(new_mem_slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unmap_mmio_regions(&mut self) {
|
||||||
|
for region in self.mmio_regions.iter() {
|
||||||
|
if let (Some(addr), Some(size)) = (region.host_addr, region.mmap_size) {
|
||||||
|
let ret = unsafe { libc::munmap(addr as *mut libc::c_void, size) };
|
||||||
|
if ret != 0 {
|
||||||
|
error!(
|
||||||
|
"Could not unmap regions, error:{}",
|
||||||
|
io::Error::last_os_error()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for VfioPciDevice {
|
impl Drop for VfioPciDevice {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
self.unmap_mmio_regions();
|
||||||
|
|
||||||
if let Some(msix) = &self.interrupt.msix {
|
if let Some(msix) = &self.interrupt.msix {
|
||||||
if msix.cap.enabled() && self.device.disable_msix().is_err() {
|
if msix.cap.enabled() && self.device.disable_msix().is_err() {
|
||||||
error!("Could not disable MSI-X");
|
error!("Could not disable MSI-X");
|
||||||
@ -884,6 +902,7 @@ impl PciDevice for VfioPciDevice {
|
|||||||
index: bar_id as u32,
|
index: bar_id as u32,
|
||||||
mem_slot: None,
|
mem_slot: None,
|
||||||
host_addr: None,
|
host_addr: None,
|
||||||
|
mmap_size: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
bar_id += 1;
|
bar_id += 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user