From patchwork Fri Mar 1 19:37:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13579017 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 6AF64524B for ; Fri, 1 Mar 2024 19:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321869; cv=none; b=n64SPH1dZ1uI3fUHIb1wp3Dfnh4YkIl8cq28671u30rhHQPrk8xvnkw6mwXhkN0fL0GqSgtP6+7XAv87d+1MniCP7ANGJtgsFnrq72nd6b3dFtIVbvqQ8BCXTzucAygdYUFD5vSEZK1HvbZMZi0mzsU78GKWuXDPORb/CEt1m64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321869; c=relaxed/simple; bh=g0JCxee9y8WM7lngp+76yN71yjIdivhG2Hy+8BSkJ0A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r8cCt0Mn8DWeM9yJ/wx92q9S/QQWPzwy+euawzU/nQpOXwlaRF1vVKanueidnmDyNDE+G283v88AuS/6XgjqpQATZi7P1D/G1NocmCBS/XvhYLkJxjN7lgYfZtvkKYEvOg0qsvI6YEIST3heySuWiSu+ZeHmFY97MmELGPivTZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LU7Yqk6v; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LU7Yqk6v" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60810219282so32832387b3.0 for ; Fri, 01 Mar 2024 11:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709321866; x=1709926666; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jJv1doVck0+J8YGpv3pY19UKzWvtwbH+sfJgs2p1WbE=; b=LU7Yqk6vDngaJVJShSRLz3wIYVNVGAZcRoDSwXDKm//qmQIlpMJU746KgeEqnBgfgN GWFeEC98BPND0QeBC483xJ83wptt1l5DFWtv2PWFeR2S8b6kIBYeYgC2LVy8zq8Hv6xK 5h8EKfglbepFvvl5hksXVtiGE8ZTD+5FfEQpjzHsunwcRojXNcmwj0jSLRxFF0JjQ+IE JpyAgof1DjE1bdhliiVjiPSc4PwMmskMBmDUigLp8OrI4Au5ovH+tGW7FmnAn4nKycz3 jsEpizhjMUmQtyevkZgTsL4I5rXAbEqtKj4V0zE7C4OVCA1ksdV5DVgSrMiTCsWL4s2a zK0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709321866; x=1709926666; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jJv1doVck0+J8YGpv3pY19UKzWvtwbH+sfJgs2p1WbE=; b=vZaiBha5vGE7ERbLsbsWeG597fhR2kVKGfpYIbtC0nu+7c1zpbw0Ij7L0Maj8wHKj8 vWowJ+zZzXO0FT1OyCydBYF1Ymgssw28aTLCcktcY+Xu3b+lbuGt3A9mhetnTxig2d97 vqMWFXFOCFK72EuJT6dd6WdYTofFARCqIvYKymQg9cylyNhPNOI4EsT22b7eP/CnLABz XiAVX7Q2FU/ba9++xlWOe3me2IXUjiQs5o6G8lcveNwZKQm/qtt++HosEYasIPAkirTH 7w43OG35ceN29mtc1+RlWXP98v595L+2kdiV0dJpRtfBWNKlDWaSNEXlYTWhFMX3kprE Gl7w== X-Forwarded-Encrypted: i=1; AJvYcCWq0+BiFa2t3AZ96dQX7ky9lEkkPrajZH0SY7D8TbbDuqD+HpO57VN/w4rqmkJmA4s7hkhbx6z4ZjQGLW8Gir4QcC1iQfwc X-Gm-Message-State: AOJu0YxeOlT/FYyG+If0fAf0fQVXVr5pdGKjydJX7oLtPkgqIdX3TgDj w+zPlM6QBUt8xUm17pnD+7x/mpZkNkB2s4ubND0v/bWD4ZDVylfVeSpMJotrpQsKFoqLkPq80Hk AELIzCn6a4A== X-Google-Smtp-Source: AGHT+IH633MuVX95LTuyMRqu9eytKNS2a4qtN96qQac8Z5wkjDpsUv86VG5QivN0rVzyN2d2YOwfsEuFEZ2ylg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:7947:0:b0:609:359a:9313 with SMTP id u68-20020a817947000000b00609359a9313mr497605ywc.1.1709321866474; Fri, 01 Mar 2024 11:37:46 -0800 (PST) Date: Fri, 1 Mar 2024 19:37:37 +0000 In-Reply-To: <20240301193740.3436871-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301193740.3436871-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240301193740.3436871-2-edumazet@google.com> Subject: [PATCH net-next 1/4] net: gro: rename skb_gro_header_hard() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Richard Gobert , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org skb_gro_header_hard() is renamed to skb_gro_may_pull() to match the convention used by common helpers like pskb_may_pull(). This means the condition is inverted: if (skb_gro_header_hard(skb, hlen)) slow_path(); becomes: if (!skb_gro_may_pull(skb, hlen)) slow_path(); Signed-off-by: Eric Dumazet --- drivers/net/geneve.c | 2 +- include/net/gro.h | 7 ++++--- net/core/gro.c | 2 +- net/ipv4/fou_core.c | 2 +- net/ipv4/gre_offload.c | 2 +- net/ipv4/tcp_offload.c | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 6f3f9b446b1d202f6c71a20ce48088691e9120bf..e25e0a31126c1527f5b4f61c83d99f0d9481e58f 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -508,7 +508,7 @@ static struct sk_buff *geneve_gro_receive(struct sock *sk, gh_len = geneve_hlen(gh); hlen = off_gnv + gh_len; - if (skb_gro_header_hard(skb, hlen)) { + if (!skb_gro_may_pull(skb, hlen)) { gh = skb_gro_header_slow(skb, hlen, off_gnv); if (unlikely(!gh)) goto out; diff --git a/include/net/gro.h b/include/net/gro.h index b435f0ddbf64f7bf740b7e479a1b28bcdef122c6..ffc2c96d263b0399a81465d903a6181271b4a3f7 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -145,9 +145,10 @@ static inline void *skb_gro_header_fast(struct sk_buff *skb, return NAPI_GRO_CB(skb)->frag0 + offset; } -static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen) +static inline bool skb_gro_may_pull(const struct sk_buff *skb, + unsigned int hlen) { - return NAPI_GRO_CB(skb)->frag0_len < hlen; + return hlen <= NAPI_GRO_CB(skb)->frag0_len; } static inline void skb_gro_frag0_invalidate(struct sk_buff *skb) @@ -172,7 +173,7 @@ static inline void *skb_gro_header(struct sk_buff *skb, void *ptr; ptr = skb_gro_header_fast(skb, offset); - if (skb_gro_header_hard(skb, hlen)) + if (!skb_gro_may_pull(skb, hlen)) ptr = skb_gro_header_slow(skb, hlen, offset); return ptr; } diff --git a/net/core/gro.c b/net/core/gro.c index 0759277dc14ee65d0a5376d48694cc1cccaee959..927ccf68149093d6dfd66a622a7db5215a483876 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -700,7 +700,7 @@ static struct sk_buff *napi_frags_skb(struct napi_struct *napi) skb_reset_mac_header(skb); skb_gro_reset_offset(skb, hlen); - if (unlikely(skb_gro_header_hard(skb, hlen))) { + if (unlikely(!skb_gro_may_pull(skb, hlen))) { eth = skb_gro_header_slow(skb, hlen, 0); if (unlikely(!eth)) { net_warn_ratelimited("%s: dropping impossible skb from %s\n", diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 0c41076e31edadd16f8e55ebc50f84db262a2f0d..a8494f796dca336ca4b30fdbc2f91f3a7e6631fb 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -351,7 +351,7 @@ static struct sk_buff *gue_gro_receive(struct sock *sk, optlen = guehdr->hlen << 2; len += optlen; - if (skb_gro_header_hard(skb, len)) { + if (!skb_gro_may_pull(skb, len)) { guehdr = skb_gro_header_slow(skb, len, off); if (unlikely(!guehdr)) goto out; diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c index 311e70bfce407a2cadaa33fbef9a3976375711f4..5028c72d494abdbf890b3270a4849b2f5c3834a3 100644 --- a/net/ipv4/gre_offload.c +++ b/net/ipv4/gre_offload.c @@ -174,7 +174,7 @@ static struct sk_buff *gre_gro_receive(struct list_head *head, grehlen += GRE_HEADER_SECTION; hlen = off + grehlen; - if (skb_gro_header_hard(skb, hlen)) { + if (!skb_gro_may_pull(skb, hlen)) { greh = skb_gro_header_slow(skb, hlen, off); if (unlikely(!greh)) goto out; diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 8311c38267b55ba97e59924c3c1c5b59f133fdcd..875456efc92ddd546e13232dd775aaaf1093ce4f 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -204,7 +204,7 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) goto out; hlen = off + thlen; - if (skb_gro_header_hard(skb, hlen)) { + if (!skb_gro_may_pull(skb, hlen)) { th = skb_gro_header_slow(skb, hlen, off); if (unlikely(!th)) goto out; From patchwork Fri Mar 1 19:37:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13579018 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 1D0D43B2A6 for ; Fri, 1 Mar 2024 19:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321870; cv=none; b=FKMzNdw30O6BFIFgTBI8ueCr7VHr8kDsMIAdY6vkKbd9pEVyb5ftkHBrYuZZwni6eMHBaAs5iTEBai5ZC5MTvb6sazcvPPenV77n4o0y/JVMSriygQnStBSrJgTV79+d87YI+I5cgJFWlOrtWVNKMAR2U2IFLytL86k0KEFndWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321870; c=relaxed/simple; bh=7QlOKeJz6CBEcvJtiJQkpdCoWIKOR4kjFWDUUQS6z7A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RY23SI8IJ6PVkAG14XeBzpHwFaomzpNz+Fom49AcnA5dMx7A2Q9hbmj7eVcdx0z6OBOe7I6wDJVffWgnrNN7FI/bPEqbuswqWs9a/Uln9jwcYEji/RrZOij9x6DeTzwKP80JwbX6Rz0seZ5S6sTW2HXVm9AxxUK9eXBHUe8kPnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nh736mtj; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nh736mtj" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcc15b03287so3588234276.3 for ; Fri, 01 Mar 2024 11:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709321868; x=1709926668; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E+XDD+X98TQ5bJaUIivjQNWZ3/8yjB1dtyzn9J17zj0=; b=nh736mtjX4b+rTBpyK60iul0KdsdwWOXRiGt+DAwGgBa3H9Ukh+SfdUQHqTLxxUfxJ fysBhk6pbH+cnSDc2tICViWtF2aFGZfdmkdGI1hYtmyPqNhPN6X6D9wCg2TCptCH0wwy uTsfOGykKCfRD9ZMbQRdCULzLgwGslSKJIeEIYgluOKY/7aFEVyEJTEUZWuexeGLiHrM vnuR1l1PfbH5lkCr8JuIbV8cJmMMeQU2Y21uUJpdqGnA0dM+5ssQsNys0sEWocV4otNW aXa14lyoLzKAp3n0JqQlAW6eUa9tpmxCNDDPSOkKVb6bUn7KPnuA04tLgJVs6eTEgiTB zO1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709321868; x=1709926668; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E+XDD+X98TQ5bJaUIivjQNWZ3/8yjB1dtyzn9J17zj0=; b=MpbF/KI+AywfsZHDcJ+GLwSI9oBOrX+cOX4F8MJy0cMsnKJK/AZVqStoClidfY0lGT ITF+7BHbTSRHfcWAS3hiiy7cXgL6tne0XKAD2AHs4r5Ui5137Znd894dcgO+lNkXfkzB iL2LSwQtacBBQScFnJ1eOmkJUb3O9qgh8ONZVKWSUb0cpBKZr0Xx2w7a/AhpB6Eriaj7 nWCHsXfos8oHor1UfM5GJg0e1y86Tu8iQEg9K8Y2Hz2c9TkdIqtGFfeHS0vgOG9CndaS OP8DcdcHIUaB+WThr8NBzBc2P6odXLSibwk/jmsPBoTaZkLxsscN1nhF7KFZ3lFhyQlr T+3w== X-Forwarded-Encrypted: i=1; AJvYcCUSfMXEnj7FvrcslV2kYV9uoWMiR8yWr6qkEWZEb7hImmX3Ed6S4uFcRDsDsLDMwoJLj5qKTi7T9MZtJozI7OsJi6oRYgnq X-Gm-Message-State: AOJu0Yzyyv7uo/sijHC86lLa4cbcpIKZb45vrjIYfsEBAf1TNdeRvrEO AFVbiH+97G8zCBNhoSmKK5jMuhZ14P/p+It+gdhDCkY3pmGjgZbE91JEQJV/fTms2MEjSXlgTtt odfoXnsNKqg== X-Google-Smtp-Source: AGHT+IFxE/drwjekMEekDuZWSXSaUKxWObSixaj/U0m0NMV2MECBIlQAHUSQLEcuVaxLEKMSO13El6Sv77dcsA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:188f:b0:dc6:b768:2994 with SMTP id cj15-20020a056902188f00b00dc6b7682994mr114391ybb.0.1709321868184; Fri, 01 Mar 2024 11:37:48 -0800 (PST) Date: Fri, 1 Mar 2024 19:37:38 +0000 In-Reply-To: <20240301193740.3436871-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301193740.3436871-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240301193740.3436871-3-edumazet@google.com> Subject: [PATCH net-next 2/4] net: gro: change skb_gro_network_header() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Richard Gobert , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Change skb_gro_network_header() to accept a const sk_buff and to no longer check if frag0 is NULL or not. This allows to remove skb_gro_frag0_invalidate() which is seen in profiles when header-split is enabled. sk_buff parameter is constified for skb_gro_header_fast(), inet_gro_compute_pseudo() and ip6_gro_compute_pseudo(). Signed-off-by: Eric Dumazet --- include/net/gro.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index ffc2c96d263b0399a81465d903a6181271b4a3f7..3c3666e46b3055caa619f2da0b6b8b20192a03b4 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -139,7 +139,7 @@ static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len) NAPI_GRO_CB(skb)->data_offset += len; } -static inline void *skb_gro_header_fast(struct sk_buff *skb, +static inline void *skb_gro_header_fast(const struct sk_buff *skb, unsigned int offset) { return NAPI_GRO_CB(skb)->frag0 + offset; @@ -151,24 +151,17 @@ static inline bool skb_gro_may_pull(const struct sk_buff *skb, return hlen <= NAPI_GRO_CB(skb)->frag0_len; } -static inline void skb_gro_frag0_invalidate(struct sk_buff *skb) -{ - NAPI_GRO_CB(skb)->frag0 = NULL; - NAPI_GRO_CB(skb)->frag0_len = 0; -} - static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, unsigned int offset) { if (!pskb_may_pull(skb, hlen)) return NULL; - skb_gro_frag0_invalidate(skb); return skb->data + offset; } -static inline void *skb_gro_header(struct sk_buff *skb, - unsigned int hlen, unsigned int offset) +static inline void *skb_gro_header(struct sk_buff *skb, unsigned int hlen, + unsigned int offset) { void *ptr; @@ -178,13 +171,16 @@ static inline void *skb_gro_header(struct sk_buff *skb, return ptr; } -static inline void *skb_gro_network_header(struct sk_buff *skb) +static inline void *skb_gro_network_header(const struct sk_buff *skb) { - return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + - skb_network_offset(skb); + if (skb_gro_may_pull(skb, skb_gro_offset(skb))) + return skb_gro_header_fast(skb, skb_network_offset(skb)); + + return skb_network_header(skb); } -static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto) +static inline __wsum inet_gro_compute_pseudo(const struct sk_buff *skb, + int proto) { const struct iphdr *iph = skb_gro_network_header(skb); @@ -422,7 +418,8 @@ static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb) return uh; } -static inline __wsum ip6_gro_compute_pseudo(struct sk_buff *skb, int proto) +static inline __wsum ip6_gro_compute_pseudo(const struct sk_buff *skb, + int proto) { const struct ipv6hdr *iph = skb_gro_network_header(skb); From patchwork Fri Mar 1 19:37:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13579019 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 BFC5E3BB36 for ; Fri, 1 Mar 2024 19:37:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321872; cv=none; b=oa71RMwZeZyqrfEuGzXFLspmgbSHnQNMbLvJ88VbtvZ732tPLDurafLQPu9ATr8W3g85uG4Mega4mysu7aieofO+xgteXOmkoMUtXUy1w3ux3lAYZq7pHYtVa4M7+6HdByqBGsfGGJB9Wcbwqh0tDqYYNIe8EmrWBGQMMh+D6dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321872; c=relaxed/simple; bh=lPUuLJtPF0HWe9ep8AFHHFXsEpn2kyHFaQLDlJsyWKA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hft10SqZLeOQY4zxT1+yxAc/OTV0yhk1luWeeCZ21p+uxkTCVqb4Xm6eNQgClGCufDgmV5HsC8SsHS3HNjNtR+7JZyxa/2XN7IAMHlk4eYncmDv55Yx4VT7/DdOpNP0bBZLP01B8SZ+Ckr43Rh2nUKi8Q4J7ufLg5FCBp0mRtxo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TUVqtQaB; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TUVqtQaB" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6093c69afafso36099497b3.2 for ; Fri, 01 Mar 2024 11:37:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709321870; x=1709926670; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3mvTIxPSmJwpwbQbgaaXOh6A0fIjvDUqijmBzbNCxO4=; b=TUVqtQaByTcZZdGVYH4b3rh9HrtCLoNM6CWOorkjlrd/M9mJBMlfVFF6ALLGqER4Va WpqjlxcU79AlrJEXWIq3fl/kvL9z/47T9J27O9chqsf8X/bQJ10rH7GS0MfkbjcNBKVc peWD30/+zHPBf5EdBIpSVRS4sxlTcvAdf3KTuesSVKeTLWdKleilmDEzXvoFV3XQZxyF UxgFMn885pVjRRvoXPnORvFaIhjcM2HKwX7x2aMuZN159FNJZsvB+6E6tEwHC0ZrpDMS c/RUHaLYQUy+N9RqCydNAaYBlZ5mUADyuqjvqLCdZ1AyaQifx5gKIjZHeIUvzooeXk0t oAqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709321870; x=1709926670; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3mvTIxPSmJwpwbQbgaaXOh6A0fIjvDUqijmBzbNCxO4=; b=pQfRw3B00QDy0r5iPseb0SPXZ7jxQjjYCtOhapgz79eFwojMPmNx5lxR1Od5/3Xl/i VAFwOw8TLfJkjflY3KEZ3yqIltMH2f35n+CQ8npPR1fv1ujVh1qpM2P8sDu2oApmNl69 5saeV3UHeeY05DS2RNblJebJ+3bMjo0nd6BH5tvbF7RtgfZR+fQpyqhS5IBOLqDafdu8 erZlUSsIBueprP4c01fNNX63FO3k8fofZ+VRBQk2ZjPW7dPGzpUWb73ivoYJpMw6cV2K M81khKwI+TpN4yt4qBJ28TF0fhKIQQqA/J+yeLl64GLkaCB14iO0czz5sWdSkdiEKZq9 uTFQ== X-Forwarded-Encrypted: i=1; AJvYcCWkv+oeAVfWXPGK3Jn2Bl4dXdTUha1q3loX8c9nykViMR0riuhe3gaVaeJW7uVPZTVxgdy5w5fN5g/GIPIE0GoenKFj07pN X-Gm-Message-State: AOJu0YzPrke/lo2/RLqzb4H9uK15Vmj+HCMDfb0bSgDUBHJzkt9cuiFw uMh0TeqL7BbdJXIhDf1Wh6AFpyRish7LZ3u7Pj4yxxtOCi2wUfFoiVpUsrzzS1aYtagi95pSu9Y zcWWaz0ONQw== X-Google-Smtp-Source: AGHT+IGazckLk3Pwl6V9VPt6Ezu5m7Q9dWV4f8lkbH+BldGM2dI0dNz2Usjfw9fVbq4xk21+ZEdgPflAfaHkmg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:57d8:0:b0:609:51a3:b409 with SMTP id l207-20020a8157d8000000b0060951a3b409mr476379ywb.0.1709321869792; Fri, 01 Mar 2024 11:37:49 -0800 (PST) Date: Fri, 1 Mar 2024 19:37:39 +0000 In-Reply-To: <20240301193740.3436871-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301193740.3436871-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240301193740.3436871-4-edumazet@google.com> Subject: [PATCH net-next 3/4] net: gro: enable fast path for more cases From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Richard Gobert , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Currently the so-called GRO fast path is only enabled for napi_frags_skb() callers. After the prior patch, we no longer have to clear frag0 whenever we pulled bytes to skb->head. We therefore can initialize frag0 to skb->data so that GRO fast path can be used in the following additional cases: - Drivers using header split (populating skb->data with headers, and having payload in one or more page fragments). - Drivers not using any page frag (entire packet is in skb->data) Add a likely() in skb_gro_may_pull() to help the compiler to generate better code if possible. Signed-off-by: Eric Dumazet --- include/net/gro.h | 2 +- net/core/gro.c | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/net/gro.h b/include/net/gro.h index 3c3666e46b3055caa619f2da0b6b8b20192a03b4..2b58671a65492bf3f9dabf1e7a2d985cee007e11 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -148,7 +148,7 @@ static inline void *skb_gro_header_fast(const struct sk_buff *skb, static inline bool skb_gro_may_pull(const struct sk_buff *skb, unsigned int hlen) { - return hlen <= NAPI_GRO_CB(skb)->frag0_len; + return likely(hlen <= NAPI_GRO_CB(skb)->frag0_len); } static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, diff --git a/net/core/gro.c b/net/core/gro.c index 927ccf68149093d6dfd66a622a7db5215a483876..6a0edbd826a17573b51c5f71e20ff0c09364fc21 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -369,15 +369,21 @@ static void gro_list_prepare(const struct list_head *head, static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) { - const struct skb_shared_info *pinfo = skb_shinfo(skb); - const skb_frag_t *frag0 = &pinfo->frags[0]; + const struct skb_shared_info *pinfo; + const skb_frag_t *frag0; + unsigned int headlen; NAPI_GRO_CB(skb)->data_offset = 0; - NAPI_GRO_CB(skb)->frag0 = NULL; - NAPI_GRO_CB(skb)->frag0_len = 0; + headlen = skb_headlen(skb); + NAPI_GRO_CB(skb)->frag0 = skb->data; + NAPI_GRO_CB(skb)->frag0_len = headlen; + if (headlen) + return; + + pinfo = skb_shinfo(skb); + frag0 = &pinfo->frags[0]; - if (!skb_headlen(skb) && pinfo->nr_frags && - !PageHighMem(skb_frag_page(frag0)) && + if (pinfo->nr_frags && !PageHighMem(skb_frag_page(frag0)) && (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0); NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int, @@ -710,7 +716,10 @@ static struct sk_buff *napi_frags_skb(struct napi_struct *napi) } } else { eth = (const struct ethhdr *)skb->data; - gro_pull_from_frag0(skb, hlen); + + if (NAPI_GRO_CB(skb)->frag0 != skb->data) + gro_pull_from_frag0(skb, hlen); + NAPI_GRO_CB(skb)->frag0 += hlen; NAPI_GRO_CB(skb)->frag0_len -= hlen; } From patchwork Fri Mar 1 19:37:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13579020 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 0989E3BBCD for ; Fri, 1 Mar 2024 19:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321873; cv=none; b=nBmy/kCp8UtM5Axv2dpwd7HY1ThIVjtC69bK95zbPZlMsG4YfnbRzyacDiI+Ufj30v2/NZpH9Dj1ykuY559mYRWLawEdzgc4k7jnoRLnHRk8+MJEPfpmhdRYCSoXq6a9S28vHEUCteoJgNljxC9EIMRGeW4a+yrbPnJeuS//YDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321873; c=relaxed/simple; bh=rAn+kOgjPT01Ybieuz+bGgltV40x2pm2cf51Jv6KDK8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QMwi64nBHjmmRMbUy0WhbBklrVqTftZ0CV0Im29yof6QRHsTq/m/b+aBbBoQqdgXLxPTlGkJ7ghPr4995s3GyCfrsROFA4wseTPdDYs9mTSFbULqBj7NIxQeEgri40QUJxR6VlQwP17SEAn5t1NRnNaI9+a9sXzcUzm5ZpvOIQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Sar4jvV0; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Sar4jvV0" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso3861075276.3 for ; Fri, 01 Mar 2024 11:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709321871; x=1709926671; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jNMTH5/4z0N5NVuRkLpaJrGHTXoTS/bT5IMcs+2HcWo=; b=Sar4jvV0PHJUsEKQSDjCIQVLY9maTKzgwZzZmhkvU9KnGQdQBSHH7pM6/ndL9BT1fZ yURPd6X4B5bOFatrA1r2vG8mTRZbVLLKU3igkBfvzihuBMIPUW2iEWEi7VUh9pWAGOoB E3pGWJcMSAZP4Lv8NF27okcqouGkO4WmVhVew8ZX+C22gyqxcC+Miuv9oc1dLLUfyFfQ 5zXrQRmZIeGPd+oDhIKu6rh7XrB7kEihcbPvraJ95EQsFD0jJTefWWPU97Ba67EL8JbU 2Erbl39Eyopv1sGXS5SsDI+1Jze96UMXo6luC2s3bW4iclG4nXscS1p4asO7dMgJkqp4 TE9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709321871; x=1709926671; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jNMTH5/4z0N5NVuRkLpaJrGHTXoTS/bT5IMcs+2HcWo=; b=smsul0V7h9ZafImHJCHihPHHYQJ0ZiywtckxsO38I6BhZKYNOKUKOqqbUjzt7f+BJU 2Q5ZiIuQR5K7A4H/vaKr6btXxolsXgljbIwrb7EGexD/v4CgnPzp5PqiIRhiZTbNZiG/ DQLhx4g95kc1jsnKhOv4SDwBT7aayScLpGphlbgpAMijklpihY9Lb7w0b55GIY4BkR6n 8LvhFq3UHYgwn9WyPUzpsEngxp5/F0rOWec3eIARNSPp2PXe7P2JZhlH3cRBrEf9g8mR TMvijrxzN/vrMUiOT/poDte2D2LALq8GLmiOHrHJahg8j0sx2juh7CecSVvf3iN7YO8Y K5yw== X-Forwarded-Encrypted: i=1; AJvYcCVJEa5Hb2JKtePHI25Bd/o5OxkXzK8s/I7Zv6KVTaM+7DWnrniKulGIFt+dy8bI/fUnAb+a/aOnqX3Ta0/CA23n6jlinsNo X-Gm-Message-State: AOJu0YxIoUgFzcXRiV40BZ64zJr3rQMe+rATpoah2pNhesaOiL3Vd/+R cLCRiLL1H9YkpSCrUS1eY//u8OqXB4AOv+KPfQQEvVL4jGFcBwcAQzDBZChUeWygirk6NxXf1Wh p/vQBWOW68g== X-Google-Smtp-Source: AGHT+IHyY0rOFwHjQMcT1kP1pRrkx5HISyqQdlcwMeSw7OMs17GhYN4gLMPSBTgR4eZ4zrvvau8FBdvVSWRQ/Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:b20b:0:b0:dcb:bc80:8333 with SMTP id i11-20020a25b20b000000b00dcbbc808333mr556607ybj.13.1709321871149; Fri, 01 Mar 2024 11:37:51 -0800 (PST) Date: Fri, 1 Mar 2024 19:37:40 +0000 In-Reply-To: <20240301193740.3436871-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301193740.3436871-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240301193740.3436871-5-edumazet@google.com> Subject: [PATCH net-next 4/4] tcp: gro: micro optimizations in tcp[4]_gro_complete() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Richard Gobert , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org In tcp_gro_complete() : Moving the skb->inner_transport_header setting allows the compiler to reuse the previously loaded value of skb->transport_header. Caching skb_shinfo() avoids duplications as well. In tcp4_gro_complete(), doing a single change on skb_shinfo(skb)->gso_type also generates better code. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_offload.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 875456efc92ddd546e13232dd775aaaf1093ce4f..b955ab3b236d965a38054efa004fe12f03074c70 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -299,18 +299,20 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) void tcp_gro_complete(struct sk_buff *skb) { struct tcphdr *th = tcp_hdr(skb); + struct skb_shared_info *shinfo; + + if (skb->encapsulation) + skb->inner_transport_header = skb->transport_header; skb->csum_start = (unsigned char *)th - skb->head; skb->csum_offset = offsetof(struct tcphdr, check); skb->ip_summed = CHECKSUM_PARTIAL; - skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; + shinfo = skb_shinfo(skb); + shinfo->gso_segs = NAPI_GRO_CB(skb)->count; if (th->cwr) - skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; - - if (skb->encapsulation) - skb->inner_transport_header = skb->transport_header; + shinfo->gso_type |= SKB_GSO_TCP_ECN; } EXPORT_SYMBOL(tcp_gro_complete); @@ -335,10 +337,9 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff) th->check = ~tcp_v4_check(skb->len - thoff, iph->saddr, iph->daddr, 0); - skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4; - if (NAPI_GRO_CB(skb)->is_atomic) - skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_FIXEDID; + skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4 | + (NAPI_GRO_CB(skb)->is_atomic * SKB_GSO_TCP_FIXEDID); tcp_gro_complete(skb); return 0;