提交 b8198bb3 编写于 作者: M Menglong Dong 提交者: Zheng Zengkai

net: tipc: fix FB_MTU eat two pages

stable inclusion
from stable-5.10.50
commit c6965316d6845bf8a02822c5529d8be3858045ff
bugzilla: 174522 https://gitee.com/openeuler/kernel/issues/I4DNFY

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c6965316d6845bf8a02822c5529d8be3858045ff

--------------------------------

[ Upstream commit 0c6de0c9 ]

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: 4c94cc2d ("tipc: fall back to smaller MTU if allocation of local send skb fails")
Signed-off-by: NMenglong Dong <dong.menglong@zte.com.cn>
Acked-by: NJon Maloy <jmaloy@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 a4b5e8a6
...@@ -699,7 +699,7 @@ int tipc_bcast_init(struct net *net) ...@@ -699,7 +699,7 @@ int tipc_bcast_init(struct net *net)
spin_lock_init(&tipc_net(net)->bclock); spin_lock_init(&tipc_net(net)->bclock);
if (!tipc_link_bc_create(net, 0, 0, NULL, if (!tipc_link_bc_create(net, 0, 0, NULL,
FB_MTU, one_page_mtu,
BCLINK_WIN_DEFAULT, BCLINK_WIN_DEFAULT,
BCLINK_WIN_DEFAULT, BCLINK_WIN_DEFAULT,
0, 0,
......
...@@ -44,12 +44,15 @@ ...@@ -44,12 +44,15 @@
#define MAX_FORWARD_SIZE 1024 #define MAX_FORWARD_SIZE 1024
#ifdef CONFIG_TIPC_CRYPTO #ifdef CONFIG_TIPC_CRYPTO
#define BUF_HEADROOM ALIGN(((LL_MAX_HEADER + 48) + EHDR_MAX_SIZE), 16) #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 #else
#define BUF_HEADROOM (LL_MAX_HEADER + 48) #define BUF_HEADROOM (LL_MAX_HEADER + 48)
#define BUF_TAILROOM 16 #define BUF_OVERHEAD BUF_HEADROOM
#endif #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) static unsigned int align(unsigned int i)
{ {
return (i + 3) & ~3u; return (i + 3) & ~3u;
...@@ -67,13 +70,8 @@ static unsigned int align(unsigned int i) ...@@ -67,13 +70,8 @@ static unsigned int align(unsigned int i)
struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp) struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp)
{ {
struct sk_buff *skb; 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) { if (skb) {
skb_reserve(skb, BUF_HEADROOM); skb_reserve(skb, BUF_HEADROOM);
skb_put(skb, size); skb_put(skb, size);
...@@ -395,7 +393,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, ...@@ -395,7 +393,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset,
if (unlikely(!skb)) { if (unlikely(!skb)) {
if (pktmax != MAX_MSG_SIZE) if (pktmax != MAX_MSG_SIZE)
return -ENOMEM; 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) if (rc != dsz)
return rc; return rc;
if (tipc_msg_assemble(list)) if (tipc_msg_assemble(list))
......
...@@ -99,9 +99,10 @@ struct plist; ...@@ -99,9 +99,10 @@ struct plist;
#define MAX_H_SIZE 60 /* Largest possible TIPC header size */ #define MAX_H_SIZE 60 /* Largest possible TIPC header size */
#define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE) #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
#define FB_MTU 3744
#define TIPC_MEDIA_INFO_OFFSET 5 #define TIPC_MEDIA_INFO_OFFSET 5
extern const int one_page_mtu;
struct tipc_skb_cb { struct tipc_skb_cb {
union { union {
struct { struct {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册