Skip to content

Commit f2e27c8

Browse files
Gerd Bayergregkh
authored andcommitted
PCI: Enable AtomicOps only if Root Port supports them
[ Upstream commit 1ae8c4c ] When inspecting the config space of a Connect-X physical function in an s390 system after it was initialized by the mlx5_core device driver, we found the function to be enabled to request AtomicOps despite the Root Port lacking support for completing them: 00:00.1 Ethernet controller: Mellanox Technologies MT2894 Family [ConnectX-6 Lx] Subsystem: Mellanox Technologies Device 0002 DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis- AtomicOpsCtl: ReqEn+ On s390 and many virtualized guests, the Endpoint is visible but the Root Port is not. In this case, pci_enable_atomic_ops_to_root() previously enabled AtomicOps in the Endpoint even though it can't tell whether the Root Port supports them as a completer. Change pci_enable_atomic_ops_to_root() to fail if there's no Root Port or the Root Port doesn't support AtomicOps. Fixes: 430a236 ("PCI: Add pci_enable_atomic_ops_to_root()") Reported-by: Alexander Schmidt <alexs@linux.ibm.com> Signed-off-by: Gerd Bayer <gbayer@linux.ibm.com> [bhelgaas: commit log, check RP first to simplify flow] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20260330-fix_pciatops-v7-2-f601818417e8@linux.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 15e7b2a commit f2e27c8

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

drivers/pci/pci.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,8 +3850,7 @@ int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
38503850
*/
38513851
int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
38523852
{
3853-
struct pci_bus *bus = dev->bus;
3854-
struct pci_dev *bridge;
3853+
struct pci_dev *root, *bridge;
38553854
u32 cap, ctl2;
38563855

38573856
/*
@@ -3881,35 +3880,35 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
38813880
return -EINVAL;
38823881
}
38833882

3884-
while (bus->parent) {
3885-
bridge = bus->self;
3883+
root = pcie_find_root_port(dev);
3884+
if (!root)
3885+
return -EINVAL;
38863886

3887-
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
3887+
pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
3888+
if ((cap & cap_mask) != cap_mask)
3889+
return -EINVAL;
38883890

3891+
bridge = pci_upstream_bridge(dev);
3892+
while (bridge != root) {
38893893
switch (pci_pcie_type(bridge)) {
3890-
/* Ensure switch ports support AtomicOp routing */
38913894
case PCI_EXP_TYPE_UPSTREAM:
3892-
case PCI_EXP_TYPE_DOWNSTREAM:
3893-
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3894-
return -EINVAL;
3895-
break;
3896-
3897-
/* Ensure root port supports all the sizes we care about */
3898-
case PCI_EXP_TYPE_ROOT_PORT:
3899-
if ((cap & cap_mask) != cap_mask)
3900-
return -EINVAL;
3901-
break;
3902-
}
3903-
3904-
/* Ensure upstream ports don't block AtomicOps on egress */
3905-
if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) {
3895+
/* Upstream ports must not block AtomicOps on egress */
39063896
pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
39073897
&ctl2);
39083898
if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK)
39093899
return -EINVAL;
3900+
fallthrough;
3901+
3902+
/* All switch ports need to route AtomicOps */
3903+
case PCI_EXP_TYPE_DOWNSTREAM:
3904+
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2,
3905+
&cap);
3906+
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3907+
return -EINVAL;
3908+
break;
39103909
}
39113910

3912-
bus = bus->parent;
3911+
bridge = pci_upstream_bridge(bridge);
39133912
}
39143913

39153914
pcie_capability_set_word(dev, PCI_EXP_DEVCTL2,

0 commit comments

Comments
 (0)