Skip to content

Commit cd3c931

Browse files
tohojokuba-moo
authored andcommitted
page_pool: Move pp_magic check into helper functions
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]>
1 parent 452446f commit cd3c931

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

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

include/linux/mm.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,4 +4248,24 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);
42484248
#define VM_SEALED_SYSMAP VM_NONE
42494249
#endif
42504250

4251+
/* Mask used for checking in page_pool_page_is_pp() below. page->pp_magic is
4252+
* OR'ed with PP_SIGNATURE after the allocation in order to preserve bit 0 for
4253+
* the head page of compound page and bit 1 for pfmemalloc page.
4254+
* page_is_pfmemalloc() is checked in __page_pool_put_page() to avoid recycling
4255+
* the pfmemalloc page.
4256+
*/
4257+
#define PP_MAGIC_MASK ~0x3UL
4258+
4259+
#ifdef CONFIG_PAGE_POOL
4260+
static inline bool page_pool_page_is_pp(struct page *page)
4261+
{
4262+
return (page->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE;
4263+
}
4264+
#else
4265+
static inline bool page_pool_page_is_pp(struct page *page)
4266+
{
4267+
return false;
4268+
}
4269+
#endif
4270+
42514271
#endif /* _LINUX_MM_H */

mm/page_alloc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,7 @@ static inline bool page_expected_state(struct page *page,
897897
#ifdef CONFIG_MEMCG
898898
page->memcg_data |
899899
#endif
900-
#ifdef CONFIG_PAGE_POOL
901-
((page->pp_magic & ~0x3UL) == PP_SIGNATURE) |
902-
#endif
900+
page_pool_page_is_pp(page) |
903901
(page->flags & check_flags)))
904902
return false;
905903

@@ -926,10 +924,8 @@ static const char *page_bad_reason(struct page *page, unsigned long flags)
926924
if (unlikely(page->memcg_data))
927925
bad_reason = "page still charged to cgroup";
928926
#endif
929-
#ifdef CONFIG_PAGE_POOL
930-
if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE))
927+
if (unlikely(page_pool_page_is_pp(page)))
931928
bad_reason = "page_pool leak";
932-
#endif
933929
return bad_reason;
934930
}
935931

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
@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)
893893
skb_get(list);
894894
}
895895

896-
static bool is_pp_netmem(netmem_ref netmem)
897-
{
898-
return (netmem_get_pp_magic(netmem) & ~0x3UL) == PP_SIGNATURE;
899-
}
900-
901896
int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
902897
unsigned int headroom)
903898
{
@@ -995,14 +990,7 @@ bool napi_pp_put_page(netmem_ref netmem)
995990
{
996991
netmem = netmem_compound_head(netmem);
997992

998-
/* page->pp_magic is OR'ed with PP_SIGNATURE after the allocation
999-
* in order to preserve any existing bits, such as bit 0 for the
1000-
* head page of compound page and bit 1 for pfmemalloc page, so
1001-
* mask those bits for freeing side when doing below checking,
1002-
* and page_is_pfmemalloc() is checked in __page_pool_put_page()
1003-
* to avoid recycling the pfmemalloc page.
1004-
*/
1005-
if (unlikely(!is_pp_netmem(netmem)))
993+
if (unlikely(!netmem_is_pp(netmem)))
1006994
return false;
1007995

1008996
page_pool_put_full_netmem(netmem_get_pp(netmem), netmem, false);
@@ -1042,7 +1030,7 @@ static int skb_pp_frag_ref(struct sk_buff *skb)
10421030

10431031
for (i = 0; i < shinfo->nr_frags; i++) {
10441032
head_netmem = netmem_compound_head(shinfo->frags[i].netmem);
1045-
if (likely(is_pp_netmem(head_netmem)))
1033+
if (likely(netmem_is_pp(head_netmem)))
10461034
page_pool_ref_netmem(head_netmem);
10471035
else
10481036
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
@@ -438,8 +438,8 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type,
438438
netmem = netmem_compound_head(netmem);
439439
if (napi_direct && xdp_return_frame_no_direct())
440440
napi_direct = false;
441-
/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
442-
* as mem->type knows this a page_pool page
441+
/* No need to check netmem_is_pp() as mem->type knows this a
442+
* page_pool page
443443
*/
444444
page_pool_put_full_netmem(netmem_get_pp(netmem), netmem,
445445
napi_direct);

0 commit comments

Comments
 (0)