Skip to content

Commit 959fe9b

Browse files
committed
page_pool: Move pp_magic check into helper functions
jira LE-3526 Rebuild_History Non-Buildable kernel-6.12.0-55.20.1.el10_0 commit-author Toke Høiland-Jørgensen <[email protected]> commit cd3c931 Since we are about to stash some more information into the pp_magic field, let's move the magic signature checks into a pair of helper functions so it can be changed in one place. Reviewed-by: Mina Almasry <[email protected]> Tested-by: Yonglong Liu <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit cd3c931) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 39f27f3 commit 959fe9b

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq,
713713
xdpi = mlx5e_xdpi_fifo_pop(xdpi_fifo);
714714
page = xdpi.page.page;
715715

716-
/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
717-
* as we know this is a page_pool page.
716+
/* No need to check page_pool_page_is_pp() as we
717+
* know this is a page_pool page.
718718
*/
719719
page_pool_recycle_direct(page->pp, page);
720720
} while (++n < num);

include/linux/mm.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,4 +4224,24 @@ static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
42244224
}
42254225
#endif /* CONFIG_MEM_ALLOC_PROFILING */
42264226

4227+
/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is
4228+
* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for
4229+
* the head page of compound page and bit 1 for pfmemalloc page.
4230+
* page_is_pfmemalloc() is checked in __page_pool_put_page() to avoid recycling
4231+
* the pfmemalloc page.
4232+
*/
4233+
#define PP_MAGIC_MASK ~0x3UL
4234+
4235+
#ifdef CONFIG_PAGE_POOL
4236+
static inline bool page_pool_page_is_pp(struct page *page)
4237+
{
4238+
return (page->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE;
4239+
}
4240+
#else
4241+
static inline bool page_pool_page_is_pp(struct page *page)
4242+
{
4243+
return false;
4244+
}
4245+
#endif
4246+
42274247
#endif /* _LINUX_MM_H */

mm/page_alloc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,7 @@ static inline bool page_expected_state(struct page *page,
872872
#ifdef CONFIG_MEMCG
873873
page->memcg_data |
874874
#endif
875-
#ifdef CONFIG_PAGE_POOL
876-
((page->pp_magic & ~0x3UL) == PP_SIGNATURE) |
877-
#endif
875+
page_pool_page_is_pp(page) |
878876
(page->flags & check_flags)))
879877
return false;
880878

@@ -901,10 +899,8 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)
901899
if (unlikely(page->memcg_data))
902900
bad_reason = "page still charged to cgroup";
903901
#endif
904-
#ifdef CONFIG_PAGE_POOL
905-
if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE))
902+
if (unlikely(page_pool_page_is_pp(page)))
906903
bad_reason = "page_pool leak";
907-
#endif
908904
return bad_reason;
909905
}
910906

net/core/netmem_priv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ static inline void netmem_clear_pp_magic(netmem_ref netmem)
1818
__netmem_clear_lsb(netmem)->pp_magic = 0;
1919
}
2020

21+
static inline bool netmem_is_pp(netmem_ref netmem)
22+
{
23+
return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE;
24+
}
25+
2126
static inline void netmem_set_pp(netmem_ref netmem, struct page_pool *pool)
2227
{
2328
__netmem_clear_lsb(netmem)->pp = pool;

net/core/skbuff.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)
921921
skb_get(list);
922922
}
923923

924-
static bool is_pp_netmem(netmem_ref netmem)
925-
{
926-
return (netmem_get_pp_magic(netmem) & ~0x3UL) == PP_SIGNATURE;
927-
}
928-
929924
int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
930925
unsigned int headroom)
931926
{
@@ -1023,14 +1018,7 @@ bool napi_pp_put_page(netmem_ref netmem)
10231018
{
10241019
netmem = netmem_compound_head(netmem);
10251020

1026-
/* page->pp_magic is OR'ed with PP_SIGNATURE after the allocation
1027-
* in order to preserve any existing bits, such as bit 0 for the
1028-
* head page of compound page and bit 1 for pfmemalloc page, so
1029-
* mask those bits for freeing side when doing below checking,
1030-
* and page_is_pfmemalloc() is checked in __page_pool_put_page()
1031-
* to avoid recycling the pfmemalloc page.
1032-
*/
1033-
if (unlikely(!is_pp_netmem(netmem)))
1021+
if (unlikely(!netmem_is_pp(netmem)))
10341022
return false;
10351023

10361024
page_pool_put_full_netmem(netmem_get_pp(netmem), netmem, false);
@@ -1070,7 +1058,7 @@ static int skb_pp_frag_ref(struct sk_buff *skb)
10701058

10711059
for (i = 0; i < shinfo->nr_frags; i++) {
10721060
head_netmem = netmem_compound_head(shinfo->frags[i].netmem);
1073-
if (likely(is_pp_netmem(head_netmem)))
1061+
if (likely(netmem_is_pp(head_netmem)))
10741062
page_pool_ref_netmem(head_netmem);
10751063
else
10761064
page_ref_inc(netmem_to_page(head_netmem));

net/core/xdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
381381
page = virt_to_head_page(data);
382382
if (napi_direct && xdp_return_frame_no_direct())
383383
napi_direct = false;
384-
/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
385-
* as mem->type knows this a page_pool page
384+
/* No need to check netmem_is_pp() as mem->type knows this a
385+
* page_pool page
386386
*/
387387
page_pool_put_full_page(page->pp, page, napi_direct);
388388
break;

0 commit comments

Comments
 (0)