Re: [RFC PATCH] net: Fix one page_pool page leak from skb_frag_unref

Mina Almasry
2024-04-26T19:04:02Z

On Fri, Apr 26, 2024 at 7:59 AM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> On Thu, 2024-04-25 at 13:42 -0700, Mina Almasry wrote:
> > On Thu, Apr 25, 2024 at 12:48 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
> > >
> > > On Thu, 2024-04-25 at 12:20 -0700, Mina Almasry wrote:
> > > > diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h
> > > > index 4dcdbe9fbc5f..4c72227dce1b 100644
> > > > --- a/include/linux/skbuff_ref.h
> > > > +++ b/include/linux/skbuff_ref.h
> > > > @@ -31,7 +31,7 @@ static inline bool napi_pp_get_page(struct page *page)
> > > > static inline void skb_page_ref(struct page *page, bool recycle)
> > > > {
> > > > #ifdef CONFIG_PAGE_POOL
> > > > - if (recycle && napi_pp_get_page(page))
> > > > + if (napi_pp_get_page(page))
> > > > return;
> > > > #endif
> > > > get_page(page);
> > > > @@ -69,7 +69,7 @@ static inline void
> > > > skb_page_unref(struct page *page, bool recycle)
> > > > {
> > > > #ifdef CONFIG_PAGE_POOL
> > > > - if (recycle && napi_pp_put_page(page))
> > > > + if (napi_pp_put_page(page))
> > > > return;
> > > > #endif
> > > > put_page(page);
> > > >
> > > >
> > > This is option 2. I thought this would fix everything. But I just tested and
> > > it's not the case: we are now reaching a negative pp_ref_count.
> > >
> I was tired and botched the revert of the code in this RFC when testing.
> Dropping the recycle flag works as expected. Do we need an RFC v2 or is this non
> RFC material?
>
> Thanks,
> Dragos
>

IMO, it needs to be cleaned up to remove the bool recycle flag dead
code, but other than that I think it's good as a non RFC.

To save you some time I did the said clean up and here is a patch
passing make allmodconfig build + checkpatch/kdoc checks + tests on my
end:

https://pastebin.com/bX5KcHTb

I could submit it to the list if you prefer.

FWIW, if this approach shows no regressions, I think we may be able to
deprecate skb->pp_recycle flag entirely, but I can look into that as a
separate change.

--
Thanks,
Mina