🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16051

[PATCH net] tun: complete the zerocopy buffer of packets consumed by XDP

#16051
From: Antonio Quartulli
Date: Fri, 13 Nov 2026 23:28
59 lines
10980 bytes
When vhost-net passes a zerocopy buffer that tun_get_user() does not use,
because the packet spans too many pages, the packet is copied and the
buffer completed. If the copy goes through build_skb() and native XDP
consumes the packet (DROP, TX or REDIRECT), tun_get_user() returns
without completing it: vhost-net never gets the descriptor back, and
closing the vhost-net device then blocks forever.

Complete it in that case too, as copied.

Reproducer: vhost-net with experimental_zcopytx=1 on a tap device with a
native XDP_DROP program; send one 806-byte packet as 40 descriptors, each
in its own page. The descriptor is never returned and close() of the
vhost-net fd does not return. With the patch it is returned.

Tested in an x86-64 VM with the reproducer and the tun kselftest.

Found by the Sashiko AI review bot, as a pre-existing issue while
reviewing an unrelated tun patch, and confirmed with the reproducer.

Link: https://sashiko.dev/#/bug/linux-f9997fb6-303f-41d6-93e2-60c392b1856f
Fixes: 761876c857cb ("tap: XDP support")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
Notes:
- Completed as copied (success false), as the copy path does: the packet
  was copied into a page fragment.
- net-next replaced ubuf_info->ops with net_zcopy_complete() in
  ecca9bb2c855; there the call becomes
  net_zcopy_complete(NULL, msg_control, false).

 drivers/net/tun.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 86fd44e10755..927196840725 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1871,8 +1871,15 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		err = PTR_ERR_OR_ZERO(skb);
 		if (err)
 			goto drop;
-		if (!skb)
+		if (!skb) {
+			/* consumed by XDP, after copying */
+			if (msg_control) {
+				struct ubuf_info *uarg = msg_control;
+
+				uarg->ops->complete(NULL, uarg, false);
+			}
 			return total_len;
+		}
 	} else {
 		if (!zerocopy) {
 			copylen = len;

base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
-- 
2.56.0
Technical Details
Message-ID: <20261113232843.2338734-1-antonio@mandelbit.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362980-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362980-linux-kernel-netdev=dewy.ru
From: antonio@mandelbit.com (Antonio Quartulli)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] tun: complete the zerocopy buffer of packets consumed by XDP
Date: Sat, 14 Nov 2026 00:28:41 +0100
Organization: Usenet Network
Message-ID: <20261113232843.2338734-1-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1465645"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zQmILB5dOud/u4h5sYOG9fdazWk= sha256:2fHVwB3vg0Y3H6tp2mlYKtbAl0g/cXHE3E6V30wuK78=
	sha1:aX0mAzaIo5Xm6lH8RBZl39DP1KA= sha256:ozED4Sa8ff33KeJbOgfpNrFSF7wfMOTFlW8CCQrmtjU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 24E5F1146E2; Sat, 14 Nov 2026 02:29:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=mandelbit.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id KLk2u2KuPn8Z;
	Sat, 14 Nov 2026 02:29:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-362980-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E8BCB11468B; Sat, 14 Nov 2026 02:29:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3C27E3FEDE; Fri, 13 Nov 2026 23:29:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794612549;
	b=0FuG3BCro0/C7ymO6H68HRX2ffXFtxs8RaL5GbFECK7yMnHmiszoBwCembr2o9zkgt92
	 RjRRXkYq38Hfj3yrEuEjfOcxbGFxMthWcF30YC9614DtawVWbRMl7EQM70PHDmG6qOWf+
	 BtxDaB9jj54NpBwn+lvGm7DGV9zClQ77G2+jDDxLqPjRzVlVIH2TNcjn8H7dDPLN3dBNJ
	 xU1A8JCpxmTXG7ovksvCHOCpgv7PcThBdsqJl0zQgd7OYZuZIUXNCEq1TuKgzXV+rIAwW
	 t7jm2IL/z5VsqYXE3DNBC79sOQ1cj3u47hTtgX1NVU1ccy3U+8hmieAiTRd5rrxi5LQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794612549;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding:X-Rspamd-Queue-Id;
	bh=YMmiURWTclyFUKjPqBzMU4kcCzHqWhA5bK0YM2ZJ3Pw=;
	b=ZcXU9dxMAqE2a0cNT6AIFsO6RTwinTGTtT51HfMol8qSBccN5wASrFbL3iQhTDPe9+OK
	 v+bdQyxzlcgG/e9w6suiRuN//QSnDmlKYakiyo+qS9uZ/g4T1JVgNThn/RmUnX/tFLjZh
	 C2gPrZoP0Q9ljMv9rvJBEk/jgMwzunrPfh7pNMAx+h/sDUuwoLJ8zknEzmpnOmLdF4mIx
	 O7deLYqKLj7FguDHAJ+B4PzhNQiqOldjQO3mZqOsWTcxBsu45YPJTEUHMBOFnEw0yD8xA
	 4JWmk68RWwlMmsPdkcnYVgIn9z2t2NfsDvp0A22f4EegkytExdgkXpWNDm55BljilIw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=ZvtB7qAH;
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A8635606A883;
	Fri, 13 Nov 2026 23:29:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=ZvtB7qAH
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.62
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794612543;
	b=vq5CdQHCSd1GlHpYF2tPnaM/LB1L8hR6SOH1Gcno2dsV5YS6ZH+8fEhaETbvhmMG+uDE
	 c6QUZ9A5XSTf7A1/67YeeEJtPQjEgvGCC+ctK3Uhp6U2zz5YJCcLZpYnb1ArlZthzLqxG
	 sx2wGs2pNj+EeB2BBiaxeFofEhOFVXIDbPEUHg9qZcg6LqQrnDL+W2Cu1kCt1qa6SVrAx
	 6ZHfHeo+NCS9zJVp2Xmkadw8hyF7wn0r+HWtO7aMRF1ROgkeTs77xuHpDKdmOkD2kLo/G
	 Vz2ZdF/0sedwBBm+f98MWAehfsQBEnxNbiG7mUtOb7uCWYx1g6ZmJtzMyEjHGptm2fg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794612543;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding:
	 X-Rspamd-Queue-Id;
	bh=YMmiURWTclyFUKjPqBzMU4kcCzHqWhA5bK0YM2ZJ3Pw=;
	b=Sx//eW+OgAjJ/q1m6HYLcF1tT0fVDgNM1iAcXjD7l+kGc+2sXs9EdtepAowwwbxbrVFJ
	 OFZk2RNDV5zNOgSapJAUghKexm7PizqaCF7zarLZbVm8IyV6HZryfnLqHLsQ2P3KFwvkT
	 XdSzthSXTPE1UxSiRgH0cLat8rRKps/OM5Q8Ql9Up9Izx1eFcb6djxisv6OaXWkPYxptm
	 NWCouaqBa5PHvF2oglXoKwCn64TuyZA51ZAjMN556KDdr8Da9NfbD2LazwM665z85s9bo
	 Ufb1bnCoR14OUvo5ZMWEwOESQrobJM5HaK+JmKuUVT9DYGqnvNb9PdPSV/cLMHp7aYw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=ZvtB7qAH;
	arc=none smtp.remote-ip=195.10.208.62
X-Received: from mout-b-202.mailbox.org (mout-b-202.mailbox.org [195.10.208.62])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29A26606A886;
	Fri, 13 Nov 2026 23:28:57 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29A26606A886
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com
X-Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mout-b-202.mailbox.org (Postfix) with ESMTPS id 4jRD3V0vmqzKnR0;
	Sat, 14 Nov 2026 00:28:54 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
	s=MBO0001; t=1794612534;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding;
	bh=YMmiURWTclyFUKjPqBzMU4kcCzHqWhA5bK0YM2ZJ3Pw=;
	b=ZvtB7qAH43vttbZJaG/JxTYoCepd8k6m73Avmyuq9kroqKWsDgrJ41LwfBnugSC2laTbKF
	hiwcnZ9qnyciDWwE+0XtL7Q88W9nzGCwomq7ABVSgZ3nk4LStdugulNRLjPHtoNujkocvm
	NAImsyqRFF9feGz35LaHRjO6BNFtP0nFeDKARmhcObOK7JdLBYjHjJj7vtHfFPkeBP3rJC
	WW5dBuuKy5YSF2GbEKQV+dVVpI6hcz9h2Y+Q2pIzE754Oi8zn6wvhpdcGeskmJZ18bCgDp
	v0lk79zU3AuX01xuUHzKUGznwMm17J9Ih/4Emx52avefCGN+IM5eN/atKIyjfQ==
X-Authentication-Results: outgoing_mbo_mout;
	dkim=none;
	spf=pass (outgoing_mbo_mout: domain of antonio@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=antonio@mandelbit.com
X-Cc: Antonio Quartulli <antonio@mandelbit.com>,
	andrew+netdev@lunn.ch,
	davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	mst@redhat.com,
	eperezma@redhat.com,
	ast@kernel.org,
	daniel@iogearbox.net,
	hawk@kernel.org,
	john.fastabend@gmail.com,
	sdf@fomichev.me,
	netdev@vger.kernel.org,
	virtualization@lists.linux.dev,
	bpf@vger.kernel.org
X-Mailer: git-send-email 2.56.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-Rspamd-Queue-Id: 4jRD3V0vmqzKnR0