diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh index 6df97a5bea..0ffa53b4a4 100755 --- a/kernel-open/conftest.sh +++ b/kernel-open/conftest.sh @@ -4067,6 +4067,23 @@ compile_test() { compile_check_conftest "$CODE" "NV_PCI_REBAR_GET_POSSIBLE_SIZES_PRESENT" "" "functions" ;; + pci_is_thunderbolt_attached) + # + # Determine if the pci_is_thunderbolt_attached() function is + # present. + # + # Added by commit 0d4ef7ce7e78 ("PCI: Identify Thunderbolt + # devices") in v4.15. + # + CODE=" + #include + void conftest_pci_is_thunderbolt_attached(void) { + pci_is_thunderbolt_attached(); + }" + + compile_check_conftest "$CODE" "NV_PCI_IS_THUNDERBOLT_ATTACHED_PRESENT" "" "functions" + ;; + pci_resize_resource_has_exclude_bars_arg) # # Determine if pci_resize_resource() has exclude_bars argument. diff --git a/kernel-open/nvidia/nv-pci.c b/kernel-open/nvidia/nv-pci.c index 996d5c0e50..7c0f1fa6b9 100644 --- a/kernel-open/nvidia/nv-pci.c +++ b/kernel-open/nvidia/nv-pci.c @@ -208,6 +208,25 @@ static int nv_resize_pcie_bars(struct pci_dev *pci_dev) { return 0; } +#if defined(NV_PCI_IS_THUNDERBOLT_ATTACHED_PRESENT) + /* + * Thunderbolt / USB4 hotplug bridges have a small prefetchable MMIO + * window that cannot accommodate a GiB-scale resized BAR. Skip + * the resize attempt proactively rather than trying and failing, + * which avoids an uninformative -ENOENT in the kernel log and + * sidesteps the failure path entirely. + */ + if (pci_is_thunderbolt_attached(pci_dev)) + { + nv_printf(NV_DBG_INFO, + "NVRM: %04x:%02x:%02x.%x: device is downstream of Thunderbolt, " + "skipping BAR1 resize\n", + NV_PCI_DOMAIN_NUMBER(pci_dev), NV_PCI_BUS_NUMBER(pci_dev), + NV_PCI_SLOT_NUMBER(pci_dev), PCI_FUNC(pci_dev->devfn)); + return 0; + } +#endif + // Check if BAR1 has PCIe rebar capabilities sizes = pci_rebar_get_possible_sizes(pci_dev, NV_GPU_BAR1); if (sizes == 0) { @@ -1949,9 +1968,18 @@ nv_pci_probe goto err_zero_dev; if (nv_resize_pcie_bars(pci_dev)) { - nv_printf(NV_DBG_ERRORS, - "NVRM: Fatal Error while attempting to resize PCIe BARs.\n"); - goto err_zero_dev; + /* + * Resizable BAR is an enhancement, not a requirement. When + * the resize fails (commonly because the upstream bridge + * prefetchable window is too small to accommodate a GiB-scale + * BAR, as seen with Thunderbolt/USB4 hotplug bridges), the + * device is still functional with its existing BAR + * allocation. Do not turn a minor performance degradation + * into a hard probe failure -- log a warning and continue. + */ + nv_printf(NV_DBG_WARNINGS, + "NVRM: PCIe BAR resize failed; continuing with the existing " + "BAR allocation.\n"); } nvl->all_mappings_revoked = NV_TRUE; diff --git a/kernel-open/nvidia/nvidia.Kbuild b/kernel-open/nvidia/nvidia.Kbuild index 6996bad113..d2e04549a4 100644 --- a/kernel-open/nvidia/nvidia.Kbuild +++ b/kernel-open/nvidia/nvidia.Kbuild @@ -120,6 +120,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += pde_data NV_CONFTEST_FUNCTION_COMPILE_TESTS += xen_ioemu_inject_msi NV_CONFTEST_FUNCTION_COMPILE_TESTS += phys_to_dma NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_rebar_get_possible_sizes +NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_is_thunderbolt_attached NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_backlight_device_by_name NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_direct_map_resource NV_CONFTEST_FUNCTION_COMPILE_TESTS += flush_cache_all