From nobody Sat Oct 4 01:47:34 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 8B88227C842; Thu, 21 Aug 2025 07:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761466; cv=none; b=MaPbU51qJ06+PGHFhF+falecRNER2cIfFoiar14GMLEzITq0cSEngnzCrp+hIhBa8WPyX2ESurG2Em4sSYUxHJXL+KUvPVrJu+4c2GOdG99YXA/wh/wRkHWX48M66W3yBeVwJ6NRJIdrBSFs+2M43q99ELolM4O0QgOSw7JlUes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761466; c=relaxed/simple; bh=mxEwkzXly/Y4JNSbz8v4T2gBOi2F4x5T/wk4kmBgl2E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aPGCCqBFRpoTziCOX2JH306cQOPsFugIJuYRivqRt2UgdZhsUNzkVNmHbe0wg7VwYkLouidfhyZv3ryv2Zfp9VZ23Jc0fWGBxBcHS00DwUBvNMqmvlnUeaf4XTq3DR8cHTxHWJw9TqFjTLNBV0eUu48Stu6c7VTY6dsKrKUjmDA= 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=XLHA8E/i; arc=none smtp.client-ip=209.85.221.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="XLHA8E/i" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3b9dc52c430so465258f8f.0; Thu, 21 Aug 2025 00:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755761463; x=1756366263; 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=mzyRYXFeRdQ0h4UzLBnS+cvLTXcS5INP1rXtO0nuLqU=; b=XLHA8E/iWkADN7Gn6MEIG6F1jR20XNqjjSERry1lokHjDXVaNe1dkutmWZj9YgNnhf B/yB4fCR/Py9alPjH7tQGsqz0FCqA1apxMT2+1P5xE1cDIatI8eMxl4WVFo9ibqPG3wK noDFTEfiOKvXsA0428g2aXdrQqgLifIPbjSQ+3TDbi9QPUVopLKRLMjo55+KBKLVbexk HbR+3/Xzzhctf5zAXr81TjbGqHeLNevDJNSj84fLaj/H6JwSzt9YlcgEQq+0g2iIxUvw 60bWUy9lk4FT6AXbyo4fo6J9JhcHO/lS+DTTUvhdQwrqyLZXXkrUh8gdf9ome0bDQjRu uWMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755761463; x=1756366263; 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=mzyRYXFeRdQ0h4UzLBnS+cvLTXcS5INP1rXtO0nuLqU=; b=dX5rZn1lWyVlDseqLKgzGTndnlkBJ/bMTdA5cZBOUb5UTAOxVS8SphGbzcl0rjePJY 0KlbxKsLCCIWHcDmH19C/tXLNDQwf8TDfOJVByIXzr1QP2jTWOasRlE1iQnmXs7yEd0l YxOatsJIqV+KJ0fEp6PL8AQz87mQM6VwaF5V2U7M/qfMG0VEHf3v/Iy2vvRpYOdNBAen sWkf2npagEuzhaexhRG/hOxbEdKAsSYjP9ArjAt3FXK19L81NR7U3lWuRp9veTwXODI5 cl0BnKSremQTBCs8q9rjcIpRo1Oc7h5rRXbXUyve9JxUCHWIj5QIZka/1eeQ+7qzflAM TRmQ== X-Forwarded-Encrypted: i=1; AJvYcCURPSpZcfh20rjJIgHMPdFRMBXijfbGRHiBGEHj/kihvgBULj13EszJfHVqicKDEBzNKJQGrdDUR4zwFwA=@vger.kernel.org X-Gm-Message-State: AOJu0YyiFdSInElfydokvd/VXEgtpuZ3Rv4JIxJJn2j1YDlpE3qdO3Um 4X8UiQ4+HjE4KVX3etFQPGo4qRMnl3P0QgvrLSBmlmF8ngBlhzTgAi1YTWBIxQ== X-Gm-Gg: ASbGncuOX8zeRAerC/d7xAsAQwnMc2s4vHuU1/bIGRKToKtQziLq06PgHu/LmUw7vW0 uQK2P7pHVhC5DAsArGEZw9uKDEIfl8gSjxH7vsIf5wwCs+td9FC+MqecLCzgP2kJITMXTD4Wf9e u+bdTijiaRAMV+ojWxoqev4+1tQf4tassIUB8ydaUULXy5n/ldYFmPqQojMJZhEVq9STI/qgZYe Sus1RI6BwdvtIbUzV24oTnyzrzvxJLcTJRI7mL3YwP7gcVEoSMY5tOk62s82DQhP7aLp9vecTJr VitiTf0l4s5yvYHjQ5wfKBY+E1ZnMmN/BukP87ktbAbr1Esa/H8ASasZo00099d9Cf7AXgBpEQ2 K/IvxbIjV9T6QqQ== X-Google-Smtp-Source: AGHT+IGEBl7wjxkI2wLJhkjfICifRA942WZKT9F56XgLWLVwQcbb6UNIvNI/RUgioKyaEu/dJn+XdA== X-Received: by 2002:a05:600c:19c8:b0:45b:4a98:91cf with SMTP id 5b1f17b1804b1-45b4d7f819dmr13940155e9.15.1755761462529; Thu, 21 Aug 2025 00:31:02 -0700 (PDT) Received: from localhost ([45.84.137.104]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b4db9fa79sm15349805e9.23.2025.08.21.00.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 00:31:02 -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, 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, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v3 1/5] net: gro: remove is_ipv6 from napi_gro_cb Date: Thu, 21 Aug 2025 09:30:43 +0200 Message-Id: <20250821073047.2091-2-richardbgobert@gmail.com> In-Reply-To: <20250821073047.2091-1-richardbgobert@gmail.com> References: <20250821073047.2091-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead. This frees up space for another ip_fixedid bit that will be added in the next commit. udp_sock_create always creates either a AP_INET or a AF_INET6 socket, so using sk->sk_family is reliable. In IPv6-FOU, cfg-ipv6_v6only is always enabled. Signed-off-by: Richard Gobert --- 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..a654a06ae7fd 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 inline 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 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 01:47:34 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97B577261A; Thu, 21 Aug 2025 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761474; cv=none; b=G06gG1I1y2N5LBZwsPh7Fb2Wo6cZ3Hgy0zhEOZ9ghkCms4lyaYvEl9DFZMp//Iv3K8ye3QD0Mh61/llnECwlhil5yRPMOTqPm/y89DpcEO2a3QZ4iot947HqiQ4tvfhUiZIlHWRkTeYye1xElGGj7D/c054YgSYEje+YHRwvXD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761474; c=relaxed/simple; bh=mpS/qipLv+bO1nEd7aKzLpLiJA+GofV5+6E0C9v+Ma4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TjLbDzN4czl5RM/1SDJ/oaceGCD1qAqSVbi5dYWEPKnlAkEvR6JvSro+08Y7bg8iEnaE6wkizp8vPTPDSRWjs9DTN45QA/HQtazuwIGYVFEGqsqPyDjPDMoypSA5lPfuyxv1NgxdJvLg8j9WmiJRe0FjORXotbPZzJYN2NhoYnA= 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=kjcNVDLP; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kjcNVDLP" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-45a1b05ac1eso3367335e9.1; Thu, 21 Aug 2025 00:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755761469; x=1756366269; 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=YfJtkCGNRyk1cCu5qIMpJWlFisW0p6hubwQ+QAr2jN8=; b=kjcNVDLPUthwx5bxpvy+53Ao1gZ10sGQno2GZHHZCWUv/KLvEAFjKk5FNhb8xtOYV1 a79D+2cRz16MV9P1Ngr1VJ7UTFHPtucZen47YKv6oWdaZE6HBhZ/Lw1oQH6YR++eXv7Q BIkbPKxw3en7S+d7GrxtEOfvT/AcDDzwnywF1ZCMqZJ8vJMour0WEw3INPGc168s82iu og+Bp9W+bgqvLOWKsLumVSAembHf5XYwPG/UlihyficAPSfPZvvFIZq87jllV+s/jaYT RecBDEJ1S/PYY1FIWigsFuh24f0ofA84bhY4jmPeNd5bS9t+S6plknNAp1ypfHLic6H2 upog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755761469; x=1756366269; 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=YfJtkCGNRyk1cCu5qIMpJWlFisW0p6hubwQ+QAr2jN8=; b=FAYuC+JPTZ8oeTzN2eYhWm46kqt2xB+B/j5DTICJAibP1L8UCWu6aW4ky4XwilIPah hWUpgS8olCjYSeqthu3rbdny6cv7gacCM+zDE+gkaAOAoK8w/Z89amlxWtpm8tzSJ7e3 QAkoJW4hyPlG5vz+smpzfZpH5lfFdhR8glREQHIwCT7G4q7DBHUPGsvYzdY7kzrRRVfQ lI/qmc6NWr0wE47fgbxlpNZ1+lilUFq9lG98c2oDDhGojoJeZdANWVhSuwXJUzD3dhC1 zkbls9ijxq/5WvCfIa9ixcBDcG6RuADdTPFOOxK277ZuNUVHIBuDLc0LZOy6bXuWnEEY q6fQ== X-Forwarded-Encrypted: i=1; AJvYcCXRMcntcJ5LXEw2zs/CuZNe/PKp2wa5KlPTj5AK/8JWr34cw+9jwiZyvSKNo/TydL0XtmfXMT5UUU4AzL4=@vger.kernel.org X-Gm-Message-State: AOJu0YzCgEowbo6QG0rIFMGQy4ykaS8mPYOi87AGWDvkpngRoW1XCqwi 2mBS3sJECFv0DJDXZVa3flUYi/C80sHsuPxBeAO7wNQ1SuOMmuOrGYcUkvOfjw== X-Gm-Gg: ASbGncvzDKdum4sNk3VUWit6qaTiTBHo0f50rHC72VzBuimYi0838mKRsTOkmULYUYn SzcK6MktrymM8FDoafkVP9+1gk02lMx9AYiXMRy3CIgfuSRA7aowua4a/cJceywe1ShnroBGCan KrtVHUXe8NWH7Shj+q4+CwkJ6fYI5nchsPq8xt6rJovoCkUe/haEf0dwud3/11wPVR8xrHFSq3S MpqW/cyj5VTtv5pSMjD24bE6slKymR8SsFLBtfYF1pEMwYpT+B0pOmZFBWTXIwBRwwPuY7bn1BI RlL48uMb5+WkfkYrFDi+p3XsXGD5CXw3C8KxYUAgsnmeONxknZTSnY9nGzoQE0r8MeTlZTO7hxM SEQc4aiMHVZQjPA== X-Google-Smtp-Source: AGHT+IE1MjyZjqCr88SWvJbcARsR/HejdVf+V7UVEGGZrs1bBEJTq0rt/IUtmws/fa9CHsceXQ+6DQ== X-Received: by 2002:a05:600c:3b23:b0:459:da89:b06 with SMTP id 5b1f17b1804b1-45b4d7dc8b1mr15927495e9.16.1755761468775; Thu, 21 Aug 2025 00:31:08 -0700 (PDT) Received: from localhost ([45.84.137.104]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b4db1be26sm16407535e9.5.2025.08.21.00.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 00:31:08 -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, 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, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v3 2/5] net: gro: only merge packets with incrementing or fixed outer ids Date: Thu, 21 Aug 2025 09:30:44 +0200 Message-Id: <20250821073047.2091-3-richardbgobert@gmail.com> In-Reply-To: <20250821073047.2091-1-richardbgobert@gmail.com> References: <20250821073047.2091-1-richardbgobert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only merge encapsulated packets if their outer IDs are either incrementing or fixed, just like for inner IDs and IDs of non-encapsulated packets. Add another ip_fixedid bit for a total of two bits: one for outer IDs (and for unencapsulated packets) and one for inner IDs. This commit preserves the current behavior of GSO where only the IDs of the inner-most headers are restored correctly. Signed-off-by: Richard Gobert --- include/net/gro.h | 37 ++++++++++++++++++------------------- net/ipv4/tcp_offload.c | 5 ++++- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 87c68007f949..4307b68afda7 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) @@ -478,28 +475,30 @@ 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) + struct sk_buff *p, bool inner) { - const void *nh =3D th - diff; - const void *nh2 =3D th2 - diff; + const void *nh, *nh2; + int off, diff; + + off =3D skb_transport_offset(p); + diff =3D off - NAPI_GRO_CB(p)->network_offsets[inner]; + nh =3D th - diff; + nh2 =3D th2 - diff; =20 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, false); + if (NAPI_GRO_CB(p)->encap_mark) + flush |=3D __gro_receive_network_flush(th, th2, p, true); =20 return flush; } diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index be5c2294610e..56817ef12ad2 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -472,6 +472,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; @@ -485,8 +486,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 Sat Oct 4 01:47:34 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 EF8F9188906; Thu, 21 Aug 2025 07:31:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761480; cv=none; b=bPPHlMK2Q4argLB10zNG5m3EjAq5DGm3E/Vqvqk92z7bDgWxTcs9W2hXy4mI+jrbOO23DicHstbWzUTLDBg5YGbtqKwO24RR08qZmHZxJJ1/AacT6jhDzNsnAuEndvGFCzAAYFsuytHVrIYhBZC2dXogLfR9CDiecWHS2AfKzQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761480; c=relaxed/simple; bh=HLGzR+DDbRyzTz2xyLktrbTmvWJRixILj4bbjktND4I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hp1XiIPPDKkaBwY/SW4th5ugNbplYpmvDGKGftlXuAytJsZygETZpCczFnqm6qHsucX5DTLbVK5NjFpGeu3CVOHdRID3uvIxXpUNreaeap0aQz4ZszhzJ0F44TEYz8hXOpxETd4JLg2+HRap+jdcsob3taWPAe33XRRhnaFNYNM= 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=IVdBqjEu; arc=none smtp.client-ip=209.85.221.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="IVdBqjEu" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3b9dc55d84bso670155f8f.1; Thu, 21 Aug 2025 00:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755761475; x=1756366275; 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=5jOReh4+cKshxOW4VBEHuCirp17ve5WnbRigcug4rX4=; b=IVdBqjEu6sTpPcXebHfcBIlKWiv16JRfu0YBcBkO/O1W3+QPC7CHaRvcK9sVy8BSwN NLym4Enxhrkbvdlwa80Qcgcz5PIPKMRi8Dsp1OxieAw+b8GYlXumK6PT42Sbe1jKTX8o Vkw+wI28Wv8UPGEaJZ6ZFGb9x+pudKCsC5XwJNeV/lhSmm06UsjrCfUcvh2ze/E7ew0o sbZOpfY8tkBqBPCY8KL15Z44oxVnopyfDniIDaWpgB13RPmVVcc5Nx/mkcaJXj+mGuUn pH1dT5iQiT2I1x11WBlPMvEZYbpsjwBFmw6hW2LX2HuLN7j3dgV5vQPYjzFJP52hyB9o AJOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755761475; x=1756366275; 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=5jOReh4+cKshxOW4VBEHuCirp17ve5WnbRigcug4rX4=; b=MW+EZ14JPZqbJOQc0+Cb+sxncwpN3vtMwUNKyyy64kqYmALqr8+xHqZJMtlc77zVPW R9LRiY4o16H0gc9w/hIKLvOBKJ95xIh4A7oE6Ip+HEUmjkoWOwzk0m6XkUY3MGJ0sHJP lt0sTSdMZbLhudSJ6BqNMxmnP1FSm9xCNoylkinmtSyS2mpmKc1zmSJIuMf7gCu1ypmi BLjVCXoKcslmEC6D1nvPZt9OGGH8gMs2xl9Bb4kEopWAYnmiZ12lZQQH3f8PofQMSXVO zWKNKySixv328ebZHixBGxzHxLYHLZcEMuAlooGp78DXHv3kZaczcWOqRXroEnQExi8C JUCQ== X-Forwarded-Encrypted: i=1; AJvYcCUQZYj9ETsx+pp2zrlZVXmIiEJgcRPl8Fu6psPBF80QL47iIcxqQ8xVKoEPbldL72A0WHdil5CmI1Yzyzk=@vger.kernel.org X-Gm-Message-State: AOJu0YzcOSWrecyQj3MdzxIjYlJgnrvCwugIhPpoCQM6t/PKUCMsFjOs fgcCDXqlB41bGlp65EnHErlmyFVLiyBFNXyaSIyujgjeooovTFAi1NFWMOKblA== X-Gm-Gg: ASbGncvOuFVPbb/YU3up7/+no4LcB4U9wIFbMhEva5pYYCDA9k0dYDtV97nOTzeDFnC PlUbku2H5jIFn7v/Zfs1D/0N7+lFrDtXrWoWQ6UaGhTtfXnRel314oNmK+H6GuTf7wxVq1VjX40 lMJj27ZCUnXacaE4HXTP55QULrKNAQyWMTlpB2Y3kEcojq5Xr+jQ/qVg0o6vHZ3Ko4ZRNbm3N2p e3BMxVbYkT+tRwdi+1vbzcV2AkKxzwETu7eXFaFlBmh0Za5HDfUo4Wd5TlFJf8Ya/HLaP/ZolX0 78GK9FMG8wZdxPT3tGaDzfQlRH+cm+GzeGVqO/744lK7Q8a5RXoFdnlUWiaHRxl7ULlDcp/g2Te N5JA= X-Google-Smtp-Source: AGHT+IEuEngzprfOZ1og99RUamkEFKIb3jxu/1ifU4zZ0UntoYSrz41rdwQcZVaNZS26rZp1Y4Hl+Q== X-Received: by 2002:adf:e588:0:b0:3c5:374c:1265 with SMTP id ffacd0b85a97d-3c5374c164bmr106205f8f.24.1755761475080; Thu, 21 Aug 2025 00:31:15 -0700 (PDT) Received: from localhost ([45.84.137.104]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c4c218c62asm1275395f8f.64.2025.08.21.00.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 00:31:14 -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, 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, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v3 3/5] net: gso: restore ids of outer ip headers correctly Date: Thu, 21 Aug 2025 09:30:45 +0200 Message-Id: <20250821073047.2091-4-richardbgobert@gmail.com> In-Reply-To: <20250821073047.2091-1-richardbgobert@gmail.com> References: <20250821073047.2091-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 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 --- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 ++++++-- drivers/net/ethernet/sfc/ef100_tx.c | 12 +++++++----- 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 | 5 +---- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/= ethernet/mellanox/mlx5/core/en_rx.c index b8c609d91d11..505c4ce7cef8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -1289,8 +1289,12 @@ static void mlx5e_shampo_update_ipv4_tcp_hdr(struct = mlx5e_rq *rq, struct iphdr * tcp->check =3D ~tcp_v4_check(skb->len - tcp_off, ipv4->saddr, ipv4->daddr, 0); skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCPV4; - if (ntohs(ipv4->id) =3D=3D rq->hw_gro_data->second_ip_id) - skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCP_FIXEDID; + if (ntohs(ipv4->id) =3D=3D rq->hw_gro_data->second_ip_id) { + bool encap =3D rq->hw_gro_data->fk.control.flags & FLOW_DIS_ENCAPSULATIO= N; + + skb_shinfo(skb)->gso_type |=3D encap ? + SKB_GSO_TCP_FIXEDID_INNER : SKB_GSO_TCP_FIXEDID; + } =20 skb->csum_start =3D (unsigned char *)tcp - skb->head; skb->csum_offset =3D offsetof(struct tcphdr, check); diff --git a/drivers/net/ethernet/sfc/ef100_tx.c b/drivers/net/ethernet/sfc= /ef100_tx.c index e6b6be549581..4efd22b44986 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; @@ -201,7 +202,9 @@ static void ef100_make_tso_desc(struct efx_nic *efx, u32 paylen; =20 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 (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..f47d4d67bce9 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 | 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..9e4540d379ba 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 =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..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 56817ef12ad2..be5c2294610e 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -472,7 +472,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; @@ -486,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 - is_fixedid =3D (NAPI_GRO_CB(skb)->ip_fixedid >> skb->encapsulation) & 1; - skb_shinfo(skb)->gso_type |=3D SKB_GSO_TCPV4 | - (is_fixedid * SKB_GSO_TCP_FIXEDID); + (NAPI_GRO_CB(skb)->ip_fixedid * SKB_GSO_TCP_FIXEDID); =20 tcp_gro_complete(skb); return 0; --=20 2.36.1 From nobody Sat Oct 4 01:47:34 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 5CF322E9EB1; Thu, 21 Aug 2025 07:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761485; cv=none; b=p4hJt7bv4U2Wr26+4fZAq7fQ8krjkxRKeBozbHI36K0d/dkC6Btmxpt74cePPQFGmuwv2LSdeGuq1OB9ulOhqiT62Va0xWvGv31ZVUDK/HL9jYBLVD0cGILrTaESIwziznyi9d29wbOWdXPrv3kRZEr86tIGvmhWElSdk3MW5wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761485; c=relaxed/simple; bh=JZmagHQuKvSBsllZFiFSahRnJkw0V5p6muM8F//GSiM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jqAJVvFOctK/3gerHehQOjYJp/pYnDjzNfjp/PnwIWGk0RjJnfXFB1sWECU2tcKTrrfTZxXEDcpC3XYjXs/Z601h7eSaSv0M0iEQ1/l+VgWXeE8qi47dC/4I+CKHIaPx5hnVV3Z/eDdzXrhKdrigC24KHFVOsZE05WgOYWES2Gs= 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=ClCVskLr; arc=none smtp.client-ip=209.85.128.49 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="ClCVskLr" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-45a1b065d58so5504665e9.1; Thu, 21 Aug 2025 00:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755761482; x=1756366282; 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=fH7FpbAGQV6EaF+HQth94hPOIxRixOJNMnh4ewvx7qI=; b=ClCVskLrFZrlfgict8kpkq3qPAb5yCcqx4ru0y5576HVbp7LQ9E5Has1TVC1Sm+PM+ 0oq3g8TWpee8GXFgyD2spDtkZQrPP3RWulUOTH9sVlfEyr1bSZkBOFv7ysE/2WyuWwVT v0jLkrzDu3BaOOxv/ze9d6oL1S/yKUWxdz3NN/Wjy9m4hJpnOImCoGyNv83HfFSsXkrz q8TMQ6NUYybiarpjG18y8AzUJjDO/eDv8jV/toG9UJCnA03SUp6UYcM0TLPxcFnE5bIK oO3NdqcihbugctnOuyiYXDBS5ZjYpCtT024w88Vo6IFx+t6PS8jqvwjOqHuENfnQMCtm jnPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755761482; x=1756366282; 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=fH7FpbAGQV6EaF+HQth94hPOIxRixOJNMnh4ewvx7qI=; b=jm87il1kXzjGJki2XWcP9MGeYsCBK5a0pa6J1JxP06FkHlfABsWm22DwyMkQvHOzDX G4xWTTuUawW46D7SpaAnKll54yvZ6FSWLTt+cSedhwLGgcfxPfuPc7ZuBSsfTlC4P4in E3qDjHcyyleOhbhAcOAXMaFES4NNoQGUdeZlkylz+1u2KzUOSiwWwMmGW+SZXaXZaz2k b1GfmS8bpqceGXsDfuMlP3/eoAmVaYuCzrdOgcpvbrxCsfmphzDsRG6j4A8DEtWkJJ0X 0dyin4psLsRdUhV8wUVBmh8dn+6NM4UmZ9RYaYSqIgIiQII+W25aikfHjxF7F4IQPqRM RBIA== X-Forwarded-Encrypted: i=1; AJvYcCXBzTM9BFlsV9H0z0EhP3kor/o8aEDEUKVxAZwJIxPLQl0QWIndj6dj8n5k6yYXlF3ula956jo5bHzXGEU=@vger.kernel.org X-Gm-Message-State: AOJu0YwKPnjYifA76qNrl/sTvnEeO76mp9B31FpYy7Fw03RqQxJf/SWZ nSJN5rAcNi1wgFsAHlHtTmkZCVL2WZtnUjgv3Dsu8RwagbQHgPYYetfZZd2rrA== X-Gm-Gg: ASbGncv3s7yr4gngeB98cln5+4jW6RgrkUYFC8pLQcOX60KDwL6iQLa3UtnmCcUDBFg ikmRMGxN3jNHJ/Ac+QuzI6z6WWRahdHFnpBryBAkZlZ8r8MW0VI+FtvJc6QrJdKbl83FWGJFnAM 6CXv7SFwMr5lmub+s72PPCId/QLruY036g2sXXtx1UJ5n1nGzZAbW/NDSZzdfPh3p/gFMtmIdeF h6dTGEyro5pqqF5L94lY52MbQDrzkjXAbynpHj3IX24Gn3EtaV3g9sPoAv6psVSpzPy97KJhBxv /R/y0DqA9ktO12+8xDb0RCH03v8Qif/UNbvyJCGDUrxmRvs7BljsuuiKtIw0U5lOT9X3NSWp4AS wDrE5Eu+mtUmEpw== X-Google-Smtp-Source: AGHT+IG0OoLlsMYLQh2dpOrwH2RnOCXzXQ+QmZeWNtpXc3IPtluo+JMaU1Q5JBn99eDNvhM9P4Ffqw== X-Received: by 2002:a05:600c:4ecf:b0:459:d4b5:623a with SMTP id 5b1f17b1804b1-45b4d7dcc65mr11225435e9.9.1755761481266; Thu, 21 Aug 2025 00:31:21 -0700 (PDT) Received: from localhost ([45.84.137.104]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b4db1ba89sm15837805e9.3.2025.08.21.00.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 00:31:20 -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, 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, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v3 4/5] net: gro: remove unnecessary df checks Date: Thu, 21 Aug 2025 09:30:46 +0200 Message-Id: <20250821073047.2091-5-richardbgobert@gmail.com> In-Reply-To: <20250821073047.2091-1-richardbgobert@gmail.com> References: <20250821073047.2091-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 --- 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 4307b68afda7..7b66fda5ad33 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 Sat Oct 4 01:47:34 2025 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 292432E8DFA; Thu, 21 Aug 2025 07:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761491; cv=none; b=hZpAVtIYITS58VrGEP5O7Dc7pU77Gntq7kN0JF384u3PTHV1POpRqzdJFLsbEW2ycou7W6eCPMSR4ffZdiewWZjkUtFYZz5Lq9EEw6eKU6++LOialESA4q1XuShevvpOyLj/Mr/7g2KZJc9nMSEFKgf2g6eyPxicXkf3Esi46a0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755761491; c=relaxed/simple; bh=Bmup3zTtr8ZOHU7szSWCp6L/22E8IeBocLNjAmRD/tg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ih/a5Y20MxZv+8mC3UdQfHRqu2y8X2rRwM3MEIOM3LQs2kCOuEfS9XMB38oxeZ9atDIUIp04FoYrqsLVyH3ibKt8xbUeXxplur3aeEdFihYorsmlQ8pYSnKxFnrl8Wua9oTVMxdu3LoY7FR/bf4VwVVn+0mFUi2OiU0RbkxI6QE= 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=iH4ZeaPa; arc=none smtp.client-ip=209.85.128.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="iH4ZeaPa" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-45a1b0c8867so4822415e9.3; Thu, 21 Aug 2025 00:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755761487; x=1756366287; 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=j3AY6EOb7TA3Vk/44dz1/Kzv3q8Ug/SBekAw+P0yOWU=; b=iH4ZeaPal/apcRiOz3M4FeXysB3FfkQ4QQYSQvJH5wiDg1YTNPxBEd3J5VaI8qm/ds 3+eeeLNoHEP9VVVv7dszkARkuptNHPH10199VKnzEDs9iX2mAgqx2f2LnfXRiwXxoYwW mOIIfluahS2qm04/z6CgbyX0T7x9Yqfly6kl+r1Ol1NIuktA4xBykzaN8JHWmVABByQ7 wovymeRf6oBDQq/h+PkDU2aOmzodv9K1pybwvbxs+XCy4gone0/S1CzN+ueWk+ZcGZpD kMx4vS0byVQMquDGbbuxpK5dgSm5/1bIV/vRRLIgikDVpAb1MeEANc1DU3bdFAo8I9NB Ud9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755761487; x=1756366287; 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=j3AY6EOb7TA3Vk/44dz1/Kzv3q8Ug/SBekAw+P0yOWU=; b=idtiLhb9H2TBe7drU3IP+qEFlYXpB5ZL0GjyrA2M2fKrRsmEMDwZgORXJW0RG7Xji3 XPGJhfvRgNtmJEAv1Mjr0U5kq8G6va3uMt6Fo2ZSee+F2w1aSqfKpwtAkW/Kc8/RJz/t +RdUY64Hs/DoELbsMCrHD7JiIJ06g/essYibOv6d6J2nOKYPDRpE64P2EOB1/oqBgb40 5a+BTI4vOp41j9qsLvPRbiZC9HfnUIkqAtrAncqn9mzTxLeWKsVB8DqvjK4lCLpsW23V W+eSHbt3seMdo43Zq5uQkY9VdGkrFUztresrbRP7DuV45fWQd2xyurZhbgHCSDGDwwQT 0kQQ== X-Forwarded-Encrypted: i=1; AJvYcCU2kOhuoDdPzjleGZKRWDTnic6AydAcsAyVscwoP0TIZcuVvHFhcbyCSZoDRa2nXzhf4zfnhMXj0vSQfA4=@vger.kernel.org X-Gm-Message-State: AOJu0YwylNpbbxARLow+Y8RXc1KjUn5JvW9s6dSwTcuM6zUgy6HJLGwj fRlKEcIvh8Nu5Rj4FO/6lubvsG2ZaAsA94WgE6rztNknC9mvYSi8RkD1njjaAQ== X-Gm-Gg: ASbGnctjRR+G3aIMGgY2h39x1NylIUPR+RUYtrcil5zUWkCl9vXBS50O3u24vDajKnV CxdtZ+kK+PvbXCepq2TmlOJQ2JMCSTr0sYq/qVFqXIFU9oenkOSOS4/sqoBn6d8ev+fhtcBMQK3 MmcvjS9y4PiXIxmCcpjahkl/fScX+LgucCjXj6CuMeZ4GBd/OICT+03/h4X24APdC3k3NdAc6GY MdySzqr1RvLDXt/IOvfpi52MhWVFCbNjbMhSBuNbClnKNfWsCXEyz6XPO5ALEMb8I9URStYZZpp nWXHBiz0Z9nl8MJQMu5xT6zmytafFNy+p3TI0A6mmXPOt3VCh1PS6Q0NPTgP3vC61h1zbah+ssz V2OjI0ksuKnUyCw== X-Google-Smtp-Source: AGHT+IEA6K2pX3lP5oONFfM9qMeCQu6OcRiAOhoIM3+7Z7qv/kdyGKHh723MIEBCgLKJPj8uK5Xl9Q== X-Received: by 2002:a05:600c:4f03:b0:458:c059:7d9c with SMTP id 5b1f17b1804b1-45b4d7d5e3emr9027515e9.6.1755761487275; Thu, 21 Aug 2025 00:31:27 -0700 (PDT) Received: from localhost ([45.84.137.104]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b4db1be26sm16421495e9.5.2025.08.21.00.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 00:31:26 -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, 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, aleksander.lobakin@intel.com, florian.fainelli@broadcom.com, willemdebruijn.kernel@gmail.com, alexander.duyck@gmail.com, linux-kernel@vger.kernel.org, linux-net-drivers@amd.com, Richard Gobert Subject: [PATCH net-next v3 5/5] selftests/net: test ipip packets in gro.sh Date: Thu, 21 Aug 2025 09:30:47 +0200 Message-Id: <20250821073047.2091-6-richardbgobert@gmail.com> In-Reply-To: <20250821073047.2091-1-richardbgobert@gmail.com> References: <20250821073047.2091-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 --- 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..451dc1c1eac5 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, "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..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