From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Ratheesh Kannoth <rkannoth@marvell.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Geethasowjanya Akula <gakula@marvell.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Subbaraya Sundeep Bhatta <sbhatta@marvell.com>,
Sunil Kovvuri Goutham <sgoutham@marvell.com>,
Thomas Gleixner <tglx@linutronix.de>,
Hariprasad Kelam <hkelam@marvell.com>
Subject: Re: RE: [EXT] [BUG] Possible unsafe page_pool usage in octeontx2
Date: Wed, 23 Aug 2023 14:54:48 +0200 [thread overview]
Message-ID: <20230823125448.Q89O9wFB@linutronix.de> (raw)
In-Reply-To: <MWHPR1801MB1918F1D7686BDBC8817E473FD31CA@MWHPR1801MB1918.namprd18.prod.outlook.com>
On 2023-08-23 12:28:58 [+0000], Ratheesh Kannoth wrote:
> > From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> > Sent: Wednesday, August 23, 2023 3:18 PM
> > Subject: [EXT] [BUG] Possible unsafe page_pool usage in octeontx2
> >
> > This breaks in octeontx2 where a worker is used to fill the buffer:
> > otx2_pool_refill_task() -> otx2_alloc_rbuf() -> __otx2_alloc_rbuf() ->
> > otx2_alloc_pool_buf() -> page_pool_alloc_frag().
> >
> As I understand, the problem is due to workqueue may get scheduled on
> other CPU. If we use BOUND workqueue, do you think this problem can be
> solved ?
It would but is still open to less obvious races for instance if the
IRQ/ NAPI is assigned to another CPU while the workqueue is scheduled.
You would have to additional synchronisation to ensure that bad can
happen. This does not make it any simpler nor prettier or serves as a
good example.
I would suggest to stay away from the lock-less buffer if not in NAPI
and feed the pool->ring instead.
> > BH is disabled but the add of a page can still happen while NAPI callback runs
> > on a remote CPU and so corrupting the index/ array.
> >
> > API wise I would suggest to
> >
> > 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() &&
> > 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.
> Could you help me understand where in_softirq() check will break ? If
> we TX a packet (dev_queue_xmit()) in
> Process context on same core, in_serving_softirq() check will prevent
> it from recycling ?
If a check is added to page_pool_alloc_pages() then it will trigger if
you fill the buffer from your ->ndo_open() callback.
Also, if you invoke dev_queue_xmit() from process context. But It will
be added to &pool->ring instead.
Sebastian
next prev parent reply other threads:[~2023-08-23 12:54 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 [this message]
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
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=20230823125448.Q89O9wFB@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hawk@kernel.org \
--cc=hkelam@marvell.com \
--cc=ilias.apalodimas@linaro.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--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).