Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: linux-pci@vger.kernel.org, linux-phy@lists.infradead.org,
	devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support
Date: Fri, 04 Dec 2026 22:51:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-250784@kernel.org> (raw)
In-Reply-To: <20261205-b4-cs7542-pcie-v4-5-6d0101b281b4@gmail.com>

Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] PCI: cs7542: Root Port MSI enable deferred until after endpoint
  probe
- [High] PCI: cs7542: cortina_pcie_intx_map() registers
  handle_simple_irq() for INTx
- [Medium] PCI: cs7542: cortina_pcie_shutdown() races with
  cortina_pcie_reset_root_port()
- [Medium] PCI: cs7542: INT_LINK_DOWN enabled before initial link
  training in probe
- [Medium] PCI: cs7542: cortina_pcie_host_init() ignores
  pp->ecam_enabled
- [Medium] PCI: cs7542: blocking DBI before pci_bus_set_ops() stalls
  pci_lock 45 ms
- [Low] PCI: cs7542: INT_LINK_DOWN remains unmasked when
  dw_pcie_stop_link() runs
- [Low] PCI: cs7542: own config ops bypass slot check at offsets >=
  0x200
- [Low] PCI: cs7542: cortina_pcie_reset_root_port() unmasks IRQs before
  clearing resetting
- [Low] PCI: cs7542: cortina_pcie_reset_root_port() mixes guard(mutex)
  and goto
- [Low] PCI: dwc: stray extra blank line before endmenu in Kconfig
--

commit cd74c745d5af7edb29d42308afe716ec1276fe81
Author: Fil Dunsky <filipp.dunsky@gmail.com>

PCI: cs7542: Add CS7542 PCIe host support

This commit adds the DesignWare PCIe host controller driver for Cortina
Systems CS7542 SoCs, including shared INTx/MSI interrupt dispatch,
DBI/configuration-space filtering, and custom Root Port reset handling.

> diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
> index 0a0d56fcf0ac9..a9b4898017706 100644
> --- a/drivers/pci/controller/dwc/Kconfig
> +++ b/drivers/pci/controller/dwc/Kconfig

[ ... ]

> @@ -577,4 +588,5 @@ config PCIE_ULTRARISC
>  	  By default, this symbol is enabled when ARCH_ULTRARISC is active,
>  	  requiring no further configuration on that platform.
>  
> +
>  endmenu

[Severity: Low]
This isn't a bug, but this adds an unrelated blank line before endmenu.

[ ... ]

> diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
> new file mode 100644
> index 0000000000000..4be7a99f006d0
> --- /dev/null
> +++ b/drivers/pci/controller/dwc/pcie-cs7542.c

[ ... ]

> +static void cortina_pcie_stop_link(struct dw_pcie *pci)
> +{
> +	struct cortina_pcie *cp = to_cortina_pcie(pci);
> +	u32 value = readl(cp->app + APP_CORE_CONFIG);
> +
> +	writel(value & ~CORE_CFG_LTSSM_EN, cp->app + APP_CORE_CONFIG);
> +}

[Severity: Low]
Can cortina_pcie_stop_link() trigger a spurious INT_LINK_DOWN interrupt
during driver removal or probe error unwind?

dw_pcie_host_deinit() and the err_stop_link path of dw_pcie_host_init()
call dw_pcie_stop_link() before pp->ops->deinit() runs
cortina_pcie_quiesce().  Because INT_LINK_DOWN is still unmasked and
cp->resetting is false, cortina_pcie_irq_handler() logs a spurious
link-lost warning and latches cp->link_lost before dw_pcie_edma_remove().

[ ... ]

> +static struct irq_chip cortina_intx_chip = {
> +	.name		= "cortina-INTx",
> +	.irq_mask	= cortina_intx_mask,
> +	.irq_unmask	= cortina_intx_unmask,
> +};
> +
> +static int cortina_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
> +				 irq_hw_number_t hwirq)
> +{
> +	irq_set_chip_and_handler(irq, &cortina_intx_chip, handle_simple_irq);
> +	irq_set_chip_data(irq, domain->host_data);
> +	return 0;
> +}

[Severity: High]
Should cortina_pcie_intx_map() register handle_level_irq() instead of
handle_simple_irq()?

cortina_intx_chip provides hardware irq_mask and irq_unmask callbacks
without irq_disable or IRQCHIP_ONESHOT_SAFE, and cortina_pcie_irq_handler()
does not mask APP_INT_ENABLE before dispatching.  Unlike handle_level_irq(),
handle_simple_irq() never calls mask_ack_irq() or mask_irq().

For IRQF_ONESHOT threaded handlers (or any PCI INTx handler under
threadirqs or CONFIG_PREEMPT_RT), INT_INTX_ASSERT remains unmasked in
APP_INT_ENABLE while the handler thread runs, allowing an interrupt storm
or re-entry on shared INTx lines.  It also breaks lazy disable_irq(),
because handle_simple_irq() returns without masking hardware when an INTx
arrives while disabled.

[ ... ]

> +	if (cp->link_lost || cp->resetting) {
> +		ret = PCIBIOS_DEVICE_NOT_FOUND;
> +	} else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) {
> +		*val = 0;
> +		ret = PCIBIOS_SUCCESSFUL;
> +	} else {
> +		ret = pci_generic_config_read(bus, devfn, where, size, val);
> +	}

[ ... ]

> +	if (cp->link_lost || cp->resetting)
> +		ret = PCIBIOS_DEVICE_NOT_FOUND;
> +	else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where)
> +		ret = PCIBIOS_SUCCESSFUL;
> +	else
> +		ret = pci_generic_config_write(bus, devfn, where, size, val);

[Severity: Low]
Do cortina_pcie_rd_own_conf() and cortina_pcie_wr_own_conf() bypass the
PCI_SLOT(devfn) > 0 check for offsets at or above RC_CFG_LIMIT?

Slot validation only happens inside dw_pcie_own_conf_map_bus().  Checking
RC_CFG_LIMIT first causes config reads to absent root-bus slots at offsets
>= 0x200 to return 0 and PCIBIOS_SUCCESSFUL (and writes to return
PCIBIOS_SUCCESSFUL) instead of PCIBIOS_DEVICE_NOT_FOUND.

[ ... ]

> +static int cortina_pcie_reset_root_port(struct pci_host_bridge *bridge,
> +					struct pci_dev *root)
> +{
> +	struct dw_pcie_rp *pp = bridge->bus->sysdata;
> +	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> +	struct cortina_pcie *cp = to_cortina_pcie(pci);
> +	struct pci_ops *saved_ops;
> +	unsigned long flags;
> +	u32 mask, status;
> +	u16 control;
> +	int ret;
> +
> +	guard(mutex)(&cp->reset_lock);

[Severity: Low]
This isn't a bug, but cortina_pcie_reset_root_port() mixes scope-based
guard(mutex) with goto finish error unwinding in the same function.  Using
mutex_lock()/mutex_unlock() or converting the cleanup avoids mixing the two
styles.

[ ... ]

> +	WRITE_ONCE(cp->resetting, true);
> +	cp->dbi_blocked = true;
> +	mask = readl(cp->app + APP_INT_ENABLE) & ~INT_INTX_ASSERT_MASK;
> +	writel(0, cp->app + APP_INT_ENABLE);
> +	readl(cp->app + APP_INT_ENABLE);
> +	raw_spin_unlock_irqrestore(&cp->lock, flags);
> +
> +	synchronize_irq(cp->irq);
> +	/* Drain in-flight PCI config access before resetting the DBI aperture. */
> +	saved_ops = pci_bus_set_ops(root->bus, &cortina_reset_pci_ops);

[Severity: Medium]
Can setting cp->dbi_blocked before pci_bus_set_ops() stall global pci_lock
for 45 ms with interrupts disabled?

On ARM, PCI config accesses take raw_spin_lock_irqsave(&pci_lock).  A
concurrent downstream config reader such as current_link_speed_show() does
not check dev->block_cfg_access and can race with reset entry:

CPU0                                  CPU1
                                      pci_bus_read_config_word()
                                        lock(&pci_lock)
                                        dw_pcie_other_conf_map_bus()
                                          dw_pcie_link_up() -> true
cortina_pcie_reset_root_port()
  cp->resetting = true
  cp->dbi_blocked = true
  pci_bus_set_ops()
    lock(&pci_lock)  <-- spins 45 ms
                                          dw_pcie_prog_outbound_atu()
                                            mdelay(9) x 5  <-- DBI returns 0

Because cortina_pcie_read_dbi() returns 0 while cp->dbi_blocked is set,
dw_pcie_prog_outbound_atu() busy-waits 45 ms under pci_lock while CPU0
spins waiting for it.  Setting cp->dbi_blocked only after synchronize_irq()
and pci_bus_set_ops() return avoids blocking in-flight config accesses.

[ ... ]

> +finish:
> +	pci_bus_set_ops(root->bus, saved_ops);
> +	raw_spin_lock_irqsave(&cp->lock, flags);
> +	if (!ret) {
> +		writel(INT_LINK_DOWN | INT_LINK_UP, cp->app + APP_INT_STATUS);
> +		if (cp->link_lost ||
> +		    !(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE))
> +			ret = -ENOLINK;
> +	}
> +	if (ret)
> +		WRITE_ONCE(cp->link_lost, true);
> +	else
> +		writel(mask | cp->intx_enabled, cp->app + APP_INT_ENABLE);
> +	cp->dbi_blocked = false;
> +	WRITE_ONCE(cp->resetting, false);
> +	raw_spin_unlock_irqrestore(&cp->lock, flags);

[Severity: Low]
Can unmasking APP_INT_ENABLE before clearing cp->resetting cause an INTx
handler on another CPU to fail downstream config accesses?

CPU0                                  CPU1
writel(..., cp->app + APP_INT_ENABLE)
                                      cortina_pcie_irq_handler()
                                        generic_handle_domain_irq()
                                          ...
                                            cortina_pcie_link_up()
                                              READ_ONCE(cp->resetting)
                                                <-- sees true, fails config
WRITE_ONCE(cp->resetting, false)

INTx dispatch runs without cp->lock, and cortina_pcie_link_up() reads
cp->resetting locklessly.  Clearing cp->dbi_blocked and cp->resetting
before writing APP_INT_ENABLE prevents this window.

[ ... ]

> +static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
> +{
> +	pp->bridge->ops = &cortina_own_pci_ops;
> +	pp->keep_rp_msi_en = true;
> +	pp->bridge->reset_root_port = cortina_pcie_reset_root_port;
> +	return 0;
> +}

[Severity: Medium]
Does cortina_pcie_host_init() cause type confusion on bus->sysdata if
dw_pcie_host_get_resources() enables ECAM?

When the DT config window is 256 MiB-aligned and covers bus-range,
dw_pcie_host_get_resources() sets pp->ecam_enabled = true and assigns
pp->bridge->sysdata = pp->cfg (a struct pci_config_window *).  Overriding
pp->bridge->ops and reset_root_port without checking pp->ecam_enabled then
makes cortina_pcie_rd_own_conf(), cortina_pcie_wr_own_conf(), and
cortina_pcie_reset_root_port() pass that pointer to to_dw_pcie_from_pp()
and lock cp->lock out of bounds, corrupting memory or panicking during
probe.  Rejecting pp->ecam_enabled here (or handling ECAM) avoids this.

[ ... ]

> +static const struct dw_pcie_host_ops cortina_pcie_host_ops = {
> +	.init		= cortina_pcie_host_init,
> +	.post_init	= cortina_pcie_enable_msi,
> +	.deinit		= cortina_pcie_host_deinit,
> +	.msi_init	= cortina_pcie_msi_init,
> +};

[Severity: High]
Does wiring cortina_pcie_enable_msi() to post_init leave Root Port
PCI_MSI_FLAGS_ENABLE cleared while downstream endpoint drivers probe?

dw_pcie_host_init() runs pci_host_probe(bridge) before pp->ops->post_init().
Inside pci_host_probe(), pci_msi_init() clears PCI_MSI_FLAGS_ENABLE on the
Root Port, and pci_bus_add_devices() then synchronously probes downstream
endpoint drivers before cortina_pcie_enable_msi() ever runs.

If an endpoint driver allocates MSIs and waits for MSI completions during
probe (for example with CONFIG_PCIEPORTBUS disabled or pcie_pme=nomsi), it
receives no MSIs and times out.  Similarly, unbinding a Root Port driver
later can clear PCI_MSI_FLAGS_ENABLE via cortina_pcie_wr_own_conf() and
break endpoint MSI delivery again.

[ ... ]

> +	irq_set_chained_handler_and_data(cp->irq, cortina_pcie_irq_handler, cp);
> +	writel(INT_MSI | INT_ERR_MASK, cp->app + APP_INT_ENABLE);
> +	pci->pp.ops = &cortina_pcie_host_ops;
> +	ret = dw_pcie_host_init(&pci->pp);

[Severity: Medium]
Can unmasking INT_LINK_DOWN before dw_pcie_host_init() permanently latch
cp->link_lost during initial link training?

INT_ERR_MASK includes INT_LINK_DOWN, and cp->resetting is false during
probe.  If initial link training or SPEED_CHANGE retraining triggers a
transient INT_LINK_DOWN, cortina_pcie_irq_handler() sets cp->link_lost =
true and writes 0 to APP_INT_ENABLE, and nothing clears cp->link_lost.

Because dw_pcie_host_init() only aborts on -ETIMEDOUT from
dw_pcie_wait_for_link() (ignoring -ENODEV and -EIO), probe can either fail
or return 0 with a permanently dead host controller whose config/DBI
accesses and interrupts are all blocked.

[ ... ]

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

[Severity: Medium]
Can cortina_pcie_shutdown() race with cortina_pcie_reset_root_port()
because it does not acquire cp->reset_lock?

device_shutdown() only holds device_lock() on the platform device and its
parent, so a concurrent secondary bus reset (for example via sysfs reset
or AER recovery) can interleave with shutdown:

CPU0                                  CPU1
cortina_pcie_reset_root_port()
  lock(&cp->reset_lock)
  writew(BUS_RESET, dbi_base + ...)
  usleep_range(2000, 3000)
                                      cortina_pcie_shutdown()
                                        cortina_pcie_quiesce()
                                        reset_control_assert(cp->reset)
  writew(..., dbi_base + ...)
    <-- DBI write while in reset

If shutdown finishes while reset_root_port() is sleeping across
reset_control_assert() or cortina_pcie_start_link(), reset_root_port()
can also deassert cp->reset and PERST# and re-enable LTSSM after shutdown
completes.  Acquiring cp->reset_lock before cortina_pcie_quiesce() drains
any active reset and causes later resets to see cp->link_lost and return
-ENOLINK.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-cs7542-pcie-v4-0-6d0101b281b4@gmail.com?part=5

  reply	other threads:[~2026-12-04 22:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 1/6] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
2026-12-04 22:33   ` sashiko-bot
2026-12-04 22:22 ` [PATCH v4 3/6] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
2026-12-04 22:33   ` sashiko-bot
2026-12-04 22:22 ` [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
2026-12-04 22:51   ` sashiko-bot [this message]
2026-12-04 22:22 ` [PATCH v4 6/6] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay
2026-12-04 22:51 ` [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-250784@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox