mm, page_pool: introduce a new page type for page pool in page type
Subsystems (12)
PATCH v3 1/1 mm, page_pool: introduce a new page type for page pool in page type
Changes from v2:
1. Rebase on linux-next as of Jul 29.
2. Skip 'niov->pp = NULL' when it's allocated using __GFP_ZERO.
3. Change trivial coding style. (feedbacked by Mina)
4. Add Co-developed-by, Acked-by, and Reviewed-by properly. Thanks to all.
Changes from v1:
1. Rebase on linux-next.
2. Initialize net_iov->pp = NULL when allocating net_iov in net_devmem_bind_dmabuf() and io_zcrx_create_area().
3. Use ->pp for net_iov to identify if it's pp rather than always consider net_iov as pp.
4. Add Suggested-by: David Hildenbrand <[email protected]>.
---8<---
From 88bcb9907a0cef65a9c0adf35e144f9eb67e0542 Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 29 Jul 2025 19:49:44 +0900
Subject: [PATCH linux-next v3] mm, page_pool: introduce a new page type for page pool in page type
->pp_magic field in struct page is current used to identify if a page belongs to a page pool. However, ->pp_magic will be removed and page type bit in struct page e.i. PGTY_netpp can be used for that purpose.
Introduce and use the page type APIs e.g. PageNetpp(), __SetPageNetpp(), and __ClearPageNetpp() instead, and remove the existing APIs accessing ->pp_magic e.g. page_pool_page_is_pp(), netmem_or_pp_magic(), and netmem_clear_pp_magic().
For net_iov, use ->pp to identify if it's pp, with making sure that ->pp is NULL for non-pp net_iov.
This work was inspired by the following link:
[1] https://lore.kernel.org/all/[email protected]/
While at it, move the sanity check for page pool to on free.
--- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 2 +- include/linux/mm.h | 27 +++---------------- include/linux/page-flags.h | 6 +++++ include/net/netmem.h | 2 +- io_uring/zcrx.c | 4 +++ mm/page_alloc.c | 7 +++-- net/core/devmem.c | 1 + net/core/netmem_priv.h | 23 +++++++--------- net/core/page_pool.c | 10 +++++-- 9 files changed, 37 insertions(+), 45 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +1 -1
@@ -707,7 +707,7 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq, xdpi =mlx5e_xdpi_fifo_pop (xdpi_fifo); page = xdpi.page.page; -/* No need to check page_pool_page_is_pp() as we +/* No need to check PageNetpp() as we * know this is a page_pool page. */ page_pool_recycle_direct(pp_page_to_nmdesc(page)->pp,
include/linux/mm.h +3 -24
@@ -4171,10 +4171,9 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);* DMA mapping IDs for page_pool * * When DMA-mapping a page, page_pool allocates an ID (from an xarray) and -* stashes it in the upper bits of page->pp_magic. We always want to be able to -* unambiguously identify page pool pages (using page_pool_page_is_pp()). Non-PP -* pages can have arbitrary kernel pointers stored in the same field as pp_magic -* (since it overlaps with page->lru.next), so we must ensure that we cannot +* stashes it in the upper bits of page->pp_magic. Non-PP pages can have +* arbitrary kernel pointers stored in the same field as pp_magic (since +* it overlaps with page->lru.next), so we must ensure that we cannot * mistake a valid kernel pointer with any of the values we write into this * field. *
@@ -4205,26 +4204,6 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) -/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is -* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for -* the head page of compound page and bit 1 for pfmemalloc page, as well as the -* bits used for the DMA index. page_is_pfmemalloc() is checked in -* __page_pool_put_page() to avoid recycling the pfmemalloc page. -*/ -#define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) - -#ifdef CONFIG_PAGE_POOL -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return (page->pp_magic &PP_MAGIC_MASK ) ==PP_SIGNATURE ; -} -#else -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return false; -} -#endif -#define PAGE_SNAPSHOT_FAITHFUL (1 << 0)#define PAGE_SNAPSHOT_PG_BUDDY (1 << 1)#define PAGE_SNAPSHOT_PG_IDLE (1 << 2)
include/linux/page-flags.h +6 -0
@@ -933,6 +933,7 @@ enum pagetype { PGTY_zsmalloc =0xf6 , PGTY_unaccepted =0xf7 , PGTY_large_kmalloc =0xf8 , + PGTY_netpp =0xf9 , PGTY_mapcount_underflow = 0xff };
@@ -1077,6 +1078,11 @@ PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) PAGE_TYPE_OPS(Unaccepted, unaccepted, unaccepted)FOLIO_TYPE_OPS (large_kmalloc, large_kmalloc) +/* +* Marks page_pool allocated pages. + */ +PAGE_TYPE_OPS (Netpp, netpp, netpp) +/** * PageHuge - Determine if the page belongs to hugetlbfs * @page: The page to test.
include/net/netmem.h +1 -1
@@ -298,7 +298,7 @@ static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)*/ #define pp_page_to_nmdesc (p) \ ({ \ - DEBUG_NET_WARN_ON_ONCE(!page_pool_page_is_pp(p)); \ + DEBUG_NET_WARN_ON_ONCE(!PageNetpp(p)); \ __pp_page_to_nmdesc(p); \ })
io_uring/zcrx.c +4 -0
@@ -444,6 +444,10 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq, area->freelist[i] = i;atomic_set (&area->user_refs[i],0 ); niov->type =NET_IOV_IOURING ; + +/* niov->pp is already initialized to NULL by +* kvmalloc_array(__GFP_ZERO). +*/ } area->free_count = nr_iovs;
mm/page_alloc.c +3 -4
@@ -1042,7 +1042,6 @@ static inline bool page_expected_state(struct page *page,#ifdef CONFIG_MEMCG page->memcg_data | #endif -page_pool_page_is_pp (page) | (page->flags & check_flags)))return false;
@@ -1069,8 +1068,6 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)if (unlikely (page->memcg_data)) bad_reason ="page still charged to cgroup" ;#endif -if (unlikely (page_pool_page_is_pp (page))) - bad_reason ="page_pool leak" ;return bad_reason; }
@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ; } -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNetpp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }if (is_check_pages_enabled ()) {if (free_page_is_bad (page))
net/core/devmem.c +1 -0
@@ -285,6 +285,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, niov = &owner->area.niovs[i]; niov->type =NET_IOV_DMABUF ; niov->owner = &owner->area; + niov->pp =NULL ;page_pool_set_dma_addr_netmem (net_iov_to_netmem (niov),net_devmem_get_dma_addr (niov));if (direction ==DMA_TO_DEVICE )
net/core/netmem_priv.h +10 -13
@@ -8,21 +8,18 @@ static inline unsigned long netmem_get_pp_magic(netmem_ref netmem)return __netmem_clear_lsb (netmem)->pp_magic & ~PP_DMA_INDEX_MASK ; } -static inline void netmem_or_pp_magic (netmem_ref netmem,unsigned long pp_magic) -{ -__netmem_clear_lsb (netmem)->pp_magic |= pp_magic; -} - -static inline void netmem_clear_pp_magic (netmem_ref netmem) -{ -WARN_ON_ONCE (__netmem_clear_lsb (netmem)->pp_magic &PP_DMA_INDEX_MASK ); - -__netmem_clear_lsb (netmem)->pp_magic =0 ; -} -static inline bool netmem_is_pp (netmem_ref netmem) { -return (netmem_get_pp_magic (netmem) &PP_MAGIC_MASK ) ==PP_SIGNATURE ; +/* Use ->pp for net_iov to identify if it's pp, which requires +* that non-pp net_iov should have ->pp NULL'd. +*/ +if (netmem_is_net_iov (netmem)) +return !!__netmem_clear_lsb (netmem)->pp; + +/* For system memory, page type bit in struct page can be used +* to identify if it's pp. +*/ +return PageNetpp (__netmem_to_page (netmem)); }static inline void netmem_set_pp (netmem_ref netmem,struct page_pool *pool)
net/core/page_pool.c +8 -2
@@ -654,7 +654,6 @@ s32 page_pool_inflight(const struct page_pool *pool, bool strict)void page_pool_set_pp_info (struct page_pool *pool,netmem_ref netmem) {netmem_set_pp (netmem, pool); -netmem_or_pp_magic (netmem,PP_SIGNATURE );/* Ensuring all pages have been split into one fragment initially: * page_pool_set_pp_info() is only called once for every page when it
@@ -665,12 +664,19 @@ void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem)page_pool_fragment_netmem (netmem,1 );if (pool->has_init_callback) pool->slow.init_callback (netmem, pool->slow.init_arg); + +/* If it's page-backed */ +if (!netmem_is_net_iov (netmem)) +__SetPageNetpp (__netmem_to_page (netmem)); }void page_pool_clear_pp_info (netmem_ref netmem) { -netmem_clear_pp_magic (netmem);netmem_set_pp (netmem,NULL ); + +/* If it's page-backed */ +if (!netmem_is_net_iov (netmem)) +__ClearPageNetpp (__netmem_to_page (netmem)); } static __always_inline void __page_pool_release_netmem_dma(struct page_pool *pool,
base-commit: 54efec8782214652b331c50646013f8526570e8d
Signature · 1 line
2.17.1
Quoted 57 lines · Byungchul Park
Changes from v2:
1. Rebase on linux-next as of Jul 29.
2. Skip 'niov->pp= NULL' when it's allocated using__GFP_ZERO.
3. Change trivial coding style. (feedbacked by Mina)
4. Add Co-developed-by, Acked-by, and Reviewed-by properly. Thanks to all.Changes from v1:
1. Rebase on linux-next.
2. Initializenet_iov->pp= NULL when allocatingnet_iovinnet_devmem_bind_dmabuf()andio_zcrx_create_area().
3. Use ->pp fornet_iovto identify if it's pp rather than always considernet_iovas pp.
4. Add Suggested-by: David Hildenbrand <[email protected]>.---8<---
From88bcb9907a0cef65a9c0adf35e144f9eb67e0542Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 29 Jul 2025 19:49:44 +0900
Subject: [PATCH linux-next v3] mm,page_pool: introduce a new page type for page pool in page type->pp_magic field in struct page is current used to identify if a page belongs to a page pool. However, ->pp_magic will be removed and page type bit in struct page e.i.
PGTY_netppcan be used for that purpose.Introduce and use the page type APIs e.g.
PageNetpp(),__SetPageNetpp(), and__ClearPageNetpp()instead, and remove the existing APIs accessing ->pp_magic e.g.page_pool_page_is_pp(),netmem_or_pp_magic(), andnetmem_clear_pp_magic().For
net_iov, use ->pp to identify if it's pp, with making sure that ->pp is NULL for non-ppnet_iov.This work was inspired by the following link:
[1] https://lore.kernel.org/all/[email protected]/
While at it, move the sanity check for page pool to on free.
Suggested-by David Hildenbrand <[email protected]>Co-developed-by Pavel Begunkov <[email protected]>Signed-off-by Pavel Begunkov <[email protected]>Signed-off-by Byungchul Park <[email protected]>Reviewed-by Mina Almasry <[email protected]>--- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 2 +- include/linux/mm.h | 27 +++---------------- include/linux/page-flags.h | 6 +++++ include/net/netmem.h | 2 +- io_uring/zcrx.c | 4 +++ mm/page_alloc.c | 7 +++-- net/core/devmem.c | 1 + net/core/netmem_priv.h | 23 +++++++--------- net/core/page_pool.c | 10 +++++-- 9 files changed, 37 insertions(+), 45 deletions(-)
<snip>
Quoted 69 lines
include/linux/mm.h +3
-24@@ -4171,10 +4171,9 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);* DMA mapping IDs for page_pool * * When DMA-mapping a page, page_pool allocates an ID (from an xarray) and -* stashes it in the upper bits of page->pp_magic. We always want to be able to -* unambiguously identify page pool pages (using page_pool_page_is_pp()). Non-PP -* pages can have arbitrary kernel pointers stored in the same field as pp_magic -* (since it overlaps with page->lru.next), so we must ensure that we cannot +* stashes it in the upper bits of page->pp_magic. Non-PP pages can have +* arbitrary kernel pointers stored in the same field as pp_magic (since +* it overlaps with page->lru.next), so we must ensure that we cannot * mistake a valid kernel pointer with any of the values we write into this * field. * @@ -4205,26 +4204,6 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) -/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is -* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for -* the head page of compound page and bit 1 for pfmemalloc page, as well as the -* bits used for the DMA index. page_is_pfmemalloc() is checked in -* __page_pool_put_page() to avoid recycling the pfmemalloc page. -*/ -#define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) - -#ifdef CONFIG_PAGE_POOL -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return (page->pp_magic &PP_MAGIC_MASK ) ==PP_SIGNATURE ; -} -#else -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return false; -} -#endif -#define PAGE_SNAPSHOT_FAITHFUL (1 << 0)#define PAGE_SNAPSHOT_PG_BUDDY (1 << 1)#define PAGE_SNAPSHOT_PG_IDLE (1 << 2)include/linux/page-flags.h +6
-0@@ -933,6 +933,7 @@ enum pagetype { PGTY_zsmalloc =0xf6 , PGTY_unaccepted =0xf7 , PGTY_large_kmalloc =0xf8 , + PGTY_netpp =0xf9 , PGTY_mapcount_underflow = 0xff };@@ -1077,6 +1078,11 @@ PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) PAGE_TYPE_OPS(Unaccepted, unaccepted, unaccepted)FOLIO_TYPE_OPS (large_kmalloc, large_kmalloc) +/* +* Marks page_pool allocated pages. + */ +PAGE_TYPE_OPS (Netpp, netpp, netpp) +/** * PageHuge - Determine if the page belongs to hugetlbfs * @page: The page to test.
<snip>
Quoted 24 lines
mm/page_alloc.c +0
-3@@ -1042,7 +1042,6 @@ static inline bool page_expected_state(struct page *page,#ifdef CONFIG_MEMCG page->memcg_data | #endif -page_pool_page_is_pp (page) | (page->flags & check_flags)))return false;@@ -1069,8 +1068,6 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)if (unlikely (page->memcg_data)) bad_reason ="page still charged to cgroup" ;#endif -if (unlikely (page_pool_page_is_pp (page))) - bad_reason ="page_pool leak" ;return bad_reason; }@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ;
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page, · line 1386
Quoted 10 lines
mm/page_alloc.c +3
-1} -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNetpp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }if (is_check_pages_enabled ()) {if (free_page_is_bad (page))
The mm part looks good to me.
Best Regards,
Yan, Zi
Jakub Kicinski
maintainerQuoted 1 line · On Tue, 29 Jul 2025 20:02:10 +0900 Byungchul Park wrote:
[PATCH linux-next v3] mm,
page_pool: introduce a new page type for page pool in page type
linux-next does not accept patches. This has to go either via networking or MM.
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page, · line 1379
Quoted 2 lines
mm/page_alloc.c +1
-1-if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) {
Maybe add :
/* networking expects to clear its page type before releasing */
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page,
Quoted 9 lines
mm/page_alloc.c +3
-1+WARN_ON_ONCE (PageNetpp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }static inline bool netmem_is_pp (netmem_ref netmem) { -return (netmem_get_pp_magic (netmem) &PP_MAGIC_MASK ) ==PP_SIGNATURE ; +/* Use ->pp for net_iov to identify if it's pp,
Please try to use precise language, this code is confusing as is. net_iov may _belong_ to a page pool.
* which requires that non-pp net_iov should have ->pp NULL'd.
I don't think this adds any information.
net/core/netmem_priv.h static inline unsigned long netmem_get_pp_magic(netmem_ref netmem) · line 19
Quoted 5 lines
net/core/netmem_priv.h +5
-0+*/ +if (netmem_is_net_iov (netmem)) +return !!__netmem_clear_lsb (netmem)->pp; + +/* For system memory, page type bit in struct page can be used
"page type bit" -> "page type", it's not a bit.
net/core/netmem_priv.h static inline unsigned long netmem_get_pp_magic(netmem_ref netmem) · line 20
Quoted 1 line
net/core/netmem_priv.h +1
-0+* to identify if it's pp.
... to identify pages which belong to a page pool.
Quoted 18 lines
net/core/netmem_priv.h +2
-0+*/ +return PageNetpp (__netmem_to_page (netmem)); }static inline void netmem_set_pp (netmem_ref netmem,struct page_pool *pool)net/core/page_pool.c +0
-1@@ -654,7 +654,6 @@ s32 page_pool_inflight(const struct page_pool *pool, bool strict)void page_pool_set_pp_info (struct page_pool *pool,netmem_ref netmem) {netmem_set_pp (netmem, pool); -netmem_or_pp_magic (netmem,PP_SIGNATURE );/* Ensuring all pages have been split into one fragment initially: * page_pool_set_pp_info() is only called once for every page when it
net/core/page_pool.c void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem) · line 668
Quoted 5 lines
net/core/page_pool.c +2
-0@@ -665,12 +664,19 @@ void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem)page_pool_fragment_netmem (netmem,1 );if (pool->has_init_callback) pool->slow.init_callback (netmem, pool->slow.init_arg); + +/* If it's page-backed */
Please don't add obvious comments.
Quoted 2 lines
net/core/page_pool.c +2
-0+if (!netmem_is_net_iov (netmem)) +__SetPageNetpp (__netmem_to_page (netmem));
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Tue, 29 Jul 2025 20:02:10 +0900 Byungchul Park wrote:
[PATCH linux-next v3] mm,
page_pool: introduce a new page type for page pool in page typelinux-next does not accept patches. This has to go either via networking or MM.
Yeah. That's what I found. Thanks for the confirmation.
Quoted 6 lines
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page, · line 1379
Quoted 2 lines
mm/page_alloc.c +1
-1-if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) {Maybe add :
/* networking expects to clear its page type before releasing */
I will.
Quoted 10 lines
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page,
Quoted 9 lines
mm/page_alloc.c +3
-1+WARN_ON_ONCE (PageNetpp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }static inline bool netmem_is_pp (netmem_ref netmem) { -return (netmem_get_pp_magic (netmem) &PP_MAGIC_MASK ) ==PP_SIGNATURE ; +/* Use ->pp for net_iov to identify if it's pp,
Quoted 4 lines
Please try to use precise language, this code is confusing as is.
net_iovmay _belong_ to a page pool.* which requires that non-pp
net_iovshould have ->pp NULL'd.
Thank you. I will.
Quoted 8 lines
I don't think this adds any information.
net/core/netmem_priv.h static inline unsigned long netmem_get_pp_magic(netmem_ref netmem) · line 19
Quoted 5 lines
net/core/netmem_priv.h +5
-0+*/ +if (netmem_is_net_iov (netmem)) +return !!__netmem_clear_lsb (netmem)->pp; + +/* For system memory, page type bit in struct page can be used
Quoted 5 lines
"page type bit" -> "page type", it's not a bit.
Quoted 1 line
+ * to identify if it's pp.
... to identify pages which belong to a page pool.
I will.
Quoted 15 lines
Quoted 15 lines
net/core/netmem_priv.h +2
-0+*/ +return PageNetpp (__netmem_to_page (netmem)); }static inline void netmem_set_pp (netmem_ref netmem,struct page_pool *pool)net/core/page_pool.c +0
-1@@ -654,7 +654,6 @@ s32 page_pool_inflight(const struct page_pool *pool, bool strict)void page_pool_set_pp_info (struct page_pool *pool,netmem_ref netmem) {netmem_set_pp (netmem, pool); -netmem_or_pp_magic (netmem,PP_SIGNATURE );
Quoted 10 lines
net/core/page_pool.c void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem) · line 668
Quoted 8 lines
net/core/page_pool.c +2
-0/* Ensuring all pages have been split into one fragment initially: * page_pool_set_pp_info() is only called once for every page when it @@ -665,12 +664,19 @@ void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem)page_pool_fragment_netmem (netmem,1 );if (pool->has_init_callback) pool->slow.init_callback (netmem, pool->slow.init_arg); + +/* If it's page-backed */ Please don't add obvious comments.
I added the comment since it's _not_ obvious. !net_iov means it's not net_iov, not it's page-backed. However, since you, as the maintainer, are okay, I will remove it. Thanks.
Byungchul
Quoted 2 lines
Quoted 2 lines
net/core/page_pool.c +2
-0+if (!netmem_is_net_iov (netmem)) +__SetPageNetpp (__netmem_to_page (netmem));
Hi,
Quoted 3 lines · On Tue, 29 Jul 2025 20:02:10 +0900 Byungchul Park <[email protected]> wrote:
Changes from v2:
1. Rebase on linux-next as of Jul 29.
Why are you basing development work in linux-next. That is a constantly rebasing tree. Please base your work on some stable tree.
Signature · 2 lines
Cheers, Stephen Rothwell
Quoted 9 lines · Stephen Rothwell
Hi,
Quoted 3 lines · On Tue, 29 Jul 2025 20:02:10 +0900 Byungchul Park <[email protected]> wrote:
Changes from v2:
1. Rebase on linux-next as of Jul 29.Why are you basing development work in linux-next. That is a constantly rebasing tree. Please base your work on some stable tree.
Sorry about the confusing. I misunderstood how to work for patches based on linux-next.
However, basing on linux-next is still required for this work since more than one subsystem is involved, and asked by David Hildenbrand:
https://lore.kernel.org/all/[email protected]/
I will base on linux-next and work aiming at either network or mm tree.
Byungchul
Quoted 3 lines
Signature · 2 lines
Cheers, Stephen Rothwell
Quoted 14 lines · Byungchul Park
Quoted 9 lines · Stephen Rothwell
Hi,
Quoted 3 lines · On Tue, 29 Jul 2025 20:02:10 +0900 Byungchul Park <[email protected]> wrote:
Changes from v2:
1. Rebase on linux-next as of Jul 29.Why are you basing development work in linux-next. That is a constantly rebasing tree. Please base your work on some stable tree.
Sorry about the confusing. I misunderstood how to work for patches based on linux-next.
Quoted 6 lines
However, basing on linux-next is still required for this work since more than one subsystem is involved, and asked by David Hildenbrand:
https://lore.kernel.org/all/[email protected]/I will base on linux-next and work aiming at either network or mm tree.
I think this is the key part: there is nothing wrong on temporarily basing your stuff on linux-next, while we are waiting for this merge window to end and relevant patches showing up in either tree after the rebase.
You should mention below the "---" your intentions like "This patch is supposed to go via the XXX tree, but it currently also depends on patches in the YYY tree. For now, this patch is based on linux-next, but will apply cleanly (or get rebased) after XXX was rebased."
Also, probably best to indicate the patch as being RFC (instead of linux-next) until there is a stable "base".
Signature · 3 lines
Cheers, David / dhildenb
Pavel Begunkov
maintainerQuoted 15 lines · Byungchul Park
Changes from v2:
1. Rebase on linux-next as of Jul 29.
2. Skip 'niov->pp= NULL' when it's allocated using__GFP_ZERO.
3. Change trivial coding style. (feedbacked by Mina)
4. Add Co-developed-by, Acked-by, and Reviewed-by properly. Thanks to all.Changes from v1:
1. Rebase on linux-next.
2. Initializenet_iov->pp= NULL when allocatingnet_iovinnet_devmem_bind_dmabuf()andio_zcrx_create_area().
3. Use ->pp fornet_iovto identify if it's pp rather than always considernet_iovas pp.
4. Add Suggested-by: David Hildenbrand <[email protected]>.
Quoted 5 lines
---8<---
From88bcb9907a0cef65a9c0adf35e144f9eb67e0542Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 29 Jul 2025 19:49:44 +0900
Subject: [PATCH linux-next v3] mm,page_pool: introduce a new page type for page pool in page type
That will conflict with "netmem: replace __netmem_clear_lsb() with netmem_to_nmdesc()", it'll need some coordination.
Signature · 1 line
Pavel Begunkov
Quoted 16 lines · Pavel Begunkov
Quoted 15 lines · Byungchul Park
Changes from v2:
1. Rebase on linux-next as of Jul 29.
2. Skip 'niov->pp= NULL' when it's allocated using__GFP_ZERO.
3. Change trivial coding style. (feedbacked by Mina)
4. Add Co-developed-by, Acked-by, and Reviewed-by properly. Thanks to all.Changes from v1:
1. Rebase on linux-next.
2. Initializenet_iov->pp= NULL when allocatingnet_iovinnet_devmem_bind_dmabuf()andio_zcrx_create_area().
3. Use ->pp fornet_iovto identify if it's pp rather than always considernet_iovas pp.
4. Add Suggested-by: David Hildenbrand <[email protected]>.
Quoted 8 lines
Quoted 5 lines
---8<---
From88bcb9907a0cef65a9c0adf35e144f9eb67e0542Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 29 Jul 2025 19:49:44 +0900
Subject: [PATCH linux-next v3] mm,page_pool: introduce a new page type for page pool in page typeThat will conflict with "netmem: replace
__netmem_clear_lsb()withnetmem_to_nmdesc()", it'll need some coordination.
Indeed. It'd better work on top of "netmem: replace __netmem_clear_lsb() with netmem_to_nmdesc()" then. You said you are going to take the patch. Please lemme know the progress so that I can track and re-work on this.
Byungchul
Quoted 3 lines
--
Pavel Begunkov
Quoted 30 lines · Byungchul Park
Changes from v2:
1. Rebase on linux-next as of Jul 29.
2. Skip 'niov->pp= NULL' when it's allocated using__GFP_ZERO.
3. Change trivial coding style. (feedbacked by Mina)
4. Add Co-developed-by, Acked-by, and Reviewed-by properly. Thanks to all.Changes from v1:
1. Rebase on linux-next.
2. Initializenet_iov->pp= NULL when allocatingnet_iovinnet_devmem_bind_dmabuf()andio_zcrx_create_area().
3. Use ->pp fornet_iovto identify if it's pp rather than always considernet_iovas pp.
4. Add Suggested-by: David Hildenbrand <[email protected]>.---8<---
Quoted 1 line
From
88bcb9907a0cef65a9c0adf35e144f9eb67e0542Mon Sep 17 00:00:00 2001From: Byungchul Park <[email protected]>
Date: Tue, 29 Jul 2025 19:49:44 +0900
Subject: [PATCH linux-next v3] mm,page_pool: introduce a new page type for page pool in page type->pp_magic field in struct page is current used to identify if a page belongs to a page pool. However, ->pp_magic will be removed and page type bit in struct page e.i.
PGTY_netppcan be used for that purpose.Introduce and use the page type APIs e.g.
PageNetpp(),__SetPageNetpp(), and__ClearPageNetpp()instead, and remove the existing APIs accessing ->pp_magic e.g.page_pool_page_is_pp(),netmem_or_pp_magic(), andnetmem_clear_pp_magic().
Quoted 8 lines
For
net_iov, use ->pp to identify if it's pp, with making sure that ->pp is NULL for non-ppnet_iov.This work was inspired by the following link:
[1] https://lore.kernel.org/all/[email protected]/
While at it, move the sanity check for page pool to on free.
Hi, Andrew and Jakub
I will spin the next one with some modified, once the following patch, [1], gets merged.
This is about both mm and network. I have no idea which tree should I aim at between mm tree and network tree? I prefer the network tree tho.
However, it's totally fine regardless of what it would be. Suggestion?
Byungchul
Quoted 247 lines
Suggested-by David Hildenbrand <[email protected]>Co-developed-by Pavel Begunkov <[email protected]>Signed-off-by Pavel Begunkov <[email protected]>Signed-off-by Byungchul Park <[email protected]>Reviewed-by Mina Almasry <[email protected]>--- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 2 +- include/linux/mm.h | 27 +++---------------- include/linux/page-flags.h | 6 +++++ include/net/netmem.h | 2 +- io_uring/zcrx.c | 4 +++ mm/page_alloc.c | 7 +++-- net/core/devmem.c | 1 + net/core/netmem_priv.h | 23 +++++++--------- net/core/page_pool.c | 10 +++++-- 9 files changed, 37 insertions(+), 45 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +1
-1@@ -707,7 +707,7 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq, xdpi =mlx5e_xdpi_fifo_pop (xdpi_fifo); page = xdpi.page.page; -/* No need to check page_pool_page_is_pp() as we +/* No need to check PageNetpp() as we * know this is a page_pool page. */ page_pool_recycle_direct(pp_page_to_nmdesc(page)->pp,include/linux/mm.h +3
-24@@ -4171,10 +4171,9 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);* DMA mapping IDs for page_pool * * When DMA-mapping a page, page_pool allocates an ID (from an xarray) and -* stashes it in the upper bits of page->pp_magic. We always want to be able to -* unambiguously identify page pool pages (using page_pool_page_is_pp()). Non-PP -* pages can have arbitrary kernel pointers stored in the same field as pp_magic -* (since it overlaps with page->lru.next), so we must ensure that we cannot +* stashes it in the upper bits of page->pp_magic. Non-PP pages can have +* arbitrary kernel pointers stored in the same field as pp_magic (since +* it overlaps with page->lru.next), so we must ensure that we cannot * mistake a valid kernel pointer with any of the values we write into this * field. * @@ -4205,26 +4204,6 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) -/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is -* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for -* the head page of compound page and bit 1 for pfmemalloc page, as well as the -* bits used for the DMA index. page_is_pfmemalloc() is checked in -* __page_pool_put_page() to avoid recycling the pfmemalloc page. -*/ -#define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) - -#ifdef CONFIG_PAGE_POOL -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return (page->pp_magic &PP_MAGIC_MASK ) ==PP_SIGNATURE ; -} -#else -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return false; -} -#endif -#define PAGE_SNAPSHOT_FAITHFUL (1 << 0)#define PAGE_SNAPSHOT_PG_BUDDY (1 << 1)#define PAGE_SNAPSHOT_PG_IDLE (1 << 2)include/linux/page-flags.h +6
-0@@ -933,6 +933,7 @@ enum pagetype { PGTY_zsmalloc =0xf6 , PGTY_unaccepted =0xf7 , PGTY_large_kmalloc =0xf8 , + PGTY_netpp =0xf9 , PGTY_mapcount_underflow = 0xff };@@ -1077,6 +1078,11 @@ PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) PAGE_TYPE_OPS(Unaccepted, unaccepted, unaccepted)FOLIO_TYPE_OPS (large_kmalloc, large_kmalloc) +/* +* Marks page_pool allocated pages. + */ +PAGE_TYPE_OPS (Netpp, netpp, netpp) +/** * PageHuge - Determine if the page belongs to hugetlbfs * @page: The page to test. include/net/netmem.h +1
-1@@ -298,7 +298,7 @@ static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)*/ #define pp_page_to_nmdesc (p) \ ({ \ - DEBUG_NET_WARN_ON_ONCE(!page_pool_page_is_pp(p)); \ + DEBUG_NET_WARN_ON_ONCE(!PageNetpp(p)); \ __pp_page_to_nmdesc(p); \ })io_uring/zcrx.c +4
-0@@ -444,6 +444,10 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq, area->freelist[i] = i;atomic_set (&area->user_refs[i],0 ); niov->type =NET_IOV_IOURING ; + +/* niov->pp is already initialized to NULL by +* kvmalloc_array(__GFP_ZERO). +*/ } area->free_count = nr_iovs;mm/page_alloc.c +3
-4@@ -1042,7 +1042,6 @@ static inline bool page_expected_state(struct page *page,#ifdef CONFIG_MEMCG page->memcg_data | #endif -page_pool_page_is_pp (page) | (page->flags & check_flags)))return false;@@ -1069,8 +1068,6 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)if (unlikely (page->memcg_data)) bad_reason ="page still charged to cgroup" ;#endif -if (unlikely (page_pool_page_is_pp (page))) - bad_reason ="page_pool leak" ;return bad_reason; }@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ; } -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNetpp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }if (is_check_pages_enabled ()) {if (free_page_is_bad (page))net/core/devmem.c +1
-0@@ -285,6 +285,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, niov = &owner->area.niovs[i]; niov->type =NET_IOV_DMABUF ; niov->owner = &owner->area; + niov->pp =NULL ;page_pool_set_dma_addr_netmem (net_iov_to_netmem (niov),net_devmem_get_dma_addr (niov));if (direction ==DMA_TO_DEVICE )net/core/netmem_priv.h +10
-13@@ -8,21 +8,18 @@ static inline unsigned long netmem_get_pp_magic(netmem_ref netmem)return __netmem_clear_lsb (netmem)->pp_magic & ~PP_DMA_INDEX_MASK ; } -static inline void netmem_or_pp_magic (netmem_ref netmem,unsigned long pp_magic) -{ -__netmem_clear_lsb (netmem)->pp_magic |= pp_magic; -} - -static inline void netmem_clear_pp_magic (netmem_ref netmem) -{ -WARN_ON_ONCE (__netmem_clear_lsb (netmem)->pp_magic &PP_DMA_INDEX_MASK ); - -__netmem_clear_lsb (netmem)->pp_magic =0 ; -} -static inline bool netmem_is_pp (netmem_ref netmem) { -return (netmem_get_pp_magic (netmem) &PP_MAGIC_MASK ) ==PP_SIGNATURE ; +/* Use ->pp for net_iov to identify if it's pp, which requires +* that non-pp net_iov should have ->pp NULL'd. +*/ +if (netmem_is_net_iov (netmem)) +return !!__netmem_clear_lsb (netmem)->pp; + +/* For system memory, page type bit in struct page can be used +* to identify if it's pp. +*/ +return PageNetpp (__netmem_to_page (netmem)); }static inline void netmem_set_pp (netmem_ref netmem,struct page_pool *pool)net/core/page_pool.c +8
-2@@ -654,7 +654,6 @@ s32 page_pool_inflight(const struct page_pool *pool, bool strict)void page_pool_set_pp_info (struct page_pool *pool,netmem_ref netmem) {netmem_set_pp (netmem, pool); -netmem_or_pp_magic (netmem,PP_SIGNATURE );/* Ensuring all pages have been split into one fragment initially: * page_pool_set_pp_info() is only called once for every page when it @@ -665,12 +664,19 @@ void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem)page_pool_fragment_netmem (netmem,1 );if (pool->has_init_callback) pool->slow.init_callback (netmem, pool->slow.init_arg); + +/* If it's page-backed */ +if (!netmem_is_net_iov (netmem)) +__SetPageNetpp (__netmem_to_page (netmem)); }void page_pool_clear_pp_info (netmem_ref netmem) { -netmem_clear_pp_magic (netmem);netmem_set_pp (netmem,NULL ); + +/* If it's page-backed */ +if (!netmem_is_net_iov (netmem)) +__ClearPageNetpp (__netmem_to_page (netmem)); } static __always_inline void __page_pool_release_netmem_dma(struct page_pool *pool,base-commit:
54efec8782214652b331c50646013f8526570e8dSignature · 1 line
2.17.1
Pavel Begunkov
maintainerQuoted 1 line · Byungchul Park
On Tue, Jul 29, 2025 at 08:02:10PM +0900, Byungchul Park wrote:
...>> For net_iov, use ->pp to identify if it's pp, with making sure that ->pp
Quoted 13 lines
Quoted 7 lines
is NULL for non-pp
net_iov.This work was inspired by the following link:
[1] https://lore.kernel.org/all/[email protected]/
While at it, move the sanity check for page pool to on free.
Hi, Andrew and Jakub
I will spin the next one with some modified, once the following patch, [1], gets merged.
Quoted 6 lines
[1] https://lore.kernel.org/all/a8643abedd208138d3d550db71631d5a2e4168d1.1754929026.git.asml.silence@gmail.com/This is about both mm and network. I have no idea which tree should I aim at between mm tree and network tree? I prefer the network tree tho.
However, it's totally fine regardless of what it would be. Suggestion?
It should go to net, there will be enough of conflicts otherwise. mm maintainers, do you like it as a shared branch or can it just go through the net tree?
It'd also be better to split mm and net changes into a separate patches. A patch I had before, it might need a rebase though.
From: Pavel Begunkov <[email protected]>
Date: Thu, 17 Jul 2025 11:46:21 +0100
Subject: [PATCH] mm: introduce a page type for page pool
Page pool currently uses ->pp_magic aliased with lru.next to check whether a page belongs to it. Add a new page type, a later patch will convert page pool to use it.
--- include/linux/mm.h | 20 -------------------- include/linux/page-flags.h | 6 ++++++ mm/page_alloc.c | 7 +++---- 3 files changed, 9 insertions(+), 24 deletions(-)
include/linux/mm.h +0 -20
@@ -4205,26 +4205,6 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) -/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is -* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for -* the head page of compound page and bit 1 for pfmemalloc page, as well as the -* bits used for the DMA index. page_is_pfmemalloc() is checked in -* __page_pool_put_page() to avoid recycling the pfmemalloc page. -*/ -#define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) - -#ifdef CONFIG_PAGE_POOL -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return (page->pp_magic &PP_MAGIC_MASK ) ==PP_SIGNATURE ; -} -#else -static inline bool page_pool_page_is_pp (const struct page *page) -{ -return false; -} -#endif -#define PAGE_SNAPSHOT_FAITHFUL (1 << 0)#define PAGE_SNAPSHOT_PG_BUDDY (1 << 1)#define PAGE_SNAPSHOT_PG_IDLE (1 << 2)
include/linux/page-flags.h +6 -0
@@ -933,6 +933,7 @@ enum pagetype { PGTY_zsmalloc =0xf6 , PGTY_unaccepted =0xf7 , PGTY_large_kmalloc =0xf8 , + PGTY_net_pp =0xf9 , PGTY_mapcount_underflow = 0xff };
@@ -1077,6 +1078,11 @@ PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) PAGE_TYPE_OPS(Unaccepted, unaccepted, unaccepted)FOLIO_TYPE_OPS (large_kmalloc, large_kmalloc) +/* +* Marks pages allocated by page_pool. See (see net/core/page_pool.c) + */ +PAGE_TYPE_OPS (Net_pp, net_pp, net_pp) +/** * PageHuge - Determine if the page belongs to hugetlbfs * @page: The page to test.
mm/page_alloc.c +3 -4
@@ -1042,7 +1042,6 @@ static inline bool page_expected_state(struct page *page,#ifdef CONFIG_MEMCG page->memcg_data | #endif -page_pool_page_is_pp (page) | (page->flags & check_flags)))return false;
@@ -1069,8 +1068,6 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)if (unlikely (page->memcg_data)) bad_reason ="page still charged to cgroup" ;#endif -if (unlikely (page_pool_page_is_pp (page))) - bad_reason ="page_pool leak" ;return bad_reason; }
@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ; } -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNet_pp (page));/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ; + }if (is_check_pages_enabled ()) {if (free_page_is_bad (page))
Signature · 1 line
Pavel Begunkov
Jakub Kicinski
maintainerQuoted 3 lines · On Wed, 13 Aug 2025 12:18:56 +0100 Pavel Begunkov wrote:
It should go to net, there will be enough of conflicts otherwise. mm maintainers, do you like it as a shared branch or can it just go through the net tree?
Looks like this is 100% in mm, and the work is not urgent at all. So I'm happy for Andrew to take this, and dependent patches (if any) can come in the next cycle.
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page, · line 1380
Quoted 7 lines
mm/page_alloc.c +2
-1@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ; } -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNet_pp (page));
I guess my ask to add a comment here got ignored?
Quoted 2 lines
mm/page_alloc.c +0
-0/* Reset the page_type (which overlays _mapcount) */ page->page_type =UINT_MAX ;
Pavel Begunkov
maintainerQuoted 6 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 13 Aug 2025 12:18:56 +0100 Pavel Begunkov wrote:
It should go to net, there will be enough of conflicts otherwise. mm maintainers, do you like it as a shared branch or can it just go through the net tree?
Looks like this is 100% in mm, and the work is not urgent at all.
There is a slight dependency in rc1, but we should be able to massage it to be mm only.
Quoted 2 lines
So I'm happy for Andrew to take this, and dependent patches (if any) can come in the next cycle.
Yeah, good option. It'd be a good idea to cut the diff down to avoid removing the relevant mm page state checks until the next cycle.
Quoted 9 lines
mm/page_alloc.c __always_inline bool free_pages_prepare(struct page *page, · line 1380
Quoted 7 lines
mm/page_alloc.c +2
-1@@ -1379,9 +1376,11 @@ __always_inline bool free_pages_prepare(struct page *page,mod_mthp_stat (order,MTHP_STAT_NR_ANON ,-1 ); folio->mapping =NULL ; } -if (unlikely (page_has_type (page))) +if (unlikely (page_has_type (page))) { +WARN_ON_ONCE (PageNet_pp (page));I guess my ask to add a comment here got ignored?
It's an old patch attached as a point of reference. Any actual submission surely will need to follow up on the reviews.
Signature · 1 line
Pavel Begunkov