netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dragos Tatulea <dtatulea@nvidia.com>
To: "kuba@kernel.org" <kuba@kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"dsahern@kernel.org" <dsahern@kernel.org>,
	Gal Pressman <gal@nvidia.com>,
	"steffen.klassert@secunet.com" <steffen.klassert@secunet.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Leon Romanovsky <leonro@nvidia.com>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"edumazet@google.com" <edumazet@google.com>,
	"almasrymina@google.com" <almasrymina@google.com>,
	"Anatoli.Chechelnickiy@m.interpipe.biz"
	<Anatoli.Chechelnickiy@m.interpipe.biz>,
	"ian.kumlien@gmail.com" <ian.kumlien@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [RFC] net: esp: fix bad handling of pages from page_pool
Date: Wed, 6 Mar 2024 16:00:46 +0000	[thread overview]
Message-ID: <320ef2399e48ba0a8a11a3b258b7ad88384f42fb.camel@nvidia.com> (raw)
In-Reply-To: <20240306072225.4a61e57c@kernel.org>

On Wed, 2024-03-06 at 07:22 -0800, Jakub Kicinski wrote:
> On Wed, 6 Mar 2024 13:05:14 +0000 Dragos Tatulea wrote:
> > On Tue, 2024-03-05 at 19:04 -0800, Jakub Kicinski wrote:
> > > On Mon, 4 Mar 2024 11:48:52 +0200 Dragos Tatulea wrote:  
> > > > When the skb is reorganized during esp_output (!esp->inline), the pages
> > > > coming from the original skb fragments are supposed to be released back
> > > > to the system through put_page. But if the skb fragment pages are
> > > > originating from a page_pool, calling put_page on them will trigger a
> > > > page_pool leak which will eventually result in a crash.  
> > > 
> > > So it just does: skb_shinfo(skb)->nr_frags = 1;
> > > and assumes that's equivalent to owning a page ref on all the frags?
> > >   
> > My understanding is different: it sets nr_frags to 1 because it's swapping out
> > the old page frag in fragment 0 with the new xfrag page frag and will use this
> > "new" skb from here. It does take a page reference for the xfrag page frag.
> 
> Same understanding, I'm just bad at explaining :)
> 
> > > Fix looks more or less good, we would need a new wrapper to avoid
> > > build issues without PAGE_POOL, 
> > >   
> > Ack. Which component would be best location for this wrapper: page_pool?
> 
> Hm, that's a judgment call.
> Part of me wants to put it next to napi_frag_unref(), since we
> basically need to factor out the insides of this function.
> When you post the patch the page pool crowd will give us
> their opinions.
> 
Why not have napi_pp_put_page simply return false if CONFIG_PAGE_POOL is not
set?

Regarding stable would I need to send a separate fix that does the raw pp page
check without the API?

> > > but I wonder if we wouldn't be better
> > > off changing the other side. Instead of "cutting off" the frags -
> > > walking them and dealing with various page types. Because Mina and co.
> > > will step onto this landmine as well.  
> > The page frags are still stored and used in the sg scatterlist. If we release
> > them at the moment when the skb is "cut off", the pages in the sg will be
> > invalid. At least that's my understanding.
> 
> I was thinking something along the lines of:
> 
> 	for each frag()
> 		if (is_pp_page()) {
> 			get_page();
> 			page_pool_unref_page(1);
> 		}
> 
> so that it's trivial to insert another check for "is this a zero-copy"
> page in there, and error our. But on reflection the zero copy check may
> be better placed in __skb_to_sgvec(), so ignore this. Just respin
> what you got with a new helper.
> 
Ignored. I was hoping we wouldn't go in that direction :).

Thanks,
Dragos

  reply	other threads:[~2024-03-06 16:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04  9:48 [RFC] net: esp: fix bad handling of pages from page_pool Dragos Tatulea
2024-03-06  3:04 ` Jakub Kicinski
2024-03-06 13:05   ` Dragos Tatulea
2024-03-06 15:22     ` Jakub Kicinski
2024-03-06 16:00       ` Dragos Tatulea [this message]
2024-03-06 16:09         ` Jakub Kicinski
2024-03-06 16:40           ` Mina Almasry
2024-03-06 17:09             ` Dragos Tatulea
2024-03-06 17:27               ` Mina Almasry
2024-03-06 17:41               ` Jakub Kicinski
2024-03-06 18:41                 ` Mina Almasry
2024-03-06 18:46                   ` Mina Almasry
2024-03-07  2:16                     ` Jakub Kicinski

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=320ef2399e48ba0a8a11a3b258b7ad88384f42fb.camel@nvidia.com \
    --to=dtatulea@nvidia.com \
    --cc=Anatoli.Chechelnickiy@m.interpipe.biz \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ian.kumlien@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.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).