Skip to content

Commit db805e9

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 134c619 commit db805e9

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
@@ -3818,8 +3818,7 @@ int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
38183818
*/
38193819
int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
38203820
{
3821-
struct pci_bus *bus = dev->bus;
3822-
struct pci_dev *bridge;
3821+
struct pci_dev *root, *bridge;
38233822
u32 cap, ctl2;
38243823

38253824
/*
@@ -3849,35 +3848,35 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
38493848
return -EINVAL;
38503849
}
38513850

3852-
while (bus->parent) {
3853-
bridge = bus->self;
3851+
root = pcie_find_root_port(dev);
3852+
if (!root)
3853+
return -EINVAL;
38543854

3855-
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
3855+
pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
3856+
if ((cap & cap_mask) != cap_mask)
3857+
return -EINVAL;
38563858

3859+
bridge = pci_upstream_bridge(dev);
3860+
while (bridge != root) {
38573861
switch (pci_pcie_type(bridge)) {
3858-
/* Ensure switch ports support AtomicOp routing */
38593862
case PCI_EXP_TYPE_UPSTREAM:
3860-
case PCI_EXP_TYPE_DOWNSTREAM:
3861-
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3862-
return -EINVAL;
3863-
break;
3864-
3865-
/* Ensure root port supports all the sizes we care about */
3866-
case PCI_EXP_TYPE_ROOT_PORT:
3867-
if ((cap & cap_mask) != cap_mask)
3868-
return -EINVAL;
3869-
break;
3870-
}
3871-
3872-
/* Ensure upstream ports don't block AtomicOps on egress */
3873-
if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) {
3863+
/* Upstream ports must not block AtomicOps on egress */
38743864
pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
38753865
&ctl2);
38763866
if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK)
38773867
return -EINVAL;
3868+
fallthrough;
3869+
3870+
/* All switch ports need to route AtomicOps */
3871+
case PCI_EXP_TYPE_DOWNSTREAM:
3872+
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2,
3873+
&cap);
3874+
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3875+
return -EINVAL;
3876+
break;
38783877
}
38793878

3880-
bus = bus->parent;
3879+
bridge = pci_upstream_bridge(bridge);
38813880
}
38823881

38833882
pcie_capability_set_word(dev, PCI_EXP_DEVCTL2,

0 commit comments

Comments
 (0)