[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87sekpmbmg.fsf@toke.dk>
Date: Wed, 28 May 2025 09:35:03 +0200
From: Toke Høiland-Jørgensen <toke@...hat.com>
To: Byungchul Park <byungchul@...com>
Cc: Mina Almasry <almasrymina@...gle.com>, willy@...radead.org,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
kernel_team@...ynix.com, kuba@...nel.org, ilias.apalodimas@...aro.org,
harry.yoo@...cle.com, hawk@...nel.org, akpm@...ux-foundation.org,
davem@...emloft.net, john.fastabend@...il.com, andrew+netdev@...n.ch,
asml.silence@...il.com, tariqt@...dia.com, edumazet@...gle.com,
pabeni@...hat.com, saeedm@...dia.com, leon@...nel.org, ast@...nel.org,
daniel@...earbox.net, david@...hat.com, lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com, vbabka@...e.cz, rppt@...nel.org,
surenb@...gle.com, mhocko@...e.com, horms@...nel.org,
linux-rdma@...r.kernel.org, bpf@...r.kernel.org, vishal.moola@...il.com
Subject: Re: [PATCH 12/18] page_pool: use netmem APIs to access
page->pp_magic in page_pool_page_is_pp()
Byungchul Park <byungchul@...com> writes:
> On Mon, May 26, 2025 at 11:54:33AM +0200, Toke Høiland-Jørgensen wrote:
>> Byungchul Park <byungchul@...com> writes:
>>
>> > On Mon, May 26, 2025 at 10:40:30AM +0200, Toke Høiland-Jørgensen wrote:
>> >> Byungchul Park <byungchul@...com> writes:
>> >>
>> >> > On Mon, May 26, 2025 at 11:23:07AM +0900, Byungchul Park wrote:
>> >> >> On Fri, May 23, 2025 at 10:21:17AM -0700, Mina Almasry wrote:
>> >> >> > On Thu, May 22, 2025 at 8:26 PM Byungchul Park <byungchul@...com> wrote:
>> >> >> > >
>> >> >> > > To simplify struct page, the effort to seperate its own descriptor from
>> >> >> > > struct page is required and the work for page pool is on going.
>> >> >> > >
>> >> >> > > To achieve that, all the code should avoid accessing page pool members
>> >> >> > > of struct page directly, but use safe APIs for the purpose.
>> >> >> > >
>> >> >> > > Use netmem_is_pp() instead of directly accessing page->pp_magic in
>> >> >> > > page_pool_page_is_pp().
>> >> >> > >
>> >> >> > > Signed-off-by: Byungchul Park <byungchul@...com>
>> >> >> > > ---
>> >> >> > > include/linux/mm.h | 5 +----
>> >> >> > > net/core/page_pool.c | 5 +++++
>> >> >> > > 2 files changed, 6 insertions(+), 4 deletions(-)
>> >> >> > >
>> >> >> > > diff --git a/include/linux/mm.h b/include/linux/mm.h
>> >> >> > > index 8dc012e84033..3f7c80fb73ce 100644
>> >> >> > > --- a/include/linux/mm.h
>> >> >> > > +++ b/include/linux/mm.h
>> >> >> > > @@ -4312,10 +4312,7 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);
>> >> >> > > #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL)
>> >> >> > >
>> >> >> > > #ifdef CONFIG_PAGE_POOL
>> >> >> > > -static inline bool page_pool_page_is_pp(struct page *page)
>> >> >> > > -{
>> >> >> > > - return (page->pp_magic & PP_MAGIC_MASK) == PP_SIGNATURE;
>> >> >> > > -}
>> >> >> >
>> >> >> > I vote for keeping this function as-is (do not convert it to netmem),
>> >> >> > and instead modify it to access page->netmem_desc->pp_magic.
>> >> >>
>> >> >> Once the page pool fields are removed from struct page, struct page will
>> >> >> have neither struct netmem_desc nor the fields..
>> >> >>
>> >> >> So it's unevitable to cast it to netmem_desc in order to refer to
>> >> >> pp_magic. Again, pp_magic is no longer associated to struct page.
>> >> >
>> >> > Options that come across my mind are:
>> >> >
>> >> > 1. use lru field of struct page instead, with appropriate comment but
>> >> > looks so ugly.
>> >> > 2. instead of a full word for the magic, use a bit of flags or use
>> >> > the private field for that purpose.
>> >> > 3. do not check magic number for page pool.
>> >> > 4. more?
>> >>
>> >> I'm not sure I understand Mina's concern about CPU cycles from casting.
>> >> The casting is a compile-time thing, which shouldn't affect run-time
>> >
>> > I didn't mention it but yes.
>> >
>> >> performance as long as the check is kept as an inline function. So it's
>> >> "just" a matter of exposing struct netmem_desc to mm.h so it can use it
>> >
>> > Then.. we should expose net_iov as well, but I'm afraid it looks weird.
>> > Do you think it's okay?
>>
>> Well, it'll be ugly, I grant you that :)
>>
>> Hmm, so another idea could be to add the pp_magic field to the inner
>> union that the lru field is in, and keep the page_pool_page_is_pp()
>> as-is. Then add an assert for offsetof(struct page, pp_magic) ==
>> offsetof(netmem_desc, pp_magic) on the netmem side, which can be removed
>> once the two structs no longer shadow each other?
>>
>> That way you can still get rid of the embedded page_pool struct in
>> struct page, and the pp_magic field will just be a transition thing
>> until things are completely separated...
>
> Or what about to do that as mm folks did in page_is_pfmemalloc()?
>
> static inline bool page_pool_page_is_pp(struct page *page)
> {
> /*
> * XXX: The space of page->lru.next is used as pp_magic in
> * struct netmem_desc overlaying on struct page temporarily.
> * This API will be unneeded shortly. Let's use the ugly but
> * temporal way to access pp_magic until struct netmem_desc has
> * its own instance.
> */
> return (((unsigned long)page->lru.next) & PP_MAGIC_MASK) == PP_SIGNATURE;
> }
Sure, that can work as a temporary solution (maybe with a static assert
somewhere that pp_magic and lru have the same offsetof())?
-Toke
Powered by blists - more mailing lists