diff options
author | Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> | 2019-12-06 18:50:49 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-21 11:45:16 +0000 |
commit | 2647a1916da0220deab4ad1ae89a92c1ba81dcf4 (patch) | |
tree | 040221322b536c8b0dee4d56ac14ba1a0bdcfb65 /devices | |
parent | 04b44e3df02e87de704080e131ed90afdf2dfd7e (diff) | |
download | crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar.gz crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar.bz2 crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar.lz crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar.xz crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.tar.zst crosvm-2647a1916da0220deab4ad1ae89a92c1ba81dcf4.zip |
Vfio: Disable msix bar's mmap
If vfio device's bar is mmappable, vcpu could access it directly through ept without trapping. But msix's table and pba exist on pci bar, they must be trapped and emulated by crosvm, so these bars mmappable must be disabled. BUG=chromium:992270 TEST=pass through a device with msix cap to guest, then test device function in guest. Change-Id: If7504a924902c940e00cc759c1ca64a116bbca17 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987815 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r-- | devices/src/pci/vfio_pci.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/devices/src/pci/vfio_pci.rs b/devices/src/pci/vfio_pci.rs index 178d4ae..c031793 100644 --- a/devices/src/pci/vfio_pci.rs +++ b/devices/src/pci/vfio_pci.rs @@ -415,6 +415,14 @@ impl VfioMsixCap { self.config.write_pba_entries(offset, data); } + fn is_msix_bar(&self, bar_index: u32) -> bool { + if bar_index == self.table_pci_bar || bar_index == self.pba_pci_bar { + true + } else { + false + } + } + fn get_msix_irqfds(&self) -> Option<Vec<&EventFd>> { let mut irqfds = Vec::new(); @@ -683,6 +691,14 @@ impl VfioPciDevice { fn add_bar_mmap(&self, index: u32, bar_addr: u64) -> Vec<MemoryMapping> { let mut mem_map: Vec<MemoryMapping> = Vec::new(); if self.device.get_region_flags(index) & VFIO_REGION_INFO_FLAG_MMAP != 0 { + // the bar storing msix table and pba couldn't mmap. + // these bars should be trapped, so that msix could be emulated. + if let Some(msix_cap) = &self.msix_cap { + if msix_cap.is_msix_bar(index) { + return mem_map; + } + } + let mmaps = self.device.get_region_mmap(index); if mmaps.is_empty() { return mem_map; |