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 v8 2/3] net: cortina: Add CS7542 CPU network datapath
Date: Sat, 05 Dec 2026 04:20:20 +0000 [thread overview]
Message-ID: <sashiko-outbox-251080@kernel.org> (raw)
In-Reply-To: <20261204-b4-cs7542-ethernet-v8-2-4b625ce9fe82@gmail.com>
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] net: cortina: netpoll/netconsole deadlocks on ne->txq.lock
- [Medium] net: cortina: missing of_node_get()/of_node_put() for port OF
nodes
- [Medium] net: cortina: atomic dev_alloc_page() used for bulk RX probe
refill
- [Medium] net: cortina: host-endian writes to coherent TX DMA
descriptors
- [Medium] net: cortina: excessive hard-IRQ-disabling ne->rx_lock use in
RX path
- [Medium] net: cortina: TX ring data race and lock contention under
ne->txq.lock
- [Medium] net: cortina: order-2 atomic RX skb allocations for jumbo
frames
- [Medium] net: cortina: loop-invariant shaper bypass in
cs752x_sch_init()
- [Medium] net: cortina: cs_ne_rx_poll() discards refreshed RX write
pointer
- [Medium] net: cortina: missing IRQ status clear and recheck in
cs_ne_rx_poll()
- [Low] net: cortina: unpaired plain writes to txq->head, tail, and
fault
- [Low] net: cortina: duplicated TX descriptor, free-space, and txq init
code
- [Low] net: cortina: unmarked ndev->stats increments race with
dev_get_tstats64()
--
commit fd19fefeb519d024c28ee4b48974974a246e10bf
Author: Fil Dunsky <filipp.dunsky@gmail.com>
net: cortina: Add CS7542 CPU network datapath
This commit adds the Cortina CS7542 Ethernet driver supporting three
GMAC ports with phylink, per-port NAPI RX, a shared coherent TX ring,
and forwarding engine, scheduler, and traffic manager 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..ad673449802c6
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_ne.c
[ ... ]
> +static int cs_ne_rx_refill(struct cs_ne_port *port, int count)
> +{
> + struct cs_ne *ne = port->ne;
> + struct cs_ne_rx_buf *buf;
> + unsigned long flags;
> + int ret, i;
> +
> + for (i = 0; i < count; i++) {
> + buf = kzalloc_obj(*buf);
> + if (!buf)
> + break;
> + buf->page = dev_alloc_page();
[Severity: Medium]
Should cs_ne_rx_refill() use alloc_page(GFP_KERNEL) instead of
dev_alloc_page()?
cs_ne_rx_refill() is only called during sleepable probe from
cs_ne_probe_port() and already uses GFP_KERNEL for kzalloc_obj() and
xa_insert(). dev_alloc_page() allocates with GFP_ATOMIC, which can
unnecessarily fail probe with -ENOMEM when filling up to 2304 RX pages
(9 MiB) on a 512 MiB platform with 64 MiB reserved for QM.
[ ... ]
> +static bool cs_ne_rx_claim(struct cs_ne *ne, const dma_addr_t *dma,
> + struct cs_ne_rx_buf **bufs, unsigned int count)
> +{
> + struct cs_ne_rx_buf *buf;
> + unsigned long flags;
> + unsigned int i;
> + bool valid = true;
> +
> + if (!count || count > CS_NE_RX_MAX_BUFS)
> + return false;
> + spin_lock_irqsave(&ne->rx_lock, flags);
> + for (i = 0; i < count; i++) {
> + bufs[i] = NULL;
> + buf = xa_load(&ne->rx_buffers, dma[i] >> CS_NE_RX_DMA_SHIFT);
> + if (!buf || buf->dma != dma[i] || buf->state != CS_NE_RX_HW) {
> + valid = false;
> + continue;
> + }
> + buf->state = CS_NE_RX_CPU;
> + buf->sync_off = 0;
> + buf->sync_len = 0;
> + bufs[i] = buf;
> + }
> + spin_unlock_irqrestore(&ne->rx_lock, flags);
> + return valid;
> +}
[ ... ]
> +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 to disable hard IRQs and be taken per packet and
per fragment on the RX path?
cs_ne_rx_irq() never acquires ne->rx_lock and zero-budget netpoll in
cs_ne_rx_poll() returns before touching it, so every caller runs in
softirq or process context. Acquiring spin_lock_irqsave(&ne->rx_lock)
in cs_ne_rx_claim() across xa_load() lookups, again per fragment in
cs_ne_rx_recycle(), and across the MMIO push loop in cs_ne_rx_kick()
masks hard interrupts and serializes concurrent NAPI polls across all
three ports. Using spin_lock_bh()/spin_lock(), doing the immutable
xa_load() lookups outside the lock, and batching recycled buffers onto
a local list spliced once per poll in cs_ne_rx_kick() would avoid this.
[ ... ]
> +static void cs_ne_tx_complete(struct cs_ne *ne)
> +{
> + struct cs_ne_txq *txq = &ne->txq;
> + struct cs_ne_tx_buf *buf;
> + u32 rptr;
> + int i;
> +
> + if (txq->fault)
> + return;
> + rptr = readl(ne->dma + DMA_LSO_TXQ_RPTR(0)) & DMA_PTR_MASK;
> + /* Never consume unsubmitted descriptors or loop past the ring boundary. */
> + if (rptr >= CS_NE_TX_DESC_NUM ||
> + ((rptr - txq->tail) & (CS_NE_TX_DESC_NUM - 1)) >
> + ((txq->head - txq->tail) & (CS_NE_TX_DESC_NUM - 1))) {
> + txq->fault = true;
> + cs_ne_tx_stop_all(ne);
> + dev_err_ratelimited(ne->dev, "invalid TX completion pointer %#x\n", rptr);
> + return;
> + }
[Severity: High]
Can netpoll or netconsole self-deadlock on ne->txq.lock here and across
the TX paths?
The driver does not set IFF_DISABLE_NETPOLL and supports zero-budget
polling in cs_ne_rx_poll(). netconsole invokes netpoll_send_skb() from
hardirq context with local IRQs disabled, reaching cs_ne_start_xmit()
and cs_ne_rx_poll(..., 0) -> cs_ne_tx_reap(), while normal callers
(cs_ne_tx_timer(), cs_ne_tx_reap(), cs_ne_start_xmit(), cs_ne_open(),
cs_ne_stop()) acquire the shared ne->txq.lock with hardirqs enabled:
cs_ne_tx_timer()
spin_lock(&txq->lock)
<hardirq>
netconsole -> netpoll_send_skb(port0)
cs_ne_start_xmit()
spin_lock(&txq->lock) <-- spins forever
In addition, calling dev_err_ratelimited() in cs_ne_tx_complete() while
holding ne->txq.lock after cs_ne_tx_stop_all() synchronously re-enters
netconsole -> netpoll_poll_dev() -> cs_ne_rx_poll(..., 0) ->
cs_ne_tx_reap(), which self-deadlocks on ne->txq.lock even with
spin_lock_irqsave().
Consider either setting IFF_DISABLE_NETPOLL, or converting all
ne->txq.lock acquisitions to spin_lock_irqsave()/spin_unlock_irqrestore()
and moving dev_err_ratelimited() outside ne->txq.lock.
> + /* This engine retires through RPTR; completed descriptors keep OWN set. */
> + while (txq->tail != rptr) {
> + buf = &txq->bufs[txq->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;
> + }
> + txq->tail = (txq->tail + 1) & (CS_NE_TX_DESC_NUM - 1);
> + }
[Severity: Medium]
Can holding the shared ne->txq.lock across DMA mapping, unmapping, and
SKB freeing cause excessive multi-port contention and data races?
cs_ne_tx_complete() holds ne->txq.lock while unmapping up to 1023
descriptors and calling dev_consume_skb_any(), while cs_ne_start_xmit()
and cs_ne_xmit_sg() hold the same device-wide lock across
dma_map_single() and skb_frag_dma_map(). In addition, cs_ne_xmit_sg()
advances txq->head per fragment inside the mapping loop before writing
DMA_LSO_TXQ_WPTR(0), exposing intermediate values to lockless
READ_ONCE(txq->head) checks in cs_ne_tx_reap() and triggering spurious
lock contention across all three ports.
[ ... ]
> +static void cs_ne_tx_reap(struct cs_ne *ne)
> +{
> + struct cs_ne_txq *txq = &ne->txq;
> +
> + if (READ_ONCE(txq->tail) == READ_ONCE(txq->head))
> + return;
> + spin_lock(&txq->lock);
> + cs_ne_tx_complete(ne);
> + spin_unlock(&txq->lock);
> +}
[Severity: Low]
Are the plain writes to txq->tail, txq->head, and txq->fault a data
race with the lockless READ_ONCE() checks here and in cs_ne_open()?
cs_ne_tx_complete(), cs_ne_xmit_sg(), and cs_ne_start_xmit() update
txq->tail, txq->head, and txq->fault with plain assignments, which will
trigger KCSAN data-race warnings against READ_ONCE(txq->tail),
READ_ONCE(txq->head), and READ_ONCE(ne->txq.fault). Pairing those
writes with WRITE_ONCE() (and publishing txq->head once an SG frame is
fully mapped) would resolve this.
[ ... ]
> + if (!valid) {
> + ndev->stats.rx_errors++;
> + goto recycle;
> + }
[Severity: Low]
Should these ndev->stats increments use DEV_STATS_INC()?
cs_ne_probe_port() sets NETDEV_PCPU_STAT_TSTATS without ndo_get_stats64
or ndo_get_stats, so dev_get_stats() reads dev->stats locklessly via
netdev_stats_to_stats64() using atomic_long_read(). Plain ++ updates
to rx_errors, rx_dropped, rx_fifo_errors, and tx_dropped across
cs_ne_rx_packet(), cs_ne_rx_poll(), cs_ne_xmit_sg(), and
cs_ne_start_xmit() race with those readers under CONFIG_KCSAN_STRICT.
> + skb = napi_alloc_skb(&port->napi, total);
> + if (!skb) {
> + ndev->stats.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 napi_alloc_skb(&port->napi, total) force order-2 atomic
allocations for jumbo frames?
cs_ne_probe_port() sets ndev->max_mtu up to 8988 bytes, allowing total
up to CS_NE_MAX_PKT_LEN (9022 bytes). Lengths above
SKB_WITH_OVERHEAD(PAGE_SIZE) bypass the NAPI page-frag cache and fall
back to GFP_ATOMIC order-2 kmalloc-16k allocations, which can cause
rx_dropped bursts under fragmentation on a 512 MiB system instead of
attaching order-0 page fragments.
[ ... ]
> + next = FIELD_GET(XR_NEXT_LINK, w1);
> + if (next == wr &&
> + (ni_rd(ne, NI_CPUXRAM_CPU_STA_RX(port->id)) & NI_XRAM_PTR_MASK) == wr) {
> + /*
> + * The next link reaches the unchanged hardware write pointer:
> + * this is the current tail packet. Retain the vendor's 16us
> + * DDR-arrival guard before reading its header and payload.
> + * NAPI softirq context cannot use a sleeping delay here.
> + */
> + udelay(CS_NE_RX_TAIL_SETTLE_US);
> + }
> + rd = next;
> + cs_ne_rx_packet(port, desc, w1);
> + done++;
[Severity: Medium]
Should cs_ne_rx_poll() update wr from the refreshed
NI_CPUXRAM_CPU_STA_RX(port->id) read when next == wr?
When hardware has already queued newer packets past wr, discarding the
re-read value causes rd = next to equal the stale wr and exit the loop
with done < budget. This flushes GRO early via napi_complete_done()
and triggers an immediate hard interrupt and NAPI reschedule for
packets already visible in XRAM.
[ ... ]
> + 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(port->id) without clearing
NI_CPUXRAM_RXPKT_INTERRUPT fire a spurious level-triggered interrupt
after every multi-packet burst?
cs_ne_rx_irq() clears the W1C NI_CPUXRAM_RXPKT_INTERRUPT bit before
NAPI runs, so any packet arriving before cs_ne_rx_poll() reads
NI_CPUXRAM_CPU_STA_RX re-latches it while INTENABLE is masked. After
draining those packets and calling napi_complete_done(), enabling
INTENABLE with the stale latch still set immediately asserts the
IRQ_TYPE_LEVEL_HIGH GIC SPI and schedules an empty 0-packet poll.
Clearing NI_CPUXRAM_RXPKT_INTERRUPT after updating
NI_CPUXRAM_CPU_CFG_RX and re-checking NI_CPUXRAM_CPU_STA_RX != rd
before re-enabling INTENABLE would avoid both spurious and missed
interrupts.
[ ... ]
> +static void cs_ne_tx_desc(struct cs_ne_txq *txq, int port_id, dma_addr_t dma,
> + u32 len, u32 total, bool sof, bool eof)
> +{
> + u32 *desc = txq->desc + txq->head * 8;
> + u32 word0, word3;
> +
> + word3 = TX_LSO_SEGMENT_EN | CS_NE_MAX_PKT_LEN;
> + if (eof && total < CS_NE_MIN_PKT_LEN)
> + word3 |= TX_LSO_IP_LENFIX_EN;
> + word0 = TX_DESC_OWN | FIELD_PREP(TX_DESC_LEN, len);
> + if (sof)
> + word0 |= TX_DESC_SOF;
> + if (eof)
> + word0 |= TX_DESC_EOF;
> +
> + desc[1] = dma;
> + desc[2] = sof ? total << 16 : 0;
> + desc[3] = word3;
> + desc[4] = CS_NE_HDRA_CPU_PKT | FIELD_PREP(TX_HDRA_DVOQ, port_id * 8);
> + desc[5] = 0;
> + desc[6] = 0;
> + desc[7] = 0;
> + dma_wmb();
> + desc[0] = word0;
> +}
[Severity: Medium]
Will writing host-endian u32 words directly to txq->desc break TX on
big-endian kernels?
CS7542_ETHERNET can be built on big-endian configurations such as ARM
BE8, and cs_ne_dma_init() does not enable a big-endian descriptor mode.
Both cs_ne_tx_desc() and cs_ne_start_xmit() write raw host-endian
values into coherent DMA memory instead of typing txq->desc as __le32 *
and converting descriptor words with cpu_to_le32().
[ ... ]
> + word3 = TX_LSO_SEGMENT_EN | CS_NE_MAX_PKT_LEN;
> + if (len < CS_NE_MIN_PKT_LEN)
> + word3 |= TX_LSO_IP_LENFIX_EN;
> +
> + desc = txq->desc + txq->head * 8;
> + desc[1] = dma;
> + desc[2] = len << 16;
> + desc[3] = word3;
> + desc[4] = CS_NE_HDRA_CPU_PKT | FIELD_PREP(TX_HDRA_DVOQ, port->id * 8);
> + desc[5] = 0;
> + desc[6] = 0;
> + desc[7] = 0;
> + dma_wmb();
> + desc[0] = TX_DESC_OWN | TX_DESC_SOF | TX_DESC_EOF |
> + FIELD_PREP(TX_DESC_LEN, len);
[Severity: Low]
Can this open-coded descriptor setup reuse cs_ne_tx_desc(txq, port->id,
dma, len, len, true, true)?
Similarly, cs_ne_tx_complete(), cs_ne_xmit_sg(), and cs_ne_start_xmit()
open-code the ring free-space expression instead of calling
cs_ne_tx_free(txq), and cs_ne_dma_init() redundantly re-initializes
txq->ne, txq->stopping, and txq->lock after cs_ne_probe() already did.
[ ... ]
> + port = netdev_priv(ndev);
> + port->ne = ne;
> + port->ndev = ndev;
> + port->np = np;
> + port->id = id;
[ ... ]
> + ndev->dev.of_node = np;
[Severity: Medium]
Does storing np in port->np and ndev->dev.of_node need of_node_get(np)
with a matching of_node_put(port->np) in cs_ne_port_cleanup()?
cs_ne_probe() iterates child nodes with
for_each_available_child_of_node(), which drops its reference to np
when the loop advances or exits. port->np is later passed to
phylink_of_phy_connect() in cs_ne_open(), so without taking a reference
it risks a use-after-free under CONFIG_OF_DYNAMIC overlay removal.
[ ... ]
> 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..5886c1bc57a86
> --- /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;
> +
> + ret = cs752x_sch_enable_port(dev, sch, port);
> + if (ret)
> + return ret;
> + ret = cs752x_sch_set_port_burst(dev, sch, port, 0);
> + if (ret)
> + return ret;
> + ret = cs752x_sch_bypass_shaper(dev, sch, port + SCH_LT_BASE_ID, 0);
> + if (ret)
> + return ret;
> + ret = cs752x_sch_bypass_shaper(dev, sch, port + SCH_ST_BASE_ID, 0);
> + if (ret)
> + return ret;
> +
> + for (q = 0; q < SCH_MAX_PORT_QUEUE; q++) {
> + ret = cs752x_sch_enable_voq_drr(dev, sch,
> + port * SCH_MAX_PORT_QUEUE + q,
> + SCH_DEFAULT_QUANTA, cpu_port);
> + if (ret)
> + return ret;
> + ret = cs752x_sch_bypass_shaper(dev, sch,
> + port + SCH_DRR_BASE_ID,
> + cpu_port);
> + if (ret)
> + return ret;
> + }
> + }
[Severity: Medium]
Is cs752x_sch_bypass_shaper() inside the queue loop supposed to bypass
the per-VOQ shaper (port * SCH_MAX_PORT_QUEUE + q) rather than
repeating port + SCH_DRR_BASE_ID eight times per port?
Because port + SCH_DRR_BASE_ID does not depend on q, this sends 98
redundant atomic scheduler commands for the per-port DRR shapers while
leaving all 112 per-VOQ shapers (IDs 0..111) unprogrammed. Also, the
per-port LT and ST shaper bypass calls pass literal 0 instead of the
computed cpu_port.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-b4-cs7542-ethernet-v8-0-4b625ce9fe82@gmail.com?part=2
next prev parent reply other threads:[~2026-12-05 4:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 3:57 [PATCH net-next v8 0/3] Add Cortina Systems CS7542 network engine support Fil Dunsky via B4 Relay
2026-12-04 3:57 ` [PATCH net-next v8 1/3] dt-bindings: net: Add Cortina CS7542 network engine Fil Dunsky via B4 Relay
2026-12-04 3:57 ` [PATCH net-next v8 2/3] net: cortina: Add CS7542 CPU network datapath Fil Dunsky via B4 Relay
2026-12-05 4:20 ` sashiko-bot [this message]
2026-12-04 3:57 ` [PATCH net-next v8 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-251080@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