Skip to content

Commit 25a912b

Browse files
tohojogregkh
authored andcommitted
page_pool: Move pp_magic check into helper functions
[ Upstream 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 65b3f76 commit 25a912b

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
@@ -706,8 +706,8 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq,
706706
xdpi = mlx5e_xdpi_fifo_pop(xdpi_fifo);
707707
page = xdpi.page.page;
708708

709-
/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
710-
* as we know this is a page_pool page.
709+
/* No need to check page_pool_page_is_pp() as we
710+
* know this is a page_pool page.
711711
*/
712712
page_pool_recycle_direct(page->pp, page);
713713
} while (++n < num);

include/linux/mm.h

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

4246+
/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is
4247+
* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for
4248+
* the head page of compound page and bit 1 for pfmemalloc page.
4249+
* page_is_pfmemalloc() is checked in __page_pool_put_page() to avoid recycling
4250+
* the pfmemalloc page.
4251+
*/
4252+
#define PP_MAGIC_MASK ~0x3UL
4253+
4254+
#ifdef CONFIG_PAGE_POOL
4255+
static inline bool page_pool_page_is_pp(struct page *page)
4256+
{
4257+
return (page->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE;
4258+
}
4259+
#else
4260+
static inline bool page_pool_page_is_pp(struct page *page)
4261+
{
4262+
return false;
4263+
}
4264+
#endif
4265+
42464266
#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
@@ -925,11 +925,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)
925925
skb_get(list);
926926
}
927927

928-
static bool is_pp_netmem(netmem_ref netmem)
929-
{
930-
return (netmem_get_pp_magic(netmem) & ~0x3UL) == PP_SIGNATURE;
931-
}
932-
933928
int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
934929
unsigned int headroom)
935930
{
@@ -1027,14 +1022,7 @@ bool napi_pp_put_page(netmem_ref netmem)
10271022
{
10281023
netmem = netmem_compound_head(netmem);
10291024

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

10401028
page_pool_put_full_netmem(netmem_get_pp(netmem), netmem, false);
@@ -1074,7 +1062,7 @@ static int skb_pp_frag_ref(struct sk_buff *skb)
10741062

10751063
for (i = 0; i < shinfo->nr_frags; i++) {
10761064
head_netmem = netmem_compound_head(shinfo->frags[i].netmem);
1077-
if (likely(is_pp_netmem(head_netmem)))
1065+
if (likely(netmem_is_pp(head_netmem)))
10781066
page_pool_ref_netmem(head_netmem);
10791067
else
10801068
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)