From: Chris Mason <clm@meta.com>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>, 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,
ihor.solodrai@linux.dev
Subject: Re: [PATCH v5 bpf 2/2] veth: update mem type in xdp_buff
Date: Fri, 31 Oct 2025 09:45:20 -0400 [thread overview]
Message-ID: <2212b2f7-d426-4f2f-abe5-3746dbb31631@meta.com> (raw)
In-Reply-To: <aQSvuMWDMyMYRI+W@boxer>
On 10/31/25 8:46 AM, Maciej Fijalkowski wrote:
> 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.
Thanks, looking at the logs, that's exactly what happened. AI thinks
the goto code looks like this:
drop:
stats->rx_drops++;
xdp_drop:
rcu_read_unlock();
kfree_skb(skb);
err_xdp:
return NULL;
Since I can't find this code snippet elsewhere in the kernel, I think it
just made it up. I'll add some language that forces it to confirm the
snippets are correct.
-chris
prev parent reply other threads:[~2025-10-31 13: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
2025-10-31 13:45 ` Chris Mason [this message]
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=2212b2f7-d426-4f2f-abe5-3746dbb31631@meta.com \
--to=clm@meta.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=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=maciej.fijalkowski@intel.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox