Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp360746imm; Sat, 1 Sep 2018 05:22:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbhEl/smto+pMgCi4vlwYv0kcRZ054X1tsSiupc2CTIaSFY/VdBw1c2vTVwsiCihBAZQrBy X-Received: by 2002:a17:902:3324:: with SMTP id a33-v6mr19665358plc.221.1535804569919; Sat, 01 Sep 2018 05:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535804569; cv=none; d=google.com; s=arc-20160816; b=oeM8szjXkrruOXVD3AbMO6ozslUk1Ox1eQOLB7L7QOg8oNFqLtM1vDZ/V1ycGtTBPc 0a0lrmjKQVDrsNLRMdMDXY62U5A4fLEt2V75OCKkuv7TowSRCsDzWcmWoVm7+35xZ9CG vyxLhQTp/FZberboe/jMsJvp/wlYcgMr83C1j9ZNcwSrfwDEZ9eblJNKr/h6NPKigz+l ktuoqan6NM65LmWHB6ziDZthhCg1whcFhRpbEthvES9JII4qQDKMn8rOBLz12Y98p8Vk q7mOwVSUQGkBGI4lkDrV+I6Q/zQz+I0Wf93t1LSA/a3CLkpDcibPPFFO5kToK/0jVtWV DYCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=FQHroXCDBgcHJgR7j2rRNMp0a4BQ/bD8Uhm3czI6kFg=; b=qbmRtdjVpSuABliOpEOi5g+wIlwWIjmO/pbE7yRYvbTP/x+OG/eyG6vG7ugetTPPTN MEQwNGEiQjDVtQF4FSdGgAyXRIdKSNzXiyGlhZjc/UTFsmlb06nIU2mB1kWWkNs2V1i6 PataAFFV46VmuXUoFQK8tYaufGi5ma+FyHGEgG1YzPDrv7dgsFGnpUcC6atYwbxCjzOF 4yBMMpTaqy695Sf9kgqvYQ7P12ndxuPOrgGL/NIwZZbUElVkF738INyYXMTiBhVudR/0 vS16e70DAul1np04oe+HElowOkr02w44lmkyoBMoHQp0lZfvhzgy1EX6yeLDJUJx3ymz vHFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VQ+BjKUJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10-v6si9490988pgk.672.2018.09.01.05.22.35; Sat, 01 Sep 2018 05:22:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VQ+BjKUJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727425AbeIAQdW (ORCPT + 99 others); Sat, 1 Sep 2018 12:33:22 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39788 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeIAQdV (ORCPT ); Sat, 1 Sep 2018 12:33:21 -0400 Received: by mail-pf1-f194.google.com with SMTP id j8-v6so6700200pff.6; Sat, 01 Sep 2018 05:21:30 -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=FQHroXCDBgcHJgR7j2rRNMp0a4BQ/bD8Uhm3czI6kFg=; b=VQ+BjKUJ+O6RJXjh4r576AeOjT41YMRDVcxZxOpGMCBIizaAnohGp7iXDZguAn/WpY Gseubthy8v7GRJBpOg2OWSHF0vNFnhH8CpyafX2yjZ/pgpZrHV+lS8paxxH9myUhEdRT CihqwvmZrim0aDtNfcJLZhy54clMaKr6EBlSMgJfaD2dGp52kf60kMeKJokgO+qZi+JM +uT1Vw0WBRHHQyPR/xthBGo7GskTnj+QVtgX546cDIStSFW3n0s7VKf4nQg7IHiN6kJ9 fpTzUClmGhky+nRleovPnEGV+samaBcM1RpOePAjHwO/VwSZGyvpEQAO3ijPXMm2COEz hwEw== 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=FQHroXCDBgcHJgR7j2rRNMp0a4BQ/bD8Uhm3czI6kFg=; b=JOmEu+FGnGNJfWTBWQHQj+SZKlFyjV3yLh3wRzYeZtunTtIVh6vJ3rjhvqndB1nfNi YS4raNpwi+RDSxuH0sTT85NmRAH7Fo0yAJ7srukiDP0kbGy8znMVpwTdtXCtKBE97CPJ t7KRycMUcVNCjjMqxW2JWSi84qSLeEKMD7ZQOd14rzbRFt8cXTMbc6lwfh6JWwLYbV9Z 7jDFcrZLJghKB6MS+KpgApxkXEjr0cp5N671J0e6igOYBNcgdbNvllq+N3kUtPMZIbrz 7k3tVjCYQgBu4HohXSeEBciC2mgYTxaGIeNJJ6/YuNAzEC4Fc4OL1ZsWvx0FKK/d5Tzq 8o3w== X-Gm-Message-State: APzg51AbZ0lTSAO+0dyWQXwCI6kMdkDQu923wgcPnRxhOFRtiRYfTE3r LiWVm0HZE6bWWC1qqRNElAE= X-Received: by 2002:a62:1192:: with SMTP id 18-v6mr20736895pfr.54.1535804489662; Sat, 01 Sep 2018 05:21:29 -0700 (PDT) Received: from bogon.didichuxing.com ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id z19-v6sm22454043pgi.33.2018.09.01.05.21.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 05:21:28 -0700 (PDT) From: Yafang Shao To: edumazet@google.com, davem@davemloft.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next v3] tcp: propagate gso_segs to the new skb built in tcp collapse Date: Sat, 1 Sep 2018 20:21:04 +0800 Message-Id: <1535804465-11795-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The gso_segs of the new built SKB in tcp collapse is inited to 0, that makes us hard to know the accurate segments number of this new SKB. We'd better propagate the gso_segs of the collapsed SKB to the new built one, so when this SKB is dropped (for example when doing tcp prune) the sk_drops will be added to the correct value. If the collapsed SKB is fully copied to the new built one, we just add its gso_segs to the new SKB. While if the collapsed SKB is partially copied to the new built SKB, we have to calculate how many segments are copied. And when do the calculation we must make sure one SKB holds the same gso_segs. Furthemore, we have to reset the gso_segs of this SKB if is is partially copied, so in the next round when the left segments are copied it could propagate the correct value. The gso_size will never exceed 65536 as the max size of the new built SKB is 4K. Signed-off-by: Yafang Shao --- net/ipv4/tcp_input.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 62508a2..6dc8e2f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4910,6 +4910,7 @@ void tcp_rbtree_insert(struct rb_root *root, struct sk_buff *skb) while (before(start, end)) { int copy = min_t(int, SKB_MAX_ORDER(0, 0), end - start); struct sk_buff *nskb; + int len = copy; nskb = alloc_skb(copy, GFP_ATOMIC); if (!nskb) @@ -4928,12 +4929,24 @@ void tcp_rbtree_insert(struct rb_root *root, struct sk_buff *skb) /* Copy data, releasing collapsed skbs. */ while (copy > 0) { - int offset = start - TCP_SKB_CB(skb)->seq; int size = TCP_SKB_CB(skb)->end_seq - start; + int offset = start - TCP_SKB_CB(skb)->seq; BUG_ON(offset < 0); if (size > 0) { - size = min(copy, size); + if (copy >= size) { + skb_shinfo(nskb)->gso_segs += + max_t(u16, 1, skb_shinfo(skb)->gso_segs); + } else { + skb_shinfo(nskb)->gso_size = + skb_shinfo(skb)->gso_size; + skb_shinfo(nskb)->gso_segs = + DIV_ROUND_UP(len, skb_shinfo(nskb)->gso_size); + skb_shinfo(skb)->gso_segs = + DIV_ROUND_UP(size - copy, skb_shinfo(skb)->gso_size); + size = copy; + } + if (skb_copy_bits(skb, offset, skb_put(nskb, size), size)) BUG(); TCP_SKB_CB(nskb)->end_seq += size; -- 1.8.3.1