From nobody Thu Oct 2 04:45:14 2025 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 5792426E718 for ; Mon, 22 Sep 2025 08:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530483; cv=none; b=d9h1565SIeOA/UaotXzd+jpabAJEfe7nbflCGJI2NjAc5+cuJ6MfatI1azzZcFiz/hJGMtcmi0pQ0AmKQlhxumt0LCjBJAxYF5rHZF8EX6TZ+mp+cMh4+iXz7LEYl08Q52vIhz/g/m+oipsPx/fMdW0YZNi6/d7ETfBOvr2x6kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530483; c=relaxed/simple; bh=5DFBuSdlxaCcOvy2y416jSTiEqL4AHa8+uh89xjhSCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SrIQeYOPpPKxxhM1ATh2yB4e2ieosKMs6kXEEFl8F+60RnB00ivYc8bj5CBzo2TghK9CenHzezvFo5hc4KoWW2vEEQxb+ZIMYGIbRJWV6c7GLj4vtEkjh1q+ZIvrHhJWpmt87EFQkdsoLXG+LakgfZdbOZUpSUA2kUVsR8D/iqQ= 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=TH4Eyr15; arc=none smtp.client-ip=209.85.128.43 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="TH4Eyr15" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-45f29e5e89bso49562815e9.2 for ; Mon, 22 Sep 2025 01:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758530480; x=1759135280; 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=nwLDNBiVN98UCDyIlQ/l+MZhscT3bhY9tzLzQhwCiT8=; b=TH4Eyr15ly7xG5pCTVxVpUAo1HBR/BHbnNEJeVqZ1Hc0S5181IuTfJYsRWBU8DlLn1 qj38WVIqYbfiLUvn0FwIpe7orUwGN9DYrtHiWi9Df7GBu7ffuHYihBj7r3WMmCzQXcnA 1PEG18FCm1JrBPG7dFJ9mToNGam/sZThllCve3NQTW2btJ+1ZgiqjCgKWmYBxPp9Jxyv ens5znhc1E5kw2R7h14+wxNJM+oGbiqxJLXuVia5WMCrtBys2jfDAQqO3wa400FMnxGz oft/7rNAISjKhqF2QX/gLmCGQDQ5PX9grFlmo89Yl5YH7RrmsPsIjj0nFqJ40JI5LB4N rS3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758530480; x=1759135280; 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=nwLDNBiVN98UCDyIlQ/l+MZhscT3bhY9tzLzQhwCiT8=; b=axL0e4leeZUlQbh1PEkD6ZgP0xcd5T/TijihpP33Pvl/e9tuLattrhrD6PyEMZC3xf bXCX1fLT0kZL+rXXCjGmT05xdImaKvwAEeq3dC8nJy6OASJKrbtgv38uryuv336ldELn 4xF9R93Mij6Hm+rDirAY1vqAq4Tp0QI0v6Tmhkzi2IFfjuZVS5efkyk3bJKgQAx+Rktd 9mZhIz2SXCkSgRXvr9HTH9ZBRAD06PA1PyjfLLA1vQbbqnXYRoVmoXM23TofcdPuqVsH y8GFpXBOxRu1Y/23E0P3wsT6FVaWAjHRmSXg4GVJVT6LAIB76BQ0wcHZ8gWvfVAHc0a/ 3guA== X-Forwarded-Encrypted: i=1; AJvYcCVI/agraJQCvDWy8mgQpvGqIJ+61LsCeFoD7M0sAX2UAcUQUIuTDa1M14Cp/EMU1jP3TZTPkScGSQtlvJE=@vger.kernel.org X-Gm-Message-State: AOJu0YxUBzB4LLE6yjYpoJIam9hvx4W66+7SDT0CtYX9R61jD9Y6/+FW R6d8KKCFAX/RmNe/nuf2d+BiaVPm80tphflKCcKDqDhsk9oO+y/ldujn X-Gm-Gg: ASbGncsmmo//Ik9i6p+0KVA1P6ycHNe0qJcEGBXRMUe0LlVSZFXrtDErBFqXG4NQpl7 dDB3Q3QncXjxR3TQ2mukq2Rl1b6eOjmhZBNupbsQGROhxGZlkqng5EKV2Jl0mYgrmR2Ty65tD4V s7PWCv+sXMjk4321+7sMLOJc+QDseI8GwlncbnVYPaYrY5+oSNWyHmOhPqpP/E2QGV/DHQmO+am EWywurDHaucGGqSFskZR5K8ixlSEKMUFT0Hg2qJ/4A7oB1gczp0rw4Oom+kRW3svpRt0a3/u3zd timP0u3IUEvvi2Wcw1qUQ8+UqvdBjp8zp4PTpnIHN76JTuszW5NxXwyrglO4L2ChxEETsuyPFkz A5yT9xFPLPK5M/HQVQ1a5uEM= X-Google-Smtp-Source: AGHT+IHaiGSsCBoFehcEyd4rvxskZuoU5lMZMYuxI8AuJMk7Xjxp08j/sF42lAeZOvktZWRU0AnQTw== X-Received: by 2002:a05:600c:3b05:b0:45f:2cd5:507c with SMTP id 5b1f17b1804b1-467ebda8e6emr110357565e9.36.1758530479585; Mon, 22 Sep 2025 01:41:19 -0700 (PDT) Received: from localhost ([45.10.155.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46da6900832sm10404135e9.0.2025.09.22.01.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 01:41:19 -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 , Willem de Bruijn Subject: [PATCH net-next v7 1/5] net: gro: remove is_ipv6 from napi_gro_cb Date: Mon, 22 Sep 2025 10:40:59 +0200 Message-Id: <20250922084103.4764-2-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250922084103.4764-1-richardbgobert@gmail.com> References: <20250922084103.4764-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 AF_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 04:45:14 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 8EEBF27F73A for ; Mon, 22 Sep 2025 08:41:25 +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=1758530487; cv=none; b=K7cZ1FdDzFFkQe0u/5YlKECClxU9XChCBKeUtSJIOdu/bTUIqiRVT0JwvrjP09m9SJhPq4yPvljQuUEbHCkxUfcfqtlkWB9UtUBiuvOtW1ACw0+JSq5E48UTd053/qtshmlIW6qhbk20CksDFFQXlrR2MD4obkpKG+AZbs2+gik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530487; c=relaxed/simple; bh=USAi/gOC4Gd3dmiYQ7sYFTZdRsnH0JxGjY8OHY6vf8g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sBvO/fr9tBi+tSD4tuO44n/0s8JPecqcTrs6iagFxeV9G3r7Vs55cGmY4T7X/uHoXXOblPVePDf+PwLcAT8g89g0Y5sRwOWUJ5b2ctSJp/yuetsOwAG5/BwrchJdZxwcRok5O6zezpoRkyVUQyLHlv10G9l9oOSB+gu4osAkQrg= 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=kRmbwzQF; 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="kRmbwzQF" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-46c7eb3ba1fso8103805e9.1 for ; Mon, 22 Sep 2025 01:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758530484; x=1759135284; 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=TWo6LZdJOajM7eDBZoJDuM0DMuX04TB4v3UVMrne7AM=; b=kRmbwzQFbEZUwO67OupfT20Ah6mq0KPaXpqhdXt51cixFCVVV8lQM6JW/soHcM93Jg UFsqtg6LxXUBh2FnMbzZIV+KiicwTcSFS2/f8SmtUDUzx7J8vkkYztniJ5h17KyPmEqB Y/pEAXa0ZacovWgjHMxbCnITf+Spn7w21I5zokwDHxxnyXT8nomTvMT8Ua/bS+2lWLpq zILZYVJZAhocYwc2jG3vBKX1kO1fOYF2aMDYPtSgvcgZaJC0yLfKq1lBGJzHnRGphWxn cv+LNaxYiFypfU5i7vjWPkujww3PVFnK2fxH1VrOPmyPquQGeE3+kZcv3VMT8fU/FxM7 ClJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758530484; x=1759135284; 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=TWo6LZdJOajM7eDBZoJDuM0DMuX04TB4v3UVMrne7AM=; b=WtCKWzSFG+hbZVPuZb+gjiLt+WD72K1Ru7f1W4CmETXNJtlJkdTVRG5ifPSFcIkE8B hx9OQZLQSbvzn13EAwPm1Hua4xD+JLqa7zLV33C8lTaaiH3EYqatK0LXDdBAAE4UiUDL nnZ5uBEPfd+BUE+RfOa5xaUDn+DsBg6nWizSr67N2IX4bWCXVnFMeeaT+7Kj+3jwJLhx NNCLFlowPssY2L000NJ7F1/EGTpv40FkHcumqkuA/ivjBx5o4Ut10ueScd2rZ0vPQBzF 2UaSp+gy7eqEemXia8keFN9ADvv7TK3jRX50ZhJZn4u1zY1K5NzbZXVw1z9sQVxDndJq E1Zg== X-Forwarded-Encrypted: i=1; AJvYcCWPRgCiAE54pbBCkUifNivICKVkYSsV7Zt68Du/bzQO6tWHQNdcQfgFrlLrY48FRnEMqfu5N662WYww2ng=@vger.kernel.org X-Gm-Message-State: AOJu0YxG/aE7aAd4f0k6lnxr7qViHdnnhRJzp2mGWo9US/Jim2vsUbM7 5dyFxmg9A81lSsLhoDBFaoNR/c/EQppVEP43T++3op5kq4M5KLURNak/ X-Gm-Gg: ASbGncvZ0oVhvtpGvcSviHE2I0/WedG1y1KOBQnz1kdFSQ3TlF6WrcP1aSo38AU+XgC clQLcs/xs9wYzeLsV7QEDT3NVX8B2JTyo4fESzCyzVYkq9aihToqCZEO0l+r2cd7ShWo5qIxpct awCga/QT84JW7eW9tUHSysqQCwx2kJM1YtyKVVur1xcS/hV4ap0fmStCWI1NLljmjxL4QyS1jeB CsENxA5utURfmJDiXeLZL1nEGZ4Ti9Hq+sRgFVXY/ZnAMugs4twmYZFJKkbiUWkwBtswoZwGLC5 2Rj73trQxFAAlZt+WFWI/hP52/SCX4ZYMwFrSVz6p6W0KWi1lj8qC8I2/AVtzhRHX0vEEmyYmu3 43DDJlOYj6mPQz6/VzLTsl2Y= X-Google-Smtp-Source: AGHT+IFrGiXGA7LHSS3EIQjiUfLhqP2WxXsbFkQVDxEHVdRpBujBxAxj+ebAXjLWlrRcB+JKw7SlRA== X-Received: by 2002:a05:600c:35ca:b0:45d:d0d6:223f with SMTP id 5b1f17b1804b1-4682c93f43emr132704465e9.0.1758530483632; Mon, 22 Sep 2025 01:41:23 -0700 (PDT) Received: from localhost ([45.10.155.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-464eadd7e11sm203246715e9.0.2025.09.22.01.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 01:41:23 -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 v7 2/5] net: gro: only merge packets with incrementing or fixed outer ids Date: Mon, 22 Sep 2025 10:41:00 +0200 Message-Id: <20250922084103.4764-3-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250922084103.4764-1-richardbgobert@gmail.com> References: <20250922084103.4764-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 Reviewed-by: Willem de Bruijn --- include/net/gro.h | 26 +++++++++++--------------- net/ipv4/tcp_offload.c | 5 ++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 87c68007f949..e7997a9fb30b 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,18 @@ 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 04:45:14 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 5B576283FEB for ; Mon, 22 Sep 2025 08:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530492; cv=none; b=adDHpM77lO+fkG9Dwv3mbF1FZHwrVw+WpjhPuLegPzqyjUhEzVm8tb4d4aCo4n4wznzWZ0E+DkZF2jU9TT0eobIv1MiFON7M3nOmlfWVy4Pk1FBQ5Q11ZDiH8t302dYIyWkUJpUTs6HhyeQM3XMZxdOAbIwoMHJKAfh1IyAnQ40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530492; c=relaxed/simple; bh=xHBeMZ40V/ndtnqJBXypca+xdQCsejF+MNlvnwTQNyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JjHOKgcRplhlulfZBB1Lq6GhlWN/i2Acy3q7TruOnQrKHcZpfEN38wZX0T48oAIdjOVwGoIH9bET6W2943GQmFEph1uI01ulaz0oxWOIkVD5f9PWYmONDC39GoDx0jgYaAH0dLU9tmXYMjNPm9KU4Sd5Ho+QUwRKmOGFFh13MkY= 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=iVlAqPTf; arc=none smtp.client-ip=209.85.221.51 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="iVlAqPTf" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3f0134ccc0cso2881592f8f.1 for ; Mon, 22 Sep 2025 01:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758530489; x=1759135289; 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=segv9PY/t+hoz3E+5VzjH8RssyHsJxDXqcIennnf5jY=; b=iVlAqPTfKkjDEVXUQRgHRVlw2M+30GkNs58EsGjSyEczg0mUKD3bwu98UBWc7sQKXy JCxphoIHTQ85PC4bQaqNQDPGoROKXqH1tQ1hFKyn+Xz0U2kH8HkgWHbOAWt57o4cJyCc 6mLH383O5umz3JWzJicPvlgfAvDTRElGcP5BHRgI2JimzmdOW7HNoCaK27hPrBWNgdDn aNOo4ml0/xXhWg7sU7m+dbECWXboh3lnSYYjhp/ovLtrOCYhNEo23Y+q6Q5WvmTStM+b OchCkWkopwH/ffv9GX1TUHiKGS5cjAf1aG72bP5aanWHe4mvl97Z/W0wLRDqdunvbXLO u3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758530489; x=1759135289; 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=segv9PY/t+hoz3E+5VzjH8RssyHsJxDXqcIennnf5jY=; b=Rw0HuDRVs30C2DJT4zEmd7vaKT12C1QmDIWVfeUJtqN3ItBROvkxgOCeUrF3DhRjhY mpwes/Ct13R7Co5BdO/ZBCkXlX2y7f+yMjP/NJEXnFuAGNrxA3yqUO5seNXPiVSDorFV mGGQ9qi8qftLHi0p5JyB+s1opb8/7oosE+C9Y7KxCMWvtbxn1meL1PIeZMR8HPNxPOMU BaQDeg7Pzv2axZT2IrCQ8dgx/oDezX2L+mPK1Nr8+kP71iNS931EPqGBc1bn2Rwu7oJo AEJfZ1a3Drq/P/4czrYqmg8vnm/bQMHSOOeHaMNL0LJJv186tiu/jyu6Ke8LLq7v1cdx xDtA== X-Forwarded-Encrypted: i=1; AJvYcCUnwV3GQL1iWsesxoHcFrvA+Ur3Xw63wN9hW9XGz5MRUavDpO051kW5YjEFLeUEK1FTnd8lN3vOs8UyPmk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2TYvswm79xXccXgixZx+3YdH0xpt3mDQ2PzUYeHZOgWfacG1c OSPJbCpX8RM4o6nnbmEqULV3kRlm//PnQZbKowFkcuQ9Tq1hGLRXyPFB X-Gm-Gg: ASbGncs/ASZ9urHeE2or5WtcIi1eq6JVai8iYkbA/2uVWyww31wQT4uSjXFru/bboaC T6SCjLxxCswbs0QyxSs6xfW9GOEn/zOo6BXLvViCrn5KUpheXe3hSckqOp0ia/xkkaa0ZjjtmNp aO4UWp+2bP6Secb8qCmOhW0+kTUEMXehOdYZ4XhGdpT3RsKQqrr4LMMpeEnunaNDiv0351xrO7X ZupYNdbeOaJj4RQvefnALAHKJXB+40sXPMB2Bh0gU3uiTD1P/Rzrve6EjJ9ilm1yLts4FunUwJz E+EUpeovFNC+WcLHZjZJKQmvY/0Lo1nt274W8OYt7RXPT/J8cvaPNcAhqhVRqN3PzfjZ6lumLYS 7A43adNM403eFgRZ2CJGyyQ9NBHruLrLqgQ== X-Google-Smtp-Source: AGHT+IHpXgUrO983XUMRbymEldceN77ulbVLPJQmMh28ZozissGSVv9VpqzPY9r72V3OFYyMD3F5Cg== X-Received: by 2002:adf:9bd5:0:b0:3ee:df4f:6c4f with SMTP id ffacd0b85a97d-3eedf4f6dc5mr6739139f8f.44.1758530488270; Mon, 22 Sep 2025 01:41:28 -0700 (PDT) Received: from localhost ([45.10.155.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3ee1227cc37sm17609297f8f.7.2025.09.22.01.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 01:41:28 -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 v7 3/5] net: gso: restore ids of outer ip headers correctly Date: Mon, 22 Sep 2025 10:41:01 +0200 Message-Id: <20250922084103.4764-4-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250922084103.4764-1-richardbgobert@gmail.com> References: <20250922084103.4764-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 | 8 ++++++- net/core/dev.c | 8 +++++-- net/ipv4/af_inet.c | 13 +++++------ net/ipv4/tcp_offload.c | 6 ++--- 8 files changed, 61 insertions(+), 30 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..480f66e21132 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..646fb66ba948 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,12 @@ 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..282497455676 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3768,8 +3768,12 @@ static netdev_features_t gso_features_check(const st= ruct sk_buff *skb, if (!(skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL)) 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. + /* Make sure to clear the IPv4 ID mangling feature if the IPv4 header + * has the potential to be fragmented so that TSO does not generate + * segments with the same ID. For encapsulated packets, the ID mangling + * feature is guaranteed not to use the same ID for the outer IPv4 + * headers of the generated segments if the headers have the potential + * to be fragmented, so there is no need to clear the IPv4 ID mangling fe= ature. */ 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..2cb93da93abc 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,9 @@ 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; - + BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID << 1 !=3D SKB_GSO_TCP_FIXEDID_INNER); 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 04:45:14 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 0431F285079 for ; Mon, 22 Sep 2025 08:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530495; cv=none; b=hE6EoP/MMS4wq4cjCnHtcyeQkUTivZ5veQ6P9A9p5NzEWMp7J5xekwWIAJpk6nZELN6iVY8XPaLqmE72YSKFZ9+ovVrwkhJ1RRUCwvd42HYrud+mIgk8J0Lqui4IesgHYDROOMdffYj+d61c131hwfyr8KYnPk4jF7oRmwCFAAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530495; c=relaxed/simple; bh=FnSCo1u0YAYhyXjCE72+PSsG+c5VoZXcmKImeHXt7po=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lWWahurxqEyCoK5kNJNBtr9ZJqmo0qTzMJjyHy8t3m3ZUhd4fFmws8oDL9jhx5A+4TVDQdxHPHEHILlThRNv+hufBRjWPPOfuHG2Dv1skoRFvSjDC9FAWNWuvlI03lm2D/cgp+P5JR9q9iy9Ln6NYBrdxmJXVVSSCfu4JewASY0= 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=geQiTDOM; arc=none smtp.client-ip=209.85.128.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="geQiTDOM" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-45dcfecdc0fso36174185e9.1 for ; Mon, 22 Sep 2025 01:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758530492; x=1759135292; 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=kbhWq7bacMfDhovko3bwV20Gk//EeQX7vpI4G5CW2zw=; b=geQiTDOMyvstNflXSSidKy9dQKkHoaALW5wbUeX5jzMak6xQvZpd5HNApLdhWyhVr6 11n0IuIYPZgbpX95yty1qrm/utLodelZENLTLrfssj74mqJQ9Qxri32ofyzH8Vfusfgh o4y1vRrhC4DAER7oDfvgQmdFwz7eV0HhqEwgHMGX5t3kzWiGNp2c2myzHeS9hpzG975G YrSjlFhOXUNb+sWmrbZb14+xjgnhV5+Zvqo30/wpCIpDAfqW5iNwy36963I99hOQ48iZ p1wh7bUOB0JS02gwnrxAPI4yg/2SCezbFnyMFAw3PPLTFlaOx5fAFaFD1PDMGnw2X1Ne MBrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758530492; x=1759135292; 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=kbhWq7bacMfDhovko3bwV20Gk//EeQX7vpI4G5CW2zw=; b=w9GWEtXEtRS2gQI/c32mSUpttnwz0v8EGDxzFAIVdZc/MBq7vX+j2yL+hBw1S+d/PO 5ERPtsPHFzDbpM9ezFtjwBccS3tI8Dz3aG1GtJzUWH3kcm2+SJpfkhBG1wVS6PnOqQZe 5MISfsyGglkcgKK8ae1K0K2IF7po/qI//eKMWKavUljwgKiJei8DJCW9/nhQX12Y8Mw6 W+IdBgyOkT+PnhZvhI2ZLC+1E0nwC9q/mUAdH4pmLfdVNW9D19pXisanI5OCqSWIdKCF ghaP8nQxaTNrQf/HDJ/NTi25ZA7woZCHugQTEhvb+kSBGbWOkBNZtJUbOmOMWR6Hquf8 uBIg== X-Forwarded-Encrypted: i=1; AJvYcCVaIID4NuSayPMzlNgARmwkXH2fVLg1b4R6l3/yevbtBsYzeWX/2oosAXM8qknjy4ExFHajVlK4oEwklbI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz32Xn1tXmC88dYKkCNEMgecJqWyvWop5lJ248LlzLSpUqIPZqj KXcngRROTt9P0odlDaontU36b+l3kqC24Z3jpZ+Kf4hUdVSO+WVucZ7P X-Gm-Gg: ASbGncuyBjMTJpIiDR9Z/9fd3/5LdX2TrohznQJQSlNy8UCb0Z+aothPYcnye+QEKdW Uo17YCIZH77J9aQBp7cdnqY3q/AL4tihf9n5unCq+gYwgfwXr8+D0sRk5cp8MzswAWL7EJwwJ8i 4V5zo7qKp41+LwRc7OrtjNQ0O6c3cVid3qx4NmULHz+Rx9jmfiGkBTBBbr431sLSBYiaKl/ZZQg 4xdQGUJC0gkPfJ5i2sjZFTCNLZQO7pW/6mnkh5oUUHNo/eGI2b8fvIn9NAuB3PFMNHkCcSk3XtW KDBMLeFpkhjErPTNePmWOnABMjcsvn8goe0S+wtnRnrD5yR20PCts+D5X6KdRIOJuG8HR1PiE76 SSHBHf4VEi/wYiONKqPhjrskkNcqi7jICRA== X-Google-Smtp-Source: AGHT+IH3SbqIF/VHujV0kvfVrh1tmvGWN3BulB05/CGMB041QtTOt1ISeqjex9uogZEaAPqqprEmdQ== X-Received: by 2002:a05:600c:c04b:20b0:468:86e0:de40 with SMTP id 5b1f17b1804b1-46886e0de83mr77577125e9.4.1758530492088; Mon, 22 Sep 2025 01:41:32 -0700 (PDT) Received: from localhost ([45.10.155.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46dea20f833sm13661605e9.10.2025.09.22.01.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 01:41:31 -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 v7 4/5] net: gro: remove unnecessary df checks Date: Mon, 22 Sep 2025 10:41:02 +0200 Message-Id: <20250922084103.4764-5-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250922084103.4764-1-richardbgobert@gmail.com> References: <20250922084103.4764-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. The merged packets will be segmented into their original forms before being forwarded, either by GSO or by TSO. The IDs will also remain identical unless NETIF_F_TSO_MANGLEID is set, in which case the IDs can become incrementing, which is also fine. Clean up the code by removing the unnecessary don't-fragment checks. Signed-off-by: Richard Gobert Reviewed-by: Willem de Bruijn --- 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 e7997a9fb30b..e3affb2e2ca8 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 04:45:14 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 26B23279DAD for ; Mon, 22 Sep 2025 08:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530502; cv=none; b=feOFdYZ6LZRG2yED2fe6kcFLzJkNDw4hIZedhkIqVic5B3WYDx+K8HuibocnXFM1ySwNGHYIPsmsYaQtza0SlpADxdofsT2yl7oJ8D54Ltz7oj2Jin5A1Pa+DEsAle7IFXY1uA/n6j/D/BrjoIL5vwBkHIydJ7hhPfV0MXF+km4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758530502; c=relaxed/simple; bh=8UM+az2cWYByr8ObEhssbPumaYByLl4dcAU6DqAxNeo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nn6KfqqjxvlvFJ5WWq31a5CPu2ccxcREIVdvKHbiA2/Ek0i7bff8G6VZnnR0CrOLql2ZZZFqh/nEe3PjgaN0bbITeE5RktzfU1/3bnXjuvOmPoLEwS4bsR4bKUB8jskoODgXYhXh2dDu8e29TRaH0GO5Dh6YFTyqh+fxXYqRIhI= 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=UkJGiM+Z; arc=none smtp.client-ip=209.85.221.44 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="UkJGiM+Z" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3ee12a63af1so1735137f8f.1 for ; Mon, 22 Sep 2025 01:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758530498; x=1759135298; 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=mRVOBg/z8tQ2d5GGqKN0EIKc3OKKueO2kHvL3hZOMP8=; b=UkJGiM+Z9RrsH3LVZr0yUeARVaP3l5eSHsNIga15/i9cRAyebKbalixgsSUxmE04no i4zvgLaKF1EctKv7BMiokxdIc6UJeJMoXv34FDELDKuKsu2CJsFpAmh2i8uqTwjacKrh lM/yWRltPMbo7EnV6QLEecDdK4m4BikVEsCSQ3l+Grmrpcp1SfguVOAPqNXS1R8PukEo XmQJJAcr/xQLDXJpaUTAam04f4glFQN3Cm62eJIEoE+1jHmWmfuy1dXTkLVnDW7wBgrN fi4/jgHgsqBkXhQSPnzDIW9mgw+rotzbDDEtCcwpdPxl3onmql8TQUjhLe1usKHySsEx A3nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758530498; x=1759135298; 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=mRVOBg/z8tQ2d5GGqKN0EIKc3OKKueO2kHvL3hZOMP8=; b=cK/goirUNvkqYLGoNpF2eEHo1KtGf9szFt3jHIOjifIC9liwLZyUrYkG862La7H1wP 0KTZe5hT/cL87G064jOksuDpwKyA4kDrD4UrCf6ZNpc7aiGgaFIxbPimMumTA5+F44JA PQ1LriMKUneOzVWvERd4w8sRzTVcoi0Ge4L67Ls7J6rU07TF9m5MO78t19n0AFYni/17 1KBvdTMcxDOHG+Ku46IAW/MRmSf83Pk4KzQ/YnNFu/xoZIU8ue3n1ZFM7pe6vsldZxSB hYRay3Q93bkStC0AyGZaHh3ydS/BzGLegS5mnHFTc7mS6giyvR464yCFMU6XRXTVUfrS YAwg== X-Forwarded-Encrypted: i=1; AJvYcCU+q28uzBk2H03p/fY5VoSNYCT7Bq9+9BHQx1Jjno0/t0gelvEWMJ5PkpFoD2xhtRbuxe5yTchf06nIqvw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu8j5sNNLQgUVutwudtgjKN9VCRpVqRwoIkYeBc2rPg6EQXUfk z5x/WTOXZoYFfGff4jtrmNwKJp989ktCqPVD4kkHVUsuytJ1XreR/EFP X-Gm-Gg: ASbGncsXITZzDJ/UYvtSMSnyUuVhivtz16Iyd5g1rAVBPzBDxB6rd4X7o6APxV5IM64 OX9Gar4lrbT5njeRsex7QKodAXObNIC3cxJ3klrtssj7g40xdlqJM1QnNPwGj2JyPrpxgU/B0+5 Nia9T2yeXN6PAFL7LxkJi6/ZY8UR6KRs1+KaVAsZZjP23UO8RB2uzIl30FnhL9OkZDaWKKjtmQN 5bI+NhE8YFsocINSO8KcfJRSHDGG7j7elCh9gBX3PYzVNDR51JaKa4nEVEDMxEmtB07RnoDXHwc gICTPB92XJM4NWlqZHtFfZzJgoUnv+fptC8rdHP/II2KaRCpKYmQtIqsQv2vo6/eQ+nfYHq2HGb ppXp4+ZnnRPVUDu2upRl8FcE= X-Google-Smtp-Source: AGHT+IEk0DIh01FwEv6QM15ji5iadLVfWC4r/azkltSnCFsc+FP7t0z1FPNur2+AnxX8pHd4+Yc2Jg== X-Received: by 2002:a05:6000:2c01:b0:3fa:2316:c20 with SMTP id ffacd0b85a97d-3fa231616fbmr3466546f8f.5.1758530498265; Mon, 22 Sep 2025 01:41:38 -0700 (PDT) Received: from localhost ([45.10.155.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3ee07408258sm19085132f8f.19.2025.09.22.01.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 01:41:37 -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 , Willem de Bruijn Subject: [PATCH net-next v7 5/5] selftests/net: test ipip packets in gro.sh Date: Mon, 22 Sep 2025 10:41:03 +0200 Message-Id: <20250922084103.4764-6-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250922084103.4764-1-richardbgobert@gmail.com> References: <20250922084103.4764-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