Vfio: Ignore vfio device's multifunction flag

PciRoot doesn't support multifunciion which forward pci config r/w
from function > 0 to function 0, so if the vfio device have multifunction
flag, guest will find the existence of all the other functions, actually it
is from the function 0. In order to fix these extra functions, this
patch clear the multifunction flag, so guest won't probe the other
functions.

BUG=chromium:992270
TEST=pass through a device with multifunction into guest

Change-Id: I395636411e0d7d2a3729de16e638d7f6b2dde552
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954221
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Xiong Zhang 2019-11-22 11:29:26 +08:00 committed by Commit Bot
parent 5c6bf3e32d
commit 3ec8cc4f52

View file

@ -27,6 +27,8 @@ const INTEL_VENDOR_ID: u16 = 0x8086;
const PCI_COMMAND: u32 = 0x4; const PCI_COMMAND: u32 = 0x4;
const PCI_COMMAND_MEMORY: u8 = 0x2; const PCI_COMMAND_MEMORY: u8 = 0x2;
const PCI_BASE_CLASS_CODE: u32 = 0x0B; const PCI_BASE_CLASS_CODE: u32 = 0x0B;
const PCI_HEADER_TYPE: usize = 0x0E;
const PCI_MULTI_FLAG: u32 = 0x0080_0000;
const PCI_INTERRUPT_PIN: u32 = 0x3D; const PCI_INTERRUPT_PIN: u32 = 0x3D;
@ -753,6 +755,10 @@ impl PciDevice for VfioPciDevice {
config = 0; config = 0;
} }
} }
} else if reg_idx == PCI_HEADER_TYPE / 4 {
// Clear multifunction flags as pci_root doesn't
// support multifunction.
config &= !PCI_MULTI_FLAG;
} }
// Quirk for intel graphic, set stolen memory size to 0 in pci_cfg[0x51] // Quirk for intel graphic, set stolen memory size to 0 in pci_cfg[0x51]