PCI: Skip the CXL state update for a VF
PATCH 1/1 PCI: Skip the CXL state update for a VF
set_pcie_cxl() runs for every device that is added. It first updates the CXL state of the upstream bridge, which walks that bridge's extended capabilities and recurses up to the root port. It then walks the device's own extended capabilities for the Flex Bus Port DVSEC.
For a VF neither walk can change anything. A CXL device exposes its Flex Bus Port DVSEC through Function 0 (CXL 4.0, section 8.1.8), so the search in a VF finds nothing and the VF's is_cxl stays false. pci_upstream_bridge() resolves a VF through its PF, so the bridge is the one that was already updated when the PF was added.
Enabling SR-IOV adds the VFs one after another, and each add repeats both walks against the same bridges.
On an NVIDIA Vera system, enabling 256 VFs on a PF whose upstream bridge has 18 extended capabilities takes 296 ms instead of 402 ms. Enabling 32 VFs on a Rubin GPU takes 218 ms instead of 235 ms. The times are for the write to sriov_numvfs, with the PF bound to pci-pf-stub and VF driver autoprobe disabled, so no VF driver probes.
Return early for a VF. Every device keeps the is_cxl value it gets today.
--- drivers/pci/probe.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pci/probe.c +8 -0
@@ -1717,6 +1717,14 @@ static void set_pcie_cxl(struct pci_dev *dev)if (!pci_is_pcie (dev))return ; +/* +* A CXL device exposes its Flex Bus Port DVSEC through Function 0, +* so a VF has none. Its upstream bridge is the PF's, which was +* updated when the PF was added. +*/ +if (dev->is_virtfn) +return ; +/* * Update parent's CXL state because alternate protocol training * may have changed
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 20 lines
set_pcie_cxl()runs for every device that is added. It first updates the CXL state of the upstream bridge, which walks that bridge's extended capabilities and recurses up to the root port. It then walks the device's own extended capabilities for the Flex Bus Port DVSEC.For a VF neither walk can change anything. A CXL device exposes its Flex Bus Port DVSEC through Function 0 (CXL 4.0, section 8.1.8), so the search in a VF finds nothing and the VF's
is_cxlstays false.pci_upstream_bridge()resolves a VF through its PF, so the bridge is the one that was already updated when the PF was added.Enabling SR-IOV adds the VFs one after another, and each add repeats both walks against the same bridges.
On an NVIDIA Vera system, enabling 256 VFs on a PF whose upstream bridge has 18 extended capabilities takes 296 ms instead of 402 ms. Enabling 32 VFs on a Rubin GPU takes 218 ms instead of 235 ms. The times are for the write to
sriov_numvfs, with the PF bound to pci-pf-stub and VF driver autoprobe disabled, so no VF driver probes.
Quoted 4 lines
Return early for a VF. Every device keeps the
is_cxlvalue it gets today.Signed-off-by Joshua Machauer <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 20 lines · Joshua Machauer
set_pcie_cxl()runs for every device that is added. It first updates the CXL state of the upstream bridge, which walks that bridge's extended capabilities and recurses up to the root port. It then walks the device's own extended capabilities for the Flex Bus Port DVSEC.For a VF neither walk can change anything. A CXL device exposes its Flex Bus Port DVSEC through Function 0 (CXL 4.0, section 8.1.8), so the search in a VF finds nothing and the VF's
is_cxlstays false.pci_upstream_bridge()resolves a VF through its PF, so the bridge is the one that was already updated when the PF was added.Enabling SR-IOV adds the VFs one after another, and each add repeats both walks against the same bridges.
On an NVIDIA Vera system, enabling 256 VFs on a PF whose upstream bridge has 18 extended capabilities takes 296 ms instead of 402 ms. Enabling 32 VFs on a Rubin GPU takes 218 ms instead of 235 ms. The times are for the write to
sriov_numvfs, with the PF bound to pci-pf-stub and VF driver autoprobe disabled, so no VF driver probes.
Quoted 4 lines
Return early for a VF. Every device keeps the
is_cxlvalue it gets today.Signed-off-by Joshua Machauer <[email protected]>
commit log a bit wordy, otherwise LGTM
Quoted 23 lines
--- drivers/pci/probe.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/pci/probe.c +8
-0@@ -1717,6 +1717,14 @@ static void set_pcie_cxl(struct pci_dev *dev)if (!pci_is_pcie (dev))return ; +/* +* A CXL device exposes its Flex Bus Port DVSEC through Function 0, +* so a VF has none. Its upstream bridge is the PF's, which was +* updated when the PF was added. +*/ +if (dev->is_virtfn) +return ; +/* * Update parent's CXL state because alternate protocol training * may have changed
Quoted 14 lines · Joshua Machauer
set_pcie_cxl()runs for every device that is added. It first updates the CXL state of the upstream bridge, which walks that bridge's extended capabilities and recurses up to the root port. It then walks the device's own extended capabilities for the Flex Bus Port DVSEC.For a VF neither walk can change anything. A CXL device exposes its Flex Bus Port DVSEC through Function 0 (CXL 4.0, section 8.1.8), so the search in a VF finds nothing and the VF's
is_cxlstays false.pci_upstream_bridge()resolves a VF through its PF, so the bridge is the one that was already updated when the PF was added.Enabling SR-IOV adds the VFs one after another, and each add repeats both walks against the same bridges.
Quoted 9 lines
On an NVIDIA Vera system, enabling 256 VFs on a PF whose upstream bridge has 18 extended capabilities takes 296 ms instead of 402 ms. Enabling 32 VFs on a Rubin GPU takes 218 ms instead of 235 ms. The times are for the write to
sriov_numvfs, with the PF bound to pci-pf-stub and VF driver autoprobe disabled, so no VF driver probes.Return early for a VF. Every device keeps the
is_cxlvalue it gets today.
Hi Joshua,
The fix looks correct to me.
One nit on the sentence above, before this patch, each VF add also re-read the Flex Bus Port Status of every bridge above the PF.
That refresh is now gone. I don't think anything depends on it, but it is a behavior change, might be worth to mention it.
Quoted 11 lines
Signed-off-by Joshua Machauer <[email protected]>--- drivers/pci/probe.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/pci/probe.c +0
-0@@ -1717,6 +1717,14 @@ static void set_pcie_cxl(struct pci_dev *dev)if (!pci_is_pcie (dev))
drivers/pci/probe.c static void set_pcie_cxl(struct pci_dev *dev) · line 1727
Quoted 10 lines
drivers/pci/probe.c +8
-0return ; +/* +* A CXL device exposes its Flex Bus Port DVSEC through Function 0, +* so a VF has none. Its upstream bridge is the PF's, which was +* updated when the PF was added. +*/ +if (dev->is_virtfn) +return ; +
I would like the spec section to be cited here, CXL r4.0, sec 8.1.8 "PCIe DVSEC for Flex Bus Port"
Quoted 7 lines
drivers/pci/probe.c +0
-0/* * Update parent's CXL state because alternate protocol training * may have changed Signature · 1 line
2.47.3
A wider question, not specifically a request for this patch.
The repeated walks are not specific to VFs. The recursion runs for every PCIe device and goes up to the Root Port, so every function added below a switch walks the extend capabilities of all the bridges above it again.
Is the walk to the RP needed, or would refreshing only the immediate parent would be enough ?
If it's the former case, we can cut more cost for non-VF devices too.
Best regards,
Richard Cheng.
Quoted 4 lines · Richard Cheng
One nit on the sentence above, before this patch, each VF add also re-read the Flex Bus Port Status of every bridge above the PF.
That refresh is now gone. I don't think anything depends on it, but it is a behavior change, might be worth to mention it.
[...]
Quoted 2 lines
I would like the spec section to be cited here, CXL r4.0, sec 8.1.8 "PCIe DVSEC for Flex Bus Port"
Thanks. v2 states the dropped refresh and cites the spec section in the comment.
Quoted 3 lines
Is the walk to the RP needed, or would refreshing only the immediate parent would be enough ?
If it's the former case, we can cut more cost for non-VF devices too.
Refreshing the immediate parent looks enough to me. A device is only visible once the link to its parent's downstream port has trained, and the links further up were already read when the device directly below each of them was added. The link speed in pci_bus is handled that way
too: it is read when the bus is added and updated on link events (retrain, bandwidth notification, hotplug), not on every child add.
I don't have a system with a CXL switch to test that change on, so I have kept v2 to the VF case.
Joshua