Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Daniel Zahka
Tue, 10 Nov 2026 22:06
[PATCH net-next v2 4/6] eth: mpnic: UDP segmentation offload
Author: Daniel Zahka
Date: Tue, 10 Nov 2026 22:06
Date: Tue, 10 Nov 2026 22:06
144 lines
16145 bytes
16145 bytes
Support segmentation of non-encapsulated udp4/udp6 packets. Like for
tcp, the segmentation engine expects the udp csum to be seeded with 0
length.
The HW inverts UDP checksums computed as 0 during segmentation.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
v2:
- fall back to SW GSO for skbs shorter than MPNIC_MIN_FRAME_LEN, since
HW LSO would segment the zero padding as payload
---
drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 2 ++
drivers/net/ethernet/meta/mpnic/mpnic_init.c | 1 +
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 3 ++-
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 36 +++++++++++++++++++-------
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
index 672ce0a98c22..2cd627d62bf5 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
@@ -20,6 +20,7 @@
#define MPNIC_TWD_L4_TYPE DESC_GENMASK(33, 32)
enum {
MPNIC_TWD_L4_TYPE_TCP = 1,
+ MPNIC_TWD_L4_TYPE_UDP = 2,
};
#define MPNIC_TWD_FLAG_REQ_LSO DESC_BIT(35)
@@ -335,6 +336,7 @@ enum {
#define MPNIC_TOF_MODE_IPV4_ZERO_CSUM CSR_BIT(1)
#define MPNIC_TOF_MODE_TCP_ZERO_CSUM CSR_BIT(2)
+#define MPNIC_TOF_MODE_UDP_ZERO_CSUM CSR_BIT(3)
#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)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
index b9a41656f8f7..ab832ec5de0e 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_init.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
@@ -304,6 +304,7 @@ static void mpnic_txglb_init(struct mpnic_dev *mpd)
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_UDP_ZERO_CSUM, 0) |
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,
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index bde327ad3154..bf3b459ba5be 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -328,7 +328,8 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
NETIF_F_RXCSUM |
NETIF_F_TSO |
NETIF_F_TSO_ECN |
- NETIF_F_TSO6;
+ NETIF_F_TSO6 |
+ NETIF_F_GSO_UDP_L4;
netdev->hw_features |= netdev->features;
netdev->vlan_features |= netdev->features;
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
index b78f8599bbe8..2a0560b7dd19 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
@@ -223,29 +223,44 @@ static void mpnic_tx_fill_hdrs(struct sk_buff *skb, struct mpnic_tx_hdrs *hdrs)
return;
}
- hdrs->l4_type = MPNIC_TWD_L4_TYPE_TCP;
+ if (skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))
+ hdrs->l4_type = MPNIC_TWD_L4_TYPE_TCP;
+ else
+ hdrs->l4_type = MPNIC_TWD_L4_TYPE_UDP;
+
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 bool
-mpnic_tx_lso(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
+mpnic_tx_lso(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta,
+ const struct mpnic_tx_hdrs *hdrs)
{
struct skb_shared_info *shinfo;
unsigned int l4len, hdrlen;
- struct tcphdr *tcph;
- __be16 payload_len;
+ unsigned char *l4hdr;
if (skb_cow_head(skb, 0))
return true;
shinfo = skb_shinfo(skb);
+ l4hdr = skb_checksum_start(skb);
+
+ if (hdrs->l4_type == MPNIC_TWD_L4_TYPE_TCP) {
+ struct tcphdr *tcph = (struct tcphdr *)l4hdr;
+ __be16 payload_len;
- 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);
+ 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);
+ } else {
+ struct udphdr *udph = (struct udphdr *)l4hdr;
+
+ l4len = sizeof(*udph);
+ csum_replace_by_diff(&udph->check, (__force __wsum)udph->len);
+ }
*meta |= cpu_to_le64(FIELD_PREP(MPNIC_TWD_L4_HLEN, l4len / 4) |
FIELD_PREP(MPNIC_TWD_MSS, shinfo->gso_size) |
@@ -276,7 +291,7 @@ mpnic_tx_offloads(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
skb->csum_offset / 2));
if (skb_is_gso(skb)) {
- if (mpnic_tx_lso(ring, skb, meta))
+ if (mpnic_tx_lso(ring, skb, meta, &hdrs))
return true;
} else {
*meta |= cpu_to_le64(MPNIC_TWD_FLAG_REQ_CSO);
@@ -369,7 +384,8 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb,
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))
+ (skb->len < MPNIC_MIN_FRAME_LEN ||
+ !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size)))
return features & ~NETIF_F_GSO_MASK;
return features;
--
2.52.0
Re: [PATCH net-next v2 4/6] eth: mpnic: UDP segmentation offload
Author: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 10:08
Date: Thu, 12 Nov 2026 10:08
88 lines
11246 bytes
11246 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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] This patch adds `skb->len < MPNIC_MIN_FRAME_LEN ||` to the
generic `skb_is_gso(skb)` branch of mpnic_features_check()…
--
eth: mpnic: UDP segmentation offload
This commit adds NETIF_F_GSO_UDP_L4 support for non-encapsulated udp4
and udp6 packets. As for TCP, the UDP checksum is seeded with a zero
length. It also makes mpnic_features_check() fall back to software GSO
for skbs shorter than MPNIC_MIN_FRAME_LEN.
> diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
> index b78f8599bbe8f..2a0560b7dd19e 100644
> --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
> +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
[ ... ]
> @@ -369,7 +384,8 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb,
> 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))
> + (skb->len < MPNIC_MIN_FRAME_LEN ||
> + !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size)))
> return features & ~NETIF_F_GSO_MASK;
[Severity: Medium]
This check applies to every GSO type. That means TCP GSO skbs shorter
than 60 bytes now fall back to software GSO too, not just UDP ones.
The commit message body only talks about UDP. The only mention of this
check is the v2 changelog below the "---", and that text is dropped when
the patch is applied:
v2:
- fall back to SW GSO for skbs shorter than MPNIC_MIN_FRAME_LEN, since
HW LSO would segment the zero padding as payload
Should the commit message describe the effect on TCP? Or should the
check move into the earlier "eth: mpnic: TCP segmentation offload"
patch?
With only the TSO patch applied, TCP seems to have the same problem. In
that version, mpnic_features_check() rejected GSO only when gso_size
didn't fit MPNIC_TWD_MSS. So a short TCP GSO skb reaches
mpnic_xmit_frame_ring() with HW TSO enabled, and gets padded first:
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:mpnic_xmit_frame_ring() {
...
if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN))
goto err_drop;
...
}
Then mpnic_tx_lso() seeds the TCP pseudo-checksum from the padded
length:
payload_len = cpu_to_be16(skb->len - skb_checksum_start_offset(skb));
csum_replace_by_diff(&tcph->check, (__force __wsum)payload_len);
Locally generated TCP GSO skbs are always longer than 60 bytes. A GSO
skb built from a virtio_net_hdr can be shorter, though. Sources include
tun/vhost and packet sockets with a vnet header. Such an skb can carry
a tiny gso_size and only a few bytes of payload.
In that case, wouldn't the receiver get the zero padding as TCP stream
data, with a valid checksum?
The check is still present at the end of the series, so the final tree
is fine. The TSO commit on its own would still corrupt data if someone
bisects to it or backports it alone.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261110-mpnic-lso-v2-0-ccd37b051d08%40gmail.com
Re: [PATCH net-next v2 4/6] eth: mpnic: UDP segmentation offload
Author: "Daniel Zahka"
Date: Thu, 12 Nov 2026 11:03
Date: Thu, 12 Nov 2026 11:03
98 lines
15094 bytes
15094 bytes
On Thu Nov 12, 2026 at 5:08 AM EST, netdev-bot+sashiko wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · 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] This patch adds `skb->len < MPNIC_MIN_FRAME_LEN ||` to the
> generic `skb_is_gso(skb)` branch of mpnic_features_check()…
>
> --
>
> eth: mpnic: UDP segmentation offload
>
> This commit adds NETIF_F_GSO_UDP_L4 support for non-encapsulated udp4
> and udp6 packets. As for TCP, the UDP checksum is seeded with a zero
> length. It also makes mpnic_features_check() fall back to software GSO
> for skbs shorter than MPNIC_MIN_FRAME_LEN.
>
>> diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
>> index b78f8599bbe8f..2a0560b7dd19e 100644
>> --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
>> +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
>
> [ ... ]
>
>> @@ -369,7 +384,8 @@ netdev_features_t mpnic_features_check(struct sk_buff *skb,
>> 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))
>> + (skb->len < MPNIC_MIN_FRAME_LEN ||
>> + !FIELD_FIT(MPNIC_TWD_MSS, skb_shinfo(skb)->gso_size)))
>> return features & ~NETIF_F_GSO_MASK;
>
> [Severity: Medium]
> This check applies to every GSO type. That means TCP GSO skbs shorter
> than 60 bytes now fall back to software GSO too, not just UDP ones.
>
> The commit message body only talks about UDP. The only mention of this
> check is the v2 changelog below the "---", and that text is dropped when
> the patch is applied:
>
> v2:
> - fall back to SW GSO for skbs shorter than MPNIC_MIN_FRAME_LEN, since
> HW LSO would segment the zero padding as payload
>
> Should the commit message describe the effect on TCP? Or should the
> check move into the earlier "eth: mpnic: TCP segmentation offload"
> patch?
>
> With only the TSO patch applied, TCP seems to have the same problem. In
> that version, mpnic_features_check() rejected GSO only when gso_size
> didn't fit MPNIC_TWD_MSS. So a short TCP GSO skb reaches
> mpnic_xmit_frame_ring() with HW TSO enabled, and gets padded first:
>
> drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:mpnic_xmit_frame_ring() {
> ...
> if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN))
> goto err_drop;
> ...
> }
>
> Then mpnic_tx_lso() seeds the TCP pseudo-checksum from the padded
> length:
>
> payload_len = cpu_to_be16(skb->len - skb_checksum_start_offset(skb));
> csum_replace_by_diff(&tcph->check, (__force __wsum)payload_len);
>
> Locally generated TCP GSO skbs are always longer than 60 bytes. A GSO
> skb built from a virtio_net_hdr can be shorter, though. Sources include
> tun/vhost and packet sockets with a vnet header. Such an skb can carry
> a tiny gso_size and only a few bytes of payload.
>
Local sashiko review surfaced the same complaint and wanted me to pull
the check forward one commit. I decided against it. The UDP case is
easily reachable because the user chooses the gso size. I don't think
producing a TSO skb shorter than 60B is really possible. The
virtio_net_hdr cases should have a min GSO size of TCP_MIN_GSO_SIZE set
in virtio_net_hdr_to_skb().
> In that case, wouldn't the receiver get the zero padding as TCP stream
> data, with a valid checksum?
>
> The check is still present at the end of the series, so the final tree
> is fine. The TSO commit on its own would still corrupt data if someone
> bisects to it or backports it alone.
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