From: Ajay Kaher <akaher@vmware.com>
To: stable@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, alexanderduyck@fb.com, soheil@google.com,
netdev@vger.kernel.org, namit@vmware.com, amakhalov@vmware.com,
vsirnapalli@vmware.com, er.ajay.kaher@gmail.com,
akaher@vmware.com
Subject: [PATCH v6.1.y 1/4] net: add SKB_HEAD_ALIGN() helper
Date: Fri, 15 Sep 2023 23:51:02 +0530 [thread overview]
Message-ID: <1694802065-1821-2-git-send-email-akaher@vmware.com> (raw)
In-Reply-To: <1694802065-1821-1-git-send-email-akaher@vmware.com>
From: Eric Dumazet <edumazet@google.com>
commit 115f1a5c42bdad9a9ea356fc0b4a39ec7537947f upstream.
We have many places using this expression:
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
Use of SKB_HEAD_ALIGN() will allow to clean them.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
[Ajay: Regenerated the patch for v6.1.y]
Signed-off-by: Ajay Kaher <akaher@vmware.com>
---
include/linux/skbuff.h | 8 ++++++++
net/core/skbuff.c | 18 ++++++------------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index cc5ed2c..2feee14 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -261,6 +261,14 @@
#define SKB_DATA_ALIGN(X) ALIGN(X, SMP_CACHE_BYTES)
#define SKB_WITH_OVERHEAD(X) \
((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+
+/* For X bytes available in skb->head, what is the minimal
+ * allocation needed, knowing struct skb_shared_info needs
+ * to be aligned.
+ */
+#define SKB_HEAD_ALIGN(X) (SKB_DATA_ALIGN(X) + \
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+
#define SKB_MAX_ORDER(X, ORDER) \
SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
#define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 24bf4aa..4aea8f5 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -504,8 +504,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
* aligned memory blocks, unless SLUB/SLAB debug is enabled.
* Both skb->head and skb_shared_info are cache line aligned.
*/
- size = SKB_DATA_ALIGN(size);
- size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+ size = SKB_HEAD_ALIGN(size);
osize = kmalloc_size_roundup(size);
data = kmalloc_reserve(osize, gfp_mask, node, &pfmemalloc);
if (unlikely(!data))
@@ -578,8 +577,7 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
goto skb_success;
}
- len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- len = SKB_DATA_ALIGN(len);
+ len = SKB_HEAD_ALIGN(len);
if (sk_memalloc_socks())
gfp_mask |= __GFP_MEMALLOC;
@@ -678,8 +676,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
data = page_frag_alloc_1k(&nc->page_small, gfp_mask);
pfmemalloc = NAPI_SMALL_PAGE_PFMEMALLOC(nc->page_small);
} else {
- len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- len = SKB_DATA_ALIGN(len);
+ len = SKB_HEAD_ALIGN(len);
data = page_frag_alloc(&nc->page, len, gfp_mask);
pfmemalloc = nc->page.pfmemalloc;
@@ -1837,8 +1834,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
if (skb_pfmemalloc(skb))
gfp_mask |= __GFP_MEMALLOC;
- size = SKB_DATA_ALIGN(size);
- size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+ size = SKB_HEAD_ALIGN(size);
size = kmalloc_size_roundup(size);
data = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);
if (!data)
@@ -6204,8 +6200,7 @@ static int pskb_carve_inside_header(struct sk_buff *skb, const u32 off,
if (skb_pfmemalloc(skb))
gfp_mask |= __GFP_MEMALLOC;
- size = SKB_DATA_ALIGN(size);
- size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+ size = SKB_HEAD_ALIGN(size);
size = kmalloc_size_roundup(size);
data = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);
if (!data)
@@ -6323,8 +6318,7 @@ static int pskb_carve_inside_nonlinear(struct sk_buff *skb, const u32 off,
if (skb_pfmemalloc(skb))
gfp_mask |= __GFP_MEMALLOC;
- size = SKB_DATA_ALIGN(size);
- size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+ size = SKB_HEAD_ALIGN(size);
size = kmalloc_size_roundup(size);
data = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);
if (!data)
--
2.7.4
next prev parent reply other threads:[~2023-09-15 18:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-15 18:21 [PATCH 0/4 v6.1.y] net: fix roundup issue in kmalloc_reserve() Ajay Kaher
2023-09-15 18:21 ` Ajay Kaher [this message]
2023-09-15 18:21 ` [PATCH v6.1.y 2/4] net: remove osize variable in __alloc_skb() Ajay Kaher
2023-09-15 18:21 ` [PATCH v6.1.y 3/4] net: factorize code in kmalloc_reserve() Ajay Kaher
2023-09-15 18:21 ` [PATCH v6.1.y 4/4] net: deal with integer overflows " Ajay Kaher
2023-09-16 11:30 ` [PATCH 0/4 v6.1.y] net: fix roundup issue " Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1694802065-1821-2-git-send-email-akaher@vmware.com \
--to=akaher@vmware.com \
--cc=alexanderduyck@fb.com \
--cc=amakhalov@vmware.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=er.ajay.kaher@gmail.com \
--cc=kuba@kernel.org \
--cc=namit@vmware.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=soheil@google.com \
--cc=stable@vger.kernel.org \
--cc=vsirnapalli@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.