Commit 811b8362 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'minor-cleanups-to-skb-frag-ref-unref'

Mina Almasry says:

====================
Minor cleanups to skb frag ref/unref (part)

This series is largely motivated by a recent discussion where there was
some confusion on how to properly ref/unref pp pages vs non pp pages:

https://lore.kernel.org/netdev/CAHS8izOoO-EovwMwAm9tLYetwikNPxC0FKyVGu1TPJWSz4bGoA@mail.gmail.com/T/#t

There is some subtely there because pp uses page->pp_ref_count for
refcounting, while non-pp uses get_page()/put_page() for ref counting.
Getting the refcounting pairs wrong can lead to kernel crash.
[...]

https://lore.kernel.org/lkml/CAHS8izN436pn3SndrzsCyhmqvJHLyxgCeDpWXA4r1ANt3RCDLQ@mail.gmail.com/T/
====================

Link: https://lore.kernel.org/r/20240408153000.2152844-1-almasrymina@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 445e6030 f58f3c95
...@@ -3522,20 +3522,8 @@ int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb, ...@@ -3522,20 +3522,8 @@ int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb,
bool napi_pp_put_page(struct page *page); bool napi_pp_put_page(struct page *page);
static inline void static inline void
skb_page_unref(const struct sk_buff *skb, struct page *page) skb_page_unref(struct page *page, bool recycle)
{ {
#ifdef CONFIG_PAGE_POOL
if (skb->pp_recycle && napi_pp_put_page(page))
return;
#endif
put_page(page);
}
static inline void
napi_frag_unref(skb_frag_t *frag, bool recycle)
{
struct page *page = skb_frag_page(frag);
#ifdef CONFIG_PAGE_POOL #ifdef CONFIG_PAGE_POOL
if (recycle && napi_pp_put_page(page)) if (recycle && napi_pp_put_page(page))
return; return;
...@@ -3553,7 +3541,7 @@ napi_frag_unref(skb_frag_t *frag, bool recycle) ...@@ -3553,7 +3541,7 @@ napi_frag_unref(skb_frag_t *frag, bool recycle)
*/ */
static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle) static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle)
{ {
napi_frag_unref(frag, recycle); skb_page_unref(skb_frag_page(frag), recycle);
} }
/** /**
......
...@@ -1101,7 +1101,7 @@ static void skb_release_data(struct sk_buff *skb, enum skb_drop_reason reason) ...@@ -1101,7 +1101,7 @@ static void skb_release_data(struct sk_buff *skb, enum skb_drop_reason reason)
} }
for (i = 0; i < shinfo->nr_frags; i++) for (i = 0; i < shinfo->nr_frags; i++)
napi_frag_unref(&shinfo->frags[i], skb->pp_recycle); __skb_frag_unref(&shinfo->frags[i], skb->pp_recycle);
free_head: free_head:
if (shinfo->frag_list) if (shinfo->frag_list)
......
...@@ -114,7 +114,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) ...@@ -114,7 +114,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)
*/ */
if (req->src != req->dst) if (req->src != req->dst)
for (sg = sg_next(req->src); sg; sg = sg_next(sg)) for (sg = sg_next(req->src); sg; sg = sg_next(sg))
skb_page_unref(skb, sg_page(sg)); skb_page_unref(sg_page(sg), skb->pp_recycle);
} }
#ifdef CONFIG_INET_ESPINTCP #ifdef CONFIG_INET_ESPINTCP
......
...@@ -131,7 +131,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) ...@@ -131,7 +131,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)
*/ */
if (req->src != req->dst) if (req->src != req->dst)
for (sg = sg_next(req->src); sg; sg = sg_next(sg)) for (sg = sg_next(req->src); sg; sg = sg_next(sg))
skb_page_unref(skb, sg_page(sg)); skb_page_unref(sg_page(sg), skb->pp_recycle);
} }
#ifdef CONFIG_INET6_ESPINTCP #ifdef CONFIG_INET6_ESPINTCP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment