File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -2192,6 +2192,15 @@ nv_pci_remove(struct pci_dev *pci_dev)
21922192 */
21932193 if ((atomic64_read (& nvl -> usage_count ) != 0 ) && !(nv -> is_external_gpu ))
21942194 {
2195+ /*
2196+ * For external GPU: wait up to 5 seconds (10 iterations * 500ms)
2197+ * For internal GPU: wait up to 60 seconds (120 iterations * 500ms)
2198+ * This prevents indefinite hangs while still allowing time for
2199+ * graceful cleanup of in-progress operations.
2200+ */
2201+ int max_wait_iterations = nv -> is_external_gpu ? 10 : 120 ;
2202+ int wait_iterations = 0 ;
2203+
21952204 nv_printf (NV_DBG_ERRORS ,
21962205 "NVRM: Attempting to remove device %04x:%02x:%02x.%x with non-zero usage count (%d)%s\n" ,
21972206 NV_PCI_DOMAIN_NUMBER (pci_dev ), NV_PCI_BUS_NUMBER (pci_dev ),
@@ -2203,7 +2212,8 @@ nv_pci_remove(struct pci_dev *pci_dev)
22032212 * We can't return from this function without corrupting state, so we wait for
22042213 * the usage count to go to zero, but with a timeout.
22052214 */
2206- while (atomic64_read (& nvl -> usage_count ) != 0 )
2215+ while ((atomic64_read (& nvl -> usage_count ) != 0 ) &&
2216+ (wait_iterations < max_wait_iterations ))
22072217 {
22082218 /*
22092219 * While waiting, release the locks so that other threads can make
You can’t perform that action at this time.
0 commit comments