Skip to contentSkip to conversation

PCI: brcmstb: Assign pcie->gen from of_pci_get_max_link_speed()

PATCH Applied Florian Fainelli 5 participants 7 messages May 6 – May 15 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): mid:[email protected]

Florian Fainelli

author maintainer
#1 lore raw

PATCH v2 1/1 PCI: brcmstb: Assign pcie->gen from of_pci_get_max_link_speed()

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")
Change-Id Ic5431469dd7a6c8b391f84f27119dad876256880

---
Changes in v2:

- utilize of_pci_get_max_link_speed() directly
- also validate against exceeding Gen3

 drivers/pci/controller/pcie-brcmstb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-brcmstb.c +3 -1
index 714bcab97b60..08a0e7091ced 100644
@@ -2072,8 +2072,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 		return PTR_ERR(pcie->clk);
 
 	ret = of_pci_get_max_link_speed(np);
-	if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+	if (ret < 0 || ret > 3)
 		pcie->gen = 0;
+	else
+		pcie->gen = ret;
 
 	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/1
#2 lore raw
Quoted 5 lines · Florian Fainelli

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Quoted 8 lines

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")

Since this is a 7.1 material:

Quoted 1 line

Change-Id: Ic5431469dd7a6c8b391f84f27119dad876256880

This Change-Id is irrelevant to upstream.

- Mani

Quoted 28 lines

---
Changes in v2:

- utilize of_pci_get_max_link_speed() directly
- also validate against exceeding Gen3

 drivers/pci/controller/pcie-brcmstb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-brcmstb.c +3 -1
index 714bcab97b60..08a0e7091ced 100644
@@ -2072,8 +2072,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 		return PTR_ERR(pcie->clk);
 
 	ret = of_pci_get_max_link_speed(np);
-	if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+	if (ret < 0 || ret > 3)
 		pcie->gen = 0;
+	else
+		pcie->gen = ret;
 
 	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
 
Signature · 1 line
2.34.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
author maintainer
#3 lore raw
Quoted 15 lines · Manivannan Sadhasivam
Quoted 5 lines · Florian Fainelli

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Quoted 8 lines

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")
Quoted 3 lines

Since this is a 7.1 material:

Thanks!

Quoted 4 lines
Quoted 2 lines

Change-Id: Ic5431469dd7a6c8b391f84f27119dad876256880

This Change-Id is irrelevant to upstream.

Should I resubmit or can it be stripped while applying?

Signature · 1 line
Florian
#4 lore raw
Quoted 20 lines · Florian Fainelli
Quoted 15 lines · Manivannan Sadhasivam
Quoted 5 lines · Florian Fainelli

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Quoted 8 lines

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")
Quoted 3 lines

Since this is a 7.1 material:

Quoted 8 lines

Thanks!

Quoted 4 lines
Quoted 2 lines

Change-Id: Ic5431469dd7a6c8b391f84f27119dad876256880

This Change-Id is irrelevant to upstream.

Should I resubmit or can it be stripped while applying?

I hope Bjorn can drop it while applying.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw
In reply to Florian Fainelli
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The error handling path in `brcm_pcie_probe()` causes a NULL pointer dereference if…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The error handling path in brcm_pcie_probe() causes a NULL pointer dereference if pci_host_probe() fails.
- [High] The driver fails to handle the msi-map device tree binding variant when determining if the internal MSI controller should be enabled. --

commit 8f216627ede49601fd793dae393dc6232ac6f438
Author: Florian Fainelli <[email protected]>

PCI: brcmstb: Assign pcie->gen from of_pci_get_max_link_speed()

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Quoted 5 lines
drivers/pci/controller/pcie-brcmstb.c +0 -0
index 714bcab97b603..08a0e7091cedc 100644

drivers/pci/controller/pcie-brcmstb.c static int brcm_pcie_probe(struct platform_device *pdev) · line 2080

Quoted 10 lines
drivers/pci/controller/pcie-brcmstb.c +3 -1
@@ -2072,8 +2072,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 		return PTR_ERR(pcie->clk);
 
 	ret = of_pci_get_max_link_speed(np);
-	if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+	if (ret < 0 || ret > 3)
 		pcie->gen = 0;
+	else
+		pcie->gen = ret;
 
 	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");

This isn't a regression from this commit, but while reviewing this function I noticed a pre-existing regression. The driver currently checks for msi-parent but does not check for the msi-map device tree binding variant:

drivers/pci/controller/pcie-brcmstb.c:brcm_pcie_probe() {
    ...
	if (pci_msi_enabled()) {
		struct device_node *msi_np = of_parse_phandle(pcie->np, "msi-parent", 0);

		if (msi_np == pcie->np)
			ret = brcm_pcie_enable_msi(pcie);
    ...
}

Will this bypass brcm_pcie_enable_msi() and prevent the creation of the local MSI domain if a platform's DT uses msi-map instead of msi-parent to reference the built-in MSI controller?

I also noticed another pre-existing regression in the probe error handling path:

drivers/pci/controller/pcie-brcmstb.c:brcm_pcie_probe() {
    ...
	ret = pci_host_probe(bridge);
	if (!ret && !brcm_pcie_link_up(pcie))
		ret = -ENODEV;

	if (ret) {
		brcm_pcie_remove(pdev);
		return ret;
	}
    ...
}

If pci_host_probe(bridge) fails early before allocating bridge->bus, bridge->bus will remain NULL.

Inside brcm_pcie_remove(pdev), bridge->bus is passed directly to pci_stop_root_bus(bridge->bus).

The function pci_stop_root_bus() evaluates pci_is_root_bus(bus), which dereferences the pointer via !(bus->parent).

Does this cause a NULL pointer dereference and a kernel panic if pci_host_probe() fails?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#6 lore raw
In reply to Florian Fainelli
Quoted 8 lines · Florian Fainelli

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Quoted 6 lines
Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")
Change-Id Ic5431469dd7a6c8b391f84f27119dad876256880
Quoted 25 lines

---
Changes in v2:

- utilize of_pci_get_max_link_speed() directly
- also validate against exceeding Gen3

  drivers/pci/controller/pcie-brcmstb.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-brcmstb.c +3 -1
index 714bcab97b60..08a0e7091ced 100644
@@ -2072,8 +2072,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
  		return PTR_ERR(pcie->clk);
 
  	ret = of_pci_get_max_link_speed(np);
-	if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+	if (ret < 0 || ret > 3)
  		pcie->gen = 0;
+	else
+		pcie->gen = ret;
 
  	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
 
#7 lore raw
In reply to Florian Fainelli
Quoted 8 lines · Florian Fainelli

After commit 03f920936977 ("PCI: controller: Validate max-link-speed"), pcie->gen stopped being assigned and as a result the established PCIe link would stop supporting Gen3 speeds on 2712 since pcie->gen is used to populate LnkCntl2 and LnkCap in brcm_pcie_set_gen().

Whether the 'max-link-speed' property is not specified, or it exceeds Gen3, resort to the HW defaults.

Quoted 6 lines
Fixes 03f920936977 ("PCI: controller: Validate max-link-speed")
Change-Id Ic5431469dd7a6c8b391f84f27119dad876256880

Applied to pci/for-linus for v7.1, thanks!

Sashiko pointed out a couple issues, but they're unrelated to this patch, so I'll watch for future patches to address them.

Quoted 28 lines

---
Changes in v2:

- utilize of_pci_get_max_link_speed() directly
- also validate against exceeding Gen3

 drivers/pci/controller/pcie-brcmstb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-brcmstb.c +3 -1
index 714bcab97b60..08a0e7091ced 100644
@@ -2072,8 +2072,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 		return PTR_ERR(pcie->clk);
 
 	ret = of_pci_get_max_link_speed(np);
-	if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+	if (ret < 0 || ret > 3)
 		pcie->gen = 0;
+	else
+		pcie->gen = ret;
 
 	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
 
Signature · 1 line
2.34.1