From patchwork Fri Jan 15 08:21:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 12021813 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4093C433E0 for ; Fri, 15 Jan 2021 08:22:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9683622BEA for ; Fri, 15 Jan 2021 08:22:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732563AbhAOIWK (ORCPT ); Fri, 15 Jan 2021 03:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbhAOIWJ (ORCPT ); Fri, 15 Jan 2021 03:22:09 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894FBC061757; Fri, 15 Jan 2021 00:21:29 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id y12so4648992pji.1; Fri, 15 Jan 2021 00:21:29 -0800 (PST) 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 :in-reply-to:references; bh=OTtsm6dyKrVJ0jbDg2f7EoVgwZ5It1gTjh6wfzgk4d0=; b=ab09OwPQFc/dVOulO/JZZqI7Lt/7OaZS6W3Fs2pUlwzyCHyYr/g/CDyJtUPhKll2cT 6zhn6aePO31JSyh0VW5N3tP0b1wXmXa2TztetggvPaSngnLfrrLW+V2rk+V2kSkNlyG3 Xs0R+L2jDbuF37bP72DzeN5UMxf3iS66Re6wRhDe5DJ1Pq3RQbYGsUfYwbtL8Jb6eOed Wbx4ut5bI5dLvtCvgOdXPFXM40a/vja9cRUohEsEBHlkfugjVa9T9TV2SZ3EDptt2LDm VJ5uabWB4DvYgSiJDUbylz7UlLetNW3zxMIdybfd0nxTE3brMe3IYMQ5ZteY9NZ5EHbD gEew== 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:in-reply-to:references; bh=OTtsm6dyKrVJ0jbDg2f7EoVgwZ5It1gTjh6wfzgk4d0=; b=tiHND1JkWSz0xv4FX8MTFAeHLW2Rlh89MRIOwIAs+sxCLvCEnVHgRs+TpFa9zJ2wDa Jyxprnq7fmYWTQOqb2jaYuUFJLEVI7jgZk/dJmib3DhxLkC91Iz/WAQZLesX7V3eXlTK gNc9LPT9lLdUBvRUntDRe2JULERaWGcvjo7/qn5MbmM3QM9wYiHnxx43lW3nY6XzXLC1 AdrF2pgolwB5yar3Pdn8OCBAN5L2R+dVpZ+cuzFd6D3yPPNDtmdM0OZtrOCvC/qBS17X XmMazk/08LOD7AmKhPsYEFkUfO2Uzg6xCaXViAYoA/smD0zkZWAzo6bPPxg3jPE9vmLe /skg== X-Gm-Message-State: AOAM530RtFptNM8JJmpEBsfhy8O59HLbfnO93CJ41GXZNta89J4XmZjf Mv1xsKiD/c5+A0dI9Eyq4U0B170gRx2gYg== X-Google-Smtp-Source: ABdhPJyW/zECmfCcKhB8La+o3Arts78sxZ54HghKqDH16ovF8o5NZIeQ8YSqwn9eWS8+zNg1Lq6Mjg== X-Received: by 2002:a17:90b:1c0d:: with SMTP id oc13mr9678051pjb.156.1610698888874; Fri, 15 Jan 2021 00:21:28 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id ay21sm7462635pjb.1.2021.01.15.00.21.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jan 2021 00:21:28 -0800 (PST) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , davem@davemloft.net, Jakub Kicinski , Alexander Duyck Subject: [PATCHv2 net-next 1/2] net: move the hsize check to the else block in skb_segment Date: Fri, 15 Jan 2021 16:21:11 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org After commit 89319d3801d1 ("net: Add frag_list support to skb_segment"), it goes to process frag_list when !hsize in skb_segment(). However, when using skb frag_list, sg normally should not be set. In this case, hsize will be set with len right before !hsize check, then it won't go to frag_list processing code. So the right thing to do is move the hsize check to the else block, so that it won't affect the !hsize check for frag_list processing. v1->v2: - change to do "hsize <= 0" check instead of "!hsize", and also move "hsize < 0" into else block, to save some cycles, as Alex suggested. Signed-off-by: Xin Long --- net/core/skbuff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 6039069..e835193 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3894,12 +3894,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, } hsize = skb_headlen(head_skb) - offset; - if (hsize < 0) - hsize = 0; - if (hsize > len || !sg) - hsize = len; - if (!hsize && i >= nfrags && skb_headlen(list_skb) && + if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) && (skb_headlen(list_skb) == len || sg)) { BUG_ON(skb_headlen(list_skb) > len); @@ -3942,6 +3938,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, skb_release_head_state(nskb); __skb_push(nskb, doffset); } else { + if (hsize > len || !sg) + hsize = len; + else if (hsize < 0) + hsize = 0; + nskb = __alloc_skb(hsize + doffset + headroom, GFP_ATOMIC, skb_alloc_rx_flag(head_skb), NUMA_NO_NODE);