From patchwork Thu Feb 22 21:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 13568135 X-Patchwork-Delegate: kuba@kernel.org 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 DBE036AFBD; Thu, 22 Feb 2024 21:05:24 +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=1708635926; cv=none; b=k1toy7XF1lxu0HSvNSDUyZt0qUKmvjWGmcCa7x2rAd85wnxateTZlsQUD+t/bNAd9uYuhl9DZGpD6nXexF/XOYIXUprFUtAuCwFxOUbIsN7VA9SwkJKC7HhTRJ3UGV83CbP8ByiVZ3/19SnaizIejN8jK4j58L+JkUqBFjDD9Js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708635926; c=relaxed/simple; bh=yD5pBPD/kYxJPTUYZvrUJwnIAwaUmh2gCraooFp2UHY=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=NXanq6YlLe9g9ysyXyls81j6e8PyHjZydsaxAH/6UCkLrb6M+Lym+Y7KJ8w908MAVDuTwztOXCbDxYNvboSF6oPaJCDh0TpE28NHswFpRh+ncYDZC0jZA9ftIJx5g9YzlPHO0Z+p+3sxOSaR/pScDOenSZb12Z5iAD+ABtlyk+g= 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=ISJ8KiXX; 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="ISJ8KiXX" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40fd72f7125so1278615e9.1; Thu, 22 Feb 2024 13:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708635923; x=1709240723; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=YIYgPTK6VpZSbtimKRFbQMOHfT2uNIHrnwc0TVN0yNI=; b=ISJ8KiXXFu+qwE59xAzQVIjJ6ss5bHBNYGQg/j+Xbkw3sgks6SNOSUzYkyUlG7Y49Z DWtS1Xf0+OfSJNeaf6kzm1hBn7p9lN0TFcSkPj/rNf2FPMHL4HJ5aE9+q+5PR4zp/7Yq 3/Eay9eDM7CdWAcxD8HLf9h5Xk35KwUBAkHOMxlT3UuqTW5RpS5u1NHBbX4B/MSEvWMM jAx3D2fS7MifpOk8SdMZC6tteZSEHtzM/ym64z9XXKGdIDK35bayOWf90eIt6Ovlea4h Fqf+YgEwINKJWTzD/0jMEcrgelHvgAPj8MuWskxJPVrjnHqzV1xYooVt0C8htDvSV0e/ P7Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708635923; x=1709240723; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=YIYgPTK6VpZSbtimKRFbQMOHfT2uNIHrnwc0TVN0yNI=; b=fKKc1px1Fj5nFVSYSduRQKIBoH7ovKHsOdbU1kFXumJx8psR6OnA9dnH6DxLMuNdNl +GBxYFnabUYU4weU5QxZE8CBXlUscydsgZFHJOqqIlseA1+5p0jDydUnAuAkcUY6EUrU P+kNRSqZnmAcpnO3yE9WGHZfKbQ1tPzDXTFLJU1hgaXy/KPuKInAXV2Lfo4rEut2jv3c 2C6g6M4sz1RuDQpGYRaHmaRV83wlK6tjQXKXDA9FKjpS5DE+s5CEBq1XqhyAAeCIhHuV 4mGB5DTxAqz+bXWMDlJH8MQdHToHl7jnrXcBrbo5+aI8bydfO3jhIPanHh/Bkotn/81A 4raQ== X-Forwarded-Encrypted: i=1; AJvYcCUuHya+qQfOiPdWmgZOTwHBBkt8T5f8R3dvEhibWKYjcWEO327kGMq23S3/oV4vs1FG+K9Hr0NFskzx335NaN/kSiMWxyEyGcdqbAAV/qOQpf5VgDUONKBFfHRIS0vsfVSVA49HBQPgiKY2Q8lk+bsKgJviK+qjeiaBsgWrgQCXAOYJKNG+ X-Gm-Message-State: AOJu0Yyh7sXWmu0iHTA858NsT+XtopJa+52bgdsDpuI9/J+g1wmvv3a/ +OKqPHLGKSeW2ywnqDKZ4OkIuw5yjdTo+vNmG47MDacOfpoiZu6hJwdDSLdq X-Google-Smtp-Source: AGHT+IHreq6rtNKAgSf+gtsztxpU6WO5jwtuaciiBvX7Jja5+hgNjWGMXWt+Z/Dsw0HBBSeVNP4WRg== X-Received: by 2002:a05:600c:19c7:b0:412:3bff:a813 with SMTP id u7-20020a05600c19c700b004123bffa813mr13897746wmq.10.1708635923137; Thu, 22 Feb 2024 13:05:23 -0800 (PST) Received: from debian ([146.70.204.204]) by smtp.gmail.com with ESMTPSA id fc13-20020a05600c524d00b00412157dc70bsm23434119wmb.30.2024.02.22.13.05.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 13:05:22 -0800 (PST) Message-ID: <446695cb-50b8-4187-bf11-63aedb6e9aed@gmail.com> Date: Thu, 22 Feb 2024 22:05:06 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: [PATCH net-next 1/3] net: gro: set {inner_,}network_header in receive phase To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, shuah@kernel.org, liujian56@huawei.com, horms@kernel.org, aleksander.lobakin@intel.com, linyunsheng@huawei.com, therbert@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: From: Richard Gobert In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org Commits a602456 ("udp: Add GRO functions to UDP socket") and 57c67ff ("udp: additional GRO support") introduce incorrect usage of {ip,ipv6}_hdr in the complete phase of gro. The functions always return skb->network_header, which in the case of encapsulated packets at the gro complete phase, is always set to the innermost L3 of the packet. That means that calling {ip,ipv6}_hdr for skbs which completed the GRO receive phase (both in gro_list and *_gro_complete) when parsing an encapsulated packet's _outer_ L3/L4 may return an unexpected value. This incorrect usage leads to a bug in GRO's UDP socket lookup. udp{4,6}_lib_lookup_skb functions use ip_hdr/ipv6_hdr respectively. These *_hdr functions return network_header which will point to the innermost L3, resulting in the wrong offset being used in __udp{4,6}_lib_lookup with encapsulated packets. Reproduction example: Endpoint configuration example (fou + local address bind) # ip fou add port 6666 ipproto 4 # ip link add name tun1 type ipip remote 2.2.2.1 local 2.2.2.2 encap fou encap-dport 5555 encap-sport 6666 mode ipip # ip link set tun1 up # ip a add 1.1.1.2/24 dev tun1 Netperf TCP_STREAM result on net-next before patch is applied: net-next main, GRO enabled: $ netperf -H 1.1.1.2 -t TCP_STREAM -l 5 Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 131072 16384 16384 5.28 2.37 net-next main, GRO disabled: $ netperf -H 1.1.1.2 -t TCP_STREAM -l 5 Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 131072 16384 16384 5.01 2745.06 patch applied, GRO enabled: $ netperf -H 1.1.1.2 -t TCP_STREAM -l 5 Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 131072 16384 16384 5.01 2877.38 This patch fixes this bug and prevents similar future misuse of network_header by setting network_header and inner_network_header to their respective values during the receive phase of GRO. This results in more coherent {inner_,}network_header values for every skb in gro_list, which also means there's no need to set/fix these values before passing the packet forward. network_header is already set in dev_gro_receive and under encapsulation we set inner_network_header. *_gro_complete functions use a new helper function - skb_gro_complete_network_header, which returns the network_header/inner_network_header offset during the GRO complete phase, depending on skb->encapsulation. Fixes: 57c67ff4bd92 ("udp: additional GRO support") Signed-off-by: Richard Gobert --- include/net/gro.h | 14 +++++++++++++- net/8021q/vlan_core.c | 3 +++ net/ipv4/af_inet.c | 8 ++++---- net/ipv4/tcp_offload.c | 2 +- net/ipv4/udp_offload.c | 2 +- net/ipv6/ip6_offload.c | 11 +++++------ net/ipv6/tcpv6_offload.c | 2 +- net/ipv6/udp_offload.c | 2 +- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index b435f0ddbf64..89502a7e35ed 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -177,10 +177,22 @@ static inline void *skb_gro_header(struct sk_buff *skb, return ptr; } +static inline int skb_gro_network_offset(struct sk_buff *skb) +{ + return NAPI_GRO_CB(skb)->encap_mark ? skb_inner_network_offset(skb) : + skb_network_offset(skb); +} + static inline void *skb_gro_network_header(struct sk_buff *skb) { return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + - skb_network_offset(skb); + skb_gro_network_offset(skb); +} + +static inline void *skb_gro_complete_network_header(struct sk_buff *skb) +{ + return skb->encapsulation ? skb_inner_network_header(skb) : + skb_network_header(skb); } static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto) diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c index f00158234505..8bc871397e47 100644 --- a/net/8021q/vlan_core.c +++ b/net/8021q/vlan_core.c @@ -478,6 +478,9 @@ static struct sk_buff *vlan_gro_receive(struct list_head *head, if (unlikely(!vhdr)) goto out; + if (!NAPI_GRO_CB(skb)->encap_mark) + skb_set_network_header(skb, hlen); + type = vhdr->h_vlan_encapsulated_proto; ptype = gro_find_receive_by_type(type); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 835f4f9d98d2..c0f3c162bf73 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1564,7 +1564,9 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb) NAPI_GRO_CB(skb)->is_atomic = !!(iph->frag_off & htons(IP_DF)); NAPI_GRO_CB(skb)->flush |= flush; - skb_set_network_header(skb, off); + if (NAPI_GRO_CB(skb)->encap_mark) + skb_set_inner_network_header(skb, off); + /* The above will be needed by the transport layer if there is one * immediately following this IP hdr. */ @@ -1643,10 +1645,8 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff) int proto = iph->protocol; int err = -ENOSYS; - if (skb->encapsulation) { + if (skb->encapsulation) skb_set_inner_protocol(skb, cpu_to_be16(ETH_P_IP)); - skb_set_inner_network_header(skb, nhoff); - } iph_set_totlen(iph, skb->len - nhoff); csum_replace2(&iph->check, totlen, iph->tot_len); diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 8311c38267b5..8bbcd3f502ac 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -330,7 +330,7 @@ struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb) INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff) { - const struct iphdr *iph = ip_hdr(skb); + const struct iphdr *iph = skb_gro_complete_network_header(skb); struct tcphdr *th = tcp_hdr(skb); th->check = ~tcp_v4_check(skb->len - thoff, iph->saddr, diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 6c95d28d0c4a..7f59cede67f5 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -709,7 +709,7 @@ EXPORT_SYMBOL(udp_gro_complete); INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff) { - const struct iphdr *iph = ip_hdr(skb); + const struct iphdr *iph = skb_gro_complete_network_header(skb); struct udphdr *uh = (struct udphdr *)(skb->data + nhoff); /* do fraglist only if there is no outer UDP encap (or we already processed it) */ diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c index cca64c7809be..db7e3db587b9 100644 --- a/net/ipv6/ip6_offload.c +++ b/net/ipv6/ip6_offload.c @@ -67,7 +67,7 @@ static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto) off += len; } - skb_gro_pull(skb, off - skb_network_offset(skb)); + skb_gro_pull(skb, off - skb_gro_network_offset(skb)); return proto; } @@ -236,7 +236,8 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, if (unlikely(!iph)) goto out; - skb_set_network_header(skb, off); + if (NAPI_GRO_CB(skb)->encap_mark) + skb_set_inner_network_header(skb, off); flush += ntohs(iph->payload_len) != skb->len - hlen; @@ -259,7 +260,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, NAPI_GRO_CB(skb)->proto = proto; flush--; - nlen = skb_network_header_len(skb); + nlen = skb_gro_offset(skb) - off; list_for_each_entry(p, head, list) { const struct ipv6hdr *iph2; @@ -353,10 +354,8 @@ INDIRECT_CALLABLE_SCOPE int ipv6_gro_complete(struct sk_buff *skb, int nhoff) int err = -ENOSYS; u32 payload_len; - if (skb->encapsulation) { + if (skb->encapsulation) skb_set_inner_protocol(skb, cpu_to_be16(ETH_P_IPV6)); - skb_set_inner_network_header(skb, nhoff); - } payload_len = skb->len - nhoff - sizeof(*iph); if (unlikely(payload_len > IPV6_MAXPLEN)) { diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c index bf0c957e4b5e..79eeaced2834 100644 --- a/net/ipv6/tcpv6_offload.c +++ b/net/ipv6/tcpv6_offload.c @@ -29,7 +29,7 @@ struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb) INDIRECT_CALLABLE_SCOPE int tcp6_gro_complete(struct sk_buff *skb, int thoff) { - const struct ipv6hdr *iph = ipv6_hdr(skb); + const struct ipv6hdr *iph = skb_gro_complete_network_header(skb); struct tcphdr *th = tcp_hdr(skb); th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr, diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index 6b95ba241ebe..897caa2e39fb 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -164,7 +164,7 @@ struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb) INDIRECT_CALLABLE_SCOPE int udp6_gro_complete(struct sk_buff *skb, int nhoff) { - const struct ipv6hdr *ipv6h = ipv6_hdr(skb); + const struct ipv6hdr *ipv6h = skb_gro_complete_network_header(skb); struct udphdr *uh = (struct udphdr *)(skb->data + nhoff); /* do fraglist only if there is no outer UDP encap (or we already processed it) */ From patchwork Thu Feb 22 21:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 13568136 X-Patchwork-Delegate: kuba@kernel.org 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 6D41E7172E; Thu, 22 Feb 2024 21:07:21 +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=1708636043; cv=none; b=lqshvHqPQ21e/kc08FtSzL44YMbdO474aWcyRXYFtkDFvgXAR74z5ZiqMhJ2m6p0m8GoXu7ApwtNLsfxjvBqnceAx65b5R+7msiupUHsSuj360X7V3HEwygHVCxGtKrLs68UAY2aP/hpb/KlvEikTYHSY7MvmQfG3tkw7ksGJ8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636043; c=relaxed/simple; bh=yEcHDxN9RLq38OaBT7T32ipqe63fnfoOEny+8083TOs=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=WHqsO0RLKJHfat6/MFNZ9gXCsylZYYep7J/3vSvyY/H3l29OzQ9NJSjzJ/2dJhpTaVZdehYZSE2dzzq0A5g9VD1BwUT/daZSvWlbRU1Pbq565B679RpIPWKz0JKPCiK311aIA5EtBvIXfHS25z7Bjo/HZj3y1HIDRUqhhjte4Xc= 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=JXD9nKE/; 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="JXD9nKE/" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3394ca0c874so107832f8f.2; Thu, 22 Feb 2024 13:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708636040; x=1709240840; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=W/LsAF7t/DjHyNUZ4YFga9FjpoydH+mPM4Uvs/yTAKk=; b=JXD9nKE/4nZXAgT2Z9S71xEsz6keTY9zT6Vorbyfa8OkjBmeCxeycdYCtjc+HSmfgP eAFWP8JEUNy2d6dZe2GtRU4qzvPL32j2eZkgIXwcyc2ZGjDTpnJ6jyyp1Zo/gGVJXFMR 13CBuJNpC3AFoP8amOx9XATng3AZfwDCr8ED93soqL+pCNqGU6zOL7mQz9NvVtG+6T8q WZVEQFQ1m87hGTiYXKDeUAxDlbShtBxOCFa+g9P+LcnOXplmci0TB2cj3n0nfDGKIn1X 7gN5DzVkamzDIr0zW/a38PVOLnwtW+SpKfktW0MhL2XUBrOrIfPE7J+wH2H+CVlOLJry hwzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708636040; x=1709240840; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=W/LsAF7t/DjHyNUZ4YFga9FjpoydH+mPM4Uvs/yTAKk=; b=EJ9XFW+NMYtXej9mQN/uC8R6uS3VnaoTJHYvLbl58Xq3C4HNEVKlplg2LeYzkSd8yC FqzWFhFLyvv/7ATVqXmMqg3QpdHTK8uvO0h3tSSG/t/qYBDwFN4jBMAgTjoy+8wur6CN RUDZjqXiXEZHalt8t+Eif1id25qna1Jy6/hwk5nSXy/AEg6pwoFEWr05LHa5uCL0hr5T AZcrRthSqGDqnxGth2bEPVprW/ey89io4RbORbD7NjUr93dQl8jhIp1ugzDVCPEthw0O +mKRXLwn23CixbDRtefvUN+jnCwdSsYtPLakdvwGR4aUEh7H+1Ya+XdR9ZD1doUENmI5 4dSA== X-Forwarded-Encrypted: i=1; AJvYcCWfFabX1UjEcBKhkvmf7fvUe19o52v9oR3G7lOlKX/Fh9a1KzUdXj2Nvu/RcUSDMI/qCIC5zmC8LFbpYkYsPjYQPkdtt8sjABWcA+ki1gyDGa2IvHVYZy45adSu8poh0PDRi1RhNjuajX+4/5u7dE2GTfLWBQsdwOYx5Y73xA47UP1zJbGl X-Gm-Message-State: AOJu0YxhoIZzIhjZSLuv73REhGFNDG634MTrYpS001MNz3LYy6/UYRZ4 ltodNoGhD3K4jeTza1leCPhfDA+ED2qUWrVIBCSe/DgXYesbMVPe X-Google-Smtp-Source: AGHT+IFXB/nbEaMFXlrONCtpl4m94bpLbDQAxbSjm81SFiVV49HMZ9AYUU5sK3Wv8De5bJ1XDyYGRw== X-Received: by 2002:a5d:5007:0:b0:33d:67a1:ba0b with SMTP id e7-20020a5d5007000000b0033d67a1ba0bmr196182wrt.61.1708636039601; Thu, 22 Feb 2024 13:07:19 -0800 (PST) Received: from debian ([146.70.204.204]) by smtp.gmail.com with ESMTPSA id bx9-20020a5d5b09000000b0033d568f8310sm198145wrb.89.2024.02.22.13.07.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 13:07:19 -0800 (PST) Message-ID: <2622ff3b-144f-4038-8f05-82c01afc5ce3@gmail.com> Date: Thu, 22 Feb 2024 22:07:00 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: [PATCH net-next 2/3] selftests/net: add local address bind in vxlan selftest To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, shuah@kernel.org, liujian56@huawei.com, horms@kernel.org, aleksander.lobakin@intel.com, linyunsheng@huawei.com, therbert@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: From: Richard Gobert In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org Add local address bind support to existing udpgro_fwd.sh vxlan selftest, to ensure UDP socket lookup in GRO is working. Signed-off-by: Richard Gobert --- tools/testing/selftests/net/udpgro_fwd.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/udpgro_fwd.sh b/tools/testing/selftests/net/udpgro_fwd.sh index c079565add39..8cc9b6ff3910 100755 --- a/tools/testing/selftests/net/udpgro_fwd.sh +++ b/tools/testing/selftests/net/udpgro_fwd.sh @@ -56,11 +56,13 @@ create_vxlan_endpoint() { local -r bm_rem_addr=$3 local -r vxlan_dev=$4 local -r vxlan_id=$5 + local -r bm_local_addr=$6 local -r vxlan_port=4789 ip -n $netns link set dev $bm_dev up ip -n $netns link add dev $vxlan_dev type vxlan id $vxlan_id \ - dstport $vxlan_port remote $bm_rem_addr + dstport $vxlan_port local $bm_local_addr \ + remote $bm_rem_addr ip -n $netns link set dev $vxlan_dev up } @@ -71,11 +73,13 @@ create_vxlan_pair() { for ns in $SRC $DST; do # note that 3 - $SRC == $DST and 3 - $DST == $SRC - create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V4$((3 - $ns)) vxlan$ns 4 + create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V4$((3 - $ns)) \ + vxlan$ns 4 $BM_NET_V4$ns ip -n $BASE$ns addr add dev vxlan$ns $OL_NET_V4$ns/24 done for ns in $SRC $DST; do - create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V6$((3 - $ns)) vxlan6$ns 6 + create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V6$((3 - $ns)) \ + vxlan6$ns 6 $BM_NET_V6$ns ip -n $BASE$ns addr add dev vxlan6$ns $OL_NET_V6$ns/24 nodad done } From patchwork Thu Feb 22 21:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 13568139 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 2788E12D1EF; Thu, 22 Feb 2024 21:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636359; cv=none; b=F/JGHyNC+TJUaRl1PP8HPDIZf6R+J7SDAkTnw/tbhReVzC8LGIbg8KwOMbAUwK6LwaIoBz+lQvSg19vEuoDgY33nxlabxplvsfkrKbJ5bFFixHzEo8XIjWOESy17OirjWA5lI2R2NPIwpEL5MdwOjtfpYsTmuopyIRSc2SRKscM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636359; c=relaxed/simple; bh=ulEVuUbmlIOcbZS/uX1ZSKeGuYNvg2+eTJ9Hnw8+geA=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=TjLq+ABPrDxFWr9S47peIM44g6rkpF/sU9mv52G6KdLJLXmpmV6AVSTDC8trzoPUT2GeR0fLG+s+DJYVBsq1s0N4SMfr4qNyxIPb97cR5ZOJn8siqLhFSbBVZHt6h/nPmc7Ifm75aIm6J80q0woqD8s2+TEoMxeUVOjlOdzqRKM= 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=Fvr9zekl; arc=none smtp.client-ip=209.85.221.45 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="Fvr9zekl" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3394b892691so140031f8f.1; Thu, 22 Feb 2024 13:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708636355; x=1709241155; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=8uZ886B2wbGi6D6+tgsf/RlPsYxVtxW0DFUXrxIudv4=; b=Fvr9zekl590HUyFChrkJQNwqepa0YjKPUBOcfMoCbb89eUxRkEvJ4IGKCo83Mf7v7e tSANNIgmlxzeGji0PYTCNfxfLdwL2Grogk3pFIQFYifvSfdx1YEPgECg2hB2Ey4fDqPM +vUduVhxfF+8/R+v7vI4TMPjWxGzmJckI5aWJfLIq9iF7S+qDXzyDgE4JMxRPDyHlpKx LCsHpjC0rUmBnhbYO7CVLPOCgzHu09lx+TLSWZCokRTKdOL+tLcz015OgG8dKwSU08IP oMHhpxgRQSs9SJVpRkE63WdB6lBaIIqTuUgdOndSar1ailbncwqe1iovmOb349I/R1tK 37nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708636355; x=1709241155; h=content-transfer-encoding:in-reply-to:from:references:to:subject :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=8uZ886B2wbGi6D6+tgsf/RlPsYxVtxW0DFUXrxIudv4=; b=uenomkQrIhXMdYrw1GEyJUrIfJOgCVYwngiMfuq6yLkA53/x87IfbYj5wbsMCi/Yh4 fKiTIRcF37ruBKfaV+ql/EeIqjql1/XQGooa25WwKBiYmFvEM7dx2QaXHrh7jOlt99in 0lQFyh1Lh2fPzrTcbp9oDjNJMHc5gwx3w0HdoKKya9+NZvqFQr+rNwKGV9zbFguthAfu jLPYGvImAJI1mr0BS6CGndTKPQXIiatOILuHswA8XAskoWXEcPtrIYK8CMP2cDYS02Mu FRHb9Py0jVEbXGLZSofC0PxQr0BZf6oBI4/eb0PXHrQ7RxXeXjlkSFLicn2g02yhOtpn bNCg== X-Forwarded-Encrypted: i=1; AJvYcCXsf5dB9poRP7k9sQ6/grDR3OkPhDi7r/WLJ8WiIsTdaHgPJ4E+oaN2Gy/ne6r1gdXCfSZ/3uhuVfNZLGp98rVDi5jyzH2rTEgMzylDPBIE+0InfcnBg0pe/fRUKkObatBHwPQJFa2F6v8asOgPHH4FDbflEt9FQbtfb1Anv1zp8AKVSItw X-Gm-Message-State: AOJu0YxYcRWJssLjnlKpjE3y874gGKqo1PxqmP8NVc4PFHsj2lmaNRW4 Dn10LeAy1H3O0z2jL4PkuTB7gx3OWviWlDzf1/w7LBaV+osIX5Jm X-Google-Smtp-Source: AGHT+IHT5PsC047o/u3D4yrVTBQYfRa0oFqzo8/IqrmGohwIxUIGmayvAhMTj5uXkm46pqPdtYVnGA== X-Received: by 2002:a5d:46c8:0:b0:33d:4dbd:d05e with SMTP id g8-20020a5d46c8000000b0033d4dbdd05emr3462949wrs.22.1708636355232; Thu, 22 Feb 2024 13:12:35 -0800 (PST) Received: from debian ([146.70.204.204]) by smtp.gmail.com with ESMTPSA id ay28-20020a5d6f1c000000b0033d60cba289sm214669wrb.68.2024.02.22.13.12.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 13:12:35 -0800 (PST) Message-ID: Date: Thu, 22 Feb 2024 22:12:12 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: [PATCH net-next 3/3] net: gro: move L3 flush checks to tcp_gro_receive To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, shuah@kernel.org, liujian56@huawei.com, horms@kernel.org, aleksander.lobakin@intel.com, linyunsheng@huawei.com, therbert@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: From: Richard Gobert In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org {inet,ipv6}_gro_receive functions perform flush checks (ttl, flags, iph->id, ...) against all packets in a loop. These flush checks are relevant only to tcp flows, and as such they're used to determine whether the packets can be merged later in tcp_gro_receive. These checks are not relevant to UDP packets. Furthermore, they need to be done only once in tcp_gro_receive and only against the found p skb, since they only affect flush and not same_flow. Leveraging the initial commit in the series, correct network header offsets are saved for both outer and inner network headers - allowing these checks to be done only once, in tcp_gro_receive. As a result, NAPI_GRO_CB(p)->flush is not used at all. In addition - flush_id checks are more declarative and contained in inet_gro_flush_id, thus removing the need for flush_id in napi_gro_cb. This results in less parsing code for UDP flows and non-loop flush tests for TCP flows. For example, running 64 IP/UDP netperf connections: ./super_netperf.sh 64 -H 1.1.1.2 -t UDP_STREAM -l 120 Running perf top for 90s we can see that relatively less time is spent on inet_gro_receive: net-next: Samples: 330K of event 'cycles:P', 4000 Hz, Event count (approx.): 45945660156 lost: 0/0 drop: 0/0 1.43% [kernel] [k] inet_gro_receive patch applied: Samples: 295K of event 'cycles:P', 4000 Hz, Event count (approx.): 44726408099 lost: 0/0 drop: 0/0 1.22% [kernel] [k] inet_gro_receive Signed-off-by: Richard Gobert --- include/net/gro.h | 9 ++---- net/core/gro.c | 3 -- net/ipv4/af_inet.c | 36 --------------------- net/ipv4/tcp_offload.c | 71 ++++++++++++++++++++++++++++++++++-------- net/ipv6/ip6_offload.c | 11 ------- 5 files changed, 61 insertions(+), 69 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 89502a7e35ed..e6db591cdc32 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -35,15 +35,15 @@ struct napi_gro_cb { /* This is non-zero if the packet cannot be merged with the new skb. */ u16 flush; - /* Save the IP ID here and check when we get to the transport layer */ - u16 flush_id; - /* Number of segments aggregated. */ u16 count; /* Used in ipv6_gro_receive() and foo-over-udp and esp-in-udp */ u16 proto; + /* used to support CHECKSUM_COMPLETE for tunneling protocols */ + __wsum csum; + /* Used in napi_gro_cb::free */ #define NAPI_GRO_FREE 1 #define NAPI_GRO_FREE_STOLEN_HEAD 2 @@ -83,9 +83,6 @@ struct napi_gro_cb { /* GRO is done by frag_list pointer chaining. */ u8 is_flist:1; ); - - /* used to support CHECKSUM_COMPLETE for tunneling protocols */ - __wsum csum; }; #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb) diff --git a/net/core/gro.c b/net/core/gro.c index 0759277dc14e..b7dced5bcef7 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -332,8 +332,6 @@ static void gro_list_prepare(const struct list_head *head, list_for_each_entry(p, head, list) { unsigned long diffs; - NAPI_GRO_CB(p)->flush = 0; - if (hash != skb_get_hash_raw(p)) { NAPI_GRO_CB(p)->same_flow = 0; continue; @@ -466,7 +464,6 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff sizeof(u32))); /* Avoid slow unaligned acc */ *(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0; NAPI_GRO_CB(skb)->flush = skb_has_frag_list(skb); - NAPI_GRO_CB(skb)->is_atomic = 1; NAPI_GRO_CB(skb)->count = 1; if (unlikely(skb_is_gso(skb))) { NAPI_GRO_CB(skb)->count = skb_shinfo(skb)->gso_segs; diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index c0f3c162bf73..fd7378ecc4e3 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1509,7 +1509,6 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb) list_for_each_entry(p, head, list) { struct iphdr *iph2; - u16 flush_id; if (!NAPI_GRO_CB(p)->same_flow) continue; @@ -1526,43 +1525,8 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb) NAPI_GRO_CB(p)->same_flow = 0; continue; } - - /* All fields must match except length and checksum. */ - NAPI_GRO_CB(p)->flush |= - (iph->ttl ^ iph2->ttl) | - (iph->tos ^ iph2->tos) | - ((iph->frag_off ^ iph2->frag_off) & htons(IP_DF)); - - NAPI_GRO_CB(p)->flush |= flush; - - /* We need to store of the IP ID check to be included later - * when we can verify that this packet does in fact belong - * to a given flow. - */ - flush_id = (u16)(id - ntohs(iph2->id)); - - /* This bit of code makes it much easier for us to identify - * the cases where we are doing atomic vs non-atomic IP ID - * checks. Specifically an atomic check can return IP ID - * values 0 - 0xFFFF, while a non-atomic check can only - * return 0 or 0xFFFF. - */ - if (!NAPI_GRO_CB(p)->is_atomic || - !(iph->frag_off & htons(IP_DF))) { - flush_id ^= NAPI_GRO_CB(p)->count; - flush_id = flush_id ? 0xFFFF : 0; - } - - /* If the previous IP ID value was based on an atomic - * datagram we can overwrite the value and ignore it. - */ - if (NAPI_GRO_CB(skb)->is_atomic) - NAPI_GRO_CB(p)->flush_id = flush_id; - else - NAPI_GRO_CB(p)->flush_id |= flush_id; } - NAPI_GRO_CB(skb)->is_atomic = !!(iph->frag_off & htons(IP_DF)); NAPI_GRO_CB(skb)->flush |= flush; if (NAPI_GRO_CB(skb)->encap_mark) skb_set_inner_network_header(skb, off); diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 8bbcd3f502ac..962c1b900e11 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -178,6 +178,60 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, return segs; } +static inline bool inet_gro_flush(struct iphdr *iph, struct iphdr *iph2) +{ + /* All fields must match except length and checksum. */ + return (iph->ttl ^ iph2->ttl) | + (iph->tos ^ iph2->tos) | + ((iph->frag_off ^ iph2->frag_off) & htons(IP_DF)); +} + +static inline bool ipv6_gro_flush(struct ipv6hdr *iph, struct ipv6hdr *iph2) +{ + /* */ + __be32 first_word = *(__be32 *)iph ^ *(__be32 *)iph2; + + /* Flush if Traffic Class fields are different. */ + return (first_word & htonl(0x0FF00000)) | + (__force __be32)(iph->hop_limit ^ iph2->hop_limit); +} + +static inline bool inet_gro_flush_id(struct sk_buff *p, struct iphdr *iph, + struct iphdr *iph2) +{ + u16 flush_id = ntohs(iph->id) - ntohs(iph2->id); + u16 is_atomic = !!(iph->frag_off & htons(IP_DF)); + u16 count_masked; + + /* 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 (NAPI_GRO_CB(p)->count == 1) + NAPI_GRO_CB(p)->is_atomic = flush_id == 0; + + /* Ignore outer IP ID value if based on atomic datagram. */ + if (NAPI_GRO_CB(p)->encap_mark && is_atomic && iph2 == ip_hdr(p)) + return false; + + is_atomic &= NAPI_GRO_CB(p)->is_atomic; + count_masked = NAPI_GRO_CB(p)->count & ~(-is_atomic | is_atomic); + + return flush_id ^ count_masked; +} + +static bool tcp_gro_network_flush(struct sk_buff *p, struct sk_buff *skb, + int offset) +{ + void *nh = (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + offset; + void *nh2 = p->data + offset; + + if (((struct iphdr *)nh)->version == 6) + return ipv6_gro_flush(nh, nh2); + + return inet_gro_flush(nh, nh2) | inet_gro_flush_id(p, nh, nh2); +} + struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) { struct sk_buff *pp = NULL; @@ -232,8 +286,10 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) goto out_check_final; found: - /* Include the IP ID check below from the inner most IP hdr */ - flush = NAPI_GRO_CB(p)->flush; + flush = tcp_gro_network_flush(p, skb, skb_network_offset(skb)); + if (NAPI_GRO_CB(skb)->encap_mark) + flush |= tcp_gro_network_flush(p, skb, skb_inner_network_offset(skb)); + flush |= (__force int)(flags & TCP_FLAG_CWR); flush |= (__force int)((flags ^ tcp_flag_word(th2)) & ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH)); @@ -242,17 +298,6 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) flush |= *(u32 *)((u8 *)th + i) ^ *(u32 *)((u8 *)th2 + i); - /* When we receive our second frame we can made a decision on if we - * continue this flow as an atomic flow with a fixed ID or if we use - * an incrementing ID. - */ - if (NAPI_GRO_CB(p)->flush_id != 1 || - NAPI_GRO_CB(p)->count != 1 || - !NAPI_GRO_CB(p)->is_atomic) - flush |= NAPI_GRO_CB(p)->flush_id; - else - NAPI_GRO_CB(p)->is_atomic = false; - mss = skb_shinfo(p)->gso_size; /* If skb is a GRO packet, make sure its gso_size matches prior packet mss. diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c index db7e3db587b9..8bf93a0e9669 100644 --- a/net/ipv6/ip6_offload.c +++ b/net/ipv6/ip6_offload.c @@ -291,19 +291,8 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, nlen - sizeof(struct ipv6hdr))) goto not_same_flow; } - /* flush if Traffic Class fields are different */ - NAPI_GRO_CB(p)->flush |= !!((first_word & htonl(0x0FF00000)) | - (__force __be32)(iph->hop_limit ^ iph2->hop_limit)); - NAPI_GRO_CB(p)->flush |= flush; - - /* If the previous IP ID value was based on an atomic - * datagram we can overwrite the value and ignore it. - */ - if (NAPI_GRO_CB(skb)->is_atomic) - NAPI_GRO_CB(p)->flush_id = 0; } - NAPI_GRO_CB(skb)->is_atomic = true; NAPI_GRO_CB(skb)->flush |= flush; skb_gro_postpull_rcsum(skb, iph, nlen);