From: Yunsheng Lin <linyunsheng@huawei.com>
To: <davem@davemloft.net>, <kuba@kernel.org>
Cc: <alexander.duyck@gmail.com>, <linux@armlinux.org.uk>,
<mw@semihalf.com>, <linuxarm@openeuler.org>,
<yisen.zhuang@huawei.com>, <salil.mehta@huawei.com>,
<thomas.petazzoni@bootlin.com>, <hawk@kernel.org>,
<ilias.apalodimas@linaro.org>, <ast@kernel.org>,
<daniel@iogearbox.net>, <john.fastabend@gmail.com>,
<akpm@linux-foundation.org>, <peterz@infradead.org>,
<will@kernel.org>, <willy@infradead.org>, <vbabka@suse.cz>,
<fenghua.yu@intel.com>, <guro@fb.com>, <peterx@redhat.com>,
<feng.tang@intel.com>, <jgg@ziepe.ca>, <mcroce@microsoft.com>,
<hughd@google.com>, <jonathan.lemon@gmail.com>, <alobakin@pm.me>,
<willemb@google.com>, <wenxu@ucloud.cn>,
<cong.wang@bytedance.com>, <haokexin@gmail.com>,
<nogikh@google.com>, <elver@google.com>, <yhs@fb.com>,
<kpsingh@kernel.org>, <andrii@kernel.org>, <kafai@fb.com>,
<songliubraving@fb.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <bpf@vger.kernel.org>,
<chenhao288@hisilicon.com>, <edumazet@google.com>,
<yoshfuji@linux-ipv6.org>, <dsahern@kernel.org>,
<memxor@gmail.com>, <linux@rempel-privat.de>,
<atenart@kernel.org>, <weiwan@google.com>, <ap420073@gmail.com>,
<arnd@arndb.de>, <mathew.j.martineau@linux.intel.com>,
<aahringo@redhat.com>, <ceggers@arri.de>, <yangbo.lu@nxp.com>,
<fw@strlen.de>, <xiangxia.m.yue@gmail.com>,
<linmiaohe@huawei.com>
Subject: [PATCH RFC 2/7] skbuff: add interface to manipulate frag count for tx recycling
Date: Wed, 18 Aug 2021 11:32:18 +0800 [thread overview]
Message-ID: <1629257542-36145-3-git-send-email-linyunsheng@huawei.com> (raw)
In-Reply-To: <1629257542-36145-1-git-send-email-linyunsheng@huawei.com>
As the skb->pp_recycle and page->pp_magic may not be enough
to track if a frag page is from page pool after the calling
of __skb_frag_ref(), mostly because of a data race, see:
commit 2cc3aeb5eccc ("skbuff: Fix a potential race while
recycling page_pool packets").
As the case of tcp, there may be fragmenting, coalescing or
retransmiting case that might lose the track if a frag page
is from page pool or not.
So increment the frag count when __skb_frag_ref() is called,
and use the bit 0 in frag->bv_page to indicate if a page is
from a page pool, which automically pass down to another
frag->bv_page when doing a '*new_frag = *frag' or memcpying
the shinfo.
It seems we could do the trick for rx too if it makes sense.
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
include/linux/skbuff.h | 43 ++++++++++++++++++++++++++++++++++++++++---
include/net/page_pool.h | 5 +++++
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 6bdb0db..2878d26 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -331,6 +331,11 @@ static inline unsigned int skb_frag_size(const skb_frag_t *frag)
return frag->bv_len;
}
+static inline bool skb_frag_is_pp(const skb_frag_t *frag)
+{
+ return (unsigned long)frag->bv_page & 1UL;
+}
+
/**
* skb_frag_size_set() - Sets the size of a skb fragment
* @frag: skb fragment
@@ -2190,6 +2195,21 @@ static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
skb->pfmemalloc = true;
}
+static inline void __skb_fill_pp_page_desc(struct sk_buff *skb, int i,
+ struct page *page, int off,
+ int size)
+{
+ skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+
+ frag->bv_page = (struct page *)((unsigned long)page | 0x1UL);
+ frag->bv_offset = off;
+ skb_frag_size_set(frag, size);
+
+ page = compound_head(page);
+ if (page_is_pfmemalloc(page))
+ skb->pfmemalloc = true;
+}
+
/**
* skb_fill_page_desc - initialise a paged fragment in an skb
* @skb: buffer containing fragment to be initialised
@@ -2211,6 +2231,14 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,
skb_shinfo(skb)->nr_frags = i + 1;
}
+static inline void skb_fill_pp_page_desc(struct sk_buff *skb, int i,
+ struct page *page, int off,
+ int size)
+{
+ __skb_fill_pp_page_desc(skb, i, page, off, size);
+ skb_shinfo(skb)->nr_frags = i + 1;
+}
+
void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
int size, unsigned int truesize);
@@ -3062,7 +3090,10 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto,
*/
static inline struct page *skb_frag_page(const skb_frag_t *frag)
{
- return frag->bv_page;
+ unsigned long page = (unsigned long)frag->bv_page;
+
+ page &= ~1UL;
+ return (struct page *)page;
}
/**
@@ -3073,7 +3104,12 @@ static inline struct page *skb_frag_page(const skb_frag_t *frag)
*/
static inline void __skb_frag_ref(skb_frag_t *frag)
{
- get_page(skb_frag_page(frag));
+ struct page *page = skb_frag_page(frag);
+
+ if (skb_frag_is_pp(frag))
+ page_pool_atomic_inc_frag_count(page);
+ else
+ get_page(page);
}
/**
@@ -3101,7 +3137,8 @@ static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle)
struct page *page = skb_frag_page(frag);
#ifdef CONFIG_PAGE_POOL
- if (recycle && page_pool_return_skb_page(page))
+ if ((recycle || skb_frag_is_pp(frag)) &&
+ page_pool_return_skb_page(page))
return;
#endif
put_page(page);
diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index 8d4ae4b..86babb2 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -270,6 +270,11 @@ static inline long page_pool_atomic_sub_frag_count_return(struct page *page,
return ret;
}
+static void page_pool_atomic_inc_frag_count(struct page *page)
+{
+ atomic_long_inc(&page->pp_frag_count);
+}
+
static inline bool is_page_pool_compiled_in(void)
{
#ifdef CONFIG_PAGE_POOL
--
2.7.4
next prev parent reply other threads:[~2021-08-18 3:34 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 3:32 [PATCH RFC 0/7] add socket to netdev page frag recycling support Yunsheng Lin
2021-08-18 3:32 ` [PATCH RFC 1/7] page_pool: refactor the page pool to support multi alloc context Yunsheng Lin
2021-08-18 3:32 ` Yunsheng Lin [this message]
2021-08-18 3:32 ` [PATCH RFC 3/7] net: add NAPI api to register and retrieve the page pool ptr Yunsheng Lin
2021-08-18 3:32 ` [PATCH RFC 4/7] net: pfrag_pool: add pfrag pool support based on page pool Yunsheng Lin
2021-08-18 3:32 ` [PATCH RFC 5/7] sock: support refilling pfrag from pfrag_pool Yunsheng Lin
2021-08-18 3:32 ` [PATCH RFC 6/7] net: hns3: support tx recycling in the hns3 driver Yunsheng Lin
2021-08-18 8:57 ` [PATCH RFC 0/7] add socket to netdev page frag recycling support Eric Dumazet
2021-08-18 9:36 ` Yunsheng Lin
2021-08-23 9:25 ` [Linuxarm] " Yunsheng Lin
2021-08-23 15:04 ` Eric Dumazet
2021-08-24 8:03 ` Yunsheng Lin
2021-08-25 16:29 ` David Ahern
2021-08-25 16:32 ` Eric Dumazet
2021-08-25 16:38 ` David Ahern
2021-08-25 17:24 ` Eric Dumazet
2021-08-26 4:05 ` David Ahern
2021-08-18 22:05 ` David Ahern
2021-08-19 8:18 ` Yunsheng Lin
2021-08-20 14:35 ` David Ahern
2021-08-23 3:32 ` Yunsheng Lin
2021-08-24 3:34 ` David Ahern
2021-08-24 8:41 ` Yunsheng Lin
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=1629257542-36145-3-git-send-email-linyunsheng@huawei.com \
--to=linyunsheng@huawei.com \
--cc=aahringo@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=alobakin@pm.me \
--cc=andrii@kernel.org \
--cc=ap420073@gmail.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=atenart@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=ceggers@arri.de \
--cc=chenhao288@hisilicon.com \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=elver@google.com \
--cc=feng.tang@intel.com \
--cc=fenghua.yu@intel.com \
--cc=fw@strlen.de \
--cc=guro@fb.com \
--cc=haokexin@gmail.com \
--cc=hawk@kernel.org \
--cc=hughd@google.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jgg@ziepe.ca \
--cc=john.fastabend@gmail.com \
--cc=jonathan.lemon@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linux@rempel-privat.de \
--cc=linuxarm@openeuler.org \
--cc=mathew.j.martineau@linux.intel.com \
--cc=mcroce@microsoft.com \
--cc=memxor@gmail.com \
--cc=mw@semihalf.com \
--cc=netdev@vger.kernel.org \
--cc=nogikh@google.com \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=salil.mehta@huawei.com \
--cc=songliubraving@fb.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vbabka@suse.cz \
--cc=weiwan@google.com \
--cc=wenxu@ucloud.cn \
--cc=will@kernel.org \
--cc=willemb@google.com \
--cc=willy@infradead.org \
--cc=xiangxia.m.yue@gmail.com \
--cc=yangbo.lu@nxp.com \
--cc=yhs@fb.com \
--cc=yisen.zhuang@huawei.com \
--cc=yoshfuji@linux-ipv6.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox