From patchwork Thu Jan 14 05:12:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 567265 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8DDF8140216 for ; Thu, 14 Jan 2016 16:12:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mirantis.com header.i=@mirantis.com header.b=E2ompvis; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754726AbcANFMZ (ORCPT ); Thu, 14 Jan 2016 00:12:25 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33334 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754651AbcANFMX (ORCPT ); Thu, 14 Jan 2016 00:12:23 -0500 Received: by mail-pa0-f44.google.com with SMTP id cy9so370589788pac.0 for ; Wed, 13 Jan 2016 21:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google; h=subject:from:to:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding; bh=YPHiKhcPxAJnkapWuGyNKRft+72q3lQ0Z5iHfnJknK0=; b=E2ompvispARbQkiB/maTh2GJ1w9Xs82hKc38iuR05J8b5wOXVKQbaNIdXgMMk2TTwP oWlr7nHMuEqssqpLR2Dka3/8/6UvxPeB4/+AkjwgXsu1Cw3aEq98BfiNorYJD0fys50w AjXGrAXooQYryTaYeF+uZVG3vnVaMwn+tx/iA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=YPHiKhcPxAJnkapWuGyNKRft+72q3lQ0Z5iHfnJknK0=; b=cjE8tWeHGGvVC9U85YcPWDoCP0hU7S0I7r95wdpyEMU9Xg99CixxGg/6oUFIs5DO22 S16P8CVLu+42GKZ29qY4DFryFXOo0hmq3yLtk9D79n4ZqlwiX8Rg4mE4XLWol+/4hrI8 NNISSbQ96BRLnOw9tEvNFYZjZRju6ZWGrLnEmR+Yr8RAbkoebpslDSR0ryHAgvwMJrez SVcu0xPGd5WdCxRFMqwC0ktbYFALeNg4SRyYpZb6BNbj6KOMJzdlzbPMBDe2IwKXkjIn a3pz4nqKbBDqipjp6MEMwlV+5EUJFiXQCsN38RvTsfdv5JIH3L4nlOrjDDxI5KKx9oSs yhdw== X-Gm-Message-State: ALoCoQmx3moPz9It11tnDki5C5jTQt9IRWRX25qDtv1+OaUtaXMk90NrcwNLQh81iQVvzykQtIe2X8zbjCbeTZT3HzhDmWR0Ww== X-Received: by 10.66.101.36 with SMTP id fd4mr3235218pab.76.1452748342612; Wed, 13 Jan 2016 21:12:22 -0800 (PST) Received: from localhost.localdomain (static-50-53-29-36.bvtn.or.frontiernet.net. [50.53.29.36]) by smtp.gmail.com with ESMTPSA id 68sm6018558pfa.78.2016.01.13.21.12.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jan 2016 21:12:22 -0800 (PST) Subject: [RFC PATCH 4/4] net: Allow UDP and GRE to use inner checksum offloads with outer checksums needed From: Alexander Duyck To: ecree@solarflare.com, netdev@vger.kernel.org, tom@herbertland.com Date: Wed, 13 Jan 2016 21:12:21 -0800 Message-ID: <20160114051221.5119.91182.stgit@localhost.localdomain> In-Reply-To: <20160114045532.5119.56124.stgit@localhost.localdomain> References: <20160114045532.5119.56124.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch enables us to use inner checksum offloads if provided by hardware with outer checksums computed by software. Signed-off-by: Alexander Duyck --- net/ipv4/gre_offload.c | 2 -- net/ipv4/udp_offload.c | 44 +++++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c index 5a8ee3282550..61608fe975fc 100644 --- a/net/ipv4/gre_offload.c +++ b/net/ipv4/gre_offload.c @@ -53,8 +53,6 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, goto out; csum = !!(greh->flags & GRE_CSUM); - if (csum) - skb->encap_hdr_csum = 1; /* setup inner skb. */ skb->protocol = greh->protocol; diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 45824f9b81c4..0a7f1207f3d3 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -39,31 +39,30 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, netdev_features_t enc_features; int udp_offset, outer_hlen; unsigned int oldlen; - bool need_csum = !!(skb_shinfo(skb)->gso_type & - SKB_GSO_UDP_TUNNEL_CSUM); bool remcsum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_TUNNEL_REMCSUM); - bool offload_csum = false, dont_encap = (need_csum || remcsum); + bool need_csum, load_csum; oldlen = (u16)~skb->len; if (unlikely(!pskb_may_pull(skb, tnl_hlen))) goto out; + /* Try to offload checksum if possible */ + need_csum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM); + load_csum = need_csum && + !(skb->dev->features & + (is_ipv6 ? (NETIF_F_HW_CSUM | NETIF_F_IPV6_CSUM) : + (NETIF_F_HW_CSUM | NETIF_F_IP_CSUM))); + skb->encapsulation = 0; __skb_pull(skb, tnl_hlen); skb_reset_mac_header(skb); skb_set_network_header(skb, skb_inner_network_offset(skb)); skb->mac_len = skb_inner_network_offset(skb); skb->protocol = new_protocol; - skb->encap_hdr_csum = need_csum; + skb->encap_hdr_csum = remcsum & load_csum; skb->remcsum_offload = remcsum; - /* Try to offload checksum if possible */ - offload_csum = !!(need_csum && - ((skb->dev->features & NETIF_F_HW_CSUM) || - (skb->dev->features & (is_ipv6 ? - NETIF_F_IPV6_CSUM : NETIF_F_IP_CSUM)))); - /* segment inner packet. */ enc_features = skb->dev->hw_enc_features & features; segs = gso_inner_segment(skb, enc_features); @@ -81,16 +80,11 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, int len; __be32 delta; - if (dont_encap) { - skb->encapsulation = 0; + if (remcsum) skb->ip_summed = CHECKSUM_NONE; - } else { - /* Only set up inner headers if we might be offloading - * inner checksum. - */ - skb_reset_inner_headers(skb); - skb->encapsulation = 1; - } + + skb_reset_inner_headers(skb); + skb->encapsulation = skb->ip_summed == CHECKSUM_PARTIAL; skb->mac_len = mac_len; skb->protocol = protocol; @@ -111,16 +105,16 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, uh->check = ~csum_fold((__force __wsum) ((__force u32)uh->check + (__force u32)delta)); - if (offload_csum) { + + if (skb->encapsulation || load_csum) { + uh->check = gso_make_checksum(skb, ~uh->check); + if (uh->check == 0) + uh->check = CSUM_MANGLED_0; + } else { skb->ip_summed = CHECKSUM_PARTIAL; skb->csum_start = skb_transport_header(skb) - skb->head; skb->csum_offset = offsetof(struct udphdr, check); gso_reset_checksum(skb, ~uh->check); - } else { - uh->check = gso_make_checksum(skb, ~uh->check); - - if (uh->check == 0) - uh->check = CSUM_MANGLED_0; } } while ((skb = skb->next)); out: