[PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 23 11:11:10 PST 2026


Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] PCI: cs7542: PCI_MSI_FLAGS_ENABLE in cortina_pcie_host_init()
  cleared on probe
- [High] PCI: cs7542: undisposed INTx virq mappings before
  irq_domain_remove()
- [Medium] PCI: cs7542: cortina_pcie_read_dbi() ~0U return masks iATU
  failure on link loss
- [Medium] PCI: cs7542: missing link_lost and IRQ sync in
  cortina_pcie_shutdown()
--

commit cd2c931b6a3541fd8734c17e2a7332622247b319
Author: Fil Dunsky <filipp.dunsky at gmail.com>

PCI: cs7542: Add CS7542 PCIe host support

This commit adds a DesignWare PCIe host controller driver for Cortina
Systems CS7542 SoCs, handling clock/reset/PHY setup, multiplexed INTx and
MSI interrupts, root configuration filtering, and link-loss blocking.

> diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
> new file mode 100644
> index 0000000000000..19225e9a292ef
> --- /dev/null
> +++ b/drivers/pci/controller/dwc/pcie-cs7542.c
[ ... ]
> +static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
> +{
> +	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> +	u8 cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI);
> +	u16 flags;
> +
> +	pp->bridge->ops = &cortina_own_pci_ops;
> +	pp->keep_rp_msi_en = true;
> +	if (cap) {
> +		flags = dw_pcie_readw_dbi(pci, cap + PCI_MSI_FLAGS);
> +		dw_pcie_writew_dbi(pci, cap + PCI_MSI_FLAGS, flags | PCI_MSI_FLAGS_ENABLE);
> +	}
> +	return 0;
> +}

[Severity: High]
Will pci_host_probe() clear PCI_MSI_FLAGS_ENABLE right after
cortina_pcie_host_init() sets it?

dw_pcie_host_init() runs pp->ops->init(pp) before calling
pci_host_probe(bridge).  Because pp->keep_rp_msi_en keeps PCI_CAP_ID_MSI
visible on the Root Port, enumerating the Root Port calls
pci_init_capabilities() -> pci_msi_init(), which clears
PCI_MSI_FLAGS_ENABLE via cortina_pcie_wr_own_conf() and leaves the Root
Port MSI receiver disabled.  Setting PCI_MSI_FLAGS_ENABLE in
pp->ops->post_init (or after dw_pcie_host_init() returns) would avoid
this.

[ ... ]

> +/* Standard RC configuration above 512 bytes wedges the CS7542 bus.
> + * The DesignWare private register bank at 0x700 and above remains accessible.
> + */
> +static u32 cortina_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
> +				 u32 reg, size_t size)
> +{
> +	struct cortina_pcie *cp = to_cortina_pcie(pci);
> +	u32 value = 0;
> +
> +	if (READ_ONCE(cp->link_lost))
> +		return ~0U;
> +	if (base == pci->dbi_base && reg < 0x700 && reg + size > RC_CFG_LIMIT)
> +		return 0;
> +	dw_pcie_read(base + reg, size, &value);
> +	return value;
> +}

[Severity: Medium]
Can returning ~0U from cortina_pcie_read_dbi() when cp->link_lost is set
trick dw_pcie_prog_outbound_atu() into reporting success?

CPU0                                    CPU1
dw_pcie_other_conf_map_bus()
  dw_pcie_link_up() -> true
                                        cortina_pcie_irq_handler()
                                          cp->link_lost = true
  dw_pcie_prog_outbound_atu()
    dw_pcie_writel_atu_ob() (dropped)
    dw_pcie_readl_atu_ob(..., ATU_REGION_CTRL2)
      cortina_pcie_read_dbi() -> ~0U
    val & ATU_ENABLE -> true
    return 0
  return pp->va_cfg0_base + where       <-- accesses downstream cfg window

Because ATU_ENABLE is BIT(31), ~0U satisfies the poll in
dw_pcie_prog_outbound_atu() even though cortina_pcie_write_dbi() dropped
the iATU writes, allowing downstream config accesses to proceed after link
loss.

[ ... ]

> +	ret = dw_pcie_host_init(&pci->pp);
> +	if (ret) {
> +		writel(0, cp->app + APP_INT_ENABLE);
> +		irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
> +		irq_domain_remove(cp->intx_domain);
> +		goto power_off;
> +	}
> +	platform_set_drvdata(pdev, cp);
> +	return 0;
> +
> +power_off:
> +	gpiod_set_value_cansleep(cp->perst, 1);
> +	reset_control_assert(cp->reset);
> +	phy_power_off(cp->phy);
> +exit_phy:
> +	phy_exit(cp->phy);
> +disable_clk:
> +	reset_control_assert(cp->reset);
> +	clk_disable_unprepare(cp->clk);
> +	return dev_err_probe(dev, ret, "host initialization\n");
> +}
> +
> +static void cortina_pcie_remove(struct platform_device *pdev)
> +{
> +	struct cortina_pcie *cp = platform_get_drvdata(pdev);
> +
> +	dw_pcie_host_deinit(&cp->pci.pp);
> +	irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
> +	irq_domain_remove(cp->intx_domain);
> +	cortina_pcie_power_off(cp);
> +}

[Severity: High]
Does removing cp->intx_domain without disposing of its mapped virtual IRQs
leak IRQ descriptors and leave dangling pointers to cp and
cortina_intx_chip?

During pci_host_probe(), pci_assign_irq() maps INTx interrupts in
cp->intx_domain (including for the Root Port itself, where
dw_pcie_setup_rc() sets PCI_INTERRUPT_PIN = 1), and the PCI core does not
unmap shared INTx lines on bus removal.  Both cortina_pcie_remove() and
the dw_pcie_host_init() error path call irq_domain_remove(cp->intx_domain)
without first calling irq_dispose_mapping(irq_find_mapping(cp->intx_domain, i))
for each INTx line, leaving allocated irq_desc entries referencing the
freed domain and driver state.

> +static void cortina_pcie_shutdown(struct platform_device *pdev)
> +{
> +	struct cortina_pcie *cp = platform_get_drvdata(pdev);
> +
> +	writel(0, cp->app + APP_INT_ENABLE);
> +	cortina_pcie_stop_link(&cp->pci);
> +	gpiod_set_value_cansleep(cp->perst, 1);
> +	reset_control_assert(cp->reset);
> +}

[Severity: Medium]
Can cortina_pcie_shutdown() race with in-flight interrupts or subsequent
DBI accesses while asserting controller reset?

CPU0                                    CPU1
cortina_pcie_shutdown()
  writel(0, cp->app + APP_INT_ENABLE)
                                        cortina_pcie_irq_handler()
                                          dw_handle_msi_irq()
  cortina_pcie_stop_link()
  reset_control_assert(cp->reset)
                                            dw_pcie_readl_dbi()  <-- DBI access in reset

cortina_pcie_shutdown() does not take cp->lock, set cp->link_lost = true,
or call synchronize_irq(cp->irq).  An in-flight IRQ handler or a
concurrent config/DBI access (which checks cp->link_lost) can access DBI
after the link is stopped and cp->reset is asserted, and a concurrent
cortina_intx_unmask() can also re-enable bits in APP_INT_ENABLE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-pcie-v1-0-4cde5201d404@gmail.com?part=7



More information about the linux-phy mailing list