enetc_start_xmit() uses tso_count_descs() to check whether the TX ring has enough free BDs for a software TSO frame. That estimates one header BD and one data BD per segment, plus one BD per frag. However, when the skb carries a VLAN tag, enetc_map_tx_tso_hdr() also adds an extension BD to every segment, which is not accounted for. With a highly segmented VLAN TSO skb and a nearly full ring, the driver can then write past next_to_clean and overwrite BDs still owned by the hardware. Add enetc_tso_count_descs() which accounts for the extension BD of each segment when VLAN insertion is needed. Fixes: fb8629e2cbfc ("net: enetc: add support for software TSO") Signed-off-by: Vladimir Oltean --- This comes from the previous patch set: https://lore.kernel.org/netdev/20261021145314.1435049-2-vladimir.oltean@nxp.com/ v1->v2: none old v5->v1: also patch enetc_features_check() old v4->old v5: patch is new --- drivers/net/ethernet/freescale/enetc/enetc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 1606ac57016f..7f089a84d9a6 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -674,6 +674,17 @@ static void enetc_tso_complete_csum(struct enetc_bdr *tx_ring, struct tso_t *tso } } +static int enetc_tso_count_descs(const struct sk_buff *skb) +{ + int count = tso_count_descs(skb); + + /* Each segment also needs an extension BD for VLAN insertion */ + if (skb_vlan_tag_present(skb)) + count += skb_shinfo(skb)->gso_segs; + + return count; +} + static int enetc_lso_count_descs(const struct sk_buff *skb) { /* 4 BDs: 1 BD for LSO header + 1 BD for extended BD + 1 BD @@ -1034,7 +1045,7 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *skb, count = enetc_lso_hw_offload(tx_ring, skb); } else { - if (enetc_bd_unused(tx_ring) < tso_count_descs(skb)) { + if (enetc_bd_unused(tx_ring) < enetc_tso_count_descs(skb)) { netif_stop_subqueue(ndev, tx_ring->index); return NETDEV_TX_BUSY; } @@ -1114,7 +1125,7 @@ netdev_features_t enetc_features_check(struct sk_buff *skb, if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb)) return features; - if (tso_count_descs(skb) >= priv->tx_bd_count) + if (enetc_tso_count_descs(skb) >= priv->tx_bd_count) features &= ~NETIF_F_GSO_MASK; return features; -- 2.53.0