PCI: Add decode disable/enable to device level and separate BAR info logging into separate function
cover PCI: Add decode disable/enable to device level and separate BAR info logging into separate function
In a virtualized environment with PCI devices passed-through, disabling and enabling decoding is not trivial, and in some configurations can take up to 2 seconds of wall clock time to complete. Since this operation could be done once around each device for devices with multiple BARs (reducing redundancy), add an additional decode disable/enable mask at the device level to prevent redundant disable/enables from occurring during each BAR sizing operation, when pci_read_bases() is the originator.
Since __pci_read_base() can also be called independently, keep the current disable/enable mask in that function as-is.
Since printk cannot be used while decoding is disabled, move the debug prints in __pci_read_base() to a separate function, __pci_print_bar_status(). To enable this, add pointers to the signature for __pci_read_base() through which the caller can access necessary data from __pci_read_base() and pass it to __pci_print_bar_status().
This has been tested on an SR670v2 host and guest VM, a DGX H100 host and guest VM, and a DGX A100 host and guest VM. I confirmed that BAR info logged to dmesg was consistent on each between unmodified 6.12.1 and with this patch, that BAR mappings in /proc/iomem were consistent between versions, and that lspci -vv results were consistent between versions. On the A100/H100, I also confirmed that the Nvidia driver loads as expected with the patch, and that VM boot time with cold-plugged, passed-through GPUs is about 2x faster. No regressions were observed.
Originally developed/tested against upstream 6.12.1, but I also confirmed that this applies cleanly to the pci tree @ v6.13-rc1 and that it results in the same boot speed decrease there when tested in an H100 guest VM.
Mitchell Augustin (1):
PCI: Add decode disable/enable to device level and separate BAR info
logging into separate function
drivers/pci/iov.c | 16 ++++- drivers/pci/pci.h | 7 ++- drivers/pci/probe.c | 149 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 158 insertions(+), 14 deletions(-)
---
base-commit: d390303b28dabbb91b2d32016a4f72da478733b9
--
2.43.0
PATCH 1/1 PCI: Add decode disable/enable to device level and separate BAR info logging into separate function
Add an additional decode disable/enable mask at the device level to prevent redundant disable/enables from occurring during each BAR sizing operation, when pci_read_bases() is the originator.
Since __pci_read_base() can also be called independently, keep the current disable/enable mask in that function as-is.
Since printk cannot be used while decoding is disabled, move the debug prints in __pci_read_base() to a separate function, __pci_print_bar_status(). To enable this, add pointers to the signature for __pci_read_base() through which the caller can access necessary data from __pci_read_base() and pass it to __pci_print_bar_status().
--- drivers/pci/iov.c | 16 ++++- drivers/pci/pci.h | 7 ++- drivers/pci/probe.c | 149 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 158 insertions(+), 14 deletions(-)
drivers/pci/iov.c +13 -3
@@ -784,6 +784,11 @@ static int sriov_init(struct pci_dev *dev, int pos)return -ENOMEM ; nres =0 ; +u64 sz64s[PCI_SRIOV_NUM_BARS ] = {0 }; +u64 l64s[PCI_SRIOV_NUM_BARS ] = {0 }; +u32 ls[PCI_SRIOV_NUM_BARS ] = {0 }; +u64 mask64s[PCI_SRIOV_NUM_BARS ] = {0 }; +bool region_matches[PCI_SRIOV_NUM_BARS ] = {0 };for (i =0 ; i <PCI_SRIOV_NUM_BARS ; i++) { res = &dev->resource[i +PCI_IOV_RESOURCES ]; res_name =pci_resource_name (dev, i +PCI_IOV_RESOURCES );
@@ -792,11 +797,16 @@ static int sriov_init(struct pci_dev *dev, int pos)* If it is already FIXED, don't change it, something * (perhaps EA or header fixups) wants it this way. */ -if (res->flags &IORESOURCE_PCI_FIXED ) +if (res->flags &IORESOURCE_PCI_FIXED ) { bar64 = (res->flags &IORESOURCE_MEM_64 ) ?1 :0 ; -else + }else { bar64 =__pci_read_base (dev, pci_bar_unknown, res, - pos +PCI_SRIOV_BAR + i *4 ); + pos +PCI_SRIOV_BAR + i *4 , + sz64s, l64s, mask64s, ls, region_matches, i); +__pci_print_bar_status (dev, pci_bar_unknown, res, + pos +PCI_SRIOV_BAR + i *4 , + sz64s[i], l64s[i], mask64s[i], ls[i], region_matches[i]); + }if (!res->flags)continue ;if (resource_size (res) & (PAGE_SIZE -1 )) {
drivers/pci/pci.h +6 -1
@@ -316,7 +316,12 @@ int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout);int pci_setup_device (struct pci_dev *dev);int __pci_read_base (struct pci_dev *dev,enum pci_bar_type type, -struct resource *res,unsigned int reg); +struct resource *res,unsigned int pos, +u64 *sz64s,u64 *l64s,u64 *mask64s,u32 *ls, +bool *region_matches,unsigned int bar_idx); +int __pci_print_bar_status (struct pci_dev *dev,enum pci_bar_type type, +struct resource *res,unsigned int pos, +u64 sz64,u64 l64,u64 mask64,u32 l,bool region_match);void pci_configure_ari (struct pci_dev *dev);void __pci_bus_size_bridges (struct pci_bus *bus,struct list_head *realloc_head);
drivers/pci/probe.c +139 -10
229 lines not on this page · raw message
Signature · 1 line
2.43.0