From patchwork Tue Aug 18 11:57:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 262376 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=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 0E64AC433DF for ; Tue, 18 Aug 2020 11:58:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8C9D2076D for ; Tue, 18 Aug 2020 11:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbgHRL6e (ORCPT ); Tue, 18 Aug 2020 07:58:34 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9835 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726370AbgHRL6d (ORCPT ); Tue, 18 Aug 2020 07:58:33 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 20A847032FD65771EB2D; Tue, 18 Aug 2020 19:58:28 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Tue, 18 Aug 2020 19:58:18 +0800 From: Miaohe Lin To: , , , , , , , , , , CC: , , Subject: [PATCH] net: Relax the npages test against MAX_SKB_FRAGS Date: Tue, 18 Aug 2020 07:57:12 -0400 Message-ID: <20200818115712.36497-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The npages test against MAX_SKB_FRAGS can be relaxed if we succeed to allocate high order pages as the note in comment said. Signed-off-by: Miaohe Lin --- net/core/skbuff.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 2f7dd689bccc..ca432bbfd90b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5758,13 +5758,6 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, struct page *page; int i; - *errcode = -EMSGSIZE; - /* Note this test could be relaxed, if we succeed to allocate - * high order pages... - */ - if (npages > MAX_SKB_FRAGS) - return NULL; - *errcode = -ENOBUFS; skb = alloc_skb(header_len, gfp_mask); if (!skb) @@ -5775,6 +5768,10 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, for (i = 0; npages > 0; i++) { int order = max_page_order; + if (unlikely(i >= MAX_SKB_FRAGS)) { + *errcode = -EMSGSIZE; + goto failure; + } while (order) { if (npages >= 1 << order) { page = alloc_pages((gfp_mask & ~__GFP_DIRECT_RECLAIM) |