From patchwork Tue Jun 5 12:04:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 925425 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MUhBJ35n"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 410Vq50Pw9z9s08 for ; Tue, 5 Jun 2018 22:04:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751722AbeFEMEp (ORCPT ); Tue, 5 Jun 2018 08:04:45 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33691 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbeFEMEo (ORCPT ); Tue, 5 Jun 2018 08:04:44 -0400 Received: by mail-pf0-f193.google.com with SMTP id b17-v6so1205184pfi.0; Tue, 05 Jun 2018 05:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ANNLc4dvmQ6UVH5TtnLcgT5R7xXm7m8BcIXoRXWwf3o=; b=MUhBJ35nz/b2zyg1nQzsiBlC1P9/PTEl9OPu7JkyTdJ4ObLv0YW9/e1b/xHGEtwezV kaYM9N7I0wVtG3y9C84NXb3psrq/2Q4WmIKm42NUUzzp51NOhyUQ0NT/uazckuiRfIfr xkqonetvUy9DaoToyWW4VO99rsuO/sJozY6e15lJhWXkMP0dERAyQrtg5jP2cXvfCKIe ySiyb03vL3B00C/eUjiXLlH/+V+JPf8EMIFd0wkkrdw712s1hVWTNalAHwCzixWpteQn IfCXxA8+8m1pQbcmSNzIm2MpaRgODa6aV4/vY57Ly5ewbpLuvhAcrgRJAKUfIysVZ35a GJow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ANNLc4dvmQ6UVH5TtnLcgT5R7xXm7m8BcIXoRXWwf3o=; b=kbLn4jVE5CzKpF0zLhOVHoDgUV9UKqScPbeZ3KxzSiQvuRlm+QASM3IDO/auWOM7dk +969ZdfAIGy1gcRvey0BtCcWF1/Qt327LlQRP/gZMJqD+1oqUVxIlfgiW/jAhizRP042 wdTIhdTaP1B63S2EAKvz/Y9txij3CJUB5AmatCrKfV0sFtEi+DSTxLruUy42WSC+PE6C IWEuPoomfdAEIrtvOmiDmfAV4l1CbQJmE92JxcVTEuXEtZHR6lZXgL8RSAtoj1rM8m2/ JAK4r0AulEtu01aIS8G6yzuZNZC7bEk4pfBMOuY2TEkSZoZBSEx+BczNSfzI66w8xet8 WHRw== X-Gm-Message-State: APt69E1+Qplr1xhVzLTyMOGAitL0vAV5ToANH25P8jO/bsnpr/4raEn1 0St5vWqUvdSgqzZR5jJEf4I= X-Google-Smtp-Source: ADUXVKLm84j+dPignHxZbsbsDMJYorRd8XAOE+QXtdeBgaOPKiOdSbAxPQWhfmK4fWK6pjzayMqSiA== X-Received: by 2002:a65:5306:: with SMTP id m6-v6mr8197603pgq.250.1528200283586; Tue, 05 Jun 2018 05:04:43 -0700 (PDT) Received: from localhost.didichuxing.com ([52.229.160.192]) by smtp.gmail.com with ESMTPSA id 4-v6sm15767190pfi.78.2018.06.05.05.04.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 05:04:42 -0700 (PDT) From: Yafang Shao To: edumazet@google.com, davem@davemloft.net Cc: netdev@vger.kernel.org, inux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next 1/2] ipv4: replace ip_hdr() with skb->data for optimization Date: Tue, 5 Jun 2018 08:04:21 -0400 Message-Id: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In ip receive path, when ip header hasn't been pulled yet, ip_hdr() and skb->data are pointing to the same byte. In ip output path, when ip header is just pushed, ip_hdr() and skb->data are pointing to the same byte. As ip_hdr() is more expensive than using skb->data, so replace ip_hdr() with skb->data in these situations for optimization. Signed-off-by: Yafang Shao --- net/ipv4/ip_input.c | 8 ++++---- net/ipv4/ip_output.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 7582713..7a03e8c 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -309,7 +309,7 @@ static inline bool ip_rcv_options(struct sk_buff *skb) static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { - const struct iphdr *iph = ip_hdr(skb); + const struct iphdr *iph = (const struct iphdr *)skb->data; int (*edemux)(struct sk_buff *skb); struct net_device *dev = skb->dev; struct rtable *rt; @@ -335,7 +335,7 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) if (unlikely(err)) goto drop_error; /* must reload iph, skb->head might have changed */ - iph = ip_hdr(skb); + iph = (const struct iphdr *)skb->data; } } @@ -433,7 +433,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, if (!pskb_may_pull(skb, sizeof(struct iphdr))) goto inhdr_error; - iph = ip_hdr(skb); + iph = (const struct iphdr *)skb->data; /* * RFC1122: 3.2.1.2 MUST silently discard any IP frame that fails the checksum. @@ -459,7 +459,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, if (!pskb_may_pull(skb, iph->ihl*4)) goto inhdr_error; - iph = ip_hdr(skb); + iph = (const struct iphdr *)skb->data; if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) goto csum_error; diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index af5a830..f5014cd 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -96,7 +96,7 @@ void ip_send_check(struct iphdr *iph) int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) { - struct iphdr *iph = ip_hdr(skb); + struct iphdr *iph = (struct iphdr *)skb->data; iph->tot_len = htons(skb->len); ip_send_check(iph); @@ -151,7 +151,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk, /* Build the IP header. */ skb_push(skb, sizeof(struct iphdr) + (opt ? opt->opt.optlen : 0)); skb_reset_network_header(skb); - iph = ip_hdr(skb); + iph = (struct iphdr *)skb->data; iph->version = 4; iph->ihl = 5; iph->tos = inet->tos; @@ -477,7 +477,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl) /* OK, we know where to send it, allocate and build IP header. */ skb_push(skb, sizeof(struct iphdr) + (inet_opt ? inet_opt->opt.optlen : 0)); skb_reset_network_header(skb); - iph = ip_hdr(skb); + iph = (struct iphdr *)skb->data; *((__be16 *)iph) = htons((4 << 12) | (5 << 8) | (inet->tos & 0xff)); if (ip_dont_fragment(sk, &rt->dst) && !skb->ignore_df) iph->frag_off = htons(IP_DF); @@ -659,7 +659,7 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, __skb_push(frag, hlen); skb_reset_network_header(frag); memcpy(skb_network_header(frag), iph, hlen); - iph = ip_hdr(frag); + iph = (struct iphdr *)skb->data; iph->tot_len = htons(frag->len); ip_copy_metadata(frag, skb); if (offset == 0) From patchwork Tue Jun 5 12:04:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 925426 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I4QpSzbH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 410Vq862xSz9s15 for ; Tue, 5 Jun 2018 22:04:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751783AbeFEMEu (ORCPT ); Tue, 5 Jun 2018 08:04:50 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:37676 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751598AbeFEMEq (ORCPT ); Tue, 5 Jun 2018 08:04:46 -0400 Received: by mail-pl0-f66.google.com with SMTP id 31-v6so1377703plc.4; Tue, 05 Jun 2018 05:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wnPzHMKULvd/BD79ZWaQLZHnzOz8v+kVRrpElbFqbU8=; b=I4QpSzbHWluoCU4nOkSwvyHw6HTl4vI6ST3GGjftLY0SL1NeaCep2cpvb/uhYMopA3 4skM3FH4smaIjQ1YZZvt3x3HeuV/FX5zGc7tlnQTOfgBk5Eya8pkKBSwrdvNGiGCdC61 M756zzyK8P722IQa5pwJrrTVaW++VBixrc9qY3anqhX/Hmw6pmGytqssHzJeqvWhZIuG DT6xz76TXq9gJW5Eam+XI0ZAqqYKj0SfltTcQ8oi1bCNndJgiGQgTsY9E1F70IJvWl8J pAo4GE2kGm1VGvxjv1P+8YEzCMjo5hpYidZBE+MJAlY2oS3rMdDYy7GHmUvmr1/Ok+WY XgQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wnPzHMKULvd/BD79ZWaQLZHnzOz8v+kVRrpElbFqbU8=; b=BT/iBx+P9hOxYcE+4xdmtO8d2kNZ9kNDMKY20wM96y/aAmTbHa5L9P+ksoXlfFBgIb bWSmxE7CcuEC9zl1vCSlQYAZN/O+kAJ3ea9xzfVT9vbBA6xlVke2lXaflsTh7Y7/tuRX 3XP1do0BRUJX5KTRkLDtWiksE+v85XAPrGDV33gPTH/dnhixVguOId9IJONVXLnKsmCE pZQBsRIorOGdAnXSEknMHODqvn6URixi8K3nwGMyk3ETJ6H4fvA8vzbJB+DbiqABse+J 9C18nqkxQGwfFDHiKRk/0zthqdLDB1Cib5IfTyobkj17NBJzMZjfeYif2A5xLUc2b82Q wekA== X-Gm-Message-State: ALKqPweGzkl2Si3aH8DmjwVPOrKc4Blx7mNFUXdLjuN4Uwab9of/WB0P crUu50JD64VyKo2q2xr1nqU= X-Google-Smtp-Source: ADUXVKIIHkqd2kLa653Q+s6v2CEjLq+ow2dqL7aMaaLnBblGNj9uY+EQQ6Qf0kynviykfkwMUbwMLQ== X-Received: by 2002:a17:902:5a1:: with SMTP id f30-v6mr25642402plf.167.1528200285972; Tue, 05 Jun 2018 05:04:45 -0700 (PDT) Received: from localhost.didichuxing.com ([52.229.160.192]) by smtp.gmail.com with ESMTPSA id 4-v6sm15767190pfi.78.2018.06.05.05.04.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 05:04:45 -0700 (PDT) From: Yafang Shao To: edumazet@google.com, davem@davemloft.net Cc: netdev@vger.kernel.org, inux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next 2/2] ipv6: replace ip_hdr() with skb->data for optimization Date: Tue, 5 Jun 2018 08:04:22 -0400 Message-Id: <1528200262-11834-2-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com> References: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In ipv6 receive path, when ip header hasn't been pulled yet, ip_hdr() and skb->data are pointing to the same byte. In ipv6 output path, when ip header is just pushed, ip_hdr() and skb->data are pointing to the same byte. As ip_hdr() is more expensive than using skb->data, so replace ip_hdr() with skb->data in these situations for optimization. Signed-off-by: Yafang Shao --- net/ipv6/ip6_input.c | 4 ++-- net/ipv6/ip6_output.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index f08d344..2ff4fe8 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -113,7 +113,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt if (unlikely(!pskb_may_pull(skb, sizeof(*hdr)))) goto err; - hdr = ipv6_hdr(skb); + hdr = (const struct ipv6hdr *)skb->data; if (hdr->version != 6) goto err; @@ -189,7 +189,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); goto drop; } - hdr = ipv6_hdr(skb); + hdr = (const struct ipv6hdr *)skb->data; } if (hdr->nexthdr == NEXTHDR_HOP) { diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 021e5ae..8bb3bc1 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -235,7 +235,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); - hdr = ipv6_hdr(skb); + hdr = (struct ipv6hdr *)skb->data; /* * Fill in the IPv6 header @@ -1659,7 +1659,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); - hdr = ipv6_hdr(skb); + hdr = (struct ipv6hdr *)skb->data; ip6_flow_hdr(hdr, v6_cork->tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel,