From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.74.67.75 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795516841; b=ReLCc+hjFdJI0iAcLILh1zju+3DSbKe8vd6FdVyuoXpBhFNPDphnOE7pZplIjatdeVAY poKNvx3ozvamgl46Wx4r9MUg94tCbb+0LAj84nEo1+Xkb1OUiiSnhrfXZLPR1g5Ovjnna N0HOBwiRdAbAdP+g9QJWnBD5HFwuPYV/pYwX6RdmorZCo2Nel1vqweD7PR/9wwVvQs5Yf 18/kRTw14+2S/Ezpawi7x4qA7nq8LzfDSKKpVA2enBTJdV77OwZ0YITbWu2dVJVbXjGKH B5vus8yFMHuxagXaXh+tFQJuR+M7ve2bcD4kRWJRDELi7MxPTTShplDICVUBIq/1IPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795516841; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: DKIM-Signature; bh=l7gGX0qSZAnyddmIyLAYR5mLAYEXg25SW0coCnTo23M=; b=kJqsNqIpuI56furFv3w05irpzzDesSwJKd9KEpcBp+aGTSA2444UiWi1l1zCax1EAfhp 9XKHoYaMwn1mSCq7BYnntx1jg7kNN15P3QXJNwrtGr3a/af1TG/4v70dOydAnhfEsFfHr JUsONBjVa5K95FusayM6As4hxBprLnWCtdE9LjWbiKCe49kw0M/ftaJQEichMNmsWNrgu uhA2BHn0oiVtdlDIHt/BEVuLMx1QCWO/Yj7ypmO5mLUPNLgYXXd2qFpNAT8ky0vUuzfPZ CvL239tgHtkHRXo/iIrqg+P7rchogWO25YTUov+TEQ9o4NrCALATXy8hMFqEeCYSK0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=poczta.fm; spf=pass smtp.mailfrom=poczta.fm; dkim=pass header.d=poczta.fm header.i=@poczta.fm header.a=rsa-sha256 header.s=dk header.b=d5jKIS6Z; arc=none smtp.remote-ip=217.74.67.75 Received: from smtpo75.interia.pl (smtpo75.interia.pl [217.74.67.75]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 273BA606A6AC for ; Tue, 24 Nov 2026 10:40:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 273BA606A6AC Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=poczta.fm Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=poczta.fm Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=poczta.fm header.i=@poczta.fm header.a=rsa-sha256 header.s=dk header.b=d5jKIS6Z Received: from localhost (unknown [80.68.231.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by poczta.interia.pl (INTERIA.PL) with ESMTPSA; Tue, 24 Nov 2026 11:40:36 +0100 (CET) From: Slawomir Stepien To: Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Maciej Fijalkowski , Tianyi Gao , Octavian Purdila , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexander Lobakin , Ilias Apalodimas , Lorenzo Bianconi , Lorenzo Bianconi , Magnus Karlsson , Ihor Solodrai , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Jiri Olsa , Kumar Kartikeya Dwivedi , Emil Tsalapatis , Shuah Khan , linux-kselftest@vger.kernel.org, Slawomir Stepien , stable@vger.kernel.org Subject: [PATCH v8 bpf 4/7] veth: use the frame mem type when running XDP on an xdp_frame Date: Tue, 24 Nov 2026 11:40:13 +0100 Message-ID: <20261124104016.532341-5-sst@poczta.fm> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261124104016.532341-1-sst@poczta.fm> References: <20261124104016.532341-1-sst@poczta.fm> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poczta.fm; s=dk; t=1795516839; bh=l7gGX0qSZAnyddmIyLAYR5mLAYEXg25SW0coCnTo23M=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=d5jKIS6Z2KkkAinVYEj/L9J2Y2E4jFJnDKjqmukGr4eh8ktQC7PmQQxLcENi/VYKK c0X1C4awPmQPzNdGuupFi+dLGOP8iAoxIcVe/sCJe6DbITJDRuQTqdjcCl/WDcqjur pchZiju/0V7vegmgGELNWPoNC6vUTXr4U4sAqJkw= veth_xdp_rcv_one() runs the XDP program on frames queued by ndo_xdp_xmit(), i.e. redirected to veth or sent back by the peer with XDP_TX. The xdp_buff points at rq->xdp_rxq, whose mem type is whatever the previous packet left there: the queue's MEM_TYPE_PAGE_SHARED, or the type of an earlier frame or skb. frame->mem_type is copied in only for XDP_TX and XDP_REDIRECT, after the program has run. bpf_xdp_adjust_tail() and bpf_xdp_pull_data() release whole frags with the rxq mem type. For a MEM_TYPE_PAGE_POOL frame and a stale MEM_TYPE_PAGE_SHARED rxq, page_frag_free() drops the reference owned by the page_pool: BUG: Bad page state in process ping pfn:2244a page dumped because: page_pool leak bad_page.cold+0x58/0x6b __free_frozen_pages+0x837/0x1280 page_frag_free+0x1a4/0x200 __xdp_return+0x3a8/0x9c0 bpf_xdp_adjust_tail+0x8a0/0xd10 bpf_prog_007aa02d10594afa_xdp_trim_drop+0x8f/0xd8 veth_xdp_rcv_one+0x389/0x10e0 veth_xdp_rcv+0x1c5/0xb20 veth_poll+0x33d/0xe00 ... kernel BUG at ./include/linux/mm.h:1820! The reverse, a MEM_TYPE_PAGE_SHARED frame after a page_pool one, hands pages that are not page_pool backed to page_pool_put_full_netmem(). Set the rxq mem type from the frame before running the program, as cpumap and devmap do, and drop the now redundant updates in the XDP_TX and XDP_REDIRECT paths. The splat above is from two veth peers with the next patch applied: one bounces multi-buffer packets with XDP_TX, the other trims all frags of the resulting frames. Page pool backed frames from other drivers can hit the same path today. Fixes: 718a18a0c8a6 ("veth: Rework veth_xdp_rcv_skb in order to accept non-linear skb") Cc: Reviewed-by: Tianyi Gao Signed-off-by: Slawomir Stepien --- drivers/net/veth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index faa837acea7b..80d3c116e757 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -658,6 +658,8 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq, xdp_convert_frame_to_buff(frame, xdp); xdp->rxq = &rq->xdp_rxq; + /* The program may release frags, do it the frame's way */ + xdp->rxq->mem.type = frame->mem_type; vxbuf.skb = NULL; act = bpf_prog_run_xdp(xdp_prog, xdp); @@ -669,7 +671,6 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq, break; case XDP_TX: orig_frame = *frame; - xdp->rxq->mem.type = frame->mem_type; if (unlikely(veth_xdp_tx(rq, xdp, bq) < 0)) { trace_xdp_exception(rq->dev, xdp_prog, act); frame = &orig_frame; @@ -681,7 +682,6 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq, goto xdp_xmit; case XDP_REDIRECT: orig_frame = *frame; - xdp->rxq->mem.type = frame->mem_type; if (xdp_do_redirect(rq->dev, xdp, xdp_prog)) { frame = &orig_frame; stats->rx_drops++; -- 2.56.0