cxl/pci: Honor -EPROBE_DEFER from component register setup
Dave Jiang
maintainerPATCH v2 1/1 cxl/pci: Honor -EPROBE_DEFER from component register setup
cxl_pci_setup_regs() for CXL_REGLOC_RBI_COMPONENT can return -EPROBE_DEFER on a Restricted CXL Host (RCD) when the upstream port has not yet been enumerated and the Component Registers must be extracted from the RCRB. cxl_pci_probe() treats every non-zero return from that call as the benign "component registers not found" case, logs a warning, and continues. The rc is then immediately overwritten by the subsequent cxl_pci_type3_init_mailbox() call, so the deferral is silently swallowed.
Return -EPROBE_DEFER instead of continuing so the probe is retried once the upstream port is available.
--- drivers/cxl/pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/cxl/pci.c +5 -2
@@ -829,10 +829,13 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &cxlds->reg_map); -if (rc) +if (rc) { +if (rc == -EPROBE_DEFER ) +return rc;dev_warn (&pdev->dev,"No component registers (%d)\n" , rc); -else if (!cxlds->reg_map.component_map.ras.valid) + }else if (!cxlds->reg_map.component_map.ras.valid) {dev_dbg (&pdev->dev,"RAS registers not found\n" ); + } rc =cxl_pci_type3_init_mailbox (cxlds);if (rc)
base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] cxl_pci_type3_init_mailbox() incorrectly evaluates component_map.ras.valid instead of device_map.mbox.valid to check mailbox presence, leading to kernel panics or functional regressions. --
--- Patch [1]: [PATCH v2] cxl/pci: Honor -EPROBE_DEFER from component register setup --- commit 04637d8b82b95fbc354ce623ffbeb09e3d57ae3e
Author: Dave Jiang <[email protected]>
cxl/pci: Honor -EPROBE_DEFER from component register setup
cxl_pci_setup_regs() can return -EPROBE_DEFER on a Restricted CXL Host (RCD) when the upstream port has not yet been enumerated. This patch ensures that cxl_pci_probe() returns -EPROBE_DEFER instead of continuing so the probe is retried once the upstream port is available.
Quoted 10 lines
drivers/cxl/pci.c +1
-1@@ -829,10 +829,13 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &cxlds->reg_map); -if (rc) +if (rc) {
drivers/cxl/pci.c static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 841
Quoted 10 lines
drivers/cxl/pci.c +4
-1+if (rc == -EPROBE_DEFER ) +return rc;dev_warn (&pdev->dev,"No component registers (%d)\n" , rc); - else if (!cxlds->reg_map.component_map.ras.valid) + }else if (!cxlds->reg_map.component_map.ras.valid) {dev_dbg (&pdev->dev,"RAS registers not found\n" ); + } rc =cxl_pci_type3_init_mailbox (cxlds);if (rc)
[Severity: High]
This isn't a bug introduced by this patch, but looking at the mailbox initialization, cxl_pci_type3_init_mailbox() checks the mbox valid flag:
drivers/cxl/pci.c:cxl_pci_type3_init_mailbox() {
if (!cxlds->reg_map.device_map.mbox.valid)
return -ENODEV;
...
}Since cxl_pci_setup_regs() was just called above with CXL_REGLOC_RBI_COMPONENT and populated cxlds->reg_map, does this mailbox check inadvertently evaluate component_map.ras.valid due to the union in struct cxl_register_map?
If a device lacks a mailbox but has RAS registers, could the presence check incorrectly pass?
drivers/cxl/pci.c:cxl_pci_setup_mailbox() {
...
const int cap = readl(cxlds->regs.mbox + CXLDEV_MBOX_CAPS_OFFSET);
...
}Would this lead to a null pointer dereference in cxl_pci_setup_mailbox() because cxlds->regs.mbox is null?
Conversely, if a device has a valid mailbox but no RAS registers, would cxl_pci_type3_init_mailbox() incorrectly return -ENODEV and fail the probe of a functional device?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 11 lines · Dave Jiang
cxl_pci_setup_regs()forCXL_REGLOC_RBI_COMPONENTcan return -EPROBE_DEFER on a Restricted CXL Host (RCD) when the upstream port has not yet been enumerated and the Component Registers must be extracted from the RCRB.cxl_pci_probe()treats every non-zero return from that call as the benign "component registers not found" case, logs a warning, and continues. The rc is then immediately overwritten by the subsequentcxl_pci_type3_init_mailbox()call, so the deferral is silently swallowed.Return -EPROBE_DEFER instead of continuing so the probe is retried once the upstream port is available.
Let's get this one merged, and go after the Sashiko pre-existing issue in new patch.
Quoted 36 lines
Fixes 733b57f262b0 ("cxl/pci: Early setup RCH dport component registers from RCRB")Reported-by [email protected]Closes https://lore.kernel.org/linux-cxl/ajzhsubot_PSYtHQ@MWDK4CY14F/T/#m063bbf76b1c9c293ade52ab311018ae6bba11a44 open hereAssisted-by Claude:claude-opus-4-8Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/cxl/pci.c +5
-2@@ -829,10 +829,13 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &cxlds->reg_map); -if (rc) +if (rc) { +if (rc == -EPROBE_DEFER ) +return rc;dev_warn (&pdev->dev,"No component registers (%d)\n" , rc); -else if (!cxlds->reg_map.component_map.ras.valid) + }else if (!cxlds->reg_map.component_map.ras.valid) {dev_dbg (&pdev->dev,"RAS registers not found\n" ); + } rc =cxl_pci_type3_init_mailbox (cxlds);if (rc)base-commit:
8cdeaa50eae8dad34885515f62559ee83e7e8ddaSignature · 1 line
2.54.0
Quoted 9 lines · Dave Jiang
cxl_pci_setup_regs()forCXL_REGLOC_RBI_COMPONENTcan return -EPROBE_DEFER on a Restricted CXL Host (RCD) when the upstream port has not yet been enumerated and the Component Registers must be extracted from the RCRB.cxl_pci_probe()treats every non-zero return from that call as the benign "component registers not found" case, logs a warning, and continues. The rc is then immediately overwritten by the subsequentcxl_pci_type3_init_mailbox()call, so the deferral is silently swallowed.
Quoted 8 lines
Return -EPROBE_DEFER instead of continuing so the probe is retried once the upstream port is available.
Fixes 733b57f262b0 ("cxl/pci: Early setup RCH dport component registers from RCRB")Reported-by [email protected]Closes https://lore.kernel.org/linux-cxl/ajzhsubot_PSYtHQ@MWDK4CY14F/T/#m063bbf76b1c9c293ade52ab311018ae6bba11a44 open hereAssisted-by Claude:claude-opus-4-8Signed-off-by Dave Jiang <[email protected]>
Applied to cxl/next430c502c80e5
Quoted 26 lines
--- drivers/cxl/pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/cxl/pci.c +5
-2@@ -829,10 +829,13 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &cxlds->reg_map); -if (rc) +if (rc) { +if (rc == -EPROBE_DEFER ) +return rc;dev_warn (&pdev->dev,"No component registers (%d)\n" , rc); -else if (!cxlds->reg_map.component_map.ras.valid) + }else if (!cxlds->reg_map.component_map.ras.valid) {dev_dbg (&pdev->dev,"RAS registers not found\n" ); + } rc =cxl_pci_type3_init_mailbox (cxlds);if (rc)base-commit:
8cdeaa50eae8dad34885515f62559ee83e7e8dda