Skip to content

Commit c696531

Browse files
Menglong Donggregkh
authored andcommitted
net: tipc: fix FB_MTU eat two pages
[ Upstream commit 0c6de0c ] 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: 4c94cc2 ("tipc: fall back to smaller MTU if allocation of local send skb fails") Signed-off-by: Menglong Dong <dong.menglong@zte.com.cn> Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1148952 commit c696531

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎net/tipc/bcast.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ int tipc_bcast_init(struct net *net)
699699
spin_lock_init(&tipc_net(net)->bclock);
700700

701701
if (!tipc_link_bc_create(net, 0, 0, NULL,
702-
FB_MTU,
702+
one_page_mtu,
703703
BCLINK_WIN_DEFAULT,
704704
BCLINK_WIN_DEFAULT,
705705
0,

‎net/tipc/msg.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
#define MAX_FORWARD_SIZE 1024
4545
#ifdef CONFIG_TIPC_CRYPTO
4646
#define BUF_HEADROOM ALIGN(((LL_MAX_HEADER + 48) + EHDR_MAX_SIZE), 16)
47-
#define BUF_TAILROOM (TIPC_AES_GCM_TAG_SIZE)
47+
#define BUF_OVERHEAD (BUF_HEADROOM + TIPC_AES_GCM_TAG_SIZE)
4848
#else
4949
#define BUF_HEADROOM (LL_MAX_HEADER + 48)
50-
#define BUF_TAILROOM 16
50+
#define BUF_OVERHEAD BUF_HEADROOM
5151
#endif
5252

53+
const int one_page_mtu = PAGE_SIZE - SKB_DATA_ALIGN(BUF_OVERHEAD) -
54+
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
55+
5356
static unsigned int align(unsigned int i)
5457
{
5558
return (i + 3) & ~3u;
@@ -67,13 +70,8 @@ static unsigned int align(unsigned int i)
6770
struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp)
6871
{
6972
struct sk_buff *skb;
70-
#ifdef CONFIG_TIPC_CRYPTO
71-
unsigned int buf_size = (BUF_HEADROOM + size + BUF_TAILROOM + 3) & ~3u;
72-
#else
73-
unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u;
74-
#endif
7573

76-
skb = alloc_skb_fclone(buf_size, gfp);
74+
skb = alloc_skb_fclone(BUF_OVERHEAD + size, gfp);
7775
if (skb) {
7876
skb_reserve(skb, BUF_HEADROOM);
7977
skb_put(skb, size);
@@ -395,7 +393,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset,
395393
if (unlikely(!skb)) {
396394
if (pktmax != MAX_MSG_SIZE)
397395
return -ENOMEM;
398-
rc = tipc_msg_build(mhdr, m, offset, dsz, FB_MTU, list);
396+
rc = tipc_msg_build(mhdr, m, offset, dsz,
397+
one_page_mtu, list);
399398
if (rc != dsz)
400399
return rc;
401400
if (tipc_msg_assemble(list))

‎net/tipc/msg.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ struct plist;
9999
#define MAX_H_SIZE 60 /* Largest possible TIPC header size */
100100

101101
#define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
102-
#define FB_MTU 3744
103102
#define TIPC_MEDIA_INFO_OFFSET 5
104103

104+
extern const int one_page_mtu;
105+
105106
struct tipc_skb_cb {
106107
union {
107108
struct {

0 commit comments

Comments
 (0)