From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Jesper Dangaard Brouer <hawk@kernel.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
netdev@vger.kernel.org, Ratheesh Kannoth <rkannoth@marvell.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Geetha sowjanya <gakula@marvell.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Subbaraya Sundeep <sbhatta@marvell.com>,
Sunil Goutham <sgoutham@marvell.com>,
Thomas Gleixner <tglx@linutronix.de>,
hariprasad <hkelam@marvell.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Qingfang DENG <qingfang.deng@siflower.com.cn>
Subject: Re: [BUG] Possible unsafe page_pool usage in octeontx2
Date: Thu, 24 Aug 2023 10:21:29 +0300 [thread overview]
Message-ID: <CAC_iWjLa9r9gxdquECoTFAvqS1Lfx+XuLyf5-yuyaYC=93AVWg@mail.gmail.com> (raw)
In-Reply-To: <d34d4c1c-2436-3d4c-268c-b971c9cc473f@kernel.org>
[...]
> >
> > diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> > index 7ff80b80a6f9f..b50e219470a36 100644
> > --- a/net/core/page_pool.c
> > +++ b/net/core/page_pool.c
> > @@ -612,7 +612,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page,
> > page_pool_dma_sync_for_device(pool, page,
> > dma_sync_size);
> >
> > - if (allow_direct && in_softirq() &&
> > + if (allow_direct && in_serving_softirq() &&
>
> This is the "return/free/put" code path, where we have "allow_direct" as
> a protection in the API. API users are suppose to use
> page_pool_recycle_direct() to indicate this, but as some point we
> allowed APIs to expose 'allow_direct'.
>
> The PP-alloc side is more fragile, and maybe the in_serving_softirq()
> belongs there.
>
> > page_pool_recycle_in_cache(page, pool))
> > return NULL;
> >
> > because the intention (as I understand it) is to be invoked from within
> > the NAPI callback (while softirq is served) and not if BH is just
> > disabled due to a lock or so.
> >
>
> True, and it used-to-be like this (in_serving_softirq), but as Ilias
> wrote it was changed recently. This was to support threaded-NAPI (in
> 542bcea4be866b ("net: page_pool: use in_softirq() instead")), which
> I understood was one of your (Sebastian's) use-cases.
>
>
> > It would also make sense to a add WARN_ON_ONCE(!in_serving_softirq()) to
> > page_pool_alloc_pages() to spot usage outside of softirq. But this will
> > trigger in every driver since the same function is used in the open
> > callback to initially setup the HW.
> >
>
> I'm very open to ideas of detecting this. Since mentioned commit PP is
> open to these kind of miss-uses of the API.
>
> One idea would be to leverage that NAPI napi->list_owner will have been
> set to something else than -1, when this is NAPI context. Getting hold
> of napi object, could be done via pp->p.napi (but as Jakub wrote this is
> opt-in ATM).
I mentioned this earlier, but can't we add the softirq check in
__page_pool_get_cached()?
In theory, when a driver comes up and allocates pages to fill in its
descriptors it will call page_pool_alloc_pages(). That will go
through the slow allocation path, fill up the caches, and return the
last page. After that, most of the allocations will be served by
__page_pool_get_cached(), and this is supposed to be running during
the driver Rx routine which runs under NAPI. So eventually we will
hit that warning.
Thanks
/Ilias
>
> --Jesper
next prev parent reply other threads:[~2023-08-24 7:22 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 9:47 [BUG] Possible unsafe page_pool usage in octeontx2 Sebastian Andrzej Siewior
2023-08-23 11:36 ` Ilias Apalodimas
2023-08-23 13:31 ` Sebastian Andrzej Siewior
2023-08-23 12:28 ` [EXT] " Ratheesh Kannoth
2023-08-23 12:54 ` Sebastian Andrzej Siewior
2023-08-24 2:49 ` Ratheesh Kannoth
2023-08-23 14:49 ` Jakub Kicinski
2023-08-23 19:45 ` Jesper Dangaard Brouer
2023-08-24 7:21 ` Ilias Apalodimas [this message]
2023-08-24 7:42 ` Ilias Apalodimas
2023-08-24 15:26 ` Alexander Lobakin
2023-08-25 13:22 ` Jesper Dangaard Brouer
2023-08-25 13:38 ` Alexander Lobakin
2023-08-25 17:25 ` Jesper Dangaard Brouer
2023-08-26 0:42 ` Jakub Kicinski
2023-08-28 10:59 ` Alexander Lobakin
2023-08-28 12:25 ` Jesper Dangaard Brouer
2023-08-28 11:07 ` Alexander Lobakin
2023-08-28 12:34 ` Jesper Dangaard Brouer
2023-08-28 16:40 ` Sebastian Andrzej Siewior
2023-08-25 13:16 ` Jesper Dangaard Brouer
2023-08-30 7:14 ` [EXT] " Ratheesh Kannoth
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='CAC_iWjLa9r9gxdquECoTFAvqS1Lfx+XuLyf5-yuyaYC=93AVWg@mail.gmail.com' \
--to=ilias.apalodimas@linaro.org \
--cc=aleksander.lobakin@intel.com \
--cc=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hawk@kernel.org \
--cc=hkelam@marvell.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qingfang.deng@siflower.com.cn \
--cc=rkannoth@marvell.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
--cc=tglx@linutronix.de \
/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).