PCI: cadence-plat: Fix host/endpoint dependencies
Aksh Garg
reviewerPATCH 1/1 PCI: cadence-plat: Fix host/endpoint dependencies
The cadence-plat driver has a single platform driver that can be built-in or a loadable module, but it calls two separate backend drivers depending on whether it is a host or endpoint.
If one of the mode is build as built-in and another as loadable module, we end up with a situation where the built-in pcie-cadence-plat driver tries to call the modular host or endpoint driver, which causes a link failure:
ld: error: undefined symbol: cdns_pcie_ep_setup
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
pcie-cadence-plat.c
drivers/pci/controller/cadence/pcie-cadence-plat.o:(cdns_plat_pcie_probe) in archive vmlinux.a
ld: error: undefined symbol: cdns_pcie_host_setup
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
pcie-cadence-plat.c
drivers/pci/controller/cadence/pcie-cadence-plat.o:(cdns_plat_pcie_probe) in archive vmlinux.a
Fix this by moving the 'select' of PCIE_CADENCE_HOST and PCIE_CADENCE_EP from the individual PLAT_HOST/PLAT_EP symbols into the common PCIE_CADENCE_PLAT symbol, conditioned on which backends (modes) are enabled.
--- drivers/pci/controller/cadence/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/cadence/Kconfig +2 -2
@@ -20,11 +20,12 @@ config PCIE_CADENCE_EP config PCIE_CADENCE_PLAT tristate + select PCIE_CADENCE_HOST if PCIE_CADENCE_PLAT_HOST != n + select PCIE_CADENCE_EP if PCIE_CADENCE_PLAT_EP != n config PCIE_CADENCE_PLAT_HOST tristate "Cadence platform PCIe controller (host mode)" depends on OF - select PCIE_CADENCE_HOST select PCIE_CADENCE_PLAT help Say Y here if you want to support the Cadence PCIe platform controller in
@@ -35,7 +36,6 @@ config PCIE_CADENCE_PLAT_EP tristate "Cadence platform PCIe controller (endpoint mode)" depends on OF depends on PCI_ENDPOINT - select PCIE_CADENCE_EP select PCIE_CADENCE_PLAT help Say Y here if you want to support the Cadence PCIe platform controller in
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Invalid drvdata cast in cdns_plat_pcie_shutdown causes out-of-bounds access and kernel panic.
- [High] Probe error paths unconditionally return 0, masquerading initialization failures as success. --
--- Patch [1]: [PATCH] PCI: cadence-plat: Fix host/endpoint dependencies --- commit f31c2dc6bdd9c13d43549cb7b505f8e0289ac1c5
Author: Aksh Garg <[email protected]>
PCI: cadence-plat: Fix host/endpoint dependencies
The cadence-plat driver has a single platform driver that can be built-in or a loadable module, but it calls two separate backend drivers depending on whether it is a host or endpoint. Fix this by moving the 'select' of PCIE_CADENCE_HOST and PCIE_CADENCE_EP into the common PCIE_CADENCE_PLAT symbol.
drivers/pci/controller/cadence/Kconfig
Quoted 4 lines
drivers/pci/controller/cadence/Kconfig +0
-0
[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed a potential problem in drivers/pci/controller/cadence/pcie-cadence-plat.c:cdns_plat_pcie_shutdown(). The function casts the drvdata to struct cdns_pcie:
drivers/pci/controller/cadence/pcie-cadence-plat.c:cdns_plat_pcie_shutdown() {
struct cdns_pcie *pcie = dev_get_drvdata(dev);
...
cdns_pcie_disable_phy(pcie);
}However, the probe function allocates a smaller wrapper struct and sets it as drvdata:
drivers/pci/controller/cadence/pcie-cadence-plat.c:cdns_plat_pcie_probe() {
cdns_plat_pcie = devm_kzalloc(dev, sizeof(*cdns_plat_pcie), GFP_KERNEL);
...
platform_set_drvdata(pdev, cdns_plat_pcie);
}Since cdns_pcie_disable_phy() attempts to read pcie->phy_count and iterates over pcie->phy[i], could this out-of-bounds access cause a kernel panic during shutdown?
[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a problem with the error handling in the probe function:
drivers/pci/controller/cadence/pcie-cadence-plat.c:cdns_plat_pcie_probe() {
...
err_init:
err_get_sync:
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
cdns_pcie_disable_phy(cdns_plat_pcie->pcie);
phy_count = cdns_plat_pcie->pcie->phy_count;
while (phy_count--)
device_link_del(cdns_plat_pcie->pcie->link[phy_count]);
return 0;
}Does this unconditionally return 0 on failure paths?
It looks like the error code is dropped, which would masquerade probe failures as successes. This could leave the driver bound while its resources are actually disabled, potentially leading to crashes on unbind or shutdown.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 17 lines · Aksh Garg
The cadence-plat driver has a single platform driver that can be built-in or a loadable module, but it calls two separate backend drivers depending on whether it is a host or endpoint.
If one of the mode is build as built-in and another as loadable module, we end up with a situation where the built-in pcie-cadence-plat driver tries to call the modular host or endpoint driver, which causes a link failure:
ld: error: undefined symbol:
cdns_pcie_ep_setupQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
pcie-cadence-plat.c
drivers/pci/controller/cadence/pcie-cadence-plat.o:(cdns_plat_pcie_probe) in archive vmlinux.ald: error: undefined symbol:
cdns_pcie_host_setupQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
pcie-cadence-plat.c
drivers/pci/controller/cadence/pcie-cadence-plat.o:(cdns_plat_pcie_probe) in archive vmlinux.a
Quoted 8 lines
Fix this by moving the 'select' of
PCIE_CADENCE_HOSTandPCIE_CADENCE_EPfrom the individual PLAT_HOST/PLAT_EP symbols into the commonPCIE_CADENCE_PLATsymbol, conditioned on which backends (modes) are enabled.Fixes 611627a4e5e4 ("PCI: cadence: Add module support for platform controller driver")Reported-by Randy Dunlap <[email protected]>Signed-off-by Aksh Garg <[email protected]>
Thanks.
Quoted 30 lines
--- drivers/pci/controller/cadence/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/controller/cadence/Kconfig +2
-2@@ -20,11 +20,12 @@ config PCIE_CADENCE_EP config PCIE_CADENCE_PLAT tristate + select PCIE_CADENCE_HOST if PCIE_CADENCE_PLAT_HOST != n + select PCIE_CADENCE_EP if PCIE_CADENCE_PLAT_EP != n config PCIE_CADENCE_PLAT_HOST tristate "Cadence platform PCIe controller (host mode)" depends on OF - select PCIE_CADENCE_HOST select PCIE_CADENCE_PLAT help Say Y here if you want to support the Cadence PCIe platform controller in@@ -35,7 +36,6 @@ config PCIE_CADENCE_PLAT_EP tristate "Cadence platform PCIe controller (endpoint mode)" depends on OF depends on PCI_ENDPOINT - select PCIE_CADENCE_EP select PCIE_CADENCE_PLAT help Say Y here if you want to support the Cadence PCIe platform controller in
Signature · 1 line
~Randy
Manivannan Sadhasivam
AppliedQuoted 10 lines · Aksh Garg
The cadence-plat driver has a single platform driver that can be built-in or a loadable module, but it calls two separate backend drivers depending on whether it is a host or endpoint.
If one of the mode is build as built-in and another as loadable module, we end up with a situation where the built-in pcie-cadence-plat driver tries to call the modular host or endpoint driver, which causes a link failure:
[...]
Applied, thanks!
[1/1] PCI: cadence-plat: Fix host/endpoint dependencies
commit: e4486b0dc8b2496133f38451babd7e84e2f4a1fd
Best regards,
Signature · 1 line
மணிவண்ணன் சதாசிவம்