On Wed, 12 Jun 2019 11:41:36 -0700 sathyanarayanan kuppuswamy <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx> wrote: > On 6/12/19 11:19 AM, Alex Williamson wrote: > > On Wed, 12 Jun 2019 10:06:47 -0700 > > sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx wrote: > > > >> From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx> > >> > >> Commit 975bb8b4dc93 ("PCI/IOV: Use VF0 cached config space size for > >> other VFs") calculates and caches the cfg_size for VF0 device before > >> initializing the pcie_cap of the device which results in using incorrect > >> cfg_size for all VF devices > 0. So set pcie_cap of the device before > >> calculating the cfg_size of VF0 device. > >> > >> Fixes: 975bb8b4dc93 ("PCI/IOV: Use VF0 cached config space size for > >> other VFs") > >> Cc: Ashok Raj <ashok.raj@xxxxxxxxx> > >> Suggested-by: Mike Campin <mike.campin@xxxxxxxxx> > >> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx> > >> --- > >> > >> Changes since v1: > >> * Fixed a typo in commit message. > >> > >> drivers/pci/iov.c | 1 + > >> 1 file changed, 1 insertion(+) > >> > >> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c > >> index 3aa115ed3a65..2869011c0e35 100644 > >> --- a/drivers/pci/iov.c > >> +++ b/drivers/pci/iov.c > >> @@ -160,6 +160,7 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) > >> virtfn->device = iov->vf_device; > >> virtfn->is_virtfn = 1; > >> virtfn->physfn = pci_dev_get(dev); > >> + virtfn->pcie_cap = pci_find_capability(virtfn, PCI_CAP_ID_EXP); > >> > >> if (id == 0) > >> pci_read_vf_config_common(virtfn); > > Why not re-order until after we've setup pcie_cap? > > > > https://lore.kernel.org/linux-pci/20190604143617.0a226555@xxxxxxx/T/# > > pci_read_vf_config_common() also caches values for properties like > class, hdr_type, susbsystem_vendor/device. These values are read/used in > pci_setup_device(). So if we can use cached values in > pci_setup_device(), we don't have to read them from registers twice for > each device. Sorry, I missed that dependency, a bit too subtle. It's still pretty ugly that pci_setup_device()->set_pcie_port_type() is the canonical location for setting pcie_cap and now we need to kludge it earlier. What about the question in the self follow-up to my patch in the link above, can we simply assume 4K config space on a VF? Thanks, Alex