From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 4/5] net: cortina: Add CS7542 CPU network datapath
Date: Tue, 24 Nov 2026 18:53:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-231860@kernel.org> (raw)
In-Reply-To: <20261123-b4-cs7542-ethernet-v1-4-fdb5e8c2d508@gmail.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] net: cortina: RX DMA buffer leak on oversized frames in
cs_ne_rx_poll()
- [Medium] net: cortina: shared MAC prefix registers clobbered in
cs_ne_set_hw_addr()
- [Medium] net: cortina: unlocked RMW on shared NI registers in
cs_ne_mac_link_up()
- [Medium] net: cortina: unvalidated napi_budget parameter in
cs_ne_probe_port()
- [Medium] net: cortina: lost RX interrupt for queued XRAM packets in
cs_ne_open()
- [Medium] net: cortina: unchecked command errors in cs752x_sch_init()
- [Medium] net: cortina: BM bypass bits cleared after init in
cs752x_tm_bm_init()
- [Medium] net: cortina: unreaped TX SKBs left in ring by cs_ne_stop()
--
commit 82b05afd45239de80ea534b48d615861a3fd0a56
Author: Fil Dunsky <filipp.dunsky@gmail.com>
net: cortina: Add CS7542 CPU network datapath
This commit adds an Ethernet driver for the Cortina CS7542 network engine
GMACs, including CPU XRAM RX queues, QM buffer management, a shared TX
descriptor ring, and FE/SCH/TM hardware initialization.
> diff --git a/drivers/net/ethernet/cortina/cs752x_ne.c b/drivers/net/ethernet/cortina/cs752x_ne.c
> new file mode 100644
> index 0000000000000..126dcdd6c5c54
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_ne.c
[ ... ]
> + pkt_size = FIELD_GET(HDRE_PKT_SIZE, hdre_lo);
> + off = CS_NE_BUF_HDR_OFF + 8 + 16 + 2;
> + total = pkt_size > 20 ? pkt_size - 20 : 0;
> + valid = total >= ETH_HLEN && total <= CS_NE_MAX_PKT_LEN;
> + nbufs = 1;
> + if (valid && total > CS_NE_BUF_DATA_MAX - (off & 0xff))
> + nbufs += DIV_ROUND_UP(total - (CS_NE_BUF_DATA_MAX - (off & 0xff)),
> + CS_NE_BUF_DATA_MAX);
> + if (nbufs > CS_NE_RX_MAX_BUFS) {
> + valid = false;
> + nbufs = CS_NE_RX_MAX_BUFS;
> + }
> + for (i = 0; i < nbufs; i++)
> + dma[i] = readl(desc + 40 + i * 4) & XRAM_BUF_MASK;
> + valid = cs_ne_rx_claim(ne, dma, bufs, nbufs) && valid;
[Severity: High]
Does gating the nbufs calculation on valid leak trailing RX DMA buffers
when total > CS_NE_MAX_PKT_LEN?
cs_ne_qm_cpu_path_init() configures QM_MAX_CPU_PKT_LEN to
CS_NE_MAX_PKT_LEN + 16, so hardware can deliver oversized multi-buffer
frames to XRAM. When total > CS_NE_MAX_PKT_LEN, valid is false and nbufs
stays 1 (which also makes the nbufs > CS_NE_RX_MAX_BUFS check unreachable).
Only dma[0] is claimed and recycled, while the remaining buffers in the
descriptor stay in CS_NE_RX_HW state permanently, depleting the fixed RX
pool allocated at probe time until reception stalls. Also, if the 4-byte
FCS subtracted from pkt_size is stored in buffer memory and crosses a
CS_NE_BUF_DATA_MAX boundary, computing nbufs from total rather than the
stored byte count will undercount nbufs by one and leak that final buffer
as well.
[ ... ]
> +static void cs_ne_set_hw_addr(struct cs_ne_port *port)
> +{
> + struct cs_ne *ne = port->ne;
> + const u8 *a = port->ndev->dev_addr;
> +
> + ni_wr(ne, NI_MAC_ADDR0, a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24));
> + ni_rmw(ne, NI_MAC_ADDR1, 0xff, a[4]);
> + ni_rmw(ne, NI_ETH_MAC_CONFIG2(port->id), 0xff, a[5]);
> +}
[Severity: Medium]
Does cs_ne_set_hw_addr() overwrite the upper five MAC address bytes for
all sibling ports?
NI_MAC_ADDR0 and NI_MAC_ADDR1 are controller-wide registers shared by all
three GMACs, while only NI_ETH_MAC_CONFIG2(port->id) is per-port. Probing
multiple ports with different 5-byte prefixes (such as when
cs_ne_probe_port() falls back to eth_hw_addr_random()) or changing one
port's MAC address via cs_ne_set_mac_address() silently clobbers the
hardware MAC prefix of the other ports, desynchronizing them from their
ndev->dev_addr.
[ ... ]
> +static void cs_ne_mac_link_up(struct phylink_config *config,
> + struct phy_device *phy, unsigned int mode,
> + phy_interface_t interface, int speed, int duplex,
> + bool tx_pause, bool rx_pause)
> +{
> + struct cs_ne_port *port = container_of(config, struct cs_ne_port,
> + phylink_config);
> + struct cs_ne *ne = port->ne;
> + int p = port->id;
> + u32 val = 0;
> +
> + cs_ne_mac_enable(port, false);
> + if (speed == SPEED_10)
> + val |= NI_MAC_SPEED_10;
> + if (duplex != DUPLEX_FULL)
> + val |= NI_MAC_HALF_DUPLEX;
> + if (!rx_pause)
> + val |= NI_MAC_RX_FLOW_DISABLE;
> + if (!tx_pause)
> + val |= NI_MAC_TX_FLOW_DISABLE;
> + ni_rmw(ne, NI_ETH_MAC_CONFIG0(p),
> + NI_MAC_SPEED_10 | NI_MAC_HALF_DUPLEX | NI_MAC_RX_FLOW_DISABLE |
> + NI_MAC_TX_FLOW_DISABLE, val);
> + ni_rmw(ne, NI_ETH_INT_CONFIG1, NI_INT_CFG_GE_MASK(p),
> + NI_INT_CFG_GE(p, speed == SPEED_1000 ? NI_INT_CFG_RGMII_1000 :
> + NI_INT_CFG_RGMII_100));
> + ni_rmw(ne, NI_ETH_INT_CONFIG2, NI_INT_CONFIG2_GE_MASK(p),
> + NI_TX_INTF_LP_TIME_GE(p));
> + cs_ne_mac_enable(port, true);
> +}
[Severity: Medium]
Can concurrent cs_ne_mac_link_up() calls race on NI_ETH_INT_CONFIG1 and
NI_ETH_INT_CONFIG2?
Each port has its own phylink instance whose resolve work runs without
rtnl_lock or a shared controller lock. Because NI_ETH_INT_CONFIG1 and
NI_ETH_INT_CONFIG2 pack per-port fields for all three ports into shared
registers, unlocked read-modify-write updates in ni_rmw() when two links
come up at the same time can overwrite one port's RGMII speed or timing
configuration.
> +
> +static const struct phylink_mac_ops cs_ne_phylink_ops = {
> + .mac_config = cs_ne_mac_config,
> + .mac_link_down = cs_ne_mac_link_down,
> + .mac_link_up = cs_ne_mac_link_up,
> +};
> +
> +static int cs_ne_open(struct net_device *ndev)
> +{
> + struct cs_ne_port *port = netdev_priv(ndev);
> + struct cs_ne *ne = port->ne;
> + unsigned long flags;
> + int ret;
> +
> + /* RTNL also protects the final probe activation. */
> + if (ne->rx_stopping)
> + return -ENODEV;
> + if (READ_ONCE(ne->txq.fault))
> + return -EIO;
> +
> + ret = phylink_of_phy_connect(port->phylink, port->np, 0);
> + if (ret) {
> + netdev_err(ndev, "phylink connect failed: %d\n", ret);
> + return ret;
> + }
> +
> + port->rd = ni_rd(ne, NI_CPUXRAM_CPU_CFG_RX(port->id)) & NI_XRAM_PTR_MASK;
> + napi_enable(&port->napi);
> + ret = request_irq(port->irq, cs_ne_rx_irq, 0, ndev->name, port);
> + if (ret) {
> + napi_disable(&port->napi);
> + phylink_disconnect_phy(port->phylink);
> + return ret;
> + }
> + spin_lock_bh(&ne->txq.lock);
> + if (ne->txq.fault) {
> + spin_unlock_bh(&ne->txq.lock);
> + free_irq(port->irq, port);
> + napi_disable(&port->napi);
> + phylink_disconnect_phy(port->phylink);
> + return -EIO;
> + }
> + WRITE_ONCE(port->opened, true);
> + ne->txq.stopping = false;
> + cs_ne_tx_arm_timer(&ne->txq);
> + /* A concurrent TX fault must be able to stop this queue permanently. */
> + netif_start_queue(ndev);
> + spin_unlock_bh(&ne->txq.lock);
> + spin_lock_irqsave(&ne->rx_lock, flags);
> + ni_wr(ne, NI_CPUXRAM_RXPKT_INTERRUPT(port->id), 1);
> + ni_wr(ne, NI_CPUXRAM_RXPKT_INTENABLE(port->id), 1);
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> + phylink_start(port->phylink);
> + return 0;
> +}
[Severity: Medium]
Can clearing NI_CPUXRAM_RXPKT_INTERRUPT in cs_ne_open() strand unread RX
packets in XRAM?
cs_ne_stop() disables NAPI without draining descriptors remaining in the
XRAM ring (and port 0 can also receive frames via the FE catch-all rule
while down). When the port is reopened, cs_ne_open() clears the pending
interrupt bit without checking whether NI_CPUXRAM_CPU_STA_RX is ahead of
port->rd or scheduling NAPI. Queued packets stay unread until a new frame
arrives, or forever if the XRAM ring is already full or at its
backpressure threshold and cannot accept another frame to trigger an
interrupt.
> +
> +static int cs_ne_stop(struct net_device *ndev)
> +{
> + struct cs_ne_port *port = netdev_priv(ndev);
> + struct cs_ne *ne = port->ne;
> + unsigned long flags;
> + bool last = true;
> + int i;
> +
> + /* Serialize queue wakeups before waiting for ndo_start_xmit to finish. */
> + spin_lock_bh(&ne->txq.lock);
> + WRITE_ONCE(port->opened, false);
> + for (i = 0; i < CS_NE_PORTS; i++)
> + if (ne->ports[i] && READ_ONCE(ne->ports[i]->opened))
> + last = false;
> + if (last)
> + ne->txq.stopping = true;
> + spin_unlock_bh(&ne->txq.lock);
> + netif_tx_disable(ndev);
> + phylink_stop(port->phylink);
> + spin_lock_irqsave(&ne->rx_lock, flags);
> + ni_wr(ne, NI_CPUXRAM_RXPKT_INTENABLE(port->id), 0);
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> + free_irq(port->irq, port);
> + napi_disable(&port->napi);
> + phylink_disconnect_phy(port->phylink);
> + if (last)
> + cs_ne_tx_cancel_timer(&ne->txq);
> + return 0;
> +}
[Severity: Medium]
Does stopping the last open port leave transmitted SKBs pinned in
ne->txq.bufs[]?
TX completions are only reaped from cs_ne_rx_poll(), cs_ne_tx_timer(), and
cs_ne_start_xmit(). When the last open port stops, cs_ne_stop() disables
NAPI and cancels ne->txq.timer without a final cs_ne_tx_complete() pass,
so any SKBs and DMA mappings still in the TX ring remain held (pinning
socket sk_wmem_alloc accounting) until a port is opened again or the
driver is unbound.
[ ... ]
> + ndev->dev.of_node = np;
> + ndev->netdev_ops = &cs_ne_netdev_ops;
> + ndev->ethtool_ops = &cs_ne_ethtool_ops;
> + ndev->hw_features = NETIF_F_SG;
> + ndev->features = NETIF_F_SG;
> + ndev->vlan_features = NETIF_F_SG;
> + ndev->min_mtu = ETH_MIN_MTU;
> + ndev->max_mtu = CS_NE_MAX_PKT_LEN - ETH_HLEN - ETH_FCS_LEN - 16;
> + netif_napi_add_weight(ndev, &port->napi, cs_ne_rx_poll, napi_budget);
[Severity: Medium]
What happens if the napi_budget module parameter is set to 0 or a negative
value?
napi_budget is a signed int passed directly to netif_napi_add_weight()
without validation. If napi_budget <= 0, cs_ne_rx_poll() returns 0
without draining packets or calling napi_complete_done() (since done <
budget is false), and __napi_poll() sees work >= weight and repolls
forever in softirq context.
[ ... ]
> diff --git a/drivers/net/ethernet/cortina/cs752x_sch_tm.c b/drivers/net/ethernet/cortina/cs752x_sch_tm.c
> new file mode 100644
> index 0000000000000..e0213c7999cef
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_sch_tm.c
[ ... ]
> + for (port = 0; port < SCH_PORT_NO; port++) {
> + cpu_port = port >= SCH_CPU_PORT0 ? port - SCH_CPU_PORT0 : 0;
> +
> + cs752x_sch_enable_port(dev, sch, port);
> + cs752x_sch_set_port_burst(dev, sch, port, 0);
> + cs752x_sch_bypass_shaper(dev, sch, port + SCH_LT_BASE_ID, 0);
> + cs752x_sch_bypass_shaper(dev, sch, port + SCH_ST_BASE_ID, 0);
> +
> + for (q = 0; q < SCH_MAX_PORT_QUEUE; q++) {
> + cs752x_sch_enable_voq_drr(dev, sch,
> + port * SCH_MAX_PORT_QUEUE + q,
> + SCH_DEFAULT_QUANTA, cpu_port);
> + cs752x_sch_bypass_shaper(dev, sch,\n+ port + SCH_DRR_BASE_ID,
> + cpu_port);
> + }
> + }
[Severity: Medium]
Should cs752x_sch_init() check and propagate the error returns from the
scheduler command helpers?
cs752x_sch_enable_port(), cs752x_sch_set_port_burst(),
cs752x_sch_bypass_shaper(), and cs752x_sch_enable_voq_drr() all return the
status from cs752x_sch_cmd(), which can fail with -ETIMEDOUT or -EIO, but
their return values are ignored here and probe succeeds with an
incompletely configured scheduler. Also, cs752x_sch_bypass_shaper() for
port + SCH_DRR_BASE_ID does not depend on q and is re-issued on every
iteration of the inner queue loop.
[ ... ]
> + cfg = readl(tm + TM_BM_CONFIG_0);
> + cfg &= ~(TM_BM_CONFIG_0_DISABLE |
> + TM_BM_CONFIG_0_RECALCULATE_GLOBAL_BUFFERS_USED |
> + TM_BM_CONFIG_0_BM2_BYPASS_CA_PROCESS |
> + TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS |
> + TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS |
> + TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS |
> + TM_BM_CONFIG_0_BM1_BYPASS_DEST_PORT_PROCESS |
> + TM_BM_CONFIG_0_BM1_BYPASS_VOQ_PROCESS |
> + TM_BM_CONFIG_0_ENQUE_HDR_ADJUST |
> + TM_BM_CONFIG_0_INIT);
> +
> + writel(cfg | TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS |
> + TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS |
> + TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS |
> + TM_BM_CONFIG_0_INIT, tm + TM_BM_CONFIG_0);
> + ret = cs752x_tm_wait_init_done(dev, tm, TM_BM_STATUS_0,
> + TM_BM_STATUS_0_INIT_DONE, "bm");
> + if (ret)
> + return ret;
> +
> + writel(cfg, tm + TM_BM_CONFIG_0);
[Severity: Medium]
Does writing cfg back to TM_BM_CONFIG_0 clear the BM1/BM2 bypass bits that
were just set?
The three bypass flags (TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS,
TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS, and
TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS) are masked out of cfg and only ORed
into the writel() that asserts TM_BM_CONFIG_0_INIT, so the final
writel(cfg, ...) that clears INIT also disables those bypasses.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-ethernet-v1-0-fdb5e8c2d508@gmail.com?part=4
next prev parent reply other threads:[~2026-11-24 18:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 18:44 [PATCH net-next 0/5] net: cortina: Add CS7542 network engine support Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
2026-11-23 18:44 ` [PATCH net-next 1/5] dt-bindings: reset: Add Cortina CS7542 network engine reset domain Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
2026-11-24 6:39 ` Krzysztof Kozlowski
2026-11-24 6:58 ` Fil Dunsky
2026-11-24 18:53 ` sashiko-bot
2026-11-23 18:44 ` [PATCH net-next 2/5] reset: Add Cortina CS7542 network engine domain control Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
2026-11-23 18:44 ` [PATCH net-next 3/5] dt-bindings: net: Add Cortina CS7542 network engine Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
2026-11-23 22:05 ` Andrew Lunn
2026-11-23 22:31 ` Fil Dunsky
2026-11-23 18:44 ` [PATCH net-next 4/5] net: cortina: Add CS7542 CPU network datapath Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
2026-11-23 22:24 ` Andrew Lunn
2026-11-23 23:41 ` Fil Dunsky
2026-11-24 18:53 ` sashiko-bot [this message]
2026-11-23 18:44 ` [PATCH net-next 5/5] MAINTAINERS: Add CS7542 network engine support Fil Dunsky
2026-11-23 18:44 ` Fil Dunsky via B4 Relay
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-231860@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=filipp.dunsky@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.