* [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup
@ 2021-06-09 10:32 menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 1/2] net: tipc: fix FB_MTU eat two pages menglong8.dong
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: menglong8.dong @ 2021-06-09 10:32 UTC (permalink / raw)
To: jmaloy
Cc: ying.xue, davem, kuba, netdev, tipc-discussion, linux-kernel,
Menglong Dong
From: Menglong Dong <dong.menglong@zte.com.cn>
In the first patch, FB_MTU is redefined to make sure data size will not
exceed PAGE_SIZE. Besides, I removed the alignment for buf_size in
tipc_buf_acquire, because skb_alloc_fclone will do the alignment job.
In the second patch, I removed align() in msg.c and replace it with
ALIGN().
Menglong Dong (2):
net: tipc: fix FB_MTU eat two pages
net: tipc: replace align() with ALIGN in msg.c
net/tipc/bcast.c | 2 +-
net/tipc/msg.c | 31 ++++++++++++++-----------------
net/tipc/msg.h | 3 ++-
3 files changed, 17 insertions(+), 19 deletions(-)
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 net-next 1/2] net: tipc: fix FB_MTU eat two pages
2021-06-09 10:32 [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup menglong8.dong
@ 2021-06-09 10:32 ` menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 2/2] net: tipc: replace align() with ALIGN in msg.c menglong8.dong
2021-06-09 10:47 ` [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup Jon Maloy
2 siblings, 0 replies; 5+ messages in thread
From: menglong8.dong @ 2021-06-09 10:32 UTC (permalink / raw)
To: jmaloy
Cc: ying.xue, davem, kuba, netdev, tipc-discussion, linux-kernel,
Menglong Dong, Zeal Robot
From: Menglong Dong <dong.menglong@zte.com.cn>
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:
FB_MTU = (PAGE_SIZE - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
- SKB_DATA_ALIGN(BUF_HEADROOM + BUF_TAILROOM))
What's more, alloc_skb_fclone() will call SKB_DATA_ALIGN for data size,
and it's not unnecessary 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")
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Menglong Dong <dong.menglong@zte.com.cn>
---
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 | 15 ++++++++-------
net/tipc/msg.h | 3 ++-
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index d4beca895992..9daace9542f4 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,
+ fb_mtu,
BCLINK_WIN_DEFAULT,
BCLINK_WIN_DEFAULT,
0,
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index ce6ab54822d8..a5c030ca7065 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -47,8 +47,14 @@
#define BUF_TAILROOM (TIPC_AES_GCM_TAG_SIZE)
#else
#define BUF_HEADROOM (LL_MAX_HEADER + 48)
-#define BUF_TAILROOM 16
+#define BUF_TAILROOM 0
#endif
+#define FB_MTU (PAGE_SIZE - \
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - \
+ SKB_DATA_ALIGN(BUF_HEADROOM + BUF_TAILROOM) \
+ )
+
+const int fb_mtu = FB_MTU;
static unsigned int align(unsigned int i)
{
@@ -69,13 +75,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_HEADROOM + size + BUF_TAILROOM, gfp);
if (skb) {
skb_reserve(skb, BUF_HEADROOM);
skb_put(skb, size);
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index 5d64596ba987..2c214691037c 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 fb_mtu;
+
struct tipc_skb_cb {
union {
struct {
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 net-next 2/2] net: tipc: replace align() with ALIGN in msg.c
2021-06-09 10:32 [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 1/2] net: tipc: fix FB_MTU eat two pages menglong8.dong
@ 2021-06-09 10:32 ` menglong8.dong
2021-06-09 10:47 ` [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup Jon Maloy
2 siblings, 0 replies; 5+ messages in thread
From: menglong8.dong @ 2021-06-09 10:32 UTC (permalink / raw)
To: jmaloy
Cc: ying.xue, davem, kuba, netdev, tipc-discussion, linux-kernel,
Menglong Dong
From: Menglong Dong <dong.menglong@zte.com.cn>
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 <dong.menglong@zte.com.cn>
---
net/tipc/msg.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index a5c030ca7065..19a7d8eb8abb 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -49,6 +49,7 @@
#define BUF_HEADROOM (LL_MAX_HEADER + 48)
#define BUF_TAILROOM 0
#endif
+#define BUF_ALIGN(x) ALIGN(x, 4)
#define FB_MTU (PAGE_SIZE - \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - \
SKB_DATA_ALIGN(BUF_HEADROOM + BUF_TAILROOM) \
@@ -56,11 +57,6 @@
const int fb_mtu = FB_MTU;
-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,10 +485,10 @@ static bool tipc_msg_bundle(struct sk_buff *bskb, struct tipc_msg *msg,
struct tipc_msg *bmsg = buf_msg(bskb);
u32 msz, bsz, offset, pad;
- msz = msg_size(msg);
- bsz = msg_size(bmsg);
- offset = align(bsz);
- pad = offset - bsz;
+ msz = msg_size(msg);
+ bsz = msg_size(bmsg);
+ offset = BUF_ALIGN(bsz);
+ pad = offset - bsz;
if (unlikely(skb_tailroom(bskb) < (pad + msz)))
return false;
@@ -548,7 +544,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)))
@@ -607,7 +603,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);
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup
2021-06-09 10:32 [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 1/2] net: tipc: fix FB_MTU eat two pages menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 2/2] net: tipc: replace align() with ALIGN in msg.c menglong8.dong
@ 2021-06-09 10:47 ` Jon Maloy
2021-06-09 12:56 ` Menglong Dong
2 siblings, 1 reply; 5+ messages in thread
From: Jon Maloy @ 2021-06-09 10:47 UTC (permalink / raw)
To: menglong8.dong
Cc: ying.xue, davem, kuba, netdev, tipc-discussion, linux-kernel,
Menglong Dong
On 6/9/21 6:32 AM, menglong8.dong@gmail.com wrote:
> From: Menglong Dong <dong.menglong@zte.com.cn>
>
> In the first patch, FB_MTU is redefined to make sure data size will not
> exceed PAGE_SIZE. Besides, I removed the alignment for buf_size in
> tipc_buf_acquire, because skb_alloc_fclone will do the alignment job.
>
> In the second patch, I removed align() in msg.c and replace it with
> ALIGN().
>
>
>
>
> Menglong Dong (2):
> net: tipc: fix FB_MTU eat two pages
> net: tipc: replace align() with ALIGN in msg.c
>
> net/tipc/bcast.c | 2 +-
> net/tipc/msg.c | 31 ++++++++++++++-----------------
> net/tipc/msg.h | 3 ++-
> 3 files changed, 17 insertions(+), 19 deletions(-)
>
NACK.
You must have missed my last mail before you sent out this. We have to
define a separate macro for bcast.c, since those buffers sometimes will
need encryption.
Sorry for the confusion.
///jon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup
2021-06-09 10:47 ` [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup Jon Maloy
@ 2021-06-09 12:56 ` Menglong Dong
0 siblings, 0 replies; 5+ messages in thread
From: Menglong Dong @ 2021-06-09 12:56 UTC (permalink / raw)
To: Jon Maloy
Cc: ying.xue, David Miller, Jakub Kicinski, netdev, tipc-discussion,
LKML, Menglong Dong
On Wed, Jun 9, 2021 at 6:47 PM Jon Maloy <jmaloy@redhat.com> wrote:
>
>
>
> On 6/9/21 6:32 AM, menglong8.dong@gmail.com wrote:
> > From: Menglong Dong <dong.menglong@zte.com.cn>
> >
> > In the first patch, FB_MTU is redefined to make sure data size will not
> > exceed PAGE_SIZE. Besides, I removed the alignment for buf_size in
> > tipc_buf_acquire, because skb_alloc_fclone will do the alignment job.
> >
> > In the second patch, I removed align() in msg.c and replace it with
> > ALIGN().
> >
> >
> >
> >
> > Menglong Dong (2):
> > net: tipc: fix FB_MTU eat two pages
> > net: tipc: replace align() with ALIGN in msg.c
> >
> > net/tipc/bcast.c | 2 +-
> > net/tipc/msg.c | 31 ++++++++++++++-----------------
> > net/tipc/msg.h | 3 ++-
> > 3 files changed, 17 insertions(+), 19 deletions(-)
> >
> NACK.
> You must have missed my last mail before you sent out this. We have to
> define a separate macro for bcast.c, since those buffers sometimes will
> need encryption.
> Sorry for the confusion.
No, no, I didn't miss your mail. I think it can make us clear about what and how
to do by sending the V2 patches.
So we can define two versions 'FB_MTU' for bcast.c and msg.c, such as CRYPTO_MTU
and NON_CRYPTO_MTU. And within tipc_buf_acquire(), we decide which version
BUF_HEADROOM to use by the data size? Such as:
int buf_size;
if (IS_ENABLED(CONFIG_TIPC_CRYPTO) && size == NON_CRYPTO_MTU) {
buf_size = size + BUF_HEADROOM_non-crypto + BUF_TAILROOM_non-crypto;
} else {
buf_size = size + BUF_HEADROOM_crypto + BUF_TAILROOM_crypto;
}
Is this feeling?
(It's a little weird to check whether the data should be crypto by data size).
Thanks!
Menglong Dong
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-09 12:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 10:32 [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 1/2] net: tipc: fix FB_MTU eat two pages menglong8.dong
2021-06-09 10:32 ` [PATCH v2 net-next 2/2] net: tipc: replace align() with ALIGN in msg.c menglong8.dong
2021-06-09 10:47 ` [PATCH v2 net-next 0/2] net: tipc: fix FB_MTU eat two pages and do some code cleanup Jon Maloy
2021-06-09 12:56 ` Menglong Dong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).