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 v9 2/3] net: cortina: Add CS7542 CPU network datapath
Date: Sun, 06 Dec 2026 14:05:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-252467@kernel.org> (raw)
In-Reply-To: <20261205-b4-cs7542-ethernet-v9-2-8fbf7e3314a5@gmail.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] net: cortina: unbounded skb->len truncates u16 TX length and
leaks DMA
- [Medium] net: cortina: excessive hard-IRQ-disabling ne->rx_lock use in
RX path
- [Medium] net: cortina: mod_delayed_work() timer thrashing in
cs_ne_rx_kick()
- [Medium] net: cortina: ne->txq.lock held across DMA map/unmap and SKB
freeing
- [Medium] net: cortina: order-2 atomic linear RX skb allocation for
jumbo frames
- [Medium] net: cortina: missing IRQ status clear and recheck in
cs_ne_rx_poll()
- [Medium] net: cortina: cs_ne_port_calendar_init() drops all pspid 2 RX
slots
- [Low] net: cortina: redundant txq->lock re-initialization in
cs_ne_dma_init()
- [Low] net: cortina: missing XR_NEXT_LINK and pool validation in
cs_ne_rx_poll()
--
commit 419d56d9b722f44c00a58d4eba793a8a53f0bd4f
Author: Fil Dunsky <filipp.dunsky@gmail.com>
net: cortina: Add CS7542 CPU network datapath
This commit adds the Cortina CS7542 network engine driver supporting three
GMAC ports with phylink, per-port NAPI RX, and a shared coherent TX ring,
along with FE, SCH, and TM initialization.
Link: https://lore.kernel.org/all/sashiko-outbox-251080@kernel.org/
> diff --git a/drivers/net/ethernet/cortina/cs752x_ne.c b/drivers/net/ethernet/cortina/cs752x_ne.c
> new file mode 100644
> index 0000000000000..1c89b62b9d878
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_ne.c
[ ... ]
> +static int cs_ne_port_calendar_init(struct cs_ne *ne)
> +{
> + int ret, i, j;
> +
> + for (i = 0; i < 12; i++) {
> + for (j = 0; j < 8; j++) {
> + ret = cs_ne_set_port_calendar(ne, i * 8 + j, j);
> + if (ret)
> + return dev_err_probe(ne->dev, ret, "port calendar timeout\n");
> + }
> + }
> + for (i = 0; i < 12; i++) {
> + ret = cs_ne_set_port_calendar(ne, i * 8 + 2, 4);
> + if (ret)
> + return dev_err_probe(ne->dev, ret, "port calendar override timeout\n");
> + }
> + return 0;
> +}
[Severity: Medium]
Does the second loop drop all RX calendar slots for GMAC2?
The first loop places pspid 2 only at slots i * 8 + 2, and the second loop
overwrites all 12 of them with pspid 4. Elsewhere the driver maps GMAC0..2
to ports 0..2, including an identity LPB table in cs752x_fe_init() with
per-port class rules for lspid 0..2, so removing pspid 2 from the enabled NI
RX port calendar appears to leave the third GMAC without RX arbitration
slots.
[ ... ]
> +static int cs_ne_dma_init(struct cs_ne *ne)
> +{
> + struct cs_ne_txq *txq = &ne->txq;
> + u32 val;
> +
> + txq->desc = dma_alloc_coherent(ne->dev, CS_NE_TX_DESC_NUM * 32,
> + &txq->desc_dma, GFP_KERNEL);
> + if (!txq->desc)
> + return -ENOMEM;
> + txq->ne = ne;
> + txq->stopping = true;
> + spin_lock_init(&txq->lock);
[Severity: Low]
cs_ne_probe() already sets ne->txq.ne, ne->txq.stopping, and calls
spin_lock_init(&ne->txq.lock). Re-initializing txq->lock here is redundant
and would corrupt lock state if cs_ne_dma_init() is ever reused on a reset
or recovery path.
[ ... ]
> + /* Serialized with the stop flag so cancellation cannot miss a requeue. */
> + if (!list_empty(&ne->rx_pending))
> + mod_delayed_work(system_wq, &ne->rx_retry, msecs_to_jiffies(1));
> +unlock:
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> +}
[Severity: Medium]
Should this use queue_delayed_work() instead of mod_delayed_work()?
Under QM FIFO backpressure, cs_ne_rx_poll() calls cs_ne_rx_kick() every 8
packets, and mod_delayed_work() cancels and re-arms the pending timer each
time while holding ne->rx_lock, thrashing timer locks and postponing the
retry worker until traffic subsides.
Separately, cs_ne_probe() queues all buffers for port 0, then port 1, then
port 2 sequentially onto ne->rx_pending before kicking them after
register_netdevice(), which can starve ports 1 and 2 if the 32-entry QM FIFO
fills during probe.
[ ... ]
> +static void cs_ne_rx_recycle(struct cs_ne *ne, struct cs_ne_rx_buf *buf)
> +{
> + unsigned long flags;
> +
> + if (!buf)
> + return;
> + /* A claimed mapping cannot be handed to another CPU while it is copied. */
> + if (WARN_ON_ONCE(buf->state != CS_NE_RX_CPU))
> + return;
> + if (buf->sync_len)
> + dma_sync_single_range_for_device(ne->dev, buf->dma, buf->sync_off,
> + buf->sync_len, DMA_FROM_DEVICE);
> + spin_lock_irqsave(&ne->rx_lock, flags);
> + buf->sync_len = 0;
> + buf->state = CS_NE_RX_PENDING;
> + list_add_tail(&buf->pending, &ne->rx_pending);
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> +}
[Severity: Medium]
Does ne->rx_lock need spin_lock_irqsave() and per-fragment locking?
cs_ne_rx_irq() never takes ne->rx_lock and IFF_DISABLE_NETPOLL prevents
hardirq netpoll entry, so spin_lock_bh()/spin_lock() is sufficient and
avoids masking hard IRQs across unbounded MMIO FIFO push loops in
cs_ne_rx_kick(). In addition, cs_ne_rx_claim() holds ne->rx_lock across
immutable xa_load() lookups, and cs_ne_rx_recycle() acquires it per fragment
instead of batching recycled buffers onto a local list.
[ ... ]
> + /* This engine retires through RPTR; completed descriptors keep OWN set. */
> + while (tail != rptr) {
> + buf = &txq->bufs[tail];
> + if (buf->len) {
> + if (buf->page)
> + dma_unmap_page(ne->dev, buf->dma, buf->len,
> + DMA_TO_DEVICE);
> + else
> + dma_unmap_single(ne->dev, buf->dma, buf->len,
> + DMA_TO_DEVICE);
> + buf->len = 0;
> + }
> + if (buf->skb) {
> + dev_consume_skb_any(buf->skb);
> + buf->skb = NULL;
> + }
> + tail = (tail + 1) & (CS_NE_TX_DESC_NUM - 1);
> + }
[Severity: Medium]
Can DMA unmapping and SKB freeing move outside ne->txq.lock?
ne->txq.lock is shared across transmit on all three ports, every port's RX
NAPI poll via cs_ne_tx_reap(), and the 200 us hrtimer. Holding it across DMA
unmaps and dev_consume_skb_any() for up to 1,023 descriptors here, as well
as across dma_map_single() and skb_frag_dma_map() in cs_ne_start_xmit() and
cs_ne_xmit_sg(), adds unnecessary SMP contention; linear mappings can run
before locking and completed SKBs can be detached and freed after unlocking.
[ ... ]
> + skb = napi_alloc_skb(&port->napi, total);
> + if (!skb) {
> + DEV_STATS_INC(ndev, rx_dropped);
> + goto recycle;
> + }
> + remaining = total;
> + for (i = 0; i < nbufs && remaining; i++) {
> + seg = min_t(u32, remaining, CS_NE_BUF_DATA_MAX - (off & 0xff));
> + data = cs_ne_rx_buf_cpu(ne, bufs[i], off, seg);
> + if (!data)
> + break;
> + skb_put_data(skb, data, seg);
> + remaining -= seg;
> + off = CS_NE_BUF_HDR_OFF;
> + }
[Severity: Medium]
Will jumbo RX frames force order-2 atomic allocations here?
Because ndev->max_mtu allows frames up to CS_NE_MAX_PKT_LEN (9,022 bytes),
napi_alloc_skb() bypasses the NAPI page-frag cache above
SKB_WITH_OVERHEAD(PAGE_SIZE) and falls back to order-1 or order-2 GFP_ATOMIC
kmalloc allocations, risking rx_dropped bursts under memory fragmentation on
a 512 MiB platform. Allocating a small header skb and attaching order-0 page
fragments for multi-buffer frames would avoid high-order atomic allocations.
[ ... ]
> + next = FIELD_GET(XR_NEXT_LINK, w1);
> + if (next == wr) {
> + wr = ni_rd(ne, NI_CPUXRAM_CPU_STA_RX(port->id)) & NI_XRAM_PTR_MASK;
> + /*
> + * Keep the vendor's DDR-arrival guard when the next
> + * link still reaches the current hardware tail.
> + */
> + if (next == wr)
> + udelay(CS_NE_RX_TAIL_SETTLE_US);
> + }
> + rd = next;
> + cs_ne_rx_packet(port, desc, w1);
[Severity: Low]
Should next be validated against the port's XRAM slice before updating rd?
XR_NEXT_LINK is 12 bits while NI_XRAM_PTR_MASK is 11 bits, so a corrupted
hardware descriptor with bit 11 set or next == rd can cause a NAPI livelock
because rd will never match wr. Validating next (and initial port->rd in
cs_ne_open()) against the port's 525-unit XRAM slice, and checking
buf->pool == port->id in cs_ne_rx_claim(), would prevent livelocks and
cross-port buffer claiming on hardware faults.
[ ... ]
> + if (done < budget && napi_complete_done(napi, done)) {
> + spin_lock_irqsave(&ne->rx_lock, flags);
> + if (READ_ONCE(port->opened) && !ne->rx_stopping) {
> + /*
> + * Keep DMA-owned buffers untouched and the IRQ masked.
> + * A delayed poll also handles completion without a new edge.
> + */
> + if (defer)
> + mod_delayed_work(system_wq, &port->rx_owned_retry,
> + msecs_to_jiffies(1));
> + else
> + ni_wr(ne, NI_CPUXRAM_RXPKT_INTENABLE(port->id), 1);
> + }
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> + }
[Severity: Medium]
Can re-enabling NI_CPUXRAM_RXPKT_INTENABLE without clearing
NI_CPUXRAM_RXPKT_INTERRUPT trigger a spurious level-high interrupt?
cs_ne_rx_irq() clears the W1C status bit before NAPI runs, so any packet
arriving while polling re-latches it. Because the RX IRQs are
level-triggered, enabling INTENABLE without W1C-clearing
NI_CPUXRAM_RXPKT_INTERRUPT and re-checking NI_CPUXRAM_CPU_STA_RX against rd
immediately fires a spurious interrupt and schedules an empty NAPI poll.
[ ... ]
> + dma = dma_map_single(ne->dev, skb->data, len, DMA_TO_DEVICE);
> + if (dma_mapping_error(ne->dev, dma)) {
> + spin_unlock(&txq->lock);
> + dev_kfree_skb_any(skb);
> + DEV_STATS_INC(ndev, tx_dropped);
> + return NETDEV_TX_OK;
> + }
> +
> + buf = &txq->bufs[txq->head];
> + buf->skb = skb;
> + buf->dma = dma;
> + buf->len = len;
[Severity: High]
Can an oversized skb truncate u16 buf->len and leak the TX DMA mapping?
cs_ne_start_xmit() does not check skb->len against CS_NE_MAX_PKT_LEN. A
local CAP_NET_RAW process using AF_PACKET with PACKET_VNET_HDR and
VIRTIO_NET_HDR_GSO_NONE bypasses the netdev MTU check in tpacket_snd() and
can submit a 65536-byte skb: dma_map_single() maps the full length, buf->len
wraps to 0, and cs_ne_tx_complete() skips dma_unmap_single() when buf->len
is 0 (or unmaps a truncated length when len > 65536), while cs_ne_tx_desc()
also truncates TX_DESC_LEN and total << 16. Rejecting and freeing frames
with skb->len > CS_NE_MAX_PKT_LEN at the start of cs_ne_start_xmit() avoids
both the DMA leak and descriptor truncation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-cs7542-ethernet-v9-0-8fbf7e3314a5@gmail.com?part=2
next prev parent reply other threads:[~2026-12-06 14:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 14:04 [PATCH net-next v9 0/3] Add Cortina Systems CS7542 network engine support Fil Dunsky via B4 Relay
2026-12-05 14:04 ` [PATCH net-next v9 1/3] dt-bindings: net: Add Cortina CS7542 network engine Fil Dunsky via B4 Relay
2026-12-05 14:04 ` [PATCH net-next v9 2/3] net: cortina: Add CS7542 CPU network datapath Fil Dunsky via B4 Relay
2026-12-06 14:05 ` sashiko-bot [this message]
2026-12-05 14:04 ` [PATCH net-next v9 3/3] MAINTAINERS: Add CS7542 network engine support 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-252467@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox