Skip to content

Commit 2cde6eb

Browse files
committed
Merge branch 'pci/aspm'
- Delay pcie_link_state deallocation to avoid dangling pointers that cause invalid references during hot-unplug (Daniel Stodden) * pci/aspm: PCI/ASPM: Fix link state exit during switch upstream function removal
2 parents 5a04a18 + cbf937d commit 2cde6eb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,16 +1273,16 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
12731273
parent_link = link->parent;
12741274

12751275
/*
1276-
* link->downstream is a pointer to the pci_dev of function 0. If
1277-
* we remove that function, the pci_dev is about to be deallocated,
1278-
* so we can't use link->downstream again. Free the link state to
1279-
* avoid this.
1276+
* Free the parent link state, no later than function 0 (i.e.
1277+
* link->downstream) being removed.
12801278
*
1281-
* If we're removing a non-0 function, it's possible we could
1282-
* retain the link state, but PCIe r6.0, sec 7.5.3.7, recommends
1283-
* programming the same ASPM Control value for all functions of
1284-
* multi-function devices, so disable ASPM for all of them.
1279+
* Do not free the link state any earlier. If function 0 is a
1280+
* switch upstream port, this link state is parent_link to all
1281+
* subordinate ones.
12851282
*/
1283+
if (pdev != link->downstream)
1284+
goto out;
1285+
12861286
pcie_config_aspm_link(link, 0);
12871287
list_del(&link->sibling);
12881288
free_link_state(link);
@@ -1293,6 +1293,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
12931293
pcie_config_aspm_path(parent_link);
12941294
}
12951295

1296+
out:
12961297
mutex_unlock(&aspm_lock);
12971298
up_read(&pci_bus_sem);
12981299
}

0 commit comments

Comments
 (0)