mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 18:56:24 +00:00
173e7622cc
This reverts commit a580ea994fd37f4105028f5a85c38ff6508a2b25. This revert is to resolve Dragos's report of page_pool leak here: https://lore.kernel.org/lkml/20240424165646.1625690-2-dtatulea@nvidia.com/ The reverted patch interacts very badly with commit 2cc3aeb5eccc ("skbuff: Fix a potential race while recycling page_pool packets"). The reverted commit hopes that the pp_recycle + is_pp_page variables do not change between the skb_frag_ref and skb_frag_unref operation. If such a change occurs, the skb_frag_ref/unref will not operate on the same reference type. In the case of Dragos's report, the grabbed ref was a pp ref, but the unref was a page ref, because the pp_recycle setting on the skb was changed. Attempting to fix this issue on the fly is risky. Lets revert and I hope to reland this with better understanding and testing to ensure we don't regress some edge case while streamlining skb reffing. Fixes: a580ea994fd3 ("net: mirror skb frag ref/unref helpers") Reported-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Mina Almasry <almasrymina@google.com> Link: https://lore.kernel.org/r/20240502175423.2456544-1-almasrymina@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Skb ref helpers.
|
|
*
|
|
*/
|
|
|
|
#ifndef _LINUX_SKBUFF_REF_H
|
|
#define _LINUX_SKBUFF_REF_H
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
/**
|
|
* __skb_frag_ref - take an addition reference on a paged fragment.
|
|
* @frag: the paged fragment
|
|
*
|
|
* Takes an additional reference on the paged fragment @frag.
|
|
*/
|
|
static inline void __skb_frag_ref(skb_frag_t *frag)
|
|
{
|
|
get_page(skb_frag_page(frag));
|
|
}
|
|
|
|
/**
|
|
* skb_frag_ref - take an addition reference on a paged fragment of an skb.
|
|
* @skb: the buffer
|
|
* @f: the fragment offset.
|
|
*
|
|
* Takes an additional reference on the @f'th paged fragment of @skb.
|
|
*/
|
|
static inline void skb_frag_ref(struct sk_buff *skb, int f)
|
|
{
|
|
__skb_frag_ref(&skb_shinfo(skb)->frags[f]);
|
|
}
|
|
|
|
bool napi_pp_put_page(struct page *page);
|
|
|
|
static inline void
|
|
skb_page_unref(struct page *page, bool recycle)
|
|
{
|
|
#ifdef CONFIG_PAGE_POOL
|
|
if (recycle && napi_pp_put_page(page))
|
|
return;
|
|
#endif
|
|
put_page(page);
|
|
}
|
|
|
|
/**
|
|
* __skb_frag_unref - release a reference on a paged fragment.
|
|
* @frag: the paged fragment
|
|
* @recycle: recycle the page if allocated via page_pool
|
|
*
|
|
* Releases a reference on the paged fragment @frag
|
|
* or recycles the page via the page_pool API.
|
|
*/
|
|
static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle)
|
|
{
|
|
skb_page_unref(skb_frag_page(frag), recycle);
|
|
}
|
|
|
|
/**
|
|
* skb_frag_unref - release a reference on a paged fragment of an skb.
|
|
* @skb: the buffer
|
|
* @f: the fragment offset
|
|
*
|
|
* Releases a reference on the @f'th paged fragment of @skb.
|
|
*/
|
|
static inline void skb_frag_unref(struct sk_buff *skb, int f)
|
|
{
|
|
struct skb_shared_info *shinfo = skb_shinfo(skb);
|
|
|
|
if (!skb_zcopy_managed(skb))
|
|
__skb_frag_unref(&shinfo->frags[f], skb->pp_recycle);
|
|
}
|
|
|
|
#endif /* _LINUX_SKBUFF_REF_H */
|