Skip to content

Commit 4749821

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 a62b3e6 commit 4749821

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
@@ -3674,8 +3674,7 @@ void pci_acs_init(struct pci_dev *dev)
36743674
*/
36753675
int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
36763676
{
3677-
struct pci_bus *bus = dev->bus;
3678-
struct pci_dev *bridge;
3677+
struct pci_dev *root, *bridge;
36793678
u32 cap, ctl2;
36803679

36813680
/*
@@ -3705,35 +3704,35 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
37053704
return -EINVAL;
37063705
}
37073706

3708-
while (bus->parent) {
3709-
bridge = bus->self;
3707+
root = pcie_find_root_port(dev);
3708+
if (!root)
3709+
return -EINVAL;
37103710

3711-
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
3711+
pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
3712+
if ((cap & cap_mask) != cap_mask)
3713+
return -EINVAL;
37123714

3715+
bridge = pci_upstream_bridge(dev);
3716+
while (bridge != root) {
37133717
switch (pci_pcie_type(bridge)) {
3714-
/* Ensure switch ports support AtomicOp routing */
37153718
case PCI_EXP_TYPE_UPSTREAM:
3716-
case PCI_EXP_TYPE_DOWNSTREAM:
3717-
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3718-
return -EINVAL;
3719-
break;
3720-
3721-
/* Ensure root port supports all the sizes we care about */
3722-
case PCI_EXP_TYPE_ROOT_PORT:
3723-
if ((cap & cap_mask) != cap_mask)
3724-
return -EINVAL;
3725-
break;
3726-
}
3727-
3728-
/* Ensure upstream ports don't block AtomicOps on egress */
3729-
if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) {
3719+
/* Upstream ports must not block AtomicOps on egress */
37303720
pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
37313721
&ctl2);
37323722
if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK)
37333723
return -EINVAL;
3724+
fallthrough;
3725+
3726+
/* All switch ports need to route AtomicOps */
3727+
case PCI_EXP_TYPE_DOWNSTREAM:
3728+
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2,
3729+
&cap);
3730+
if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
3731+
return -EINVAL;
3732+
break;
37343733
}
37353734

3736-
bus = bus->parent;
3735+
bridge = pci_upstream_bridge(bridge);
37373736
}
37383737

37393738
pcie_capability_set_word(dev, PCI_EXP_DEVCTL2,

0 commit comments

Comments
 (0)