Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Linus Walleij
Tue, 10 Nov 2026 22:13
[PATCH net-next v7 17/18] net: ethernet: cortina: Reject TX rings smaller than retained pointers
Author: Linus Walleij
Date: Tue, 10 Nov 2026 22:13
Date: Tue, 10 Nov 2026 22:13
101 lines
11306 bytes
11306 bytes
The hardware-owned TX read pointers can retain their positions when the
queues are rebuilt. After shrinking the TX ring with ethtool -G while
the interface is down, gmac_setup_txqs() copies those pointers into the
write and clean pointers without checking the new ring size. A retained
pointer outside the smaller ring can then index past both the skb table
and the coherent descriptor allocation.
Reject a TX ring size that cannot contain every retained read pointer,
before applying any RX ring changes in the same ethtool request. Check
again before allocating and programming the TX rings on open, including
for pointer state inherited from firmware. DMA is stopped at both checks.
Do not just mask the software pointers, which would leave the hardware
read pointer outside the new ring.
Found during Sashiko review and confirmed with a pointer arithmetic
model: a retained pointer of 200 with 16 entries reports 15 free entries
and permits the first TX write at index 200. Checked all 16-bit pointer
values against queue orders 0 through 15 and cross-built the driver for
ARM.
Tested on the D-Link DIR-685 with intense transfers and ping storms.
Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
drivers/net/ethernet/cortina/gemini.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 58d6ed81a59c..1007fd54cb05 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -568,6 +568,20 @@ static int gmac_init(struct net_device *netdev)
return 0;
}
+static bool gmac_txq_size_valid(struct net_device *netdev, unsigned int entries)
+{
+ struct gemini_ethernet_port *port = netdev_priv(netdev);
+ unsigned int i;
+
+ /* DMA is stopped, so the hardware read pointers cannot advance. */
+ for (i = 0; i < netdev->num_tx_queues; i++)
+ if (GET_RPTR(port->dma_base + GMAC_SW_TX_QUEUE_PTR_REG(i)) >=
+ entries)
+ return false;
+
+ return true;
+}
+
static int gmac_setup_txqs(struct net_device *netdev)
{
struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -582,6 +596,12 @@ static int gmac_setup_txqs(struct net_device *netdev)
unsigned int r;
int i;
+ if (!gmac_txq_size_valid(netdev, entries)) {
+ netdev_err(netdev,
+ "TX ring is too small for the retained read pointer\n");
+ return -EINVAL;
+ }
+
rwptr_reg = port->dma_base + GMAC_SW_TX_QUEUE0_PTR_REG;
skb_tab = kzalloc_objs(*skb_tab, len);
@@ -2581,11 +2601,21 @@ static int gmac_set_ringparam(struct net_device *netdev,
{
struct gemini_ethernet_port *port = netdev_priv(netdev);
unsigned int old_rxq_order;
+ unsigned int txq_order = port->txq_order;
int err = 0;
if (netif_running(netdev))
return -EBUSY;
+ if (rp->tx_pending) {
+ txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+ if (!gmac_txq_size_valid(netdev, BIT(txq_order))) {
+ NL_SET_ERR_MSG(extack,
+ "TX ring is too small for the retained read pointer");
+ return -EINVAL;
+ }
+ }
+
if (rp->rx_pending) {
old_rxq_order = port->rxq_order;
port->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
@@ -2596,7 +2626,7 @@ static int gmac_set_ringparam(struct net_device *netdev,
}
}
if (rp->tx_pending) {
- port->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+ port->txq_order = txq_order;
port->irq_every_tx_packets = 1 << (port->txq_order - 2);
}
--
2.56.0
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads