Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Daniel Zahka
Tue, 10 Nov 2026 22:06
[PATCH net-next v2 3/6] eth: mpnic: TCP segmentation offload
Author: Daniel Zahka
Date: Tue, 10 Nov 2026 22:06
Date: Tue, 10 Nov 2026 22:06
365 lines
23566 bytes
23566 bytes
Support segmentation of non-encapsulated tcp4/tcp6 packets. When doing
segmentation the device expects the l4 checksum to be seeded with 0
length.
IPv4 header and TCP checksums that compute to zero are sent as 0 rather
than 0xffff when the HW segments packets. IPv4 IDs are incrementing
starting from the value that is in the skb's IPv4 header.
Count gso wire packets and report via the netdev qstats API.
Completions are counted in wire packets, but dropped TSO skbs are still
counted once per super packet, matching the core's per skb tx_dropped
accounting that gets summed into the same counter.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
v2:
- count discarded skbs rather than segments in twq.dropped, matching
the xmit error path and the core's tx_dropped
- report only hw_gso_wire_packets; drop the super-packet counter
---
drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 27 ++++++++
drivers/net/ethernet/meta/mpnic/mpnic_init.c | 11 ++++
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 14 ++--
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 1 +
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 88 ++++++++++++++++++++++----
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 1 +
6 files changed, 125 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
index 1c86f114ab0c..672ce0a98c22 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
@@ -16,8 +16,21 @@
#define MPNIC_TWD_L2_HLEN DESC_GENMASK(5, 0)
#define MPNIC_TWD_L3_IHLEN DESC_GENMASK(23, 16)
#define MPNIC_TWD_CSUM_OFFSET DESC_GENMASK(27, 24)
+#define MPNIC_TWD_L4_HLEN DESC_GENMASK(31, 28)
+#define MPNIC_TWD_L4_TYPE DESC_GENMASK(33, 32)
+enum {
+ MPNIC_TWD_L4_TYPE_TCP = 1,
+};
+
+#define MPNIC_TWD_FLAG_REQ_LSO DESC_BIT(35)
#define MPNIC_TWD_FLAG_REQ_CSO DESC_BIT(36)
#define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37)
+#define MPNIC_TWD_L3_TYPE DESC_GENMASK(42, 40)
+enum {
+ MPNIC_TWD_L3_TYPE_IPV4 = 1,
+ MPNIC_TWD_L3_TYPE_IPV6 = 2,
+};
+
#define MPNIC_TWD_FLAG_DEST_MAC DESC_BIT(43)
#define MPNIC_TWD_TYPE DESC_GENMASK(47, 46)
enum {
@@ -26,6 +39,8 @@ enum {
MPNIC_TWD_TYPE_LAST_AL = 3,
};
+#define MPNIC_TWD_MSS DESC_GENMASK(61, 48)
+
#define MPNIC_TWD_ADDR DESC_GENMASK(45, 0)
#define MPNIC_TWD_LEN DESC_GENMASK(63, 48)
@@ -312,7 +327,19 @@ enum {
/* NIC_CORE_TOF */
#define MPNIC_TOF_TCAM_DEST_REMAP 0x7e3022 /* 0x1f8c088 */
#define MPNIC_TOF_MODE 0x7e302e /* 0x1f8c0b8 */
+#define MPNIC_TOF_MODE_IPV4_ID_MODE CSR_GENMASK(0, 0)
+enum {
+ MPNIC_IPV4_ID_MODE_FIXED = 0,
+ MPNIC_IPV4_ID_MODE_INCREMENT = 1,
+};
+
+#define MPNIC_TOF_MODE_IPV4_ZERO_CSUM CSR_BIT(1)
+#define MPNIC_TOF_MODE_TCP_ZERO_CSUM CSR_BIT(2)
#define MPNIC_TOF_MODE_L4_ZERO_CSUM CSR_BIT(4)
+#define MPNIC_TOF_TCP_FLAG_CLR 0x7e3030 /* 0x1f8c0c0 */
+#define MPNIC_TOF_TCP_FLAG_CLR_FIRST_SEGMENT CSR_GENMASK(8, 0)
+#define MPNIC_TOF_TCP_FLAG_CLR_MIDDLE_SEGMENT CSR_GENMASK(24, 16)
+#define MPNIC_TOF_TCP_FLAG_CLR_LAST_SEGMENT CSR_GENMASK(40, 32)
/* PEMO_WRAPPER */
#define MPNIC_OB_ATTR_RO CSR_BIT(1)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
index 71d13bec7ec4..b9a41656f8f7 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_init.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
@@ -8,6 +8,7 @@
#include <linux/iopoll.h>
#include <linux/log2.h>
#include <linux/sizes.h>
+#include <net/tcp.h>
#include "mpnic.h"
#include "mpnic_txrx.h"
@@ -299,7 +300,17 @@ static void mpnic_txglb_init(struct mpnic_dev *mpd)
*/
mpnic_wr64(mpd, MPNIC_TOF_TCAM_DEST_REMAP, 0);
mpnic_wr64(mpd, MPNIC_TOF_MODE,
+ FIELD_PREP(MPNIC_TOF_MODE_IPV4_ID_MODE,
+ MPNIC_IPV4_ID_MODE_INCREMENT) |
+ FIELD_PREP(MPNIC_TOF_MODE_IPV4_ZERO_CSUM, 1) |
+ FIELD_PREP(MPNIC_TOF_MODE_TCP_ZERO_CSUM, 1) |
FIELD_PREP(MPNIC_TOF_MODE_L4_ZERO_CSUM, 0));
+ mpnic_wr64(mpd, MPNIC_TOF_TCP_FLAG_CLR,
+ FIELD_PREP(MPNIC_TOF_TCP_FLAG_CLR_FIRST_SEGMENT,
+ TCPHDR_PSH | TCPHDR_FIN) |
+ FIELD_PREP(MPNIC_TOF_TCP_FLAG_CLR_MIDDLE_SEGMENT,
+ TCPHDR_PSH | TCPHDR_CWR | TCPHDR_FIN) |
+ FIELD_PREP(MPNIC_TOF_TCP_FLAG_CLR_LAST_SEGMENT, TCPHDR_CWR));
mpnic_wr64(mpd, MPNIC_TCM_MEM_INIT_REQ, MPNIC_MEM_INIT_TCM_VAL);
mpnic_wr64(mpd, MPNIC_TDE_MEM_INIT_REQ, MPNIC_MEM_INIT_TDE_VAL);
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index 35173f8999cb..bde327ad3154 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -207,9 +207,9 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
struct mpnic_ring *txr = mpn->tx[idx];
struct mpnic_queue_stats *stats;
u64 bytes, packets, stop, wake;
+ u64 csum_partial, hw_gso_wire;
struct mpnic_q_triad *qt;
unsigned int start;
- u64 csum_partial;
if (!txr)
return;
@@ -228,12 +228,14 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
do {
start = u64_stats_fetch_begin(&stats->syncp);
csum_partial = u64_stats_read(&stats->twq.csum_partial);
+ hw_gso_wire = u64_stats_read(&stats->twq.hw_gso_wire);
stop = u64_stats_read(&stats->twq.stop);
} while (u64_stats_fetch_retry(&stats->syncp, start));
tx->bytes = bytes;
tx->packets = packets;
- tx->needs_csum = csum_partial;
+ tx->needs_csum = csum_partial + hw_gso_wire;
+ tx->hw_gso_wire_packets = hw_gso_wire;
tx->stop = stop;
tx->wake = wake;
}
@@ -249,7 +251,8 @@ static void mpnic_get_base_stats(struct net_device *dev,
tx->bytes = base->tx.bytes;
tx->packets = base->tx.packets;
- tx->needs_csum = base->tx.csum_partial;
+ tx->needs_csum = base->tx.csum_partial + base->tx.hw_gso_wire;
+ tx->hw_gso_wire_packets = base->tx.hw_gso_wire;
tx->stop = base->tx.stop;
tx->wake = base->tx.wake;
@@ -322,7 +325,10 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
netdev->features |=
NETIF_F_SG |
NETIF_F_HW_CSUM |
- NETIF_F_RXCSUM;
+ NETIF_F_RXCSUM |
+ NETIF_F_TSO |
+ NETIF_F_TSO_ECN |
+ NETIF_F_TSO6;
netdev->hw_features |= netdev->features;
netdev->vlan_features |= netdev->features;
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h
index 76ec9811e79e..697b3ebb74b9 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h
@@ -17,6 +17,7 @@ struct mpnic_base_stats {
u64 bytes;
u64 dropped;
u64 csum_partial;
+ u64 hw_gso_wire;
u64 stop;
u64 wake;
} tx;
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
index a35ce8998409..b78f8599bbe8 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
@@ -16,11 +16,14 @@
struct mpnic_xmit_cb {
u32 bytecount;
+ u16 gso_segs;
u8 desc_count;
};
struct mpnic_tx_hdrs {
unsigned int i3len;
+ unsigned int l3_type;
+ unsigned int l4_type;
};
#define MPNIC_XMIT_CB(__skb) ((struct mpnic_xmit_cb *)((__skb)->cb))
@@ -215,30 +218,81 @@ mpnic_tx_map(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
static void mpnic_tx_fill_hdrs(struct sk_buff *skb, struct mpnic_tx_hdrs *hdrs)
{
- hdrs->i3len = skb_checksum_start(skb) - skb_network_header(skb);
+ if (!skb_is_gso(skb)) {
+ hdrs->i3len = skb_checksum_start(skb) - skb_network_header(skb);
+ return;
+ }
+
+ hdrs->l4_type = MPNIC_TWD_L4_TYPE_TCP;
+ hdrs->i3len = skb_transport_offset(skb) - skb_network_offset(skb);
+ hdrs->l3_type = ip_hdr(skb)->version == 4 ?
+ MPNIC_TWD_L3_TYPE_IPV4 : MPNIC_TWD_L3_TYPE_IPV6;
}
-static void
+static bool
+mpnic_tx_lso(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
+{
+ struct skb_shared_info *shinfo;
+ unsigned int l4len, hdrlen;
+ struct tcphdr *tcph;
+ __be16 payload_len;
+
+ if (skb_cow_head(skb, 0))
+ return true;
+
+ shinfo = skb_shinfo(skb);
+
+ tcph = (struct tcphdr *)skb_checksum_start(skb);
+ l4len = __tcp_hdrlen(tcph);
+ payload_len = cpu_to_be16(skb->len - skb_checksum_start_offset(skb));
+ csum_replace_by_diff(&tcph->check, (__force __wsum)payload_len);
+
+ *meta |= cpu_to_le64(FIELD_PREP(MPNIC_TWD_L4_HLEN, l4len / 4) |
+ FIELD_PREP(MPNIC_TWD_MSS, shinfo->gso_size) |
+ MPNIC_TWD_FLAG_REQ_LSO);
+
+ hdrlen = skb_checksum_start_offset(skb) + l4len;
+ MPNIC_XMIT_CB(skb)->bytecount += (shinfo->gso_segs - 1) * hdrlen;
+ MPNIC_XMIT_CB(skb)->gso_segs = shinfo->gso_segs;
+
+ u64_stats_update_begin(&ring->stats.syncp);
+ u64_stats_add(&ring->stats.twq.hw_gso_wire, shinfo->gso_segs);
+ u64_stats_update_end(&ring->stats.syncp);
+
+ return false;
+}
+
+static bool
mpnic_tx_offloads(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
{
struct mpnic_tx_hdrs hdrs = {};
if (skb->ip_summed != CHECKSUM_PARTIAL)
- return;
+ return false;
mpnic_tx_fill_hdrs(skb, &hdrs);
*meta |= cpu_to_le64(FIELD_PREP(MPNIC_TWD_CSUM_OFFSET,
- skb->csum_offset / 2) |
- MPNIC_TWD_FLAG_REQ_CSO);
+ skb->csum_offset / 2));
- u64_stats_update_begin(&ring->stats.syncp);
- u64_stats_inc(&ring->stats.twq.csum_partial);
- u64_stats_update_end(&ring->stats.syncp);
+ if (skb_is_gso(skb)) {
+ if (mpnic_tx_lso(ring, skb, meta))
+ return true;
+ } else {
+ *meta |= cpu_to_le64(MPNIC_TWD_FLAG_REQ_CSO);
+
+ u64_stats_update_begin(&ring->stats.syncp);
+ u64_stats_inc(&ring->stats.twq.csum_partial);
+ u64_stats_update_end(&ring->stats.syncp);
+ }
*meta |= cpu_to_le64(FIELD_PREP(MPNIC_TWD_L2_HLEN,
skb_mac_header_len(skb) / 2) |
- FIELD_PREP(MPNIC_TWD_L3_IHLEN, hdrs.i3len / 2));
+ FIELD_PREP(MPNIC_TWD_L3_IHLEN, hdrs.i3len / 2) |
+ FIELD_PREP(MPNIC_TWD_L3_TYPE, hdrs.l3_type) |
+ FIELD_PREP(MPNIC_TWD_L4_TYPE, hdrs.l4_type));
+
+ return false;
}
#define MPNIC_MIN_FRAME_LEN 60
@@ -261,9 +315,11 @@ static netdev_tx_t mpnic_xmit_frame_ring(struct sk_buff *skb,
*meta = cpu_to_le64(MPNIC_TWD_FLAG_DEST_MAC);
MPNIC_XMIT_CB(skb)->bytecount = skb->len;
+ MPNIC_XMIT_CB(skb)->gso_segs = 1;
MPNIC_XMIT_CB(skb)->desc_count = 0;
- mpnic_tx_offloads(ring, skb, meta);
+ if (mpnic_tx_offloads(ring, skb, meta))
+ goto err_free;
if (mpnic_tx_map(ring, skb, meta))
goto err_free;
@@ -312,6 +368,10 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb,
l2len + i3len + sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE > 256)
return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
+ if (skb_is_gso(skb) &&
+ !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size))
+ return features & ~NETIF_F_GSO_MASK;
+
return features;
}
@@ -319,7 +379,7 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget,
struct mpnic_q_triad *qt, bool discard,
unsigned int hw_head)
{
- u64 total_bytes = 0, total_packets = 0;
+ u64 total_bytes = 0, total_packets = 0, total_skbs = 0;
struct mpnic_ring *ring = &qt->sub0;
struct mpnic_ring *cmpl = &qt->cmpl;
unsigned int head = ring->head;
@@ -357,7 +417,8 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget,
}
total_bytes += MPNIC_XMIT_CB(skb)->bytecount;
- total_packets++;
+ total_packets += MPNIC_XMIT_CB(skb)->gso_segs;
+ total_skbs++;
napi_consume_skb(skb, napi_budget);
}
@@ -370,7 +431,7 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget,
if (discard) {
local_bh_disable();
u64_stats_update_begin(&ring->stats.syncp);
- u64_stats_add(&ring->stats.twq.dropped, total_packets);
+ u64_stats_add(&ring->stats.twq.dropped, total_skbs);
u64_stats_update_end(&ring->stats.syncp);
local_bh_enable();
return;
@@ -811,6 +872,7 @@ static void mpnic_aggregate_ring_twq_counters(struct mpnic_base_stats *base,
{
base->tx.dropped += u64_stats_read(&twq->stats.twq.dropped);
base->tx.csum_partial += u64_stats_read(&twq->stats.twq.csum_partial);
+ base->tx.hw_gso_wire += u64_stats_read(&twq->stats.twq.hw_gso_wire);
base->tx.stop += u64_stats_read(&twq->stats.twq.stop);
}
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h
index 714f09f4160e..0d732ac4dde9 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h
@@ -90,6 +90,7 @@ struct mpnic_queue_stats {
struct {
u64_stats_t dropped;
u64_stats_t csum_partial;
+ u64_stats_t hw_gso_wire;
u64_stats_t stop;
} twq;
struct {
--
2.52.0
Re: [PATCH net-next v2 3/6] eth: mpnic: TCP segmentation offload
Author: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 10:08
Date: Thu, 12 Nov 2026 10:08
133 lines
13393 bytes
13393 bytes
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] At this commit, mpnic_xmit_frame_ring() (drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:306) calls… - [Medium] eth: mpnic: GSO validation bypass in mpnic_features_check() -- eth: mpnic: TCP segmentation offload This adds hardware segmentation for non-encapsulated TCPv4/TCPv6 packets to the mpnic driver. It also programs the TOF mode and TCP flag clear registers, and reports hw_gso_wire_packets through the netdev qstats API. > diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c > index a35ce8998409d..b78f8599bbe8f 100644 > --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c > +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c [ ... ] > @@ -312,6 +368,10 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb, > l2len + i3len + sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE > 256) > return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); > > + if (skb_is_gso(skb) && > + !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size)) > + return features & ~NETIF_F_GSO_MASK; > + > return features; > } [Severity: Medium] Does this MSS check cover every GSO skb that reaches mpnic_tx_lso()? Earlier in mpnic_features_check() there is an early return when skb->ip_summed != CHECKSUM_PARTIAL. For those skbs, neither the header geometry checks above nor the new gso_size check run, and NETIF_F_TSO and NETIF_F_TSO6 stay set. Those skbs can still end up offloaded. __virtio_net_hdr_to_skb() accepts VIRTIO_NET_HDR_GSO_TCPV4/TCPV6 without VIRTIO_NET_HDR_F_NEEDS_CSUM. So a tap or virtio guest, or a PACKET_VNET_HDR sender, can hand us a GSO skb with CHECKSUM_NONE and SKB_GSO_DODGY. The path from there looks like this: - validate_xmit_skb() sees netif_needs_gso() and calls skb_gso_segment(). - tcp4_gso_segment() or tcp6_gso_segment() seeds the pseudo-header checksum and switches ip_summed to CHECKSUM_PARTIAL. - tcp_gso_segment() then returns NULL, because skb_gso_ok() is still true for the advertised features. The original skb then goes to mpnic_xmit_frame() unsegmented, having skipped every check in this function. In mpnic_tx_lso(), shinfo->gso_size then goes into the 14-bit MPNIC_TWD_MSS field unchecked. gso_features_check() only bounds gso_segs and skb->len. A gso_size of 16384 with a total length under 64K therefore gets through, and FIELD_PREP() truncates it to an MSS of 0. The header lengths that mpnic_tx_offloads() writes into MPNIC_TWD_L2_HLEN and MPNIC_TWD_L3_IHLEN are also unvalidated for these skbs. The same goes for the even-length and 256 byte header limits. Here the transport header was set by the flow dissector, not by a trusted stack. What does the hardware do with an MSS of 0, or with truncated header lengths? At best it seems to put malformed segments on the wire. I see two possible fixes, and I'm not sure which you'd prefer: - Clear NETIF_F_GSO_MASK for GSO skbs that are not CHECKSUM_PARTIAL yet. - Move the gso_size check above the early return, and validate the headers from skb_transport_header() in that case. Either way, this patch is the one that turns TSO on, so the fix probably belongs here. [Severity: Medium] Can a TCP GSO skb shorter than MPNIC_MIN_FRAME_LEN get to hardware LSO here? The only GSO fallback in this check is for a gso_size that doesn't fit MPNIC_TWD_MSS. Eth + IPv4 + TCP headers add up to 54 bytes, so a TCPv4 GSO skb can be 56 bytes long with gso_size 1 and gso_segs 2. mpnic_xmit_frame_ring() pads every skb before the offloads are set up: if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN)) goto err_drop; That puts the zero pad inside the buffer lengths that mpnic_tx_map() programs. Will the LSO engine then segment the pad as TCP payload? That would produce more wire segments than shinfo->gso_segs, carrying zero bytes at sequence numbers past the real data. The checksum seed also looks wrong for these skbs. mpnic_tx_lso() takes the length out of the pseudo-header using the padded skb->len: payload_len = cpu_to_be16(skb->len - skb_checksum_start_offset(skb)); csum_replace_by_diff(&tcph->check, (__force __wsum)payload_len); The sender, or tcp4_gro_complete(), seeded tcph->check with the unpadded L4 length. So the seed ends up off by the pad size. Won't every segment the hardware generates then carry a bad TCP checksum? One way to reach this is a remote peer sending back-to-back non-PSH 1-byte segments. A forwarding host GRO-merges them and sends them out an mpnic port. tun/tap/virtio and PACKET_VNET_HDR sources can also build such skbs. Now that NETIF_F_TSO is advertised, these skbs reach the driver unsegmented. Before this patch GSO was never offloaded, so the padding did no harm. The next patch in the series, "eth: mpnic: UDP segmentation offload", adds skb->len < MPNIC_MIN_FRAME_LEN to this condition. Could that check move into this patch, so this commit doesn't send bad segments on its own? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261110-mpnic-lso-v2-0-ccd37b051d08%40gmail.com
Re: [PATCH net-next v2 3/6] eth: mpnic: TCP segmentation offload
Author: "Daniel Zahka"
Date: Thu, 12 Nov 2026 11:49
Date: Thu, 12 Nov 2026 11:49
149 lines
17382 bytes
17382 bytes
On Thu Nov 12, 2026 at 5:08 AM EST, netdev-bot+sashiko wrote: > Thank you for your contribution! Sashiko AI review found 2 potential > issue(s) to consider. > > Critical: 0 · High: 0 · Medium: 2 · Low: 0 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwork > know by including "pw-bot: cr" as a separate line at the end of your reply > (one such reply per series is enough). > > - [Medium] At this commit, mpnic_xmit_frame_ring() > (drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:306) calls… > - [Medium] eth: mpnic: GSO validation bypass in mpnic_features_check() > > -- > > eth: mpnic: TCP segmentation offload > > This adds hardware segmentation for non-encapsulated TCPv4/TCPv6 packets > to the mpnic driver. It also programs the TOF mode and TCP flag clear > registers, and reports hw_gso_wire_packets through the netdev qstats API. > >> diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c >> index a35ce8998409d..b78f8599bbe8f 100644 >> --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c >> +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c > > [ ... ] > >> @@ -312,6 +368,10 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb, >> l2len + i3len + sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE > 256) >> return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); >> >> + if (skb_is_gso(skb) && >> + !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size)) >> + return features & ~NETIF_F_GSO_MASK; >> + >> return features; >> } > > [Severity: Medium] > Does this MSS check cover every GSO skb that reaches mpnic_tx_lso()? > Earlier in mpnic_features_check() there is an early return when > skb->ip_summed != CHECKSUM_PARTIAL. For those skbs, neither the header > geometry checks above nor the new gso_size check run, and NETIF_F_TSO > and NETIF_F_TSO6 stay set. > > Those skbs can still end up offloaded. __virtio_net_hdr_to_skb() > accepts VIRTIO_NET_HDR_GSO_TCPV4/TCPV6 without > VIRTIO_NET_HDR_F_NEEDS_CSUM. So a tap or virtio guest, or a > PACKET_VNET_HDR sender, can hand us a GSO skb with CHECKSUM_NONE and > SKB_GSO_DODGY. > > The path from there looks like this: > > - validate_xmit_skb() sees netif_needs_gso() and calls > skb_gso_segment(). > - tcp4_gso_segment() or tcp6_gso_segment() seeds the pseudo-header > checksum and switches ip_summed to CHECKSUM_PARTIAL. > - tcp_gso_segment() then returns NULL, because skb_gso_ok() is still > true for the advertised features. > > The original skb then goes to mpnic_xmit_frame() unsegmented, having > skipped every check in this function. > > In mpnic_tx_lso(), shinfo->gso_size then goes into the 14-bit > MPNIC_TWD_MSS field unchecked. gso_features_check() only bounds > gso_segs and skb->len. A gso_size of 16384 with a total length under > 64K therefore gets through, and FIELD_PREP() truncates it to an MSS > of 0. > > The header lengths that mpnic_tx_offloads() writes into > MPNIC_TWD_L2_HLEN and MPNIC_TWD_L3_IHLEN are also unvalidated for > these skbs. The same goes for the even-length and 256 byte header > limits. Here the transport header was set by the flow dissector, not > by a trusted stack. > > What does the hardware do with an MSS of 0, or with truncated header > lengths? At best it seems to put malformed segments on the wire. > > I see two possible fixes, and I'm not sure which you'd prefer: > > - Clear NETIF_F_GSO_MASK for GSO skbs that are not CHECKSUM_PARTIAL > yet. This came up in a local sashiko run, but I declined it. The issue is from vnet headers that request gso without csum. A handful of drivers have an early return passing through the features if the skb is not CHECKSUM_PARTIAL. Seems like something core might want to handle. > - Move the gso_size check above the early return, and validate the > headers from skb_transport_header() in that case. > > Either way, this patch is the one that turns TSO on, so the fix > probably belongs here. > > [Severity: Medium] > Can a TCP GSO skb shorter than MPNIC_MIN_FRAME_LEN get to hardware LSO > here? The only GSO fallback in this check is for a gso_size that doesn't > fit MPNIC_TWD_MSS. Eth + IPv4 + TCP headers add up to 54 bytes, so a TCPv4 > GSO skb can be 56 bytes long with gso_size 1 and gso_segs 2. > This is the same feedback I addressed in the udp segmentation patch. Shouldn't really be reachable for TSO skbs, but the check is there in the next patch anyway. > mpnic_xmit_frame_ring() pads every skb before the offloads are set up: > > if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN)) > goto err_drop; > > That puts the zero pad inside the buffer lengths that mpnic_tx_map() > programs. Will the LSO engine then segment the pad as TCP payload? That > would produce more wire segments than shinfo->gso_segs, carrying zero > bytes at sequence numbers past the real data. > > The checksum seed also looks wrong for these skbs. mpnic_tx_lso() takes > the length out of the pseudo-header using the padded skb->len: > > payload_len = cpu_to_be16(skb->len - skb_checksum_start_offset(skb)); > csum_replace_by_diff(&tcph->check, (__force __wsum)payload_len); > > The sender, or tcp4_gro_complete(), seeded tcph->check with the unpadded > L4 length. So the seed ends up off by the pad size. Won't every segment > the hardware generates then carry a bad TCP checksum? > > One way to reach this is a remote peer sending back-to-back non-PSH > 1-byte segments. A forwarding host GRO-merges them and sends them out an > mpnic port. tun/tap/virtio and PACKET_VNET_HDR sources can also build > such skbs. > > Now that NETIF_F_TSO is advertised, these skbs reach the driver > unsegmented. Before this patch GSO was never offloaded, so the padding > did no harm. > > The next patch in the series, "eth: mpnic: UDP segmentation offload", > adds skb->len < MPNIC_MIN_FRAME_LEN to this condition. Could that check > move into this patch, so this commit doesn't send bad segments on its own?
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