net: unify symmetric netmem and page_pool refcounting
Status from this message: This series was applied to netdev/net-next.git (main)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest6 patches 14 repliesApplied 6/6
- v26 patches 3 repliesSuperseded
- v16 patches 2 repliesSuperseded
Changes in v3 from the cover letter
- 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/[email protected]/
Patches in v3 All 6 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | netmem: rename __get/__put_netmem() to get/put_net_iov()include/ net/ | +46 | 1 reply | Applied |
| 2/6 | net: skbuff: add napi_pp_get_page() and use it in tcp_recvmsg_dmabuf()include/ net/ net/ | +37 | 1 reply | Applied |
| 3/6 | net: skbuff: replace skb_page_unref() and __skb_frag_unref() with skb_netmem_unref()drivers/ drivers/ include/ +5 more | +29 | 4 replies | Applied |
| 4/6 | net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref()drivers/ drivers/ drivers/ +4 more | +51 | 2 replies | Applied |
| 5/6 | net: skbuff: use skb_frag_ref() in skb_try_coalesce()net/ | +2 | 0 replies | Applied |
| 6/6 | net: kunit: test netmem, page_pool, and skb frag refcountingnet/ net/ | +1224 | 0 replies | Applied |
Reviews trailers per patch
1 of 6 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Aleksandr Loktionov | Stanislav Fomichev | Antony Antony |
|---|---|---|---|
| Series | A-b | ||
| 1/6 | |||
| 2/6 | |||
| 3/6 | |||
| 4/6 | T-b | ||
| 5/6 | |||
| 6/6 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting
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.
---
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/[email protected]/
v2:
- Clear NETIF_F_SG in skb_segment() when frag_list SKBs mix pp_recycle
flags (patch 4).
- Export skb_shift() via EXPORT_SYMBOL_IF_KUNIT() to fix the
CONFIG_NET_TEST=m modpost error reported by NIPA (patch 6).
- Reset mac_header before skb_segment() and check skb_clone() results in
KUnit (Sashiko), and extend KUnit coverage to compound tail pages, skb_try_coalesce(), TCP devmem recvmsg, skb_zerocopy() rollbacks, skb_split()/skb_shift() edge cases, and mixed pp_recycle frag_list GSO.
- Note how the issues were found and tested (netdev-bot), and add
Assisted-by tags.
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
Mina Almasry (6):
netmem: rename __get/__put_netmem() to get/put_net_iov()
net: skbuff: add napi_pp_get_page() and use it in tcp_recvmsg_dmabuf()
net: skbuff: replace skb_page_unref() and __skb_frag_unref() with
skb_netmem_unref()
net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref()
net: skbuff: use skb_frag_ref() in skb_try_coalesce()
net: kunit: test netmem, page_pool, and skb frag refcounting
.../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 2 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +- drivers/net/ethernet/sun/cassini.c | 4 +- drivers/net/veth.c | 2 +- include/linux/skbuff_ref.h | 64 +- include/net/netmem.h | 24 +- net/core/net_test.c | 1222 +++++++++++++++++ net/core/skbuff.c | 157 ++- net/ipv4/esp4.c | 4 +- net/ipv4/tcp.c | 6 +- net/ipv6/esp6.c | 4 +- net/tls/tls_device.c | 2 +- net/tls/tls_device_fallback.c | 2 +- net/tls/tls_strp.c | 2 +- net/xfrm/xfrm_iptfs.c | 3 +- 16 files changed, 1387 insertions(+), 115 deletions(-)
base-commit: 05b5019b01fb9443b09ae4ed34af1135a80a84c8
Signature · 1 line
2.56.0.212.g129ede20d9-goog