From patchwork Tue May 28 18:22:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Tranchetti X-Patchwork-Id: 1106470 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=none (p=none dis=none) header.from=codeaurora.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45D2Kt6tCpz9s1c for ; Wed, 29 May 2019 04:24:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728004AbfE1SYB (ORCPT ); Tue, 28 May 2019 14:24:01 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:6354 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbfE1SYB (ORCPT ); Tue, 28 May 2019 14:24:01 -0400 Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 May 2019 11:24:00 -0700 X-IronPort-AV: E=McAfee;i="5900,7806,9271"; a="340031320" Received: from stranche-lnx.qualcomm.com ([129.46.14.77]) by ironmsg01-sd.qualcomm.com with ESMTP; 28 May 2019 11:24:00 -0700 Received: by stranche-lnx.qualcomm.com (Postfix, from userid 383980) id 29EE84378; Tue, 28 May 2019 12:24:00 -0600 (MDT) From: Sean Tranchetti To: davem@davemloft.net, netdev@vger.kernel.org Cc: Sean Tranchetti , Paolo Abeni , Subash Abhinov Kasiviswanathan Subject: [PATCH net-next v2] udp: Avoid post-GRO UDP checksum recalculation Date: Tue, 28 May 2019 12:22:54 -0600 Message-Id: <1559067774-613-1-git-send-email-stranche@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, when resegmenting an unexpected UDP GRO packet, the full UDP checksum will be calculated for every new SKB created by skb_segment() because the netdev features passed in by udp_rcv_segment() lack any information about checksum offload capabilities. Usually, we have no need to perform this calculation again, as 1) The GRO implementation guarantees that any packets making it to the udp_rcv_segment() function had correct checksums, and, more importantly, 2) Upon the successful return of udp_rcv_segment(), we immediately pull the UDP header off and either queue the segment to the socket or hand it off to a new protocol handler. Unless userspace has set the IP_CHECKSUM sockopt to indicate that they want the final checksum values, we can pass the needed netdev feature flags to __skb_gso_segment() to avoid checksumming each segment in skb_segment(). Fixes: cf329aa42b66 ("udp: cope with UDP GRO packet misdirection") Cc: Paolo Abeni Cc: Subash Abhinov Kasiviswanathan Signed-off-by: Sean Tranchetti Acked-by: Paolo Abeni --- include/net/udp.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/net/udp.h b/include/net/udp.h index d8ce937..dbe030d 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -471,12 +471,19 @@ struct udp_iter_state { static inline struct sk_buff *udp_rcv_segment(struct sock *sk, struct sk_buff *skb, bool ipv4) { + netdev_features_t features = NETIF_F_SG; struct sk_buff *segs; + /* Avoid csum recalculation by skb_segment unless userspace explicitly + * asks for the final checksum values + */ + if (!inet_get_convert_csum(sk)) + features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; + /* the GSO CB lays after the UDP one, no need to save and restore any * CB fragment */ - segs = __skb_gso_segment(skb, NETIF_F_SG, false); + segs = __skb_gso_segment(skb, features, false); if (unlikely(IS_ERR_OR_NULL(segs))) { int segs_nr = skb_shinfo(skb)->gso_segs;