From nobody Sat Oct 4 08:08:46 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 416F01AF0C8; Tue, 19 Aug 2025 06:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585172; cv=none; b=n0E3WaU8FQePLTrWpFq2VyXPv8t6O+QdPz7tGu/geX5AeVCgxFKZgMU666N9HXEe15+YM2bCaYEbunjztvbzDqQWVqqLlOPEAeZufnFQJ7w+/OvaKUjifsBrP7Iq5FR7kDKr7MWYR5zmRiWtf8BNvLXcda8lM/a7KEtK72MmFj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585172; c=relaxed/simple; bh=arDp3ryU9yRhuo+FkoXFEHu+sjYP396linIvHkBVA8w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ILHlMXA/XIaAxdjZJMlHqgdEmAGzPfs4U356ASWEh6V2NoM09+gVswkVP+z3LXe3I6abTp/5MhRlxm+hY4n4BoicVm9qg9C/mVEodUKnjXd8DCClUdrIIGnwCs/DGZDwKy0Q8nnQ1G5zJIa1ApwTDlPDauXkaZyiUpFQXq0ex9Y= 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=NVkJ2x5s; arc=none smtp.client-ip=209.85.128.41 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="NVkJ2x5s" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45a15fd04d9so37488425e9.1; Mon, 18 Aug 2025 23:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755585169; x=1756189969; 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=IJOzXwjsw+va6rIlGFDKglckvIIOuznJ64OBg1nYDeI=; b=NVkJ2x5sw7aKV3XDzAS5EqgYGDB8iSpJAyEz1wN8XL5+4yGy87GchWdi5Ms3zRBh06 97budWT+EhNH+9037rV54GZyLh90+Liot6Bz+XKWD4rq9wYCvNaS2ulXbW95asr9Sh78 5Z9cmx0cTVzpa+vshyHdFEDgbIx2FhYRQGeUEAaVa1G769k6hAQMJDK1cSIxOfXXyec1 354b+u1/Q9UDlmpmCrNAbLzKzbNr7JNg5z/v7RV63ugrFsgrZNgxbtk9pppaxgKHESK/ ImdLmaSPb4j5kcp3pHw4qAPSSshF6hkQ4o16lfsfxMcnheTG8PzqXP8/gfmsSbmP1xAs roqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755585169; x=1756189969; 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=IJOzXwjsw+va6rIlGFDKglckvIIOuznJ64OBg1nYDeI=; b=XNFdP2WSaB9p5oxunpLSM5Muy9ZHXmv7XkjBNcHqx9dr4JHGipwcpuEwRDCFPikmKh cAH+tUfQe6EVDuFb/VyeawJ6YL8AEoutpaR8sJs72ScAJARcRHt+2M90s5D3+FvQuFf1 aFpHisDbHHS/PyGRRTw/DCsTkGNqPeIkASEXeMmv9GrB+i9V8+Fis4mbqQW6Q8FPsJXH SwCTFs6GUR1ERu66zaTzPayryizBHQ9S2gVgB71EDYaTx5CWhgf4KS6AVnVattz+MCKe IWzJUm0ISkduokuiDBybGKKAfwjx3+gdzdo7NXbPRohSChHBU37IHOdPPHoMQBGBWdUZ IyCA== X-Forwarded-Encrypted: i=1; AJvYcCWgcMCNmfnA3UrOcKE+uo4pC1tdoaWSeVoaENcah0VzEZ/uqY7LwBWy4nTyrxezLS27TgK021AcmG5Tg/Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxCD5/6ajjl9pBgcPp4DES7jSt5NhBnA7JsZEcdqHWroMrbpzOM hpioR47Pu6RiyQVwYFr6m/hvQcBjFgTjMDGmgF4Zf9OraKLE7LwuV7tnAz/QawRe8Dw= X-Gm-Gg: ASbGncs/IXFVmxj14rvO7Kd6bEIQuu/t6OJR/Q+KqVu31XvAKMkzrrWgRpW+h7nDLuk TkQuSDZzMwVrub42Zpd9pamEWXITTTcMwWn2P3Z91+8B3llKjhmbVW9G/gxs/nTRkw1YwYlNWxc jQ6YgAZuCx6eKnSOzIC/pDR8DDIhZKaT3J11qBmmomF0YcD0OMaSXWAkuJDZSqcjQDu5Bj6bvd3 VaT09f59mSlNoGG96al4qwhlu/TgloZyTzN7FtK5LkopymH2al3zHXuoZ1Ln6wpQ3BjJvum710F a70nSE9eRN/aldighmqoqRDuBogB+F7H0CmcOoP/mz4VazQbBfjI4IvkA9HpBBJn8XAiJDm5dSn lOMaKTlJ9DCN1i88A8KqoYI9F4lPqIDiv/dqsl3IbS0cGSJzpWxi+4W4= X-Google-Smtp-Source: AGHT+IGYXFoLTEzMTPqfAvZdgN0wllJO473IdrA37DPaI+5al7xoC3sLYRQRzrjTCrIdwxDyawtkeA== X-Received: by 2002:a05:6000:2484:b0:3b4:9ade:4e8a with SMTP id ffacd0b85a97d-3c148492064mr864750f8f.21.1755585168330; Mon, 18 Aug 2025 23:32:48 -0700 (PDT) Received: from localhost ([45.10.155.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c077788b39sm2251145f8f.47.2025.08.18.23.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Aug 2025 23:32:48 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, corbet@lwn.net, shenjian15@huawei.com, salil.mehta@huawei.com, shaojijie@huawei.com, andrew+netdev@lunn.ch, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, ecree.xilinx@gmail.com, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v2 1/5] net: gro: remove is_ipv6 from napi_gro_cb Date: Tue, 19 Aug 2025 08:32:19 +0200 Message-Id: <20250819063223.5239-2-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250819063223.5239-1-richardbgobert@gmail.com> References: <20250819063223.5239-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. Using sk->sk_family is reliable since udp_sock_create always creates either a AF_INET or a AF_INET6 socket, and IPv6-FOU doesn't support receiving IPv4 packets. Signed-off-by: Richard Gobert --- include/net/gro.h | 3 --- net/ipv4/fou_core.c | 31 +++++++++++++------------------ net/ipv4/udp_offload.c | 2 -- net/ipv6/udp_offload.c | 2 -- 4 files changed, 13 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..261ea2cf460f 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -228,21 +228,26 @@ static int gue_udp_recv(struct sock *sk, struct sk_bu= ff *skb) return 0; } =20 +static inline const struct net_offload *fou_gro_ops(struct sock *sk, int p= roto) +{ + 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 +259,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 +272,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 +281,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 +322,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 +448,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 +464,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 +490,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 5128e2a5b00a..683689cf4293 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 Sat Oct 4 08:08:46 2025 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 8EE2226D4C6; Tue, 19 Aug 2025 06:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585177; cv=none; b=CI3xjhgAJKtSuAF/KEGb1lCyapGFO4lDBmltJ5BXtMSw6ZHRX1hSVA5yGJm44wDiPBEs7wary/t+YD8136A+Ls4OlX5G72c/WDheaIiO2hnH2vjIgCPv0aYVFT2Df+wTNiAYhPCnseK5i1uMK2DFqUf2ChT47nrMCApKfWogb8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585177; c=relaxed/simple; bh=kUrenFG87YWzm25TOBbzZcKcuHImxpugKXwDvaYI9w8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gQVTbJIPRvXqnvAuUUUyYbaoo4sLe/sxwkKfSjX4tVixDfLD4U0MlN2NxBREJgi8zaaEVwdej4mqL/yKaudVcjlRZq+plKhb5HrBdQZZ63P2wpobuOcuY9Pj1q760WuSnPL7oaoMyi8VaBHB4Hu1wPQerVuzGyBjviir49NHlSc= 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=V5IwroRu; arc=none smtp.client-ip=209.85.221.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="V5IwroRu" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3b9e4106460so3901425f8f.2; Mon, 18 Aug 2025 23:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755585174; x=1756189974; 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=32/S4IqfOpUydKeSRhvHvpvUd1ekQaBREl//8hnY74M=; b=V5IwroRulzttVcFbMBa6Hzxt4K/uL0yrQHCPv/LEmPJCLaBqwuUdF+mu5CH9zjnQkZ kB6j2sBf+LH6+EkzqX3wFDn1s/Zy/3wefIjfAYFwD9jJG9YTnq8oiSSD+vXo2ubhSqtx z3R7WGtL8iBX8c+xsVsYZhjOD/rtwOQRucm0sPkRKNkVVuHgOisUpc3tS8DQFrt2hb08 q8NwF+mhYwZCPu1vtvWRGQg+2HG6NDmAXDEpuqim1RXEkTQEg14uvv37lsKOlqrlDP1/ AAJKmX2Ukrvx22wtAiB+e1JjJ/ys0RIE+ZS0BD0zIy/WSN592bsPL+AemaNic3xssF/N iNrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755585174; x=1756189974; 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=32/S4IqfOpUydKeSRhvHvpvUd1ekQaBREl//8hnY74M=; b=gicwNfy4kqvUymNIouDrFu67T+gum7EXpeSL7kGV2RZ2/6U8V4dfxRHMn/oyv1pwnq U8LoLtrC5yebRufpyrik0177ak4hN0r3IQJ8IRUakB81KCfPdC+GZuCCzP1sP/XWfpLP MG14iYfQl0v9V7R4L93fVI1/GS/mZGVBk/nt9X3lzVTqvSZxM2I3BM9p3y0HL+qDeiDB AKHiTpbGNuvhuYI+zcaD3cPP4IRSsM3N1JJbT6zW3VmTrOxOvdz72Vm8YXNxV9avc8iU Ce+7/P5kxy7ZW+Pc+xb62zK3Pvl72wYnB9l2kxmoGckZaaXO2GNzH0PjwcJomCsE2mZf jpvA== X-Forwarded-Encrypted: i=1; AJvYcCVnsPPo85uWjaN6zY1lsjCl1WkDk2NzvUxA4h7NUb5N4+0O9fJPhQjwFDU/Qnp5nronRgZdL+7VVxL7MVo=@vger.kernel.org X-Gm-Message-State: AOJu0YxnW7IDXF5YKe8NJySPbtsRv9xFDNZt71f5h1KjDiRZjkVDxyp/ 639htbZfSM1Dej3iBp3aeUiN4M4kzN4PpV9MOFGGdtYZpI+VrKCNOpHaRkxmKFBlTJc= X-Gm-Gg: ASbGncva0RSddpZS/sfljhnbKrDiWZpFGXvuXU/S3qlcP0iDFBa+N3LTZRLuM2W4rTO 9c4fuiNMaxWPxgizbwCNl3WpgLZoBl7tmOZfwAoYEOpgG6ZXzgwLQJLSrIlWObrE0wr5ZGbwrjg tMzyN+XSptxlPeGcWy03Tahw6QVKXYA71aas2zDIcdRqLvprHZ/t/2+5ntGy4bOlMVsOMGhy7tk exaFQIz4cqqBI3aceezSuhuWhq+1yx/+GxE0fUQS4C7lztHBOxWsX5x7Vzott7M8I5NocnEJVZp EtYdn+5rA99t/hqHsEHjTHw9XYPy6I75CukzVVHlx33omEO1at3a8RDO1W2hvpFObdJmn3Bw8QP jd0a6VXnAF3/TQTO6DkuVh5B+/F07iw+9h0YNWu6SpUYRQtMgx2zdedg= X-Google-Smtp-Source: AGHT+IG8kdPAyjBwXOM8zA9O/MnZNRknHXdXvW+YxW/KE9AqTSsSEyMyXZ4A2di1+HomO6RXH7g/1w== X-Received: by 2002:a05:6000:250c:b0:3b6:1a8c:569f with SMTP id ffacd0b85a97d-3c0ea3cf143mr913405f8f.1.1755585173570; Mon, 18 Aug 2025 23:32:53 -0700 (PDT) Received: from localhost ([45.10.155.18]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b42a771d1sm25996795e9.7.2025.08.18.23.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Aug 2025 23:32:53 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, corbet@lwn.net, shenjian15@huawei.com, salil.mehta@huawei.com, shaojijie@huawei.com, andrew+netdev@lunn.ch, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, ecree.xilinx@gmail.com, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v2 2/5] net: gro: only merge packets with incrementing or fixed outer ids Date: Tue, 19 Aug 2025 08:32:20 +0200 Message-Id: <20250819063223.5239-3-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250819063223.5239-1-richardbgobert@gmail.com> References: <20250819063223.5239-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 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 | 26 +++++++++++--------------- net/ipv4/tcp_offload.c | 4 +++- 2 files changed, 14 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 be5c2294610e..74f46663eeae 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -485,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 + bool 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 Sat Oct 4 08:08:46 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 C3F3426AA88; Tue, 19 Aug 2025 06:33:01 +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=1755585183; cv=none; b=E+OTag6mxf7fnTh8OmkdUWsom7lk1eSjdKDYYErn99uppWdgBc4V38zbSZaNKHgois9+s/FQNDabdYc0VdBGaURkwABGMen1InrmNzSvjCkOkFNAt8FU80kbcW7WCvkbn5s/2pLv8EVMjcOPSQ9Rf9vlP9Vrq5g/UvBkgCaAczg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585183; c=relaxed/simple; bh=OfLyoH0cg9GZUNRAwURHWhCQ0NMGnYXZtKLKS7BlHK8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VvRCHs2rejY1bA01p5Ev37eGzMhwGIWgsxpbOyMbENqkjEcCWE5z94ap3qAZ6biiY2pVkT0H+aLEd8Wou/4zq/ZM0YEr/kIcs1UhwCt16QAmrwO0WQDoVorieMzzl1P30JHyMNURaBSMqBiurki1eB1bYtUXDh0Ls5rjZJldDF8= 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=IrQWDh45; 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="IrQWDh45" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3b9edf504e6so2318879f8f.3; Mon, 18 Aug 2025 23:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755585180; x=1756189980; 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=3lA0Q2VNB/j3y3014rbHE36ssQRvnzL/ofA2ZgCqaRk=; b=IrQWDh45sKZ/ybZN688hHQHZ3y2wr98RibUgWT9b/YJHTPcTC8SINPRaiIqP8Z0w/M 9pmVPmZF3ANuih2D+2NYOaPQEuYJ5n1bOr43yiunegr+GeDiBNXlQ3CSgkyE9P5kUekU jBCGGif6mNNaQI0/HvuWoJU8vGdIubfm9z9G01q6hkyBl0MjV7qh5T6Ao+tdL61cvSzp +cgxuxiJfX+1LODVefdAq83GyoAlcPqrQ2tQrNFqhfEGhZ1ES4g4eH8uIIQJXrhAV3ZC DnsQlJMs5dTdC6uKAtnVXBSGJXRuHl8dTzUjWFPoDBQEKVC2jGYRp3ktFtt23GCvNzoQ pjfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755585180; x=1756189980; 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=3lA0Q2VNB/j3y3014rbHE36ssQRvnzL/ofA2ZgCqaRk=; b=s1NBLRT3Y0r77e33E93VuCkzqEW9/ci4P91PPsBpO5qQHkMb6wT9kx671IMb7akrIa g2wIT0rgWU6J9lOp3mJ1ytbLQQUm0Q3m9S/dzF3D581mXoxnk5W60y8tGf8RSF84d7J+ CYcE7D0fDgUECNJie5bawafSBha/yTcrsNiWX9/xUiZIh7Yfowdj+xnV9yye0GlGVagY 0vORrwHaOLJnbeiChCvvUhn4wlcjxFnPLpY2r2mHEpAN91U/avPHOoaQs5eDis/bSfGy 68HQCBOu3s6U2Ha0ofyng4o1M25CQihnXq+f+eutzEFcDQ2tI3TTxFZgIxcij4/O7XwP KubA== X-Forwarded-Encrypted: i=1; AJvYcCUBCtLfGbmYsgrm2GoU7bclsW/GZcaD/PhIZ3i54lBdQstZwUKMAL2Xns5S8Eevm/UCKUQs/lFW18Hc8Tk=@vger.kernel.org X-Gm-Message-State: AOJu0YwcltHw+43cwkZCS961lr5vBe34H60J2ANBK6vd4dXW6OpEDFGr HEkEmM8DmTKiHDo6LLi0qSYtEkTPEFzp3XnH/CspoM7sF1/x0Cm4LIO5SfvfKCSIWPo= X-Gm-Gg: ASbGncvk1aps1msaTwnAq4E7SfYbhxPzLfJGhkt+TJNcOPO1k3VG4BvwecTbxZB4TO9 x4cQVLrXYo4uUzuc+Zd81SGh0Lm7K2xBJbFXRHlRrGEP9bdNd1u/jAxbm6PM35TI2FveYBC4EB8 wZp5I/diACP+EGd0aaJmg/s0h+7tBdI/OsKLGcgG4ei3Rf3JKp83xIaBO2M/CaBbmrWo+3WXTVE 5jfumUL2QUotJjjGPDtMojDwfFVttwFSfp3DW3xg+4/4GqAwxD7/kumG+Lf0mnshFsdgCP4P2ib PNlhihxBfxWzgjz6UboEdsB2jnl8iua3AM3AzgIKx9KMQvifJaFpEY0x1FctDoyGZe2Q/+ffU5n PBW+lfNdP8/v1Ihy1HQPQnw3tx91WYN0Yhw== X-Google-Smtp-Source: AGHT+IEBs20KmwTJSX6hRMbY4Z681eGmU5/G+LjS/vApaV8EC2YwgwzYwXikSV51QPfovELicuhK2A== X-Received: by 2002:a05:6000:230a:b0:3b8:d7c7:71bb with SMTP id ffacd0b85a97d-3c0e92984e1mr1022370f8f.21.1755585179599; Mon, 18 Aug 2025 23:32:59 -0700 (PDT) Received: from localhost ([45.10.155.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c074d43956sm2317648f8f.19.2025.08.18.23.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Aug 2025 23:32:59 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, corbet@lwn.net, shenjian15@huawei.com, salil.mehta@huawei.com, shaojijie@huawei.com, andrew+netdev@lunn.ch, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, ecree.xilinx@gmail.com, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v2 3/5] net: gso: restore ids of outer ip headers correctly Date: Tue, 19 Aug 2025 08:32:21 +0200 Message-Id: <20250819063223.5239-4-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250819063223.5239-1-richardbgobert@gmail.com> References: <20250819063223.5239-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. In the future, we could add NETIF_F_TSO_MANGLEID_{INNER,OUTER} to provide more granular control to drivers. This commit also modifies a few drivers that use SKB_GSO_FIXEDID directly. Signed-off-by: Richard Gobert --- Documentation/networking/segmentation-offloads.rst | 4 ++-- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 ++++++-- drivers/net/ethernet/sfc/ef100_tx.c | 14 ++++++++------ include/linux/netdevice.h | 9 +++++++-- include/linux/skbuff.h | 6 +++++- net/core/dev.c | 7 +++---- net/ipv4/af_inet.c | 13 ++++++------- net/ipv4/tcp_offload.c | 4 +--- 9 files changed, 39 insertions(+), 28 deletions(-) diff --git a/Documentation/networking/segmentation-offloads.rst b/Documenta= tion/networking/segmentation-offloads.rst index 085e8fab03fd..21c759b81f4e 100644 --- a/Documentation/networking/segmentation-offloads.rst +++ b/Documentation/networking/segmentation-offloads.rst @@ -42,8 +42,8 @@ also point to the TCP header of the packet. =20 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 +GSO type SKB_GSO_TCP_FIXEDID_{OUTER,INNER} 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. diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/= ethernet/hisilicon/hns3/hns3_enet.c index bfa5568baa92..b28f890b0af5 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3868,7 +3868,7 @@ static int hns3_gro_complete(struct sk_buff *skb, u32= l234info) skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCP_ECN; =20 if (l234info & BIT(HNS3_RXD_GRO_FIXID_B)) - skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCP_FIXEDID; + skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCP_FIXEDID_OUTER; =20 skb->csum_start =3D (unsigned char *)th - skb->head; skb->csum_offset =3D offsetof(struct tcphdr, check); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/= ethernet/mellanox/mlx5/core/en_rx.c index b8c609d91d11..78df60c62225 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_OUTER; + } =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..aab2425e62bb 100644 --- a/drivers/net/ethernet/sfc/ef100_tx.c +++ b/drivers/net/ethernet/sfc/ef100_tx.c @@ -189,7 +189,8 @@ 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 =3D ESE_GZ_TX_DESC_IP4_ID_INC_MOD16; + u32 mangleid_outer =3D ESE_GZ_TX_DESC_IP4_ID_INC_MOD16; + u32 mangleid_inner =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); u32 mss =3D skb_shinfo(skb)->gso_size; @@ -200,8 +201,10 @@ 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 (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID_OUTER) + mangleid_outer =3D ESE_GZ_TX_DESC_IP4_ID_NO_OP; + if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID_INNER) + mangleid_inner =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 @@ -239,14 +242,13 @@ static void ef100_make_tso_desc(struct efx_nic *efx, ESF_GZ_TX_TSO_CSO_INNER_L4, 1, ESF_GZ_TX_TSO_INNER_L3_OFF_W, ip_offset >> 1, ESF_GZ_TX_TSO_INNER_L4_OFF_W, tcp_offset >> 1, - ESF_GZ_TX_TSO_ED_INNER_IP4_ID, mangleid, + ESF_GZ_TX_TSO_ED_INNER_IP4_ID, mangleid_inner, ESF_GZ_TX_TSO_ED_INNER_IP_LEN, 1, ESF_GZ_TX_TSO_OUTER_L3_OFF_W, outer_ip_offset >> 1, 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 5e5de4b0a433..e55ba6918b0a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5287,13 +5287,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_OUTER | 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 14b923ddb6df..5cfbf6e8c7ea 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,10 @@ enum { SKB_GSO_FRAGLIST =3D 1 << 18, =20 SKB_GSO_TCP_ACCECN =3D 1 << 19, + + /* These don't correspond with netdev features. */ + SKB_GSO_TCP_FIXEDID_OUTER =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 68dc47d7e700..9941c39b5970 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3772,10 +3772,9 @@ static netdev_features_t gso_features_check(const st= ruct sk_buff *skb, * IPv4 header has the potential to be fragmented. */ if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { - struct iphdr *iph =3D skb->encapsulation ? - inner_ip_hdr(skb) : ip_hdr(skb); - - if (!(iph->frag_off & htons(IP_DF))) + if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || + (skb->encapsulation && + !(inner_ip_hdr(skb)->frag_off & htons(IP_DF)))) features &=3D ~NETIF_F_TSO_MANGLEID; } =20 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 76e38092cd8a..7f29b485009d 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_OUTER << = 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 74f46663eeae..83fa6b2aecf4 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -485,10 +485,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 - bool 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_OUTER); =20 tcp_gro_complete(skb); return 0; --=20 2.36.1 From nobody Sat Oct 4 08:08:46 2025 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 C872026AA88; Tue, 19 Aug 2025 06:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585191; cv=none; b=ayVNx+WBob8pRhi3UGjkmthXHXUaFaGFODdjWP0ltQEXeVEdXZXl4JDJT4WG1EGnsUg+wrwPjNykcXJqOAT5g6TxO8lI3AozlqgAmdu0x/gI7C3UinMHTdo8RUi5FOoGbcV/GY+UOI9hS42HcKJS1jkQsVifnClvMhELfjanwgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585191; c=relaxed/simple; bh=3mc9d2A6u3r3oUg0hEgXlYh1GPhKCuMUPAX7+Fzff5I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qbJ7zimdMyKWS2IkW1j6T7eVPO/k8S+KG7xwEzHSOaWGbAmuagRPVLYzDFftrRIH34bKJSt/mPI5OCYUkZ+J4bMidYnsynHPsuoItk1UGW4cgbPOtYfT0PZjxmh1yG5oYMw7KGRYBgJsWMRaunRd6jPAlUAjlfGjuzdgJWKB/aw= 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=Ii5m1Gut; arc=none smtp.client-ip=209.85.128.54 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="Ii5m1Gut" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-45a1b00797dso32456835e9.0; Mon, 18 Aug 2025 23:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755585188; x=1756189988; 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=EuRJoY3GNkyWfDlJezuldyXpAwYPVRBuFKt2MQIP7HE=; b=Ii5m1GutsgaRS1pnoz6nc8c7BkdVC8Kn6zxHtp7Dq68bupSadPRaceZFFLEezDJH/o ziYWqangE3pBLcGqJMaJgEMGrfdwv1zGu+yrOT3EXVfbGjbHd7MXmrQ6566g57QeD4CM ZWw7uebTzRxKlE1+sD8xG277MCoxXS9xcFpSpYnzC3dG8oTKgeoMPcj9eL6jD67lwWdV 0yRx5TcNHVX9RSlSaLMdVqhIsds/YtQZXmYvh7onesDFsUFATh8fugSuCynwo6Gztrxo UJOXBp1L7li7+RyGp8HLE2Cmy+H5xNX6C9gKLPapNfv28UlqLQRxmwvzNfHzwEjBZaVd lC2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755585188; x=1756189988; 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=EuRJoY3GNkyWfDlJezuldyXpAwYPVRBuFKt2MQIP7HE=; b=rJarQNN7TJkxTXt5Fby97MTtU3TQ1c0XGX+uNxph+oDJip6iZrYmoJ5OQVL3bt4h7v mZU0hwP595YwAErkCRmkzW3cCdS3n4Jyhv/WRXrOMT9ZdDbe/LPfjbgS8Nxp33XCQiry DqH3hevGkCIdUSLWG/dAYoWEpOA8Mt4mMOeHMHa02+ghWm6+pW7Npcv60ztiEDt62tVB vPjpGIbEsQX24NRheebkP5TOnKUYd/iUXKM+NUfJf9+hUzcKZLWcxiI11WcGUiiQJ9QE 2XQqykxxbh1eso95cv2NGd7ALwBdmmYd5SAzV4Ka7kLoaTYLdwY5hYz6z/inG0VB+pcN 9a1g== X-Forwarded-Encrypted: i=1; AJvYcCVmRGz3FCMm/PPw+DDxFF0bXSIg5SRisdMhe1zxXdwWqBV1kiDLvdYe1ukcC8P3H+slpBf+aBy3safyT0U=@vger.kernel.org X-Gm-Message-State: AOJu0YzgEq/O9D4TExtLJzW1wd4Sb/Npu9Y8NXr+dGE/QfXAHjIhD665 AZP/GtUYHGu9SNWuOaA9mBsKCAdAvxQgV6Z8/lH1EeHX9LNiGxXfK5SW/dXkS4gxbW4= X-Gm-Gg: ASbGnctf79VwShr2geP/62zm9Jyom8iUNo2K4kvSYMx6mytTCqk+C33m3x6VQcVp2Kk anGlHFSztDEa94XYlnX7vxAdtJNlx0x1007XfOGGbLlbsTC+G9rZwbcUOktNzc0mmoWJfGZo5Wl Cd191/GTDSAnEoMfldtGhr87/uNAGL0clBGQBUBi++5ecXvNLdhxIvQj+A1wVAq7J1LqVqXs9b0 YdAOLztJF3wNBzmG49nCW7n4OMZ+ZIlW33oAa7aeIOHuBIVJzDpYIuDIuqXgk6sSNfIhfyCMgVp ads/7Ibclxmg13o1rS9HSkkbUmApxw8fCXZ6IK8ej6zL8F3xgGk9J1RwirhwiRIULr5IpcI7CVh wP/Hy1q181k8SPmTk3pSuGTy8XGqUJilhiA== X-Google-Smtp-Source: AGHT+IE+TDhp+9y/Zga0Mp5C1jmqV34Ag3mxyaG5ZBaBqiVPctxCCiamXOSO0Y0Mb5V9w9L97PamLg== X-Received: by 2002:a05:600c:1392:b0:459:dfde:3329 with SMTP id 5b1f17b1804b1-45b43e152cfmr9077705e9.31.1755585187888; Mon, 18 Aug 2025 23:33:07 -0700 (PDT) Received: from localhost ([45.10.155.18]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b43f88e79sm7500065e9.3.2025.08.18.23.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Aug 2025 23:33:07 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, corbet@lwn.net, shenjian15@huawei.com, salil.mehta@huawei.com, shaojijie@huawei.com, andrew+netdev@lunn.ch, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, ecree.xilinx@gmail.com, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v2 4/5] net: gro: remove unnecessary df checks Date: Tue, 19 Aug 2025 08:32:22 +0200 Message-Id: <20250819063223.5239-5-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250819063223.5239-1-richardbgobert@gmail.com> References: <20250819063223.5239-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. Merged packets are re-split into segments before being fragmented, so the result is the same as if the packets weren't merged to begin with. Remove 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 7f29b485009d..b4052cabdfc4 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_OUTER << = 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 Sat Oct 4 08:08:46 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 5A60D26AA88; Tue, 19 Aug 2025 06:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585199; cv=none; b=Lz0Fc8wsMi6EBIkMwqNcsYDvJAoDZ9+DPXxYHi8ANxVrC48tVppdohoiyjBTDk6ZSyeDOgZIAvhXuoIOfX7l80YWV+m5Kp0zS1K+r2r3RzNY0BXn+8vEILDARdiOIdDshUNVIpAFPGsiVjnhWF4AGrklvkPyCRQ15FcyhPE/UZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755585199; c=relaxed/simple; bh=xvzymDWEGxe/xBACaTmXXspmwx9DLfQ4QvefG6YwyZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fj9AQC6MeU+wYks+xnAz7fNUixT7NjopDGU0L98zNXDgz+txbno3JD9W1HYHbXKyaDhjF09LQeXs9MpIxJlx6IXLRQCKa3k9wEq0kTnnK/EjyB9FPkJ7tdoZ/xqRHgZRSYX34lg8HL29zJLxib9JDF9lOL92J0+/73xi9/ucKmg= 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=H73SxU9d; arc=none smtp.client-ip=209.85.221.50 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="H73SxU9d" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3b9dc5c6521so3367579f8f.1; Mon, 18 Aug 2025 23:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755585196; x=1756189996; 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=B2YkWRHa8ZjnqV/hoZ6DnKm4WSJDYwBX+XFMg2TnUH0=; b=H73SxU9dyn9NeQ6V50qrFR2q22xVqGyWw8l+Cx2u4LCshkAf8zp6mUX29CrWkxOv5s cHkoeis1muN9i7Vp/+99MH4KNGYq67E3U1nd5IWvg2andFJPmsB+JloMb9eVJofSIjaF H5bAAd+9ZtM5aDmGYWX98LxshPeEejHA4g394o3aGHhL8C+J1iW73FLYVRYiY5jYK+iU oy2nCRgyBAfD16aN6Ia+6g3iE2J0KzAm3cOR93D4NJUHu6fU9vmMikVkwRGHVfOxmPCI BMNUA6HvqDJyB+p/WubNynfuS/2Am+qjhxDXPHemvleQxRKidRjDr1uoRCurnXndXJyy 42GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755585196; x=1756189996; 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=B2YkWRHa8ZjnqV/hoZ6DnKm4WSJDYwBX+XFMg2TnUH0=; b=p/aaUdjT4Firg8gsDtdloGTHEsqjFSYNxFDwfkktsTjqIVJq9mDuSpQNILXG3XeMev FqF32zUhu6ELkHs7LHC2k82WnCCFogVc18d7nzoCZsVgTU16pqVpaVE/kdVZFRVF2VC4 lv1LEC+wVgygByDiC/sRhuFMyFwClpTIp+MnAbQ4lyy3kEj2SLVEF3lUJ8HzFEfHswPc dPBZBsHj1XKMEcRiherIfzF5pFbwDOrBjBpFRnoisvAJFVmaZdwyDoS+4SIzGN6O87oL 6uZI4ezqxfeo61rFvP5wkW9wE++ye0X533P6pRTCi8cmXphXpXwHSxc8qeYVNh1aUrlS 4sfw== X-Forwarded-Encrypted: i=1; AJvYcCWFNwQAvdqDdyhtGNdv3BlDSYknDsX2dIEEb6zDulTWBJmsj9rlsZUy2vIKgWImPiOG4DCe7rhvouPnVxo=@vger.kernel.org X-Gm-Message-State: AOJu0Yyyzakg+7z7rSLlsbfKpP0vc9Za+pWyvgeBb4LpclKvGMXK/6a/ 1RdURAc37MLX2CQnCFLjy9aHgxAMGiI3tnI+NVJUAmZhY398VDZMK6e5LeGynT0XenI= X-Gm-Gg: ASbGnct4mjSd3VAQ/jr02dxHUpHZXZuvzzq39e7IFbjh/mR9Dg0OH71/IqCKkcNRwX4 j9AOhQe+pBbBr15RmjRiX60Xjt1Bv+Tfx6zSPa1FjREALe60NXWGLtZQopxg+7Zn/NPBGbFRz9g MxyW2QvpjRILwcqZW68/GyzntHFZQcvU0ZECtS2OoNpwppa/AgG1/iNVyD2LqdvZE8+gzqFXR6M tV9NNhUPBvSrz8WKtkpQ/Ry6RPQXFO53kIhOXZE1jRWmI3Q+IxIBHjlXC3B+jq1NbjyfAraFt/S MHfCxp4HMLPfkqJAMNaJB+Zb9ltp6+DAROY8GqhnQr33HfTBAS76oHQfOahpM8F4FSMm2l09iFs W1j0MOTPgmZBOxpPAFlgu0cfRELr1KYX/eA== X-Google-Smtp-Source: AGHT+IHI1rQCsl7UDf/eQok1lYe4Qp0HhxA01N6rXziGgDsFHZGQG+c5oUewhNGmzC87GWABEBy0aQ== X-Received: by 2002:a5d:64e7:0:b0:3b8:ffd2:6745 with SMTP id ffacd0b85a97d-3c0ed0fe599mr959663f8f.44.1755585195502; Mon, 18 Aug 2025 23:33:15 -0700 (PDT) Received: from localhost ([45.10.155.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c074d43ba5sm2331052f8f.22.2025.08.18.23.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Aug 2025 23:33:15 -0700 (PDT) From: Richard Gobert To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, corbet@lwn.net, shenjian15@huawei.com, salil.mehta@huawei.com, shaojijie@huawei.com, andrew+netdev@lunn.ch, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org, ecree.xilinx@gmail.com, dsahern@kernel.org, ncardwell@google.com, kuniyu@google.com, shuah@kernel.org, sdf@fomichev.me, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v2 5/5] selftests/net: test ipip packets in gro.sh Date: Tue, 19 Aug 2025 08:32:23 +0200 Message-Id: <20250819063223.5239-6-richardbgobert@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250819063223.5239-1-richardbgobert@gmail.com> References: <20250819063223.5239-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. Signed-off-by: Richard Gobert --- tools/testing/selftests/net/gro.c | 49 ++++++++++++++++++++++++------ tools/testing/selftests/net/gro.sh | 5 +-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/net/gro.c b/tools/testing/selftests/ne= t/gro.c index 3d4a82a2607c..aeb4973418a4 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 + sizeof(struct iphdr), + payload_len, IPPROTO_TCP); + fill_networklayer(buf + ETH_HLEN, payload_len + sizeof(struct iphdr), + IPPROTO_IPIP); + } 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, "46ed:D:i: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..d16ec365b3cf 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" @@ -31,7 +31,8 @@ run_test() { 1>>log.txt wait "${server_pid}" exit_code=3D$? - if [[ ${test} =3D=3D "large" && -n "${KSFT_MACHINE_SLOW}" && \ + if [[ ( ${test} =3D=3D "large" || ${protocol} =3D=3D "ipip" ) && \ + -n "${KSFT_MACHINE_SLOW}" && \ ${exit_code} -ne 0 ]]; then echo "Ignoring errors due to slow environment" 1>&2 exit_code=3D0 --=20 2.36.1