BPF List
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf.kernel@gmail.com>
To: Mina Almasry <almasrymina@google.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rdma@vger.kernel.org, bpf@vger.kernel.org,
	"Ayush Sawal" <ayush.sawal@chelsio.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	"Simon Horman" <horms@kernel.org>,
	"Steffen Klassert" <steffen.klassert@secunet.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Neal Cardwell" <ncardwell@google.com>,
	"Kuniyuki Iwashima" <kuniyu@google.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Sabrina Dubroca" <sd@queasysnail.net>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Kees Cook" <kees@kernel.org>,
	"Aleksandr Loktionov" <aleksandr.loktionov@intel.com>,
	"Petr Machata" <petrm@nvidia.com>,
	"Uwe Kleine-König (The Capable Hub)"
	<u.kleine-koenig@baylibre.com>,
	"Jakub Raczynski" <j.raczynski@samsung.com>,
	"Wang Zhan" <wang.zhan@smartx.com>,
	"Willem de Bruijn" <willemb@google.com>
Subject: Re: [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting
Date: Thu, 15 Oct 2026 14:36:38 -0700	[thread overview]
Message-ID: <atFHX4ryLonqXpn4@devvm7509.cco0.facebook.com> (raw)
In-Reply-To: <20261014173945.373295-1-almasrymina@google.com>

On 10/14, Mina Almasry wrote:
> netmems (pages and net_iovs) have two independent refcounts: a non-pp
> refcount (page._refcount or binding->ref) governing backing memory
> lifetime, and pp_ref_count governing recycling within a page_pool while
> page_pool holds a single backing non-pp reference. SKBs with
> pp_recycle=1 own pp_ref_count references on page_pool fragments; SKBs
> with pp_recycle=0 own non-pp references.
> 
> Core helpers currently mix these two refcounts asymmetrically:
> skb_frag_ref() always increments the non-pp refcount via get_netmem(),
> whereas skb_frag_unref() decrements pp_ref_count when skb->pp_recycle
> is set. Any path that refs a fragment on a pp_recycle=1 SKB (or unrefs
> with a hardcoded recycle=false) increments one counter and decrements
> the other, leaking the backing memory while underflowing pp_ref_count
> (e.g., IP-TFS [1], skb_split(), skb_shift(), and cloned SKB uncloning).
> Unclear core APIs also led drivers and ULPs to open-code pp_ref_count
> manipulations or add one-off helpers like skb_pp_frag_ref().
> 
> Unify fragment refcounting into symmetric pairs where each layer clearly
> specifies which refcount it touches:
> 
> - Non-PP refcount: get/put_page(), get/put_net_iov(), get/put_netmem()
> - PP refcount:     napi_pp_get/put_page()
> - SKB netmem:      skb_netmem_ref/unref(netmem, recycle)
> - SKB fragment:    skb_frag_ref/unref(skb, f)
> 
> Found by code inspection while reviewing [1] and confirmed with the KUnit
> tests in patch 6; not observed in production. Driver and ULP call-site
> changes are compile-tested only.
> 
> Link: https://lore.kernel.org/netdev/xfrm-iptfs-pp_ref_count-underflow-v4-1-912fa72106f0@secunet.com/ [1]
> 
> ---
> v3:
> - Linearize straddling output segments in skb_segment() when frag_list
>   SKBs mix pp_recycle flags instead of clearing NETIF_F_SG, and add a
>   KUnit regression test (Sashiko).
> - Link to v2: https://lore.kernel.org/netdev/20261012082148.1698596-1-almasrymina@google.com/

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

      parent reply	other threads:[~2026-10-15 21:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 17:37 [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting Mina Almasry
2026-10-14 17:37 ` [PATCH net-next v3 1/6] netmem: rename __get/__put_netmem() to get/put_net_iov() Mina Almasry
2026-10-15 20:37   ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 2/6] net: skbuff: add napi_pp_get_page() and use it in tcp_recvmsg_dmabuf() Mina Almasry
2026-10-15 20:37   ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 3/6] net: skbuff: replace skb_page_unref() and __skb_frag_unref() with skb_netmem_unref() Mina Almasry
2026-10-14 21:25   ` Stanislav Fomichev
2026-10-14 22:05     ` Mina Almasry
2026-10-14 22:39       ` Stanislav Fomichev
2026-10-15 20:37   ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 4/6] net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref() Mina Almasry
2026-10-15 20:37   ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 5/6] net: skbuff: use skb_frag_ref() in skb_try_coalesce() Mina Almasry
2026-10-14 17:37 ` [PATCH net-next v3 6/6] net: kunit: test netmem, page_pool, and skb frag refcounting Mina Almasry
2026-10-15 20:37   ` netdev-bot+sashiko
2026-10-15 21:36 ` Stanislav Fomichev [this message]

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=atFHX4ryLonqXpn4@devvm7509.cco0.facebook.com \
    --to=sdf.kernel@gmail.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=ayush.sawal@chelsio.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=j.raczynski@samsung.com \
    --cc=john.fastabend@gmail.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=tariqt@nvidia.com \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=wang.zhan@smartx.com \
    --cc=willemb@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox