From 3ec8cc4f52b3c4314b2d02a08d4851e58daef587 Mon Sep 17 00:00:00 2001 From: Xiong Zhang Date: Fri, 22 Nov 2019 11:29:26 +0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954221 Tested-by: kokoro Reviewed-by: Daniel Verkamp --- devices/src/pci/vfio_pci.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'devices/src/pci/vfio_pci.rs') diff --git a/devices/src/pci/vfio_pci.rs b/devices/src/pci/vfio_pci.rs index 38615d9..216f5eb 100644 --- a/devices/src/pci/vfio_pci.rs +++ b/devices/src/pci/vfio_pci.rs @@ -27,6 +27,8 @@ const INTEL_VENDOR_ID: u16 = 0x8086; const PCI_COMMAND: u32 = 0x4; const PCI_COMMAND_MEMORY: u8 = 0x2; 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; @@ -753,6 +755,10 @@ impl PciDevice for VfioPciDevice { 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] -- cgit 1.4.1