mirror of
https://github.com/torvalds/linux.git
synced 2026-09-11 20:13:02 +02:00
net: stmmac: fix TX descriptor availability check for TSO traffic
stmmac_tso_xmit() estimates the number of free TX descriptors required by
a TSO skb as:
(skb->len - proto_hdr_len) / TSO_MAX_BUFF_SIZE + 1
which assumes the payload is split into TSO_MAX_BUFF_SIZE chunks. This
underestimates the descriptors actually consumed by stmmac_tso_allocator(),
since each fragment is mapped individually and so it needs at least one
descriptor regardless of its size. Moreover, one descriptor is used for
the L2/L3/L4 headers and, when the MSS changes, one more is consumed for
the MSS context descriptor.
For a highly fragmented TSO skb the check can therefore pass even when the
ring has too few free slots. stmmac_tso_allocator() then writes past the
available descriptors, overwriting descriptors still owned by the DMA
engine, corrupting the TX ring.
Add stmmac_tso_get_num_desc() to compute the exact number of descriptors
needed for the header, the linear payload and each fragment, plus the MSS
context descriptor when required, and use it in the availability check.
Fixes: f748be531d ("stmmac: support new GMAC4")
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
Link: https://patch.msgid.link/20260907-stmmac-fix-tso-nfrags-check-v1-1-328459906cdb@oss.qualcomm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
2ac09b5353
commit
5e38d732ec
|
|
@ -4454,6 +4454,26 @@ static bool stmmac_tso_valid_packet(struct sk_buff *skb)
|
|||
header_len + gso_size < 16383;
|
||||
}
|
||||
|
||||
static int stmmac_tso_get_num_desc(struct stmmac_tx_queue *tx_q,
|
||||
struct sk_buff *skb, u32 pay_len)
|
||||
{
|
||||
int i, ndesc = 1;
|
||||
|
||||
/* head payload */
|
||||
ndesc += DIV_ROUND_UP(pay_len, TSO_MAX_BUFF_SIZE);
|
||||
/* frag payload */
|
||||
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
||||
const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
||||
|
||||
ndesc += DIV_ROUND_UP(skb_frag_size(frag),
|
||||
TSO_MAX_BUFF_SIZE);
|
||||
}
|
||||
/* MSS update requires a new descriptor */
|
||||
ndesc += !!(skb_shinfo(skb)->gso_size != tx_q->mss);
|
||||
|
||||
return ndesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* stmmac_tso_xmit - Tx entry point of the driver for oversized frames (TSO)
|
||||
* @skb : the socket buffer
|
||||
|
|
@ -4497,10 +4517,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||
struct stmmac_priv *priv = netdev_priv(dev);
|
||||
unsigned int first_entry, entry, tx_packets;
|
||||
struct stmmac_txq_stats *txq_stats;
|
||||
int i, first_tx, nfrags, ndesc;
|
||||
struct stmmac_tx_queue *tx_q;
|
||||
bool set_ic, is_last_segment;
|
||||
u32 pay_len, mss, queue;
|
||||
int i, first_tx, nfrags;
|
||||
u8 proto_hdr_len, hdr;
|
||||
dma_addr_t des;
|
||||
|
||||
|
|
@ -4513,14 +4533,15 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||
|
||||
/* Compute header lengths */
|
||||
proto_hdr_len = stmmac_tso_header_size(skb);
|
||||
pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */
|
||||
|
||||
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
|
||||
hdr = sizeof(struct udphdr);
|
||||
else
|
||||
hdr = tcp_hdrlen(skb);
|
||||
|
||||
/* Desc availability based on threshold should be enough safe */
|
||||
if (unlikely(stmmac_tx_avail(priv, queue) <
|
||||
(((skb->len - proto_hdr_len) / TSO_MAX_BUFF_SIZE + 1)))) {
|
||||
ndesc = stmmac_tso_get_num_desc(tx_q, skb, pay_len);
|
||||
if (unlikely(stmmac_tx_avail(priv, queue) < ndesc)) {
|
||||
if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, queue))) {
|
||||
netif_tx_stop_queue(netdev_get_tx_queue(priv->dev,
|
||||
queue));
|
||||
|
|
@ -4532,8 +4553,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||
return NETDEV_TX_BUSY;
|
||||
}
|
||||
|
||||
pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */
|
||||
|
||||
mss = skb_shinfo(skb)->gso_size;
|
||||
|
||||
/* set new MSS value if needed */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user