From nobody Thu Oct 2 15:19:15 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4242FDC55 for ; Mon, 15 Sep 2025 11:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936447; cv=none; b=DhXg1iI2tHUPmAzXnlYYqrc1LwYkvm/sWpGTPLlyhu5G1HEiQC8LpxTWQJXy74NWQn/jGmujrtFtv10EqqmWINIyoGq0Dgmg0rw/p54U9VC3y+FC5bFBSSaZ99zBQYprTqLmgVsKDOAjJfXGvR6q8nLiwLFm1jhaBM9suUNOgCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936447; c=relaxed/simple; bh=jY+pUy3kBJwFzbCPyETA5Zsp5XhOgceDU1qzIwyTQQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HjgIf92X7bmzEh9kiB/FyTSReMQrCsEi8oJQP0b+Z5mMmICpGmqAeDbl6RuytDvIihc5pi3PsmA3dN5llRRNQQP8IZHK6TOlu+k9F9HAdzEgxC4rkBqQF65gM3tMJWUBRZLjA9JqxWksS+e8xRniOBnzfb6mGOdZMljG6mo3STE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fbXMyGZs; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fbXMyGZs" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-45f2c5ef00fso9699605e9.1 for ; Mon, 15 Sep 2025 04:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757936444; x=1758541244; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u72Um79V9re5ZHDgqOQkBEh3WxfHhzUFF1gdhHx0vU8=; b=fbXMyGZsrsV0xIA71jMP0I83hcZNesLmYP00dtadSjJMbYaUvEGPrP4Y52BmF/asAL Dikpl4u+as0H6fWVDcgwYtx94u7YEmV5ZkG43DkXUJYxu6uu+uOrkzWTT0Zlzv7FplJW MYD0fPtiRHPGq7jxRAOAJ63j7kTgw6sDsNWHG/W1DJ8ZHO9fldLgdt8R0m0kb4I4fW+U hwS/icP2pnPsppeNQjd4see1hWPl2DZQJTGP732pVq4JMzsf+aKaTQySSWL1a2ApRNPF 02CzNSI2RSPDN8z5fgzpeK0voOCgBUUq5iX5nCTbE200HJSxBRlMqwCh1E+e0Hd1cXwb NPbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757936444; x=1758541244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u72Um79V9re5ZHDgqOQkBEh3WxfHhzUFF1gdhHx0vU8=; b=I0TY5jsiDfYSu8pCzkYjuI+pQ7YnSV3H1BueQoCRDmaMGWuXayTk0hkIXrqbqwD/BL bHZR6A447vcJ4BYsKdsrSe6o9FvTflxzCpyfsiuJPLMizrt7hOIbDT+cBSvIyFXFgK8C 2k0Aq5ooEJSb71dBlZ5+h0zFERL8cnXUMjcO4IbNwVcqzyIS2t7X8YXOKfGPT90Rmma/ ZeeGHDNXxnEPW9o7TCE1k1iPseSox5rr+773Z4mqiLJFjo1x3k2lSDiiHuUknnGF4FIb bnzaMx3eF+k3IUCp6sEb+8cmCn612pj3V0IDpKHdZ2CdvWQ5+3l81Q4Sm/XAsL7ByE5g 6L8A== X-Forwarded-Encrypted: i=1; AJvYcCW6yTDTe9xnwRh/H9q3s9rsMY06zmei8vhCfV0rO55aV9I28SZRY6av99qjKWqDc7e9dTbu/n/6gK5zHB8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywo0mg2IZbf8sBkMeTXBfX22Bq4wRRJulwe3DQ94Ct22/AzBJuF NMfgv6YtJyxmDM5qJtnkjIHozZpSmLsigDulNwFD144UDJzj7LTWGij0 X-Gm-Gg: ASbGncuk0DTzFCTYWPbfyi5bPW3XCwN+gKyXEDjfuKT0Q3rcnrSstWOselXV12s5eps kNG5vrJOn1dfskhgk13PYJW+EvfnsDawzl3fgIDDBwnFQNFXZU3TSKxmQur6eJTgp5DKAOVnWjJ 6IBVD4bEpPdMu33B5BdRx1x3e2OzskBL7FDiWXbgpqHjfv2eKmKTZ9h+CABdHZ+lSYX5Ijdh4UY 80jtbAYfqJaqPMQZ7S+QDHaG1+E1LWk9dMReh/ExYfPZVVR81T2rq3860Epp0ss9p3mlwGszCvl uBx+YE8JzjOT4ivf8MY/wQ/FUlaH7GYUlYpvPzzSJqBhwQOV70aJfbTkYTVrGIA3PJCL4jHru+D LVV/kddYZA4CCf4tzUQXd4he5vTglifitdg== X-Google-Smtp-Source: AGHT+IGpIAfhEWKviy6ghsA1Oo3PFra/49ftGsD+pneSeFbYGHiRKmO1SKhfzhhcCROEejBqjwMaNw== X-Received: by 2002:a05:6000:2313:b0:3ea:6680:8fa1 with SMTP id ffacd0b85a97d-3ea66809518mr3649315f8f.12.1757936443405; Mon, 15 Sep 2025 04:40:43 -0700 (PDT) Received: from localhost ([45.10.155.13]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3ea21a6e4basm5604532f8f.11.2025.09.15.04.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:40:43 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org, pabeni@redhat.com, ecree.xilinx@gmail.com, willemdebruijn.kernel@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, corbet@lwn.net, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v5 1/5] net: gro: remove is_ipv6 from napi_gro_cb Date: Mon, 15 Sep 2025 13:39:29 +0200 Message-Id: <20250915113933.3293-2-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915113933.3293-1-richardbgobert@gmail.com> References: <20250915113933.3293-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead. This frees up space for another ip_fixedid bit that will be added in the next commit. udp_sock_create always creates either a AP_INET or a AF_INET6 socket, so using sk->sk_family is reliable. In IPv6-FOU, cfg->ipv6_v6only is always enabled. Signed-off-by: Richard Gobert Reviewed-by: Willem de Bruijn --- include/net/gro.h | 3 --- net/ipv4/fou_core.c | 32 ++++++++++++++------------------ net/ipv4/udp_offload.c | 2 -- net/ipv6/udp_offload.c | 2 -- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index a0fca7ac6e7e..87c68007f949 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -71,9 +71,6 @@ struct napi_gro_cb { /* Free the skb? */ u8 free:2; =20 - /* Used in foo-over-udp, set in udp[46]_gro_receive */ - u8 is_ipv6:1; - /* Used in GRE, set in fou/gue_gro_receive */ u8 is_fou:1; =20 diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 3e30745e2c09..3970b6b7ace5 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -228,21 +228,27 @@ static int gue_udp_recv(struct sock *sk, struct sk_bu= ff *skb) return 0; } =20 +static const struct net_offload *fou_gro_ops(const struct sock *sk, + int proto) +{ + const struct net_offload __rcu **offloads; + + /* FOU doesn't allow IPv4 on IPv6 sockets. */ + offloads =3D sk->sk_family =3D=3D AF_INET6 ? inet6_offloads : inet_offloa= ds; + return rcu_dereference(offloads[proto]); +} + static struct sk_buff *fou_gro_receive(struct sock *sk, struct list_head *head, struct sk_buff *skb) { - const struct net_offload __rcu **offloads; struct fou *fou =3D fou_from_sock(sk); const struct net_offload *ops; struct sk_buff *pp =3D NULL; - u8 proto; =20 if (!fou) goto out; =20 - proto =3D fou->protocol; - /* We can clear the encap_mark for FOU as we are essentially doing * one of two possible things. We are either adding an L4 tunnel * header to the outer L3 tunnel header, or we are simply @@ -254,8 +260,7 @@ static struct sk_buff *fou_gro_receive(struct sock *sk, /* Flag this frame as already having an outer encap header */ NAPI_GRO_CB(skb)->is_fou =3D 1; =20 - offloads =3D NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; - ops =3D rcu_dereference(offloads[proto]); + ops =3D fou_gro_ops(sk, fou->protocol); if (!ops || !ops->callbacks.gro_receive) goto out; =20 @@ -268,10 +273,8 @@ static struct sk_buff *fou_gro_receive(struct sock *sk, static int fou_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff) { - const struct net_offload __rcu **offloads; struct fou *fou =3D fou_from_sock(sk); const struct net_offload *ops; - u8 proto; int err; =20 if (!fou) { @@ -279,10 +282,7 @@ static int fou_gro_complete(struct sock *sk, struct sk= _buff *skb, goto out; } =20 - proto =3D fou->protocol; - - offloads =3D NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; - ops =3D rcu_dereference(offloads[proto]); + ops =3D fou_gro_ops(sk, fou->protocol); if (WARN_ON(!ops || !ops->callbacks.gro_complete)) { err =3D -ENOSYS; goto out; @@ -323,7 +323,6 @@ static struct sk_buff *gue_gro_receive(struct sock *sk, struct list_head *head, struct sk_buff *skb) { - const struct net_offload __rcu **offloads; const struct net_offload *ops; struct sk_buff *pp =3D NULL; struct sk_buff *p; @@ -450,8 +449,7 @@ static struct sk_buff *gue_gro_receive(struct sock *sk, /* Flag this frame as already having an outer encap header */ NAPI_GRO_CB(skb)->is_fou =3D 1; =20 - offloads =3D NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; - ops =3D rcu_dereference(offloads[proto]); + ops =3D fou_gro_ops(sk, proto); if (!ops || !ops->callbacks.gro_receive) goto out; =20 @@ -467,7 +465,6 @@ static struct sk_buff *gue_gro_receive(struct sock *sk, static int gue_gro_complete(struct sock *sk, struct sk_buff *skb, int nhof= f) { struct guehdr *guehdr =3D (struct guehdr *)(skb->data + nhoff); - const struct net_offload __rcu **offloads; const struct net_offload *ops; unsigned int guehlen =3D 0; u8 proto; @@ -494,8 +491,7 @@ static int gue_gro_complete(struct sock *sk, struct sk_= buff *skb, int nhoff) return err; } =20 - offloads =3D NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; - ops =3D rcu_dereference(offloads[proto]); + ops =3D fou_gro_ops(sk, proto); if (WARN_ON(!ops || !ops->callbacks.gro_complete)) goto out; =20 diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index b1f3fd302e9d..19d0b5b09ffa 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -891,8 +891,6 @@ struct sk_buff *udp4_gro_receive(struct list_head *head= , struct sk_buff *skb) skb_gro_checksum_try_convert(skb, IPPROTO_UDP, inet_gro_compute_pseudo); skip: - NAPI_GRO_CB(skb)->is_ipv6 =3D 0; - if (static_branch_unlikely(&udp_encap_needed_key)) sk =3D udp4_gro_lookup_skb(skb, uh->source, uh->dest); =20 diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index d8445ac1b2e4..046f13b1d77a 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -154,8 +154,6 @@ struct sk_buff *udp6_gro_receive(struct list_head *head= , struct sk_buff *skb) ip6_gro_compute_pseudo); =20 skip: - NAPI_GRO_CB(skb)->is_ipv6 =3D 1; - if (static_branch_unlikely(&udpv6_encap_needed_key)) sk =3D udp6_gro_lookup_skb(skb, uh->source, uh->dest); =20 --=20 2.36.1 From nobody Thu Oct 2 15:19:15 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD5D278170 for ; Mon, 15 Sep 2025 11:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936457; cv=none; b=N9g38G4HUKCFnJ6LUcxY5wNCQ1ty0E3PcfnjXZlWrJ7dXzJs5DcK/aR2d+MQ6KZtoMmS/BlVeVhaSKC64PgNkrZ7ocgWCmxrMkGYBXgd2iC7OBnv2ymnHZpW+N6P7B9ixp9FCPJ0/GEK+yt4UwE4AUtuFhUf92vu/VJqmQNQV+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936457; c=relaxed/simple; bh=bNIaNEm4LT6TFP6CWRAKFGRqH4Wptaj+KdxK6aWaJOQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ClKKMyBmjSDVZAV+zfgA+UIUCO1OTFrJr+C7n/nT2KJVYjj7QpD/bXMMUqQvljr7+L631Q9xpahJu1/26U66Ap9Gulf9xORw86Nxxaa4l+W1hS1Er8qFavV7MmqDGkqYCcqLgiF4vt+fsOOsNNK68hB1X4HhPTppulr9ZTBsSvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YlGzuOcP; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YlGzuOcP" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3b9edf4cf6cso3069799f8f.3 for ; Mon, 15 Sep 2025 04:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757936452; x=1758541252; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cZBtrYTmjnky2Xi391d5zrqPiMva7ofI4h9J6siEdNw=; b=YlGzuOcPnZYyCWugYt4EL6oS0oR9FPUkgmBjZSGR/ShLZy130XBReTef48BLMEQbdd R77LnJAncDp7nLkCGhH6PBqhyxb082t0axqbi6Y8YOb4NVLHva8groRizjH1Laq9Nhhh XWeFJMLdT8QOq4V8BdKhNssEEVQb9C3a51VZXKMruGfPI6XodN1Tc142nFKynBTXqXn6 iKFwF6a0+1Z8kmrRyla718MLrv9klTtxYm6uftsKS1HrOawha0G5WPK99ioOUrIPUyCW CY3zoiDEwXkYaGUXIafSxQXI8VGwDinjviE4VTSobmM0mjflvagPCG2rc3Tukd4reQN7 bgKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757936452; x=1758541252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cZBtrYTmjnky2Xi391d5zrqPiMva7ofI4h9J6siEdNw=; b=u+4MBNrMItD33xNMC/f42KUv5D3Fl0INGpv5PLH3a6ACSv+d+KNC5GXKnf+nkOCfOJ s7jybNiF7rFoYkyqTjH815Ur+oph8rTazATteMw6XKkI6pgSkdC/0e0UqgW0QPyDa97Q kgzFYrDpTht8oPqL+ETMzKrbzUKBYe8bQFb750xdJNMlG1T6DZtXE43IULfhlCkStEiU I7xhL8XE8nQiZdtDGShrq78aWfgBYGFfye3Yu3LjfXWeOExRc3KtoY04g8q/2i3LpuRV Yj8Mb2OKstacEn6ErDeNWi0JbFCZRIZ7SjUBo+Gx+jnbdoihLjLA/hHZpZuE6ZGlftcH c7QQ== X-Forwarded-Encrypted: i=1; AJvYcCVvtgDavy9nFsY2ACKSdW/OkaIdBpeVgUXoZYmdhp32lzQQfxzIj8JsNtOrjcE6e6v6yDbsTCcbWYx5FaY=@vger.kernel.org X-Gm-Message-State: AOJu0YwbTqOHXHjk1Va/b9AycSwEJwC8ZwJlgy1nywa6Lu/Rs5OfIXgT Vt7J0wJXW9HgmAuvYBREbWe2BjHHfL7mqde//G4G5CjyST/F3FeP4JyI X-Gm-Gg: ASbGncuq74NG5ihOakX7QXzC4sJjD5zwQZWcnbE+IUdWlQ1ITu1duMVrBa1RnITRiDP a452FJDMKthFwPRfqWvd1qJC2hlYc/y8u+Di8Co1y0DjW/TJ4kbzQAnfvHdptECDK5Yi5/BOUO8 tMCBM7Gc8/2MJf62x4/v7jOevSUHFT5WpRCIgYU9W1UXh97I14RSccy0zpOBqlxY4z3qULkWPDk oSgTLYyJxKrQtzRJo3ehnGN3rarOq23fEvwWD3KvhJvR+ORK2ov0XMohDR9s6JyJDHIUCXYvLNJ u0CQo/APp70S5nU69rBKMY7pgWwH5RyD30TwM3hAbIzryLEDtDHQzxuZLJrPO6dHxg+kJlBQgyM W28nrEs1MMI6YVK5NxinyjVToA0wQrqCmgdkcO00cUFBX X-Google-Smtp-Source: AGHT+IEPBDET+aq7aWqMBXc4+ldGUX/PWl3peX+qrYQPG3n1Y29xuY+8jud+W1D227pp/+3seZYrkw== X-Received: by 2002:a05:6000:2013:b0:3eb:5e99:cbd3 with SMTP id ffacd0b85a97d-3eb5e99ce8cmr1458035f8f.2.1757936452358; Mon, 15 Sep 2025 04:40:52 -0700 (PDT) Received: from localhost ([45.10.155.13]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e0372bbd3sm172482185e9.10.2025.09.15.04.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:40:52 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org, pabeni@redhat.com, ecree.xilinx@gmail.com, willemdebruijn.kernel@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, corbet@lwn.net, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v5 2/5] net: gro: only merge packets with incrementing or fixed outer ids Date: Mon, 15 Sep 2025 13:39:30 +0200 Message-Id: <20250915113933.3293-3-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915113933.3293-1-richardbgobert@gmail.com> References: <20250915113933.3293-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only merge encapsulated packets if their outer IDs are either incrementing or fixed, just like for inner IDs and IDs of non-encapsulated packets. Add another ip_fixedid bit for a total of two bits: one for outer IDs (and for unencapsulated packets) and one for inner IDs. This commit preserves the current behavior of GSO where only the IDs of the inner-most headers are restored correctly. Signed-off-by: Richard Gobert --- include/net/gro.h | 27 ++++++++++++--------------- net/ipv4/tcp_offload.c | 5 ++++- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 87c68007f949..6aa563eec3d0 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -75,7 +75,7 @@ struct napi_gro_cb { u8 is_fou:1; =20 /* Used to determine if ipid_offset can be ignored */ - u8 ip_fixedid:1; + u8 ip_fixedid:2; =20 /* Number of gro_receive callbacks this packet already went through */ u8 recursion_counter:4; @@ -442,29 +442,26 @@ static inline __wsum ip6_gro_compute_pseudo(const str= uct sk_buff *skb, } =20 static inline int inet_gro_flush(const struct iphdr *iph, const struct iph= dr *iph2, - struct sk_buff *p, bool outer) + struct sk_buff *p, bool inner) { const u32 id =3D ntohl(*(__be32 *)&iph->id); const u32 id2 =3D ntohl(*(__be32 *)&iph2->id); const u16 ipid_offset =3D (id >> 16) - (id2 >> 16); const u16 count =3D NAPI_GRO_CB(p)->count; const u32 df =3D id & IP_DF; - int flush; =20 /* All fields must match except length and checksum. */ - flush =3D (iph->ttl ^ iph2->ttl) | (iph->tos ^ iph2->tos) | (df ^ (id2 & = IP_DF)); - - if (flush | (outer && df)) - return flush; + if ((iph->ttl ^ iph2->ttl) | (iph->tos ^ iph2->tos) | (df ^ (id2 & IP_DF)= )) + return true; =20 /* When we receive our second frame we can make a decision on if we * continue this flow as an atomic flow with a fixed ID or if we use * an incrementing ID. */ if (count =3D=3D 1 && df && !ipid_offset) - NAPI_GRO_CB(p)->ip_fixedid =3D true; + NAPI_GRO_CB(p)->ip_fixedid |=3D 1 << inner; =20 - return ipid_offset ^ (count * !NAPI_GRO_CB(p)->ip_fixedid); + return ipid_offset ^ (count * !(NAPI_GRO_CB(p)->ip_fixedid & (1 << inner)= )); } =20 static inline int ipv6_gro_flush(const struct ipv6hdr *iph, const struct i= pv6hdr *iph2) @@ -479,7 +476,7 @@ static inline int ipv6_gro_flush(const struct ipv6hdr *= iph, const struct ipv6hdr =20 static inline int __gro_receive_network_flush(const void *th, const void *= th2, struct sk_buff *p, const u16 diff, - bool outer) + bool inner) { const void *nh =3D th - diff; const void *nh2 =3D th2 - diff; @@ -487,19 +484,19 @@ static inline int __gro_receive_network_flush(const v= oid *th, const void *th2, if (((struct iphdr *)nh)->version =3D=3D 6) return ipv6_gro_flush(nh, nh2); else - return inet_gro_flush(nh, nh2, p, outer); + return inet_gro_flush(nh, nh2, p, inner); } =20 static inline int gro_receive_network_flush(const void *th, const void *th= 2, struct sk_buff *p) { - const bool encap_mark =3D NAPI_GRO_CB(p)->encap_mark; int off =3D skb_transport_offset(p); int flush; =20 - flush =3D __gro_receive_network_flush(th, th2, p, off - NAPI_GRO_CB(p)->n= etwork_offset, encap_mark); - if (encap_mark) - flush |=3D __gro_receive_network_flush(th, th2, p, off - NAPI_GRO_CB(p)-= >inner_network_offset, false); + flush =3D __gro_receive_network_flush(th, th2, p, off - NAPI_GRO_CB(p)->n= etwork_offset, false); + if (NAPI_GRO_CB(p)->encap_mark) { + flush |=3D __gro_receive_network_flush(th, th2, p, off - NAPI_GRO_CB(p)-= >inner_network_offset, true); + } =20 return flush; } diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index e6612bd84d09..1949eede9ec9 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -471,6 +471,7 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk= _buff *skb, int thoff) const u16 offset =3D NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation= ]; const struct iphdr *iph =3D (struct iphdr *)(skb->data + offset); struct tcphdr *th =3D tcp_hdr(skb); + bool is_fixedid; =20 if (unlikely(NAPI_GRO_CB(skb)->is_flist)) { skb_shinfo(skb)->gso_type |=3D SKB_GSO_FRAGLIST | SKB_GSO_TCPV4; @@ -484,8 +485,10 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct s= k_buff *skb, int thoff) th->check =3D ~tcp_v4_check(skb->len - thoff, iph->saddr, iph->daddr, 0); =20 + is_fixedid =3D (NAPI_GRO_CB(skb)->ip_fixedid >> skb->encapsulation) & 1; + skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCPV4 | - (NAPI_GRO_CB(skb)->ip_fixedid * SKB_GSO_TCP_FIXEDID); + (is_fixedid * SKB_GSO_TCP_FIXEDID); =20 tcp_gro_complete(skb); return 0; --=20 2.36.1 From nobody Thu Oct 2 15:19:15 2025 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE4C52FFDE8 for ; Mon, 15 Sep 2025 11:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936466; cv=none; b=oTQ3nVDWAahl2ekJFn4BnFFD6UL9Lcn3Vdi9COJYqCgpMSXG2DkP4ZE04HLF3+Nh38l+VGmyxSPmNTWyNuJfw2foM8kKjs+rXSE+5GaWKbX+oet49U3QCb5HVDblHzImKoQWVsOCO2eJSk47Dle5A0fu96CoeBhwKJRycVmWz6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936466; c=relaxed/simple; bh=UXREEZK2NziXQSKKStkYfsmh3QLPUsYjgNjh74i7tCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YkMruGZOvhzCxqX800Ahd8VYu/KyuCCBylzv57tZJERWmbluNbpDQbJYQoZop8omRhXxh4zFNshp9VOzOUlfv/vd0DFWt8SVN8Wfe2oTmJCx78dLF73v1HeCgThYI0JpAdf4/sip462aukHPpELU2H8Ba3c62Q2sFBM70wn1V0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=i+YdFM55; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i+YdFM55" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3ea3e223ba2so1082406f8f.2 for ; Mon, 15 Sep 2025 04:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757936462; x=1758541262; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SEEzEOMG9HaUmq/icWE1bJefltqVLb5a0fvlZJLZ7Ck=; b=i+YdFM55IMXEUFoacPimbN2oeHbAPgZzXGYhBRT0KULctS2/TeHz9PkPocjso41WtO XJxCHEKgTOwl5iPyLFJbEDYu6BnyiI6jR2c4cAWqXNcNLBJzcIL3Puv5lv19xK0ardvD j+ybQq5oiklY+wGJqe3G8mXNfgWSi/YmywJYGOEE5vyAIwrLFQFjKQKJGzBACkiFunt9 4ZxJ7/I72Q8AeferTMdDrXl3yvQmuHFWNcfIyBcbCPEzXcQBhSepQsHzvcMZQyUBUNli dl8aDsHCEMiv4/of0ZM0UtDl08DAV6ORoSZrZovj8xFhOERbMDQJ6GDcVCyhNjtG/cNH qASQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757936462; x=1758541262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SEEzEOMG9HaUmq/icWE1bJefltqVLb5a0fvlZJLZ7Ck=; b=ckloWu4hbyuOOOr2lS5sCyPjSV8nqCfkgZb3nHSij70R6kw0jCjfXYa4zjkT0RE7ql PUvlkSbIMfMeJKfM+HyvU5jOz/9QPp8rQZoMjaH2ScEi5N3PcWJQ9ciCSEyVuYx3wbkU e/dABff7aoBcis286XgJD3iVfH2/Xv0GBvv6O6KU9XDJDygMkDIBwp/dee0g4WiDBwDX J1GgJfwufGFLuixk2xsoi3w06t4+4NuQ77/HnI1e7bQM6F8O9CHDIlRtjZm+gdw42cxV zTkvmHlQqw9/KwVyOWfQuwQvDiVRuqIiyDTgZ0pCqCxYSQYqU9mHc3wxJENlFW7WzQSI 6U5Q== X-Forwarded-Encrypted: i=1; AJvYcCXNYRGGIL/gcx21TTuQ6eEB1R41wfVhTpwvCW7vwIkwn9VkTYf+Hus0N2nHEafaobzgnUq86Fr5xKWR1vc=@vger.kernel.org X-Gm-Message-State: AOJu0YwlgD0VXc8I/czTjbq4ooXqNGWvtgh9nxGwMRyrm/3eZGXj8kdP Mv8H9ZARZdXT1zRxwioaaYdGRFjgm7eqMY2JUh9q4m/KFkgB3ZNX+REz X-Gm-Gg: ASbGncvSG9Tygp3Oe9MnG8Q4q1TfcBCPbkVonAZptUF8yEWfHic3H9f72bsnOyGCs0V FY5ouUxqPiuOqzp7uaQYw+BUkbugBxLfUJ9LrSaSsK+rycnbpSCFVHHuELNT4cpgQn21DZTl0xh ljH2amxXsfbBZqIPN27PjPhJTmzI5OFOlJ+1nuM79JyRDtF6xneiOoIhkEQM49TsHUNFeDgm8L6 O2jkwfIUk4iY04LcZ93XHsis0lopbaDpWL4mBIIHtDX4UOUbzpLGhU08fqRiDspFhOAX8Q5KbVH UulfOCaO4kTWWk5O6tOSln8a+O72fqtRWWUfUdNXDpNl8gW83hSNGyVpO7P1162bry+5RdEi4kC agAF7z5dzdyP3BT7o8qnvOcScuJLSaFOVmg== X-Google-Smtp-Source: AGHT+IHStjIYYW28Yz9d+XhgU9dCj9H1WcDjP2+awpyGDBT+XbZVvZTQoiJfbTPn3TYFsLSz9uzO+Q== X-Received: by 2002:a05:6000:2f87:b0:3de:c5b3:dda3 with SMTP id ffacd0b85a97d-3e765a0879cmr11697007f8f.44.1757936461982; Mon, 15 Sep 2025 04:41:01 -0700 (PDT) Received: from localhost ([45.10.155.13]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e7607cd0a7sm17325854f8f.39.2025.09.15.04.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:41:01 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org, pabeni@redhat.com, ecree.xilinx@gmail.com, willemdebruijn.kernel@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, corbet@lwn.net, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v5 3/5] net: gso: restore ids of outer ip headers correctly Date: Mon, 15 Sep 2025 13:39:31 +0200 Message-Id: <20250915113933.3293-4-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915113933.3293-1-richardbgobert@gmail.com> References: <20250915113933.3293-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, NETIF_F_TSO_MANGLEID indicates that the inner-most ID can be mangled. Outer IDs can always be mangled. Make GSO preserve outer IDs by default, with NETIF_F_TSO_MANGLEID allowing both inner and outer IDs to be mangled. This commit also modifies a few drivers that use SKB_GSO_FIXEDID directly. Signed-off-by: Richard Gobert Reviewed-by: Edward Cree # for sfc --- .../networking/segmentation-offloads.rst | 22 ++++++++++++------- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 8 +++++-- drivers/net/ethernet/sfc/ef100_tx.c | 17 ++++++++++---- include/linux/netdevice.h | 9 ++++++-- include/linux/skbuff.h | 9 +++++++- net/core/dev.c | 5 ++++- net/ipv4/af_inet.c | 13 +++++------ net/ipv4/tcp_offload.c | 5 +---- 8 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Documentation/networking/segmentation-offloads.rst b/Documenta= tion/networking/segmentation-offloads.rst index 085e8fab03fd..72f69b22b28c 100644 --- a/Documentation/networking/segmentation-offloads.rst +++ b/Documentation/networking/segmentation-offloads.rst @@ -43,10 +43,19 @@ also point to the TCP header of the packet. For IPv4 segmentation we support one of two types in terms of the IP ID. The default behavior is to increment the IP ID with every segment. If the GSO type SKB_GSO_TCP_FIXEDID is specified then we will not increment the IP -ID and all segments will use the same IP ID. If a device has -NETIF_F_TSO_MANGLEID set then the IP ID can be ignored when performing TSO -and we will either increment the IP ID for all frames, or leave it at a -static value based on driver preference. +ID and all segments will use the same IP ID. + +For encapsulated packets, SKB_GSO_TCP_FIXEDID refers only to the outer hea= der. +SKB_GSO_TCP_FIXEDID_INNER can be used to specify the same for the inner he= ader. +Any combination of these two GSO types is allowed. + +If a device has NETIF_F_TSO_MANGLEID set then the IP ID can be ignored when +performing TSO and we will either increment the IP ID for all frames, or l= eave +it at a static value based on driver preference. For encapsulated packets, +NETIF_F_TSO_MANGLEID is relevant for both outer and inner headers, unless = the +DF bit is not set on the outer header, in which case the device driver must +guarantee that the IP ID field is incremented in the outer header with eve= ry +segment. =20 =20 UDP Fragmentation Offload @@ -124,10 +133,7 @@ Generic Receive Offload Generic receive offload is the complement to GSO. Ideally any frame assembled by GRO should be segmented to create an identical sequence of frames using GSO, and any sequence of frames segmented by GSO should be -able to be reassembled back to the original by GRO. The only exception to -this is IPv4 ID in the case that the DF bit is set for a given IP header. -If the value of the IPv4 ID is not sequentially incrementing it will be -altered so that it is when a frame assembled via GRO is segmented via GSO. +able to be reassembled back to the original by GRO. =20 =20 Partial Generic Segmentation Offload diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/= ethernet/mellanox/mlx5/core/en_rx.c index b8c609d91d11..505c4ce7cef8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -1289,8 +1289,12 @@ static void mlx5e_shampo_update_ipv4_tcp_hdr(struct = mlx5e_rq *rq, struct iphdr * tcp->check =3D ~tcp_v4_check(skb->len - tcp_off, ipv4->saddr, ipv4->daddr, 0); skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCPV4; - if (ntohs(ipv4->id) =3D=3D rq->hw_gro_data->second_ip_id) - skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCP_FIXEDID; + if (ntohs(ipv4->id) =3D=3D rq->hw_gro_data->second_ip_id) { + bool encap =3D rq->hw_gro_data->fk.control.flags & FLOW_DIS_ENCAPSULATIO= N; + + skb_shinfo(skb)->gso_type |=3D encap ? + SKB_GSO_TCP_FIXEDID_INNER : SKB_GSO_TCP_FIXEDID; + } =20 skb->csum_start =3D (unsigned char *)tcp - skb->head; skb->csum_offset =3D offsetof(struct tcphdr, check); diff --git a/drivers/net/ethernet/sfc/ef100_tx.c b/drivers/net/ethernet/sfc= /ef100_tx.c index e6b6be549581..03005757c060 100644 --- a/drivers/net/ethernet/sfc/ef100_tx.c +++ b/drivers/net/ethernet/sfc/ef100_tx.c @@ -189,6 +189,7 @@ static void ef100_make_tso_desc(struct efx_nic *efx, { bool gso_partial =3D skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL; unsigned int len, ip_offset, tcp_offset, payload_segs; + u32 mangleid_outer =3D ESE_GZ_TX_DESC_IP4_ID_INC_MOD16; u32 mangleid =3D ESE_GZ_TX_DESC_IP4_ID_INC_MOD16; unsigned int outer_ip_offset, outer_l4_offset; u16 vlan_tci =3D skb_vlan_tag_get(skb); @@ -200,8 +201,17 @@ static void ef100_make_tso_desc(struct efx_nic *efx, bool outer_csum; u32 paylen; =20 - if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID) - mangleid =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + if (encap) { + if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID_INNER) + mangleid =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID) + mangleid_outer =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + } else { + if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID) + mangleid =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + mangleid_outer =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + } + if (efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_TX) vlan_enable =3D skb_vlan_tag_present(skb); =20 @@ -245,8 +255,7 @@ static void ef100_make_tso_desc(struct efx_nic *efx, ESF_GZ_TX_TSO_OUTER_L4_OFF_W, outer_l4_offset >> 1, ESF_GZ_TX_TSO_ED_OUTER_UDP_LEN, udp_encap && !gso_partial, ESF_GZ_TX_TSO_ED_OUTER_IP_LEN, encap && !gso_partial, - ESF_GZ_TX_TSO_ED_OUTER_IP4_ID, encap ? mangleid : - ESE_GZ_TX_DESC_IP4_ID_NO_OP, + ESF_GZ_TX_TSO_ED_OUTER_IP4_ID, mangleid_outer, ESF_GZ_TX_TSO_VLAN_INSERT_EN, vlan_enable, ESF_GZ_TX_TSO_VLAN_INSERT_TCI, vlan_tci ); diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f3a3b761abfb..3d19c888b839 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5290,13 +5290,18 @@ void skb_warn_bad_offload(const struct sk_buff *skb= ); =20 static inline bool net_gso_ok(netdev_features_t features, int gso_type) { - netdev_features_t feature =3D (netdev_features_t)gso_type << NETIF_F_GSO_= SHIFT; + netdev_features_t feature; + + if (gso_type & (SKB_GSO_TCP_FIXEDID | SKB_GSO_TCP_FIXEDID_INNER)) + gso_type |=3D __SKB_GSO_TCP_FIXEDID; + + feature =3D ((netdev_features_t)gso_type << NETIF_F_GSO_SHIFT) & NETIF_F_= GSO_MASK; =20 /* check flags correspondence */ BUILD_BUG_ON(SKB_GSO_TCPV4 !=3D (NETIF_F_TSO >> NETIF_F_GSO_SHIFT)); BUILD_BUG_ON(SKB_GSO_DODGY !=3D (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIF= T)); BUILD_BUG_ON(SKB_GSO_TCP_ECN !=3D (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT)); - BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID !=3D (NETIF_F_TSO_MANGLEID >> NETIF_F_GS= O_SHIFT)); + BUILD_BUG_ON(__SKB_GSO_TCP_FIXEDID !=3D (NETIF_F_TSO_MANGLEID >> NETIF_F_= GSO_SHIFT)); BUILD_BUG_ON(SKB_GSO_TCPV6 !=3D (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT)); BUILD_BUG_ON(SKB_GSO_FCOE !=3D (NETIF_F_FSO >> NETIF_F_GSO_SHIFT)); BUILD_BUG_ON(SKB_GSO_GRE !=3D (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT)); diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index ca8be45dd8be..937acb1869a1 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -674,7 +674,7 @@ enum { /* This indicates the tcp segment has CWR set. */ SKB_GSO_TCP_ECN =3D 1 << 2, =20 - SKB_GSO_TCP_FIXEDID =3D 1 << 3, + __SKB_GSO_TCP_FIXEDID =3D 1 << 3, =20 SKB_GSO_TCPV6 =3D 1 << 4, =20 @@ -707,6 +707,13 @@ enum { SKB_GSO_FRAGLIST =3D 1 << 18, =20 SKB_GSO_TCP_ACCECN =3D 1 << 19, + + /* These indirectly map onto the same netdev feature. + * If NETIF_F_TSO_MANGLEID is set it may mangle both inner and outer + * IDs. + */ + SKB_GSO_TCP_FIXEDID =3D 1 << 30, + SKB_GSO_TCP_FIXEDID_INNER =3D 1 << 31, }; =20 #if BITS_PER_LONG > 32 diff --git a/net/core/dev.c b/net/core/dev.c index 93a25d87b86b..17cb399cdc2a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3769,7 +3769,10 @@ static netdev_features_t gso_features_check(const st= ruct sk_buff *skb, features &=3D ~dev->gso_partial_features; =20 /* Make sure to clear the IPv4 ID mangling feature if the - * IPv4 header has the potential to be fragmented. + * IPv4 header has the potential to be fragmented. For + * encapsulated packets, the outer headers are guaranteed to + * have incrementing IDs if DF is not set so there is no need + * to clear the IPv4 ID mangling feature. */ if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { struct iphdr *iph =3D skb->encapsulation ? diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 76e38092cd8a..fc7a6955fa0a 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1393,14 +1393,13 @@ struct sk_buff *inet_gso_segment(struct sk_buff *sk= b, =20 segs =3D ERR_PTR(-EPROTONOSUPPORT); =20 - if (!skb->encapsulation || encap) { - udpfrag =3D !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP); - fixedid =3D !!(skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID); + /* fixed ID is invalid if DF bit is not set */ + fixedid =3D !!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCP_FIXEDID << encap)= ); + if (fixedid && !(ip_hdr(skb)->frag_off & htons(IP_DF))) + goto out; =20 - /* fixed ID is invalid if DF bit is not set */ - if (fixedid && !(ip_hdr(skb)->frag_off & htons(IP_DF))) - goto out; - } + if (!skb->encapsulation || encap) + udpfrag =3D !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP); =20 ops =3D rcu_dereference(inet_offloads[proto]); if (likely(ops && ops->callbacks.gso_segment)) { diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 1949eede9ec9..e6612bd84d09 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -471,7 +471,6 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk= _buff *skb, int thoff) const u16 offset =3D NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation= ]; const struct iphdr *iph =3D (struct iphdr *)(skb->data + offset); struct tcphdr *th =3D tcp_hdr(skb); - bool is_fixedid; =20 if (unlikely(NAPI_GRO_CB(skb)->is_flist)) { skb_shinfo(skb)->gso_type |=3D SKB_GSO_FRAGLIST | SKB_GSO_TCPV4; @@ -485,10 +484,8 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct s= k_buff *skb, int thoff) th->check =3D ~tcp_v4_check(skb->len - thoff, iph->saddr, iph->daddr, 0); =20 - is_fixedid =3D (NAPI_GRO_CB(skb)->ip_fixedid >> skb->encapsulation) & 1; - skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCPV4 | - (is_fixedid * SKB_GSO_TCP_FIXEDID); + (NAPI_GRO_CB(skb)->ip_fixedid * SKB_GSO_TCP_FIXEDID); =20 tcp_gro_complete(skb); return 0; --=20 2.36.1 From nobody Thu Oct 2 15:19:15 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147443002BC for ; Mon, 15 Sep 2025 11:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936475; cv=none; b=l4FRlL3W3HtpNu9vzAD80MjK4ka5OIqMdvyKhd8YIRyiDSuE71GdVRtUNGoIMdFYG6Ki2lE0bI2wcjWQUBtLqrV8paSSlQg4r4TtEp//I80G0jGT0Lpqj7AHPt9SmGlPRiFVPbg09fKH5vVOn1I+XrM86VhYys7GC8l/BVeGJnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936475; c=relaxed/simple; bh=8q80aBTQPjYYcwHdvoV/1qmUgBNMkH1Czcrvfq9fhug=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rWyqCVXcjJ1Cv+gL+K80JUOXe42BSll3VP1YfAXYkkofrJgzLyHiHXSRRZn7mFAZoP6w0EXuCvQxzOVoqfsQQeaSE3dYfWhkdHc6FTHXeCY8N8nswTRCG9wouJisL+n16XnpX0MIakkBxdMLdWrvKIWv3TFVTG7XDZfyyMbiOC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QayV/Pdn; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QayV/Pdn" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3e9c5faa858so1530049f8f.3 for ; Mon, 15 Sep 2025 04:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757936470; x=1758541270; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=faZ2FtGaHZnHqLeK6MKy11AsyFTDtBKCXM47SFEYvtI=; b=QayV/PdnaAW8+1/LxiHDIwHAPiaF2Sk1tWhubYga7DfalENWIf29zUNlEwieq6fjSh 2SnY2+tioUsE0dWYvoyPfB3+ydTGNhCgpmDNQgvn78uxhYlkicAtonqx4DIym+wcBSib E9yOSRjj89MuG/4E7kJI5sRtAo2WA28iZEeXwzkFkXVisSzVRPUsQXFj8gMAJ0sBtarG awF2myMXlLaqZNtEJneyfp8zF0l8QxGDK6bra1Sun0gh+ZlhrpyUpEIJef5iQKMyYnCR VNGvouxl6oJw+P0ta/XwQms2GkvSjHWkBUYPlHGv9P2uSGLbJtAQwkPqXDTn3UI4cr/I BY3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757936470; x=1758541270; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=faZ2FtGaHZnHqLeK6MKy11AsyFTDtBKCXM47SFEYvtI=; b=rRKqqizy8XM2jUIydJrOASo6nKXJajqP0L5Eq8dvcI4LLVJhH3kmFolHQqbO1avQvR 1L4HFFlYwK/UPVeQUHLzJ6m4SppZEeFAeQM4HYpTAwdZfZqALvWToi+jnWbDveCzBawg OnykhVgttqjYjxWWq3TOWD6Uv6d7mV7QGv9wRtK/9nBaZELVaP/2IhZ9qetLPszGUdVJ 2JrKSY/KG1kh/h+oL0PXL+0OJLK1TMohSBRM6XMcVqef9isvsnXqgtP4lGO7OxU8SZGs KLAxC42oPpvnz63jvyscdFdCLP1Yx1zxgyunf9+r3hjOSKx5arCqHUFwO+XBa4YV+U8L woMw== X-Forwarded-Encrypted: i=1; AJvYcCWFlW3/nkUyAWl+ZrTBFkT9P8ku7bbM+jYcR9VX1YZziB4Iz2QU9qYNgqIBO4FT0KHgmw9b27YTqvASGko=@vger.kernel.org X-Gm-Message-State: AOJu0YwnXUkXRKLJFKjy5qpv3EE57rfgYIdtiOz7Djzt9HTwYnAKqtkc u4NmsfMMCRsGoTt23zTsXuIB6KTucOC/U1XP9Kx3EW1xdfaqyE33kI28 X-Gm-Gg: ASbGncvdIs3iQwItYG2QFbdTibESFFVMmpzkVCwUefTu83j6Fl9gE+O1rD1LDSQdvJy x6gxx8E5khNekfZ0VVWwapkxPwWJgMDIjoCMMbcioHw/2vNQh5iOrBUhPo8bCCk8nHHgzTd1Hof QNcaAfiUsmEmw9fMuJWnWA/7egXeQ1o4wVkbWpUMUmJAjmGtK2Ibf2g8suqkfvGuwt/cyZ5fINe UPkFEU30X6KE8R4U/pB8YfPPxmzBZ0kSuTcnb15x16p70CgKjqnACllapEXxre5sNxatGZ+XOxr ZP/6uWqKoePrf9P4ISx0G8UaQb6s64LqikSYrz2tmlUKG7sHT2HtSl2B94J5XZuJnkuGnqWNrsE 20ulErhVE3KddrdcPJX5K6otd30vH2ZS/EVHMdU+xt2DkxQUFQ765KSE= X-Google-Smtp-Source: AGHT+IGajJbXZZVwboMey3sfU/K6MaEBD+sg7n7w1uuG0pzd7ufEQNmXEJ4XRt3u3ojHc6lTpukOgg== X-Received: by 2002:a05:6000:607:b0:3df:b9e7:359f with SMTP id ffacd0b85a97d-3e7659ebc2cmr10191578f8f.35.1757936470227; Mon, 15 Sep 2025 04:41:10 -0700 (PDT) Received: from localhost ([45.10.155.13]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45f2cf19c68sm49708445e9.14.2025.09.15.04.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:41:09 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org, pabeni@redhat.com, ecree.xilinx@gmail.com, willemdebruijn.kernel@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, corbet@lwn.net, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v5 4/5] net: gro: remove unnecessary df checks Date: Mon, 15 Sep 2025 13:39:32 +0200 Message-Id: <20250915113933.3293-5-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915113933.3293-1-richardbgobert@gmail.com> References: <20250915113933.3293-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, packets with fixed IDs will be merged only if their don't-fragment bit is set. This restriction is unnecessary since packets without the don't-fragment bit will be forwarded as-is even if they were merged together. If packets are merged together and then fragmented, they will first be re-split into segments before being further fragmented, so the behavior is identical whether or not the packets were first merged together. Clean up the code by removing the unnecessary don't-fragment checks. Signed-off-by: Richard Gobert --- include/net/gro.h | 5 ++--- net/ipv4/af_inet.c | 3 --- tools/testing/selftests/net/gro.c | 9 ++++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 6aa563eec3d0..f14b7e88dbef 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -448,17 +448,16 @@ static inline int inet_gro_flush(const struct iphdr *= iph, const struct iphdr *ip const u32 id2 =3D ntohl(*(__be32 *)&iph2->id); const u16 ipid_offset =3D (id >> 16) - (id2 >> 16); const u16 count =3D NAPI_GRO_CB(p)->count; - const u32 df =3D id & IP_DF; =20 /* All fields must match except length and checksum. */ - if ((iph->ttl ^ iph2->ttl) | (iph->tos ^ iph2->tos) | (df ^ (id2 & IP_DF)= )) + if ((iph->ttl ^ iph2->ttl) | (iph->tos ^ iph2->tos) | ((id ^ id2) & IP_DF= )) return true; =20 /* When we receive our second frame we can make a decision on if we * continue this flow as an atomic flow with a fixed ID or if we use * an incrementing ID. */ - if (count =3D=3D 1 && df && !ipid_offset) + if (count =3D=3D 1 && !ipid_offset) NAPI_GRO_CB(p)->ip_fixedid |=3D 1 << inner; =20 return ipid_offset ^ (count * !(NAPI_GRO_CB(p)->ip_fixedid & (1 << inner)= )); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index fc7a6955fa0a..c0542d9187e2 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1393,10 +1393,7 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb, =20 segs =3D ERR_PTR(-EPROTONOSUPPORT); =20 - /* fixed ID is invalid if DF bit is not set */ fixedid =3D !!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCP_FIXEDID << encap)= ); - if (fixedid && !(ip_hdr(skb)->frag_off & htons(IP_DF))) - goto out; =20 if (!skb->encapsulation || encap) udpfrag =3D !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP); diff --git a/tools/testing/selftests/net/gro.c b/tools/testing/selftests/ne= t/gro.c index d5824eadea10..3d4a82a2607c 100644 --- a/tools/testing/selftests/net/gro.c +++ b/tools/testing/selftests/net/gro.c @@ -670,7 +670,7 @@ static void send_flush_id_case(int fd, struct sockaddr_= ll *daddr, int tcase) iph2->id =3D htons(9); break; =20 - case 3: /* DF=3D0, Fixed - should not coalesce */ + case 3: /* DF=3D0, Fixed - should coalesce */ iph1->frag_off &=3D ~htons(IP_DF); iph1->id =3D htons(8); =20 @@ -1188,10 +1188,9 @@ static void gro_receiver(void) correct_payload[0] =3D PAYLOAD_LEN * 2; check_recv_pkts(rxfd, correct_payload, 1); =20 - printf("DF=3D0, Fixed - should not coalesce: "); - correct_payload[0] =3D PAYLOAD_LEN; - correct_payload[1] =3D PAYLOAD_LEN; - check_recv_pkts(rxfd, correct_payload, 2); + printf("DF=3D0, Fixed - should coalesce: "); + correct_payload[0] =3D PAYLOAD_LEN * 2; + check_recv_pkts(rxfd, correct_payload, 1); =20 printf("DF=3D1, 2 Incrementing and one fixed - should coalesce only fir= st 2 packets: "); correct_payload[0] =3D PAYLOAD_LEN * 2; --=20 2.36.1 From nobody Thu Oct 2 15:19:15 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5028D2FF145 for ; Mon, 15 Sep 2025 11:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936494; cv=none; b=UdEOTRkVplnDdBsCcDYVG6Ut2hi4HYNx80aYmLa549R7GAw1r3ha9WsPxy2XfBiJRcLjxLWTD140049vxuPak8j9Dt4U0ECmveKUR/ZqSa6HE7ILwyJlQMAGBMLe2YfFw1BEOjAFHlv5b5N+1qURGkYt30Q5YoKlHW6bQ8savJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757936494; c=relaxed/simple; bh=8MEzHqJEQ2aWHJMkJzMjK33JjxtCm1bYj3TNlfG4lVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RKXNKRMjnyAPr0a/elHarSVhLCIKIeMezR4ywLhZeYc5ZGptiZzZwe1XiOsZFPf5TDz498AWhhp+WJqoUqD7O6QsGCGGGNGFSxLU77Jhcomh81SY9J3KoY8elZHgDZPFQVW4UXXjipw1QBsGfps1jtnScXYm3UZ5gUU7pEjfpI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NbjMSBgJ; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NbjMSBgJ" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-45df0cde41bso31343875e9.3 for ; Mon, 15 Sep 2025 04:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757936490; x=1758541290; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zcBD+Qv0ZPeDmK2bvIZ8tL4Dih4YYu9zRXXKcI28lv8=; b=NbjMSBgJlPPzyfiU+R3X/YFiXbOytOJ3U0k9hYXACgN/TzDvXGIe5i0lDEVHJmjJ7T HDzmgWRBQ/AP+3Ihkh2FEOpHYIU9NbYC2MxEIAv+olZ/K1z+n+TgLAnqwrqFMNT3O48W cmcebkH9Sfh8VUwZ+J+AhU++O2arADiNSTE5aSiA+JbzONovwwWwFFOq3qImAB4gIocX DXsLQAuWoskliqUeMK0FR5K5PePH1FJoZqLxw8aX8vHqrXyPRxhKW/WRfaiwEgIq3fmk RSKqLTdeweGDfxPP/x0vAvxSx1quFdlzC+md9DnPhVe8UEyIRoGggf5xihjddOpSH9kg cXcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757936490; x=1758541290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zcBD+Qv0ZPeDmK2bvIZ8tL4Dih4YYu9zRXXKcI28lv8=; b=DD+/xvlg+5zOsEafdnVRtIX9iCT7kAISmRAIbZXLBBBjXCLln07oE3R1qnMtGULclh v8sUbvFs5TxOu4k+rYNQDkLcR2I8Y9AXarP3cu5WXJsq6IPPrFoC2hgbc7LiwdftDBow 6EYbcgKe7b0guJAGqrVQfNFPmX/mR9QNQd2wJ6/KgXiyE6GdYBc7Ws/+RGcfi6jsO7a/ GPbTR+L+zTU26ZY+mt7j3as8eSh+g3unMTO+ntUM7owuqKwoeTRrQmvnp5P0klAgr98s hLaC9ZEVjo81ExFm6pS7yOBzG1DGwDsQ5n48558K0iBNCxJhfAh8xC+A0fKohkOkmtrz oIkw== X-Forwarded-Encrypted: i=1; AJvYcCXdxLwzxOi2MnhiontDHF5rdPymp5ezKA/eXmsrgARblgQ01EjXKb3X2cKq2lNDbNDJILNmUeW8TdhrUkg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1gEfRz+jope+zZZsVmNrTMh64zXmup0yWdoT8nm5ONioSYTx+ 6x/aTW+/Sa/c56Xe8j4hFk0ccoZlEYBi1YBOdMZ59LwbGmfbZwP18jeL X-Gm-Gg: ASbGncs9RRuBlwRfXu4V8r1zXP4XjNjQp411hqMKFtHMSZ2Z64WrtpVM5io4hgRBEW9 FlnHP68M01Yu7nh4qSxfkrMwqc3YXSVfjxoM2oZ4zZXx4L0tqUy7CcyxsqDDdYgbO8/qz+U7J0B T2HkM1l1WfoflvT5DLjzOUk+TlmRndULEDo+tPYul/kYECKFhHuphXDpIlmwYeqXbzitdyJ7bbG +HtWpO7sJo8rcoYRpy8h601XO7EsMfzcvONaj4ku4m6pxvqn6myS4XmasnlmmDHMqv250l4Ae6w 3W/H1Oc0QliO9BsRlVoM3aidN0lYRDADPnrHRzbMQXqWmXfZUT5qwNTGmFvpTdjuoQ3IQNPqGlB U2FCCQW6IO2RSDcLm4sC5th+HPwZ4XCROog== X-Google-Smtp-Source: AGHT+IEybk2FVYM0GPYM41odfQqYVDDvs/3s6JOJaYyRBYx9Z2H+EzWndEX4GODHUYF/31REBO66tQ== X-Received: by 2002:a05:600c:3511:b0:45f:2805:1d0 with SMTP id 5b1f17b1804b1-45f282562a2mr59040855e9.34.1757936490172; Mon, 15 Sep 2025 04:41:30 -0700 (PDT) Received: from localhost ([45.10.155.13]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45f28c193f9sm94955855e9.2.2025.09.15.04.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:41:29 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org, pabeni@redhat.com, ecree.xilinx@gmail.com, willemdebruijn.kernel@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, corbet@lwn.net, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v5 5/5] selftests/net: test ipip packets in gro.sh Date: Mon, 15 Sep 2025 13:39:33 +0200 Message-Id: <20250915113933.3293-6-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915113933.3293-1-richardbgobert@gmail.com> References: <20250915113933.3293-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add IPIP test-cases to the GRO selftest. This selftest already contains IP ID test-cases. They are now also tested for encapsulated packets. This commit also fixes ipip packet generation in the test. Signed-off-by: Richard Gobert Reviewed-by: Willem de Bruijn --- tools/testing/selftests/net/gro.c | 49 ++++++++++++++++++++++++------ tools/testing/selftests/net/gro.sh | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/net/gro.c b/tools/testing/selftests/ne= t/gro.c index 3d4a82a2607c..2b1d9f2b3e9e 100644 --- a/tools/testing/selftests/net/gro.c +++ b/tools/testing/selftests/net/gro.c @@ -93,6 +93,7 @@ static bool tx_socket =3D true; static int tcp_offset =3D -1; static int total_hdr_len =3D -1; static int ethhdr_proto =3D -1; +static bool ipip; static const int num_flush_id_cases =3D 6; =20 static void vlog(const char *fmt, ...) @@ -114,7 +115,9 @@ static void setup_sock_filter(int fd) int ipproto_off, opt_ipproto_off; int next_off; =20 - if (proto =3D=3D PF_INET) + if (ipip) + next_off =3D sizeof(struct iphdr) + offsetof(struct iphdr, protocol); + else if (proto =3D=3D PF_INET) next_off =3D offsetof(struct iphdr, protocol); else next_off =3D offsetof(struct ipv6hdr, nexthdr); @@ -244,7 +247,7 @@ static void fill_datalinklayer(void *buf) eth->h_proto =3D ethhdr_proto; } =20 -static void fill_networklayer(void *buf, int payload_len) +static void fill_networklayer(void *buf, int payload_len, int protocol) { struct ipv6hdr *ip6h =3D buf; struct iphdr *iph =3D buf; @@ -254,7 +257,7 @@ static void fill_networklayer(void *buf, int payload_le= n) =20 ip6h->version =3D 6; ip6h->payload_len =3D htons(sizeof(struct tcphdr) + payload_len); - ip6h->nexthdr =3D IPPROTO_TCP; + ip6h->nexthdr =3D protocol; ip6h->hop_limit =3D 8; if (inet_pton(AF_INET6, addr6_src, &ip6h->saddr) !=3D 1) error(1, errno, "inet_pton source ip6"); @@ -266,7 +269,7 @@ static void fill_networklayer(void *buf, int payload_le= n) iph->version =3D 4; iph->ihl =3D 5; iph->ttl =3D 8; - iph->protocol =3D IPPROTO_TCP; + iph->protocol =3D protocol; iph->tot_len =3D htons(sizeof(struct tcphdr) + payload_len + sizeof(struct iphdr)); iph->frag_off =3D htons(0x4000); /* DF =3D 1, MF =3D 0 */ @@ -313,9 +316,19 @@ static void create_packet(void *buf, int seq_offset, i= nt ack_offset, { memset(buf, 0, total_hdr_len); memset(buf + total_hdr_len, 'a', payload_len); + fill_transportlayer(buf + tcp_offset, seq_offset, ack_offset, payload_len, fin); - fill_networklayer(buf + ETH_HLEN, payload_len); + + if (ipip) { + fill_networklayer(buf + ETH_HLEN, payload_len + sizeof(struct iphdr), + IPPROTO_IPIP); + fill_networklayer(buf + ETH_HLEN + sizeof(struct iphdr), + payload_len, IPPROTO_TCP); + } else { + fill_networklayer(buf + ETH_HLEN, payload_len, IPPROTO_TCP); + } + fill_datalinklayer(buf); } =20 @@ -416,6 +429,13 @@ static void recompute_packet(char *buf, char *no_ext, = int extlen) iph->tot_len =3D htons(ntohs(iph->tot_len) + extlen); iph->check =3D 0; iph->check =3D checksum_fold(iph, sizeof(struct iphdr), 0); + + if (ipip) { + iph +=3D 1; + iph->tot_len =3D htons(ntohs(iph->tot_len) + extlen); + iph->check =3D 0; + iph->check =3D checksum_fold(iph, sizeof(struct iphdr), 0); + } } else { ip6h->payload_len =3D htons(ntohs(ip6h->payload_len) + extlen); } @@ -777,7 +797,7 @@ static void send_fragment4(int fd, struct sockaddr_ll *= daddr) */ memset(buf + total_hdr_len, 'a', PAYLOAD_LEN * 2); fill_transportlayer(buf + tcp_offset, PAYLOAD_LEN, 0, PAYLOAD_LEN * 2, 0); - fill_networklayer(buf + ETH_HLEN, PAYLOAD_LEN); + fill_networklayer(buf + ETH_HLEN, PAYLOAD_LEN, IPPROTO_TCP); fill_datalinklayer(buf); =20 iph->frag_off =3D htons(0x6000); // DF =3D 1, MF =3D 1 @@ -1071,7 +1091,7 @@ static void gro_sender(void) * and min ipv6hdr size. Like MAX_HDR_SIZE, * MAX_PAYLOAD is defined with the larger header of the two. */ - int offset =3D proto =3D=3D PF_INET ? 20 : 0; + int offset =3D (proto =3D=3D PF_INET && !ipip) ? 20 : 0; int remainder =3D (MAX_PAYLOAD + offset) % MSS; =20 send_large(txfd, &daddr, remainder); @@ -1221,7 +1241,7 @@ static void gro_receiver(void) check_recv_pkts(rxfd, correct_payload, 2); } } else if (strcmp(testname, "large") =3D=3D 0) { - int offset =3D proto =3D=3D PF_INET ? 20 : 0; + int offset =3D (proto =3D=3D PF_INET && !ipip) ? 20 : 0; int remainder =3D (MAX_PAYLOAD + offset) % MSS; =20 correct_payload[0] =3D (MAX_PAYLOAD + offset); @@ -1250,6 +1270,7 @@ static void parse_args(int argc, char **argv) { "iface", required_argument, NULL, 'i' }, { "ipv4", no_argument, NULL, '4' }, { "ipv6", no_argument, NULL, '6' }, + { "ipip", no_argument, NULL, 'e' }, { "rx", no_argument, NULL, 'r' }, { "saddr", required_argument, NULL, 's' }, { "smac", required_argument, NULL, 'S' }, @@ -1259,7 +1280,7 @@ static void parse_args(int argc, char **argv) }; int c; =20 - while ((c =3D getopt_long(argc, argv, "46d:D:i:rs:S:t:v", opts, NULL)) != =3D -1) { + while ((c =3D getopt_long(argc, argv, "46d:D:ei:rs:S:t:v", opts, NULL)) != =3D -1) { switch (c) { case '4': proto =3D PF_INET; @@ -1269,6 +1290,11 @@ static void parse_args(int argc, char **argv) proto =3D PF_INET6; ethhdr_proto =3D htons(ETH_P_IPV6); break; + case 'e': + ipip =3D true; + proto =3D PF_INET; + ethhdr_proto =3D htons(ETH_P_IP); + break; case 'd': addr4_dst =3D addr6_dst =3D optarg; break; @@ -1304,7 +1330,10 @@ int main(int argc, char **argv) { parse_args(argc, argv); =20 - if (proto =3D=3D PF_INET) { + if (ipip) { + tcp_offset =3D ETH_HLEN + sizeof(struct iphdr) * 2; + total_hdr_len =3D tcp_offset + sizeof(struct tcphdr); + } else if (proto =3D=3D PF_INET) { tcp_offset =3D ETH_HLEN + sizeof(struct iphdr); total_hdr_len =3D tcp_offset + sizeof(struct tcphdr); } else if (proto =3D=3D PF_INET6) { diff --git a/tools/testing/selftests/net/gro.sh b/tools/testing/selftests/n= et/gro.sh index 9e3f186bc2a1..4c5144c6f652 100755 --- a/tools/testing/selftests/net/gro.sh +++ b/tools/testing/selftests/net/gro.sh @@ -4,7 +4,7 @@ readonly SERVER_MAC=3D"aa:00:00:00:00:02" readonly CLIENT_MAC=3D"aa:00:00:00:00:01" readonly TESTS=3D("data" "ack" "flags" "tcp" "ip" "large") -readonly PROTOS=3D("ipv4" "ipv6") +readonly PROTOS=3D("ipv4" "ipv6" "ipip") dev=3D"" test=3D"all" proto=3D"ipv4" --=20 2.36.1