Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net-next] net: mana: add UDP segmentation offload support
@ 2026-11-30 23:14 Hamza Mahfooz
  2026-11-30 23:21 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Hamza Mahfooz @ 2026-11-30 23:14 UTC (permalink / raw)
  To: netdev
  Cc: Haiyang Zhang, Wei Liu, Dexuan Cui, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Wei Hu,
	Konstantin Taranov, Willem de Bruijn, Simon Horman, linux-hyperv,
	linux-rdma, Hamza Mahfooz

The hardware segments both TCP and UDP. In LSO mode it takes the L4
protocol from the parsed header, rewrites the IP total/payload length,
the IPv4 ID and the UDP length of each segment, and computes the L4
checksum from scratch. However, it reports a non-fatal error if neither
the TCP nor the UDP checksum offload bit is set in the TX OOB.

Advertise NETIF_F_GSO_UDP_L4 and, for SKB_GSO_UDP_L4 skbs, set
comp_udp_csum instead of comp_tcp_csum and seed the UDP checksum
rather than the TCP one. Everything else, including the header size
calculation in mana_get_gso_hs(), is shared with TSO.

Advertise this change to the PF with the new driver capability flag
GDMA_DRV_CAP_FLAG_1_UDP_SEGMENTATION_OFFLOAD.

Tested between two Azure Standard_E372is_v7 VMs on different hosts,
where the MANA device is the VM's only network interface. The changes
below are relative to the same kernel with tx-udp-segmentation turned
off.

udpgso_bench_tx, one sender pinned to a CPU, 61600 byte sends split
into 1400 byte segments, median of three 10 second runs:

                 throughput  CPU per byte
  IPv4                +307%          -84%
  IPv6                +348%          -84%
  IPv4 zerocopy       +498%          -80%
  IPv6 zerocopy       +190%          -79%

CPU is the user plus system time of the sending process. With USO a
single sender is no longer CPU bound. Its throughput varied widely,
both within and between runs, but its CPU time per byte did not.

With 8 IPv4 senders, each on its own core, the total throughput went
up by 432% while the senders' CPU usage went down by 51%. With the
default 212992 byte send buffer, a socket can only have about three
such sends in flight, so the rate also depends on TX completion
latency. With net.core.wmem_default raised to 4 MiB, 8, 16 and 32
senders all came close to the VMs' network limit, with 604% to 656%
more throughput than software GSO.

Uploads with msquic's secnetperf (which uses UDP_SEGMENT):

                 throughput  CPU per byte
  1 connection         +39%          -48%
  8 connections       +104%          -56%

IPv6 results were similar. Sending without GSO is unaffected.

NOTE: netvsc does not advertise NETIF_F_GSO_UDP_L4. On VMs with
accelerated networking, where traffic goes through the netvsc device
and is then passed to the VF, UDP GSO packets are therefore still
segmented in software until netvsc supports USO as well. Where the
MANA device is the VM's network interface, as in the tests above,
this patch is enough.

Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
---
 drivers/net/ethernet/microsoft/mana/mana_en.c | 26 ++++++++++++-------
 include/net/mana/gdma.h                       |  6 ++++-
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 95bf153c3e1a8..b8c21e26a2aeb 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -441,6 +441,9 @@ netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev,
 		ipv6 = true;
 
 	if (skb_is_gso(skb)) {
+		bool is_uso = skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4;
+		u8 l4_proto = is_uso ? IPPROTO_UDP : IPPROTO_TCP;
+		__sum16 *l4_check;
 		int num_sge;
 
 		gso_hs = mana_get_gso_hs(skb);
@@ -465,7 +468,13 @@ netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev,
 		pkg.tx_oob.s_oob.is_outer_ipv6 = ipv6;
 
 		pkg.tx_oob.s_oob.comp_iphdr_csum = 1;
-		pkg.tx_oob.s_oob.comp_tcp_csum = 1;
+		if (is_uso) {
+			pkg.tx_oob.s_oob.comp_udp_csum = 1;
+			l4_check = &udp_hdr(skb)->check;
+		} else {
+			pkg.tx_oob.s_oob.comp_tcp_csum = 1;
+			l4_check = &tcp_hdr(skb)->check;
+		}
 		pkg.tx_oob.s_oob.trans_off = skb_transport_offset(skb);
 
 		pkg.wqe_req.client_data_unit = skb_shinfo(skb)->gso_size;
@@ -473,16 +482,14 @@ netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev,
 		if (ipv4) {
 			ip_hdr(skb)->tot_len = 0;
 			ip_hdr(skb)->check = 0;
-			tcp_hdr(skb)->check =
-				~csum_tcpudp_magic(ip_hdr(skb)->saddr,
-						   ip_hdr(skb)->daddr, 0,
-						   IPPROTO_TCP, 0);
+			*l4_check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
+						       ip_hdr(skb)->daddr, 0,
+						       l4_proto, 0);
 		} else {
 			ipv6_hdr(skb)->payload_len = 0;
-			tcp_hdr(skb)->check =
-				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						 &ipv6_hdr(skb)->daddr, 0,
-						 IPPROTO_TCP, 0);
+			*l4_check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
+						     &ipv6_hdr(skb)->daddr, 0,
+						     l4_proto, 0);
 		}
 	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
 		csum_type = mana_checksum_info(skb);
@@ -4000,6 +4007,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
 	ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 	ndev->hw_features |= NETIF_F_RXCSUM;
 	ndev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
+	ndev->hw_features |= NETIF_F_GSO_UDP_L4;
 	ndev->hw_features |= NETIF_F_RXHASH;
 	ndev->features = ndev->hw_features | NETIF_F_HW_VLAN_CTAG_TX |
 			 NETIF_F_HW_VLAN_CTAG_RX;
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index e17219a29fa5f..7d957241ee0c1 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -783,6 +783,9 @@ enum {
 /* Enforce min 1 usec, 1 frames for Interrupt Moderation */
 #define GDMA_DRV_CAP_FLAG_1_SET_MIN_INTR_MOD_VALUE BIT_ULL(33)
 
+/* Driver supports USO */
+#define GDMA_DRV_CAP_FLAG_1_UDP_SEGMENTATION_OFFLOAD BIT_ULL(35)
+
 /* Capabilities in the PCI-only group below rely on dynamic MSI-X allocation
  * and on the servicing and reset paths reached through
  * mana_schedule_serv_work(). Transports that provide neither leave
@@ -809,7 +812,8 @@ enum {
 	 GDMA_DRV_CAP_FLAG_1_DYN_INTERRUPT_MODERATION | \
 	 GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS | \
 	 GDMA_DRV_CAP_FLAG_1_THROTTLED_EVENT_QUEUE | \
-	 GDMA_DRV_CAP_FLAG_1_SET_MIN_INTR_MOD_VALUE)
+	 GDMA_DRV_CAP_FLAG_1_SET_MIN_INTR_MOD_VALUE | \
+	 GDMA_DRV_CAP_FLAG_1_UDP_SEGMENTATION_OFFLOAD)
 
 #define GDMA_DRV_CAP_FLAGS2 0
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: mana: add UDP segmentation offload support
  2026-11-30 23:14 [PATCH net-next] net: mana: add UDP segmentation offload support Hamza Mahfooz
@ 2026-11-30 23:21 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 23:21 UTC (permalink / raw)
  To: Hamza Mahfooz; +Cc: linux-rdma

> The hardware segments both TCP and UDP. In LSO mode it takes the L4
> protocol from the parsed header, rewrites the IP total/payload length,
> the IPv4 ID and the UDP length of each segment, and computes the L4
> checksum from scratch. However, it reports a non-fatal error if neither
> the TCP nor the UDP checksum offload bit is set in the TX OOB.
> 
> Advertise NETIF_F_GSO_UDP_L4 and, for SKB_GSO_UDP_L4 skbs, set
> comp_udp_csum instead of comp_tcp_csum and seed the UDP checksum
> rather than the TCP one. Everything else, including the header size
> calculation in mana_get_gso_hs(), is shared with TSO.
> 
> Advertise this change to the PF with the new driver capability flag
> GDMA_DRV_CAP_FLAG_1_UDP_SEGMENTATION_OFFLOAD.
> 
> Tested between two Azure Standard_E372is_v7 VMs on different hosts,
> [ ... ]
> segmented in software until netvsc supports USO as well. Where the
> MANA device is the VM's network interface, as in the tests above,
> this patch is enough.
> 
> Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130231409.2567518-1-hamzamahfooz@linux.microsoft.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 23:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 23:14 [PATCH net-next] net: mana: add UDP segmentation offload support Hamza Mahfooz
2026-11-30 23:21 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox