linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <hawk@kernel.org>
To: "Zi Yan" <ziy@nvidia.com>, "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Horman <horms@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mina Almasry <almasrymina@google.com>,
	Yonglong Liu <liuyonglong@huawei.com>,
	Yunsheng Lin <linyunsheng@huawei.com>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-mm@kvack.org,
	kernel-team <kernel-team@cloudflare.com>
Subject: Re: [PATCH net-next v7 1/2] page_pool: Move pp_magic check into helper functions
Date: Mon, 7 Apr 2025 16:43:50 +0200	[thread overview]
Message-ID: <4d35bda2-d032-49db-bb6e-b1d70f10d436@kernel.org> (raw)
In-Reply-To: <893B4BFD-1FDA-46DE-82D5-9E5CBDD90068@nvidia.com>



On 07/04/2025 16.15, Zi Yan wrote:
> On 7 Apr 2025, at 9:36, Zi Yan wrote:
> 
>> On 7 Apr 2025, at 9:14, Toke Høiland-Jørgensen wrote:
>>
>>> Zi Yan<ziy@nvidia.com>  writes:
>>>
>>>> Resend to fix my signature.
>>>>
>>>> On 7 Apr 2025, at 4:53, Toke Høiland-Jørgensen wrote:
>>>>
>>>>> "Zi Yan"<ziy@nvidia.com>  writes:
>>>>>
>>>>>> On Fri Apr 4, 2025 at 6:18 AM EDT, Toke Høiland-Jørgensen wrote:
>>>>>>> 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<almasrymina@google.com>
>>>>>>> Tested-by: Yonglong Liu<liuyonglong@huawei.com>
>>>>>>> Acked-by: Jesper Dangaard Brouer<hawk@kernel.org>
>>>>>>> Reviewed-by: Ilias Apalodimas<ilias.apalodimas@linaro.org>
>>>>>>> Signed-off-by: Toke Høiland-Jørgensen<toke@redhat.com>
>>>>>>> ---
>>>>>>>   drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c |  4 ++--
>>>>>>>   include/net/page_pool/types.h                    | 18 ++++++++++++++++++
>>>>>>>   mm/page_alloc.c                                  |  9 +++------
>>>>>>>   net/core/netmem_priv.h                           |  5 +++++
>>>>>>>   net/core/skbuff.c                                | 16 ++--------------
>>>>>>>   net/core/xdp.c                                   |  4 ++--
>>>>>>>   6 files changed, 32 insertions(+), 24 deletions(-)
>>>>>>>
>>>>>> <snip>
[...]

>>>>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>>>>>>> index f51aa6051a99867d2d7d8c70aa7c30e523629951..347a3cc2c188f4a9ced85e0d198947be7c503526 100644
>>>>>>> --- a/mm/page_alloc.c
>>>>>>> +++ b/mm/page_alloc.c
>>>>>>> @@ -55,6 +55,7 @@
>>>>>>>   #include <linux/delayacct.h>
>>>>>>>   #include <linux/cacheinfo.h>
>>>>>>>   #include <linux/pgalloc_tag.h>
>>>>>>> +#include <net/page_pool/types.h>
>>>>>>>   #include <asm/div64.h>
>>>>>>>   #include "internal.h"
>>>>>>>   #include "shuffle.h"
>>>>>>> @@ -897,9 +898,7 @@ static inline bool page_expected_state(struct page *page,
>>>>>>>   #ifdef CONFIG_MEMCG
>>>>>>>   			page->memcg_data |
>>>>>>>   #endif
>>>>>>> -#ifdef CONFIG_PAGE_POOL
>>>>>>> -			((page->pp_magic & ~0x3UL) == PP_SIGNATURE) |
>>>>>>> -#endif
>>>>>>> +			page_pool_page_is_pp(page) |
>>>>>>>   			(page->flags & check_flags)))
>>>>>>>   		return false;
>>>>>>>
>>>>>>> @@ -926,10 +925,8 @@ 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
>>>>>>> -#ifdef CONFIG_PAGE_POOL
>>>>>>> -	if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE))
>>>>>>> +	if (unlikely(page_pool_page_is_pp(page)))
>>>>>>>   		bad_reason = "page_pool leak";
>>>>>>> -#endif
>>>>>>>   	return bad_reason;
>>>>>>>   }
>>>>>>>
>>>>>> I wonder if it is OK to make page allocation depend on page_pool from
>>>>>> net/page_pool.
>>>>> Why? It's not really a dependency, just a header include with a static
>>>>> inline function...
>>>> The function is checking, not even modifying, an core mm data structure,
>>>> struct page, which is also used by almost all subsystems. I do not get
>>>> why the function is in net subsystem.
>>> Well, because it's using details of the PP definitions, so keeping it
>>> there nicely encapsulates things. I mean, that's the whole point of
>>> defining a wrapper function - encapsulating the logic 🙂
>>>
>>>>>> Would linux/mm.h be a better place for page_pool_page_is_pp()?
>>>>> That would require moving all the definitions introduced in patch 2,
>>>>> which I don't think is appropriate.
>>>> Why? I do not see page_pool_page_is_pp() or PP_SIGNATURE is used anywhere
>>>> in patch 2.
>>> Look again. Patch 2 redefines PP_MAGIC_MASK in terms of all the other
>>> definitions.
>> OK. Just checked. Yes, the function depends on PP_MAGIC_MASK.
>>
>> But net/types.h has a lot of unrelated page_pool functions and data structures
>> mm/page_alloc.c does not care about. Is there a way of moving page_pool_page_is_pp()
>> and its dependency to a separate header and including that in mm/page_alloc.c?
>>
>> Looking at the use of page_pool_page_is_pp() in mm/page_alloc.c, it seems to be
>> just error checking. Why can't page_pool do the error checking?
 >
> Or just remove page_pool_page_is_pp() in mm/page_alloc.c. Has it really been used?

We have actually used this at Cloudflare to catch some page_pool bugs.
And this have been backported to our 6.1 and 6.6 kernels and we have
enabled needed config CONFIG_DEBUG_VM (which we measured have low enough
overhead to enable in production).  AFAIK this is also enabled for our
6.12 kernels.

--Jesper



  reply	other threads:[~2025-04-07 14:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04 10:18 [PATCH net-next v7 0/2] Fix late DMA unmap crash for page pool Toke Høiland-Jørgensen
2025-04-04 10:18 ` [PATCH net-next v7 1/2] page_pool: Move pp_magic check into helper functions Toke Høiland-Jørgensen
2025-04-06 18:56   ` Zi Yan
2025-04-07  8:53     ` Toke Høiland-Jørgensen
2025-04-07 11:53       ` Zi Yan
2025-04-07 12:24       ` Zi Yan
2025-04-07 13:14         ` Toke Høiland-Jørgensen
2025-04-07 13:36           ` Zi Yan
2025-04-07 14:15             ` Zi Yan
2025-04-07 14:43               ` Jesper Dangaard Brouer [this message]
2025-04-07 15:50                 ` Zi Yan
2025-04-07 16:05                   ` Toke Høiland-Jørgensen
2025-04-07 16:06                     ` Zi Yan
2025-04-04 10:18 ` [PATCH net-next v7 2/2] page_pool: Track DMA-mapped pages and unmap them when destroying the pool Toke Høiland-Jørgensen
2025-04-04 15:55   ` Alexander Lobakin
2025-04-04 16:14     ` Alexander Lobakin
2025-04-05 12:50       ` Toke Høiland-Jørgensen
2025-04-07 11:26         ` Yunsheng Lin
2025-04-07 11:49           ` Toke Høiland-Jørgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d35bda2-d032-49db-bb6e-b1d70f10d436@kernel.org \
    --to=hawk@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=asml.silence@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=toke@redhat.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).