All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: <bot+bpf-ci@kernel.org>
Cc: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<hawk@kernel.org>, <netdev@vger.kernel.org>,
	<magnus.karlsson@intel.com>, <aleksander.lobakin@intel.com>,
	<ilias.apalodimas@linaro.org>, <toke@redhat.com>,
	<lorenzo@kernel.org>, <kuba@kernel.org>, <andrii@kernel.org>,
	<martin.lau@kernel.org>, <eddyz87@gmail.com>,
	<yonghong.song@linux.dev>, <clm@meta.com>,
	<ihor.solodrai@linux.dev>
Subject: Re: [PATCH v5 bpf 2/2] veth: update mem type in xdp_buff
Date: Fri, 31 Oct 2025 13:46:48 +0100	[thread overview]
Message-ID: <aQSvuMWDMyMYRI+W@boxer> (raw)
In-Reply-To: <e9f13992d679d08d193cb40c15c70fbf4adfe9d94a6235b20858fbe161be58a1@mail.kernel.org>

On Wed, Oct 29, 2025 at 10:59:36PM +0000, bot+bpf-ci@kernel.org wrote:
> 
> ```
> commit 96d6e22337a81e8606de33d22173ff80ab961bc8
> Author: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> 
> veth: update mem type in xdp_buff
> 
> The commit fixes a page_pool leak by properly detecting page_pool memory
> and using appropriate reference counting APIs. The xdp_buff mem type is
> now dynamically set based on skb->pp_recycle instead of always using
> MEM_TYPE_PAGE_SHARED.
> 
> Closes: https://lore.kernel.org/bpf/CAADnVQ+bBofJDfieyOYzSmSujSfJwDTQhiz3aJw7hE+4E2_iPA@mail.gmail.com/
> 
> > diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> > index a3046142c..187f30e2c 100644
> > --- a/drivers/net/veth.c
> > +++ b/drivers/net/veth.c
> 
> [ ... ]
> 
> > @@ -733,7 +733,7 @@ static void veth_xdp_rcv_bulk_skb(struct veth_rq *rq, void **frames,
> >  	}
> >  }
> >
> > -static void veth_xdp_get(struct xdp_buff *xdp)
> > +static void veth_xdp_get_shared(struct xdp_buff *xdp)
> >  {
> >  	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> >  	int i;
> > @@ -746,12 +746,33 @@ static void veth_xdp_get(struct xdp_buff *xdp)
> >  		__skb_frag_ref(&sinfo->frags[i]);
> >  }
> >
> > +static void veth_xdp_get_pp(struct xdp_buff *xdp)
> > +{
> > +	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> > +	int i;
> > +
> > +	page_pool_ref_page(virt_to_page(xdp->data));
> > +	if (likely(!xdp_buff_has_frags(xdp)))
> > +		return;
> > +
> > +	for (i = 0; i < sinfo->nr_frags; i++) {
> > +		skb_frag_t *frag = &sinfo->frags[i];
> > +
> > +		page_pool_ref_page(netmem_to_page(frag->netmem));
> > +	}
> > +}
> > +
> > +static void veth_xdp_get(struct xdp_buff *xdp)
> > +{
> > +	xdp->rxq->mem.type == MEM_TYPE_PAGE_POOL ?
> > +		veth_xdp_get_pp(xdp) : veth_xdp_get_shared(xdp);
> > +}
> > +
> 
> [ ... ]
> 
> > @@ -822,24 +831,24 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
> >  	case XDP_TX:
> >  		veth_xdp_get(xdp);
> >  		consume_skb(skb);
> > -		xdp->rxq->mem = rq->xdp_mem;
> >  		if (unlikely(veth_xdp_tx(rq, xdp, bq) < 0)) {
> >  			trace_xdp_exception(rq->dev, xdp_prog, act);
> >  			stats->rx_drops++;
> >  			goto err_xdp;
> >  		}
> 
> Can veth_xdp_rcv_skb() leak page references in the XDP_TX error path?
> When veth_xdp_tx() fails, the code jumps to err_xdp without releasing
> the page references acquired by veth_xdp_get(). The skb was already
> consumed, so the pages still have the extra references from either
> veth_xdp_get_pp() or veth_xdp_get_shared().

You're missing xdp_return_buff() on err_xdp path.

> 
> veth_xdp_tx() can return -EOVERFLOW when xdp_convert_buff_to_frame()
> returns NULL, which is a reachable error path.
> 
> >  		stats->xdp_tx++;
> > +		rq->xdp_rxq.mem = rq->xdp_mem;
> >  		rcu_read_unlock();
> >  		goto xdp_xmit;
> >  	case XDP_REDIRECT:
> >  		veth_xdp_get(xdp);
> >  		consume_skb(skb);
> > -		xdp->rxq->mem = rq->xdp_mem;
> >  		if (xdp_do_redirect(rq->dev, xdp, xdp_prog)) {
> >  			stats->rx_drops++;
> >  			goto err_xdp;
> >  		}
> 
> Similar question for the XDP_REDIRECT case - when xdp_do_redirect()
> fails, does this also leak the page references taken by veth_xdp_get()?
> 
> >  		stats->xdp_redirect++;
> > +		rq->xdp_rxq.mem = rq->xdp_mem;
> >  		rcu_read_unlock();
> >  		goto xdp_xmit;
> >  	default:
> 
> 
> ```
> 
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
> 
> In-Reply-To-Subject: `veth: update mem type in xdp_buff`
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/18923812102


  reply	other threads:[~2025-10-31 12:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 22:13 [PATCH v5 bpf 0/2] xdp: fix page_pool leaks Maciej Fijalkowski
2025-10-29 22:13 ` [PATCH v5 bpf 1/2] xdp: introduce xdp_convert_skb_to_buff() Maciej Fijalkowski
2025-10-29 23:50   ` Jakub Kicinski
2025-10-30 12:14     ` Maciej Fijalkowski
2025-10-30 15:25       ` Jakub Kicinski
2025-10-30 20:22         ` Maciej Fijalkowski
2025-10-31  2:05           ` Jakub Kicinski
2025-10-31 11:37             ` Maciej Fijalkowski
2025-10-31 18:49               ` Jakub Kicinski
2025-11-03 12:16                 ` Maciej Fijalkowski
2025-11-05 18:39                   ` Jesper Dangaard Brouer
2025-10-29 22:13 ` [PATCH v5 bpf 2/2] veth: update mem type in xdp_buff Maciej Fijalkowski
2025-10-29 22:59   ` bot+bpf-ci
2025-10-31 12:46     ` Maciej Fijalkowski [this message]
2025-10-31 13:45       ` Chris Mason

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=aQSvuMWDMyMYRI+W@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hawk@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.com \
    --cc=yonghong.song@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.