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=1796565908; b=C0izLqZwLbysixDubBFpqVzLT65k6KPtSOC8AZZbPoivqcPZOu9zNsOKcQ2FlqxeKGGW a3Q0o/val2shBIbOGtINKqf7JbZpqBS3bswgC9kXLxEOFsw3a37MwjJN/Uikf/FDI0tVx 6QNoj5OzbeMoH9FSk/4qJNwbxdjkIQnTpOt6y0UvKmK8zKeJLeLUQcRdfKSTa2Z1996AG MhxEmHfj9XcaMHPHTNXHGgZr0ff99w/SIdVXeuFSssDViPBMv5GdxSaGqPxKSvOtkQdUs avKj6B+zahH6Kq6RXSyxPUMcapEbmVZi7NwE8AZ8EvUksFEVyDb6mABoCKVyFRJzNgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796565908; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/REKQsN4xj5+XBKDReo+34GCV0oWgq2bRunnRmd/h24=; b=GG0P9ZAjAMBw0yJ96IPmlLQu9/6c/xn78U7BMzeor8Q+KekNjApmXRLo+4VJfqEZQVP9 d4F47sFOyYsQVWqNCdtUUJApGMLNMOH3G7+zDzr/EWmzzixwxnsLfPhWWacBukLsMogzl 757A2pYWzNpzh55+Tnc/VKvLVJcJ9o6D1W1+oFtWu3kwuV6muDi7XREvDkpEuZ7cyhNXM mXjitK1PNwNxRVsl5/oUBJftPBSFg0PC87c7jEHEejC3Mv0ZPM7uc+2y7z0QXlgd8rH61 lG9yXc3I3KWAmIvAmeXxGgXcnKa4yog88VjDUOJvhmwwAUukVd7HX8ihWWoIwoi7e3w== 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="hB1iw6N/"; 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 956EA606A321 for ; Sun, 6 Dec 2026 14:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hB1iw6N/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A7AB1F0093B; Sun, 6 Dec 2026 14:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796565908; bh=/REKQsN4xj5+XBKDReo+34GCV0oWgq2bRunnRmd/h24=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hB1iw6N/H2J+QZTQdA5leOAgT84UOTWfm6S2/NrQ1EOVtCTabWh4qaQhycgHk+45M sO/Pnrw25JeyCO3ZRsL55r5GA9BwfX8WMW8JjDEss9qmlXQ9N0MR1Dorirm9+2J/8L 4m1cHHFZ6a45RtDA39cTzSYKMIoFZTZA7hM+CT8z2QjOJCfFsWP/tekCUts2ZCkB1z j0zAF1h+ZwtNY+GEFL89ZhsQ/iynLlAC0VAsKSxwmTkNEt8cg9uQjjYsh6idVcL99p M0ck84yXIjfRKr5wiO+YDLi1Ry/TST0uoDvwXo4hiIbI2cV2kFQNuwc7aYswoNmLBE NnqwwC92tc/jg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next v9 2/3] net: cortina: Add CS7542 CPU network datapath Reply-To: sashiko-reviews@lists.linux.dev To: "Fil Dunsky" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261205-b4-cs7542-ethernet-v9-2-8fbf7e3314a5@gmail.com> References: <20261205-b4-cs7542-ethernet-v9-0-8fbf7e3314a5@gmail.com> <20261205-b4-cs7542-ethernet-v9-2-8fbf7e3314a5@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 14:05:07 +0000 X-Mailing-List: devicetree@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 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 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/ether= net/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 =3D 0; i < 12; i++) { > + for (j =3D 0; j < 8; j++) { > + ret =3D 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 =3D 0; i < 12; i++) { > + ret =3D 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 =3D &ne->txq; > + u32 val; > + > + txq->desc =3D dma_alloc_coherent(ne->dev, CS_NE_TX_DESC_NUM * 32, > + &txq->desc_dma, GFP_KERNEL); > + if (!txq->desc) > + return -ENOMEM; > + txq->ne =3D ne; > + txq->stopping =3D 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 !=3D 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 =3D 0; > + buf->state =3D 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 !=3D rptr) { > + buf =3D &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 =3D 0; > + } > + if (buf->skb) { > + dev_consume_skb_any(buf->skb); > + buf->skb =3D NULL; > + } > + tail =3D (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 =3D napi_alloc_skb(&port->napi, total); > + if (!skb) { > + DEV_STATS_INC(ndev, rx_dropped); > + goto recycle; > + } > + remaining =3D total; > + for (i =3D 0; i < nbufs && remaining; i++) { > + seg =3D min_t(u32, remaining, CS_NE_BUF_DATA_MAX - (off & 0xff)); > + data =3D cs_ne_rx_buf_cpu(ne, bufs[i], off, seg); > + if (!data) > + break; > + skb_put_data(skb, data, seg); > + remaining -=3D seg; > + off =3D 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 =3D FIELD_GET(XR_NEXT_LINK, w1); > + if (next =3D=3D wr) { > + wr =3D 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 =3D=3D wr) > + udelay(CS_NE_RX_TAIL_SETTLE_US); > + } > + rd =3D 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 =3D=3D rd can cause a NAPI live= lock 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 =3D=3D 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 =3D 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 =3D &txq->bufs[txq->head]; > + buf->skb =3D skb; > + buf->dma =3D dma; > + buf->len =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-b4-cs7542-= ethernet-v9-0-8fbf7e3314a5@gmail.com?part=3D2