From patchwork Mon Jun 28 06:37:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12347305 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.7 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,URIBL_BLOCKED,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 395A1C2B9F4 for ; Mon, 28 Jun 2021 06:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 212B261490 for ; Mon, 28 Jun 2021 06:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232221AbhF1Gjr (ORCPT ); Mon, 28 Jun 2021 02:39:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbhF1Gjq (ORCPT ); Mon, 28 Jun 2021 02:39:46 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C932C061766; Sun, 27 Jun 2021 23:37:21 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id y17so2334554pgf.12; Sun, 27 Jun 2021 23:37:21 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=0U+GFK5+ASUpYIZN5wZJe4LLDUPulqe3gqEw+XxORcw=; b=qdEHKKeMIvux/dXOKaw/Kab8cJR/us+atFI9PMZYl2qtXvZGFpR56rgSO7kGYZkRv2 dyEwk4PQmbAw2cMS22dDwrrkUvFFICwJRRZDRTgl7J4RwtJFDl+pSbb3wf8TV5yYzv7B GD/Y3nRwQUddrMw2e88dtcElRgdhtKZ+6QoX6hJCv8WkqixdSHuDy1zbECdysvfLxwTG a8ybEJWPTOxnHaKBe/+nFVBgRZD6MwN7+KtCIAwC7PyF+v0CqAyRYvmqXWNqJZFAbpyq o2F6U+nwmdghhAtzYP8+SWgx7cGHxOLUTWvSmsuTbOA7LO/sCYtzIE6F52aTFVCx6Qpd frOw== 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:mime-version:content-transfer-encoding; bh=0U+GFK5+ASUpYIZN5wZJe4LLDUPulqe3gqEw+XxORcw=; b=YXAuZg8MaP1irdSboKGqHd8m3CQUc/AwQZOsUUvCInhCFreifuGZ9AbwEBxnUy+4vN 4kcifxUnuSlQxOiJRJLwBMYj6kPhpLya9vsgrI6s16tJyJN2YcyC7ClTl6jPGtP6Ma7i +oSvtn5Dc/+TWy+5eL9x64pacNePNDsk6QMIkcUuiZGRgNBFo3RUdMfiPQG7BEgIGcrC LGvwGikkSbFSOO6kydkmqk9RwD3BrmnVGGQ4yOgvX1gWpkkTAcFAPWfbHc+IkPWQGhPA TLivB2AUrgcFEpAI++dm4CDn1smznexGf/oL2G++vejGzKBT6rEuL0cq7qOhb5+UyLfd /lvQ== X-Gm-Message-State: AOAM532q8VElZid9ZyzzOdUQwmjIX7Z9c5MDdlS7mcZ4Qcks7KiG1Bto N6kqKZhQxPAkjatVSXN76g4= X-Google-Smtp-Source: ABdhPJyAFWt7izIop7hEkOdd+kxKNhp7k7cialKjb5K0jfX0/yA8UAOci2Sxk2mU7Bg3XrWxNKyoEw== X-Received: by 2002:aa7:8749:0:b029:2f1:3dd0:674 with SMTP id g9-20020aa787490000b02902f13dd00674mr23400261pfo.65.1624862240599; Sun, 27 Jun 2021 23:37:20 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id y21sm2980379pfb.120.2021.06.27.23.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 23:37:20 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: jmaloy@redhat.com Cc: ying.xue@windriver.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, lxin@redhat.com, hoang.h.le@dektech.com.au, Menglong Dong Subject: [PATCH v6 net-next 1/2] net: tipc: fix FB_MTU eat two pages Date: Sun, 27 Jun 2021 23:37:44 -0700 Message-Id: <20210628063745.3935-2-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210628063745.3935-1-dong.menglong@zte.com.cn> References: <20210628063745.3935-1-dong.menglong@zte.com.cn> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong FB_MTU is used in 'tipc_msg_build()' to alloc smaller skb when memory allocation fails, which can avoid unnecessary sending failures. The value of FB_MTU now is 3744, and the data size will be: (3744 + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \ SKB_DATA_ALIGN(BUF_HEADROOM + BUF_TAILROOM + 3)) which is larger than one page(4096), and two pages will be allocated. To avoid it, replace '3744' with a calculation: (PAGE_SIZE - SKB_DATA_ALIGN(BUF_OVERHEAD) - \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) What's more, alloc_skb_fclone() will call SKB_DATA_ALIGN for data size, and it's not necessary to make alignment for buf_size in tipc_buf_acquire(). So, just remove it. Fixes: 4c94cc2d3d57 ("tipc: fall back to smaller MTU if allocation of local send skb fails") Signed-off-by: Menglong Dong Acked-by: Jon Maloy --- V6: - remove blank line after Fixes in commit log V5: - remove ONE_PAGE_SKB_SZ and replace it with one_page_mtu V4: - fallback to V2 V3: - split tipc_msg_build to tipc_msg_build and tipc_msg_frag - introduce tipc_buf_acquire_flex, which is able to alloc skb for local message - add the variate 'local' in tipc_msg_build to check if this is a local message. V2: - define FB_MTU in msg.c instead of introduce a new file - remove align for buf_size in tipc_buf_acquire() --- net/tipc/bcast.c | 2 +- net/tipc/msg.c | 17 ++++++++--------- net/tipc/msg.h | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index d4beca895992..593846d25214 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c @@ -699,7 +699,7 @@ int tipc_bcast_init(struct net *net) spin_lock_init(&tipc_net(net)->bclock); if (!tipc_link_bc_create(net, 0, 0, NULL, - FB_MTU, + one_page_mtu, BCLINK_WIN_DEFAULT, BCLINK_WIN_DEFAULT, 0, diff --git a/net/tipc/msg.c b/net/tipc/msg.c index ce6ab54822d8..7053c22e393e 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c @@ -44,12 +44,15 @@ #define MAX_FORWARD_SIZE 1024 #ifdef CONFIG_TIPC_CRYPTO #define BUF_HEADROOM ALIGN(((LL_MAX_HEADER + 48) + EHDR_MAX_SIZE), 16) -#define BUF_TAILROOM (TIPC_AES_GCM_TAG_SIZE) +#define BUF_OVERHEAD (BUF_HEADROOM + TIPC_AES_GCM_TAG_SIZE) #else #define BUF_HEADROOM (LL_MAX_HEADER + 48) -#define BUF_TAILROOM 16 +#define BUF_OVERHEAD BUF_HEADROOM #endif +const int one_page_mtu = PAGE_SIZE - SKB_DATA_ALIGN(BUF_OVERHEAD) - + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + static unsigned int align(unsigned int i) { return (i + 3) & ~3u; @@ -69,13 +72,8 @@ static unsigned int align(unsigned int i) struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp) { struct sk_buff *skb; -#ifdef CONFIG_TIPC_CRYPTO - unsigned int buf_size = (BUF_HEADROOM + size + BUF_TAILROOM + 3) & ~3u; -#else - unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u; -#endif - skb = alloc_skb_fclone(buf_size, gfp); + skb = alloc_skb_fclone(BUF_OVERHEAD + size, gfp); if (skb) { skb_reserve(skb, BUF_HEADROOM); skb_put(skb, size); @@ -395,7 +393,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, if (unlikely(!skb)) { if (pktmax != MAX_MSG_SIZE) return -ENOMEM; - rc = tipc_msg_build(mhdr, m, offset, dsz, FB_MTU, list); + rc = tipc_msg_build(mhdr, m, offset, dsz, + one_page_mtu, list); if (rc != dsz) return rc; if (tipc_msg_assemble(list)) diff --git a/net/tipc/msg.h b/net/tipc/msg.h index 5d64596ba987..64ae4c4c44f8 100644 --- a/net/tipc/msg.h +++ b/net/tipc/msg.h @@ -99,9 +99,10 @@ struct plist; #define MAX_H_SIZE 60 /* Largest possible TIPC header size */ #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE) -#define FB_MTU 3744 #define TIPC_MEDIA_INFO_OFFSET 5 +extern const int one_page_mtu; + struct tipc_skb_cb { union { struct { From patchwork Mon Jun 28 06:37:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12347307 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.7 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,URIBL_BLOCKED,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 67372C2B9F4 for ; Mon, 28 Jun 2021 06:37:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BDA761490 for ; Mon, 28 Jun 2021 06:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232272AbhF1Gjw (ORCPT ); Mon, 28 Jun 2021 02:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232230AbhF1Gjt (ORCPT ); Mon, 28 Jun 2021 02:39:49 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB97C061766; Sun, 27 Jun 2021 23:37:24 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id g192so13286107pfb.6; Sun, 27 Jun 2021 23:37:24 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=/1Rwnm8wm01ORDHn/DlKmW7MPMS9lQBNMJF6mJ4+ZYk=; b=KVqO1gHWaal3aKJHWEstTDg4vQt6826B6Hwx6rjufZiY85YOUfD3rEi5/SavY+VPEt +uT1JSO6XYN2qPcoyln9ed+PN2j1RZwhxt8Rr09uFXVhDpTlB0RN4+jiZUz7pfVzJtdv 6jt1roYfxOv2/lTdLn6TwAP1KNP6vGBA2jZrofq2sXqcu1MUniGuR2eun1ob+s17/Isf Jjnwq6PzbuV6LxLcw7czRLMbUag5JGxqg3kcoQOHaH2s8sSO816sHyz50HWdsaYiqrbQ PeWRx2PEEsD21xJp5M5hd/FR+o5v1p9ctuOSqxewbMWM1l44fYi3Phw0DxrOTBZyznzc PGwg== 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:mime-version:content-transfer-encoding; bh=/1Rwnm8wm01ORDHn/DlKmW7MPMS9lQBNMJF6mJ4+ZYk=; b=ekhlyq+n9lWwZJV1MgaJpqcZ9WpuYEsXsWGnT8+HvOb6mVTrd2N+zcVzrGqpRwWJkt kD8N2Q5N59ozAml51SxDSg4LoKPGS56d0ANm+G4BbQFQuy0EeapFDnhbtuQBrYdtYX/a YTRlUTwF2C3As/YiS/bMPshTQ5Sy6Z4IQg/yGxSQPxnuIKBsaytC1ZeaizIuk1hIA2vo QHx1fNrfCPrwZ+JIDXW4rQUzweOA5iULY1q/+jr20Wed+H1MHB7qK3emo6Zb7h25W6h3 QivIexLGTmBKcYmBSVL3FD5wHysICfLOGWur8x0l/+NIa1kbOl2yAbifOY2DJjxiwG23 RKKg== X-Gm-Message-State: AOAM533Zz+205AvamGH7xOFGX3RSXYWheBgOPEsfdockedd8HIH7dLpW G99FijHSPqeWGJkGT31gSnQ= X-Google-Smtp-Source: ABdhPJyBq3fnHYoXqq8L2x6SuggRUM0f9dD8GWRf6urPQc5QvPkLoJzZndjECPAnJIjZ9+oY97vv/Q== X-Received: by 2002:aa7:8390:0:b029:305:983b:42ad with SMTP id u16-20020aa783900000b0290305983b42admr23734574pfm.0.1624862244408; Sun, 27 Jun 2021 23:37:24 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id y21sm2980379pfb.120.2021.06.27.23.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 23:37:24 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: jmaloy@redhat.com Cc: ying.xue@windriver.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, lxin@redhat.com, hoang.h.le@dektech.com.au, Menglong Dong Subject: [PATCH v6 net-next 2/2] net: tipc: replace align() with ALIGN in msg.c Date: Sun, 27 Jun 2021 23:37:45 -0700 Message-Id: <20210628063745.3935-3-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210628063745.3935-1-dong.menglong@zte.com.cn> References: <20210628063745.3935-1-dong.menglong@zte.com.cn> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong The function align() which is defined in msg.c is redundant, replace it with ALIGN() and introduce a BUF_ALIGN(). Signed-off-by: Menglong Dong Acked-by: Jon Maloy --- net/tipc/msg.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 7053c22e393e..5c9fd4791c4b 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c @@ -41,6 +41,7 @@ #include "name_table.h" #include "crypto.h" +#define BUF_ALIGN(x) ALIGN(x, 4) #define MAX_FORWARD_SIZE 1024 #ifdef CONFIG_TIPC_CRYPTO #define BUF_HEADROOM ALIGN(((LL_MAX_HEADER + 48) + EHDR_MAX_SIZE), 16) @@ -53,11 +54,6 @@ const int one_page_mtu = PAGE_SIZE - SKB_DATA_ALIGN(BUF_OVERHEAD) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); -static unsigned int align(unsigned int i) -{ - return (i + 3) & ~3u; -} - /** * tipc_buf_acquire - creates a TIPC message buffer * @size: message size (including TIPC header) @@ -489,7 +485,7 @@ static bool tipc_msg_bundle(struct sk_buff *bskb, struct tipc_msg *msg, msz = msg_size(msg); bsz = msg_size(bmsg); - offset = align(bsz); + offset = BUF_ALIGN(bsz); pad = offset - bsz; if (unlikely(skb_tailroom(bskb) < (pad + msz))) @@ -546,7 +542,7 @@ bool tipc_msg_try_bundle(struct sk_buff *tskb, struct sk_buff **skb, u32 mss, /* Make a new bundle of the two messages if possible */ tsz = msg_size(buf_msg(tskb)); - if (unlikely(mss < align(INT_H_SIZE + tsz) + msg_size(msg))) + if (unlikely(mss < BUF_ALIGN(INT_H_SIZE + tsz) + msg_size(msg))) return true; if (unlikely(pskb_expand_head(tskb, INT_H_SIZE, mss - tsz - INT_H_SIZE, GFP_ATOMIC))) @@ -605,7 +601,7 @@ bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos) if (unlikely(!tipc_msg_validate(iskb))) goto none; - *pos += align(imsz); + *pos += BUF_ALIGN(imsz); return true; none: kfree_skb(skb);