Skip to content

Commit 8113587

Browse files
tylerzhao7684jbarnes993
authored andcommitted
PCI: fix ARI code to be compatible with mixed ARI/non-ARI systems
The original ARI support code has a compatibility problem with non-ARI devices. If a device doesn't support ARI, turning on ARI forwarding on its upper level bridge will cause undefined behavior. This fix turns on ARI forwarding only when the subordinate devices support it. Tested-by: Suresh Siddha <[email protected]> Signed-off-by: Yu Zhao <[email protected]> Signed-off-by: Jesse Barnes <[email protected]>
1 parent d2174c3 commit 8113587

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

drivers/pci/pci.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,27 +1309,32 @@ void pci_enable_ari(struct pci_dev *dev)
13091309
int pos;
13101310
u32 cap;
13111311
u16 ctrl;
1312+
struct pci_dev *bridge;
13121313

1313-
if (!dev->is_pcie)
1314+
if (!dev->is_pcie || dev->devfn)
13141315
return;
13151316

1316-
if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
1317-
dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)
1317+
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
1318+
if (!pos)
13181319
return;
13191320

1320-
pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1321+
bridge = dev->bus->self;
1322+
if (!bridge || !bridge->is_pcie)
1323+
return;
1324+
1325+
pos = pci_find_capability(bridge, PCI_CAP_ID_EXP);
13211326
if (!pos)
13221327
return;
13231328

1324-
pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
1329+
pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap);
13251330
if (!(cap & PCI_EXP_DEVCAP2_ARI))
13261331
return;
13271332

1328-
pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
1333+
pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl);
13291334
ctrl |= PCI_EXP_DEVCTL2_ARI;
1330-
pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
1335+
pci_write_config_word(bridge, pos + PCI_EXP_DEVCTL2, ctrl);
13311336

1332-
dev->ari_enabled = 1;
1337+
bridge->ari_enabled = 1;
13331338
}
13341339

13351340
int

0 commit comments

Comments
 (0)