From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796424704; b=wqueviRQicXH+R7z3zoLG/rH56LdSiDl173xMyoH9HziaB6yrd8H5nED4S3uB8c12xD5 p1BvlydR1oKKQ22VpWCf0cfuTcuTPn1sZFHkuPJwOD3sv1W+asvIE6ffbytzi0LYRkfYD Cn28XVfVIXY8CDQSmPHs7wJdHySbhaFiMet/J28yigAicR+7ltxxTRqCx01VlA0IRbbJh 8FW+faFY6246eyx0sQJMFzaGw53cQQb2ONvdvlvNCEWRBWU0M6ujh1jo/d21F72ZReKlZ xYsc5zy/Ti7KGvLYb28/d6sR9OUhGunsXeexbBpmOjN5lbJHaGu31XuyhO10S62Tj+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796424704; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=6oWKCNu3oIANBB7HvClEniEILI4/OvXWvEq4WxnxygU=; b=zKgB/MlG936sa+ACl5QW+gNRelaUAaPoje6YoJbWUtNIosq8PdPeeUDXOaa336ZMQHgq XyQ5RprnUA6XRri8j23K0E9hB0MQLZ7wPGmzkArRMlMymlV8zvnHm/wLj1e4i+3Q2kqeq fhaS5Bfp+1P4CVo9yZu2/kQUq0gvCzHhdNjA/idIbKGCiTNsO+yBRj1PJ2T92puoAxLAQ qYWY4NSgvRBoUtCP/ct88c6xRQEJpr9Lv06IxAJ7G2g0X6jNqNGzFeSBG4vE5zgRHk2v8 sE7s0DNQZYDYPKNK1rmhOBd/Z0ggmBk5LlSZcLNQG2154u1lIlA4mf4Bf3P83fKeq+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JO9br+gL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C96D606A32C; Fri, 4 Dec 2026 22:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JO9br+gL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 512C91F00936; Fri, 4 Dec 2026 22:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796424703; bh=6oWKCNu3oIANBB7HvClEniEILI4/OvXWvEq4WxnxygU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JO9br+gLe/1rO9/0dt1IsG3CblCHUurNY+sWdo5Z259UVML3IMzqIGmktGZ7h63Pf 8lSg77x3PgM6fV6MKKhiQGFNX7Hvu4n/P9m49SForcX+Bv5t6fSF1kU6VmfEGR4XQi FFcKSrPAaDCOts2HK/3JmQV2qEvzp6DN0oqd+i8K+afc9Ra4HHaT+OhdKIPQpHMlsu SNaOsz25dvnloIS0FrGfCnpaOj7PO9upioBk5cxMhHOPF8ND2O2ANgL8GKZiS7if7Y DqD4uL3avPpC//9DZPR/BMywe8XBMB6VJrcXCkpmvY4AybpgRKSq31Q3g0cLVh+B97 5blLDQhB3NUIQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support Reply-To: sashiko-reviews@lists.linux.dev To: "Fil Dunsky" 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 In-Reply-To: <20261205-b4-cs7542-pcie-v4-5-6d0101b281b4@gmail.com> References: <20261205-b4-cs7542-pcie-v4-0-6d0101b281b4@gmail.com> <20261205-b4-cs7542-pcie-v4-5-6d0101b281b4@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:51:42 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 >=3D 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 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. > =20 > + > 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/contr= oller/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 =3D to_cortina_pcie(pci); > + u32 value =3D 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 =3D { > + .name =3D "cortina-INTx", > + .irq_mask =3D cortina_intx_mask, > + .irq_unmask =3D 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 =3D PCIBIOS_DEVICE_NOT_FOUND; > + } else if (where >=3D RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) { > + *val =3D 0; > + ret =3D PCIBIOS_SUCCESSFUL; > + } else { > + ret =3D pci_generic_config_read(bus, devfn, where, size, val); > + } [ ... ] > + if (cp->link_lost || cp->resetting) > + ret =3D PCIBIOS_DEVICE_NOT_FOUND; > + else if (where >=3D RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) > + ret =3D PCIBIOS_SUCCESSFUL; > + else > + ret =3D 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 >=3D 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 =3D bridge->bus->sysdata; > + struct dw_pcie *pci =3D to_dw_pcie_from_pp(pp); > + struct cortina_pcie *cp =3D 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 =3D true; > + mask =3D 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 =3D 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 =3D true cp->dbi_blocked =3D 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 =3D -ENOLINK; > + } > + if (ret) > + WRITE_ONCE(cp->link_lost, true); > + else > + writel(mask | cp->intx_enabled, cp->app + APP_INT_ENABLE); > + cp->dbi_blocked =3D 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 =3D &cortina_own_pci_ops; > + pp->keep_rp_msi_en =3D true; > + pp->bridge->reset_root_port =3D 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 =3D true and assigns pp->bridge->sysdata =3D 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 =3D { > + .init =3D cortina_pcie_host_init, > + .post_init =3D cortina_pcie_enable_msi, > + .deinit =3D cortina_pcie_host_deinit, > + .msi_init =3D 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=3Dnomsi), 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 =3D &cortina_pcie_host_ops; > + ret =3D 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 =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-b4-cs7542-= pcie-v4-0-6d0101b281b4@gmail.com?part=3D5