* [PATCH net v2] gve: fix checksum state and gso_segs of HW-GRO packets
@ 2026-11-16 22:43 Joshua Washington
2026-11-17 23:32 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Joshua Washington @ 2026-11-16 22:43 UTC (permalink / raw)
To: netdev
Cc: Joshua Washington, Harshitha Ramamurthy, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Jordan Rhee, Ankit Garg, Tim Hostetler, Willem de Bruijn,
linux-kernel, stable, Praveen Kaligineedi
From: Ankit Garg <nktgrg@google.com>
With HW-GRO enabled, gve_rx_complete_rsc() turns a coalesced packet into
a GSO skb by setting gso_size, gso_segs and gso_type, but leaves it
CHECKSUM_UNNECESSARY with th->check as the device wrote it. Unlike
tcp4_gro_complete() and tcp6_gro_complete() for a SW-GRO packet, it does
not seed th->check with the TCP pseudo-header checksum or set
CHECKSUM_PARTIAL.
The GRO stack completes a HW-GRO skb itself only if it holds the skb for
merging (since commit 5eddb24901ee ("gro: add support of (hw)gro packets
to gro stack")). Otherwise the skb is delivered as is, e.g. with rx-gro
off or for a packet that is flushed immediately (e.g. with PSH set). If
such an skb is forwarded out of a TSO-capable device, netif_needs_gso()
accepts it as CHECKSUM_UNNECESSARY and the device segments it with a
bogus checksum seed, so every segment is dropped by the receiver. This
blackholes forwarded TCP traffic on VMs acting as routers or NAT
gateways and was observed on VMs in real use.
Fix it in a manner consistent with other drivers with HW-GRO: set the
network and transport headers and, for packets whose checksum the device
verified, seed th->check with the pseudo-header checksum and call
tcp_gro_complete(), passing gso_segs through NAPI_GRO_CB(skb)->count.
skb->data points at the Ethernet header on the napi_gro_frags() path and
at the IP header on the header-split and copybreak paths, so account for
that when setting the network header. Since the header layout now
matters, tell IPv4 from IPv6 by the EtherType, as qede and bnx2x do,
rather than by the packet type.
The device does not coalesce VLAN tagged frames, so the IP header always
follows the Ethernet header. The IP and TCP header lengths are read from
the packet, so check that the headers are in the linear part before
using them, and drop the packet otherwise.
Also compute gso_segs from the TCP payload length. It was computed from
skb->data_len, which is 0 for a packet that rx_copybreak copied whole
into the linear part, leaving such packets with gso_segs 0 and a
non-zero gso_size. Such small packets usually carry a single segment, so
deliver a packet with at most one segment of payload as a non-GSO skb.
Fixes: e637c244b954 ("gve: Advertise NETIF_F_GRO_HW instead of NETIF_F_LRO")
Cc: stable@vger.kernel.org
Reviewed-by: Jordan Rhee <jordanrhee@google.com>
Reviewed-by: Praveen Kaligineedi <pkaligineedi@google.com>
Signed-off-by: Ankit Garg <nktgrg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
---
Changes in v2:
- Check that the IP and TCP headers are in the linear part before
using them (Eric Dumazet)
- Note in the changelog that the device does not coalesce VLAN tagged
frames (Eric Dumazet)
- Do not mark packets with at most one segment of payload as GSO
- Link to v1: https://lore.kernel.org/netdev/20261113195553.2220562-1-joshwash@google.com/
drivers/net/ethernet/google/gve/gve_rx_dqo.c | 84 ++++++++++++++++----
1 file changed, 68 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
index 82ed5e48b00a..b4dbfb1ba39b 100644
--- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c
+++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
@@ -13,6 +13,7 @@
#include <linux/ipv6.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
+#include <net/gro.h>
#include <net/ip6_checksum.h>
#include <net/ipv6.h>
#include <net/tcp.h>
@@ -1000,13 +1001,34 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
return -ENOMEM;
}
+/* Prepare a HW-GRO packet the way tcp4/6_gro_complete() prepare a SW-GRO
+ * packet, so that it can be resegmented by GSO or TSO if it is forwarded:
+ * seed th->check with the TCP pseudo-header checksum and set CHECKSUM_PARTIAL.
+ */
+static void gve_rx_fixup_gro_checksum(struct sk_buff *skb)
+{
+ int len = skb->len - skb_transport_offset(skb);
+ struct tcphdr *th = tcp_hdr(skb);
+
+ if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
+ th->check = ~tcp_v4_check(len, ip_hdr(skb)->saddr,
+ ip_hdr(skb)->daddr, 0);
+ else
+ th->check = ~tcp_v6_check(len, &ipv6_hdr(skb)->saddr,
+ &ipv6_hdr(skb)->daddr, 0);
+
+ NAPI_GRO_CB(skb)->count = skb_shinfo(skb)->gso_segs;
+ tcp_gro_complete(skb);
+}
+
static int gve_rx_complete_rsc(struct sk_buff *skb,
const struct gve_rx_compl_desc_dqo *desc,
struct gve_ptype ptype)
{
struct skb_shared_info *shinfo = skb_shinfo(skb);
- int rsc_segments, rsc_seg_len, hdr_len;
+ int rsc_seg_len, hdr_len, nhoff, thoff, gso_type, payload;
skb_frag_t *frag;
+ __be16 proto;
void *va;
/* HW-GRO only coalesces TCP. */
@@ -1017,20 +1039,11 @@ static int gve_rx_complete_rsc(struct sk_buff *skb,
if (!rsc_seg_len)
return 0;
- switch (ptype.l3_type) {
- case GVE_L3_TYPE_IPV4:
- shinfo->gso_type = SKB_GSO_TCPV4;
- break;
- case GVE_L3_TYPE_IPV6:
- shinfo->gso_type = SKB_GSO_TCPV6;
- break;
- default:
- return -EINVAL;
- }
-
if (skb_headlen(skb)) {
- /* With header-split, payload is in the non-linear part */
- rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_seg_len);
+ /* With header-split or copybreak, eth_type_trans() has already
+ * pulled the Ethernet header.
+ */
+ nhoff = 0;
} else {
/* HW-GRO packets are guaranteed to have complete TCP/IP
* headers in frag[0] when header-split is not enabled.
@@ -1039,7 +1052,6 @@ static int gve_rx_complete_rsc(struct sk_buff *skb,
va = skb_frag_address(frag);
hdr_len =
eth_get_headlen(skb->dev, va, skb_frag_size(frag));
- rsc_segments = DIV_ROUND_UP(skb->len - hdr_len, rsc_seg_len);
skb_copy_to_linear_data(skb, va, hdr_len);
skb_frag_size_sub(frag, hdr_len);
/* Verify we didn't empty the fragment completely as that could
@@ -1049,10 +1061,50 @@ static int gve_rx_complete_rsc(struct sk_buff *skb,
skb_frag_off_add(frag, hdr_len);
skb->data_len -= hdr_len;
skb->tail += hdr_len;
+ /* napi_gro_frags() pulls the Ethernet header later. */
+ nhoff = ETH_HLEN;
+ }
+
+ /* The header lengths come from the packet, so make sure the headers are
+ * in the linear part before reading them and writing th->check.
+ */
+ if (unlikely(skb_headlen(skb) < nhoff + sizeof(struct iphdr)))
+ return -EINVAL;
+
+ skb_set_network_header(skb, nhoff);
+ proto = nhoff ? ((struct ethhdr *)skb->data)->h_proto : skb->protocol;
+ switch (proto) {
+ case htons(ETH_P_IP):
+ gso_type = SKB_GSO_TCPV4;
+ thoff = nhoff + ip_hdrlen(skb);
+ break;
+ case htons(ETH_P_IPV6):
+ gso_type = SKB_GSO_TCPV6;
+ thoff = nhoff + sizeof(struct ipv6hdr);
+ break;
+ default:
+ return -EINVAL;
}
+ if (unlikely(skb_headlen(skb) < thoff + sizeof(struct tcphdr)))
+ return -EINVAL;
+ skb_set_transport_header(skb, thoff);
+ if (unlikely(skb->len < thoff + tcp_hdrlen(skb)))
+ return -EINVAL;
+
+ /* With at most one segment of payload, this is not a GSO packet. */
+ payload = skb->len - thoff - tcp_hdrlen(skb);
+ if (payload <= rsc_seg_len)
+ return 0;
+
+ shinfo->gso_type = gso_type;
shinfo->gso_size = rsc_seg_len;
- shinfo->gso_segs = rsc_segments;
+ shinfo->gso_segs = DIV_ROUND_UP(payload, rsc_seg_len);
+
+ if (!IS_ENABLED(CONFIG_INET) ||
+ unlikely(skb->ip_summed != CHECKSUM_UNNECESSARY))
+ return 0;
+ gve_rx_fixup_gro_checksum(skb);
return 0;
}
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
--
2.56.0.679.gc527c65306-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] gve: fix checksum state and gso_segs of HW-GRO packets
2026-11-16 22:43 [PATCH net v2] gve: fix checksum state and gso_segs of HW-GRO packets Joshua Washington
@ 2026-11-17 23:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 23:32 UTC (permalink / raw)
To: joshwash
Cc: netdev, hramamurthy, andrew+netdev, davem, edumazet, kuba, pabeni,
jordanrhee, nktgrg, thostet, willemb, linux-kernel, stable,
pkaligineedi
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] gve_rx_complete_rsc()
(drivers/net/ethernet/google/gve/gve_rx_dqo.c) works out where the TCP…
--
gve: fix checksum state and gso_segs of HW-GRO packets
This patch makes gve_rx_complete_rsc() set the network and transport
headers on HW-GRO packets. For device-verified packets it also seeds
th->check with the TCP pseudo-header checksum and calls tcp_gro_complete(),
so forwarded HW-GRO skbs can be resegmented correctly. IPv4 and IPv6 are
now told apart by EtherType, and gso_segs is computed from the TCP payload
length.
> diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
> index 82ed5e48b00ab..b4dbfb1ba39b0 100644
> --- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c
> +++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
[ ... ]
> @@ -1049,10 +1061,50 @@ static int gve_rx_complete_rsc(struct sk_buff *skb,
> skb_frag_off_add(frag, hdr_len);
> skb->data_len -= hdr_len;
> skb->tail += hdr_len;
> + /* napi_gro_frags() pulls the Ethernet header later. */
> + nhoff = ETH_HLEN;
> + }
> +
> + /* The header lengths come from the packet, so make sure the headers are
> + * in the linear part before reading them and writing th->check.
> + */
> + if (unlikely(skb_headlen(skb) < nhoff + sizeof(struct iphdr)))
> + return -EINVAL;
> +
> + skb_set_network_header(skb, nhoff);
> + proto = nhoff ? ((struct ethhdr *)skb->data)->h_proto : skb->protocol;
> + switch (proto) {
> + case htons(ETH_P_IP):
> + gso_type = SKB_GSO_TCPV4;
> + thoff = nhoff + ip_hdrlen(skb);
> + break;
> + case htons(ETH_P_IPV6):
> + gso_type = SKB_GSO_TCPV6;
> + thoff = nhoff + sizeof(struct ipv6hdr);
[Severity: Medium]
Is it safe to assume the TCP header comes right after the fixed IPv6
header here?
Nothing checks ipv6_hdr(skb)->nexthdr == IPPROTO_TCP or desc->ipv6_ex_add.
The IPv4 case above also uses ip_hdrlen() without checking
ip_hdr(skb)->protocol == IPPROTO_TCP. The only sign that L4 is TCP is the
ptype.l4_type check at the top of gve_rx_complete_rsc().
The descriptor suggests the device does parse IPv6 extension headers:
gve_desc_dqo.h:
/* Set when IPv6 packet contains a destination options header or routing
* header.
*/
u8 ipv6_ex_add: 1;
gve_rx_skb_csum() only holds back CHECKSUM_UNNECESSARY when that bit is
set:
} else if (ptype.l3_type == GVE_L3_TYPE_IPV6) {
/* Checksum should be skipped if this flag is set. */
if (unlikely(desc->ipv6_ex_add))
return;
}
So an IPv6/TCP packet with a hop-by-hop header and a device-verified
checksum would still be CHECKSUM_UNNECESSARY when it gets here.
Suppose the device coalesces such a packet, or a tunnelled packet whose
ptype reports the inner L4 as TCP. Then thoff would point into the
extension or tunnel header, and tcp_hdrlen() would read doff from the
wrong bytes.
gve_rx_fixup_gro_checksum() would then write the pseudo-header seed at
that offset:
th->check = ~tcp_v6_check(len, &ipv6_hdr(skb)->saddr,
&ipv6_hdr(skb)->daddr, 0);
tcp_gro_complete() would also set csum_start, csum_offset and
CHECKSUM_PARTIAL at that offset.
Wouldn't a forwarded packet then leave through TSO/GSO with a bad
checksum? That is the same blackholing this patch sets out to fix.
The destination-options and routing cases are CHECKSUM_NONE, but they
still hit the wrong doff. That could drop a valid packet with -EINVAL or
give it a wrong gso_segs. It could also take the new early return:
payload = skb->len - thoff - tcp_hdrlen(skb);
if (payload <= rsc_seg_len)
return 0;
and deliver a multi-segment coalesced packet without gso_size.
Before this patch the RSC path never read or wrote the TCP header, so
this assumption is new. The changelog gives the VLAN guarantee ("The
device does not coalesce VLAN tagged frames"), but says nothing about
IPv6 extension headers or encapsulation.
For comparison, bnx2x_set_gro_params() documents the matching hardware
guarantee ("TPA aggregation won't have either IP options or TCP options
other than timestamp or IPv6 extension headers"). The mlx5 SHAMPO path
checks ipv6->nexthdr == IPPROTO_TCP.
Could the device guarantee be documented in the changelog and in a
comment? Alternatively, could this check ip_hdr(skb)->protocol and
ipv6_hdr(skb)->nexthdr against IPPROTO_TCP (and ihl >= 5), and skip the
GSO and checksum fixup otherwise?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116224308.986555-1-joshwash%40google.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 23:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 22:43 [PATCH net v2] gve: fix checksum state and gso_segs of HW-GRO packets Joshua Washington
2026-11-17 23:32 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox