🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10446

[PATCH net v4 0/2] tun: bound the NAPI receive queue

#10446
From: Antonio Quartulli
Date: Tue, 03 Nov 2026 14:22
57 lines
11541 bytes
With IFF_NAPI, tun queues written packets for NAPI on an unbounded
list, which an unprivileged user can grow until the system runs out of
memory. Patch 1 bounds it by netdev_max_backlog; patch 2 adds a
kselftest for the vhost-net paths into that queue.

v4:
- Keep the poll's leftovers on a separate queue, like process_backlog():
  v3 did not bound the queue when the poll ran on another CPU (Sashiko)
- Schedule NAPI when dropping: with netdev_max_backlog below
  NAPI_POLL_WEIGHT, MSG_MORE senders (vhost-net) stalled the queue
  (Sashiko)
- Use goto free_skb for the locked drop (Willem)
- Add a vhost-net kselftest (patch 2); the tun kselftest passes (Willem)
- Cc vhost, kselftest and XDP maintainers and the Fixes author/acker

v3: https://lore.kernel.org/netdev/20261031231444.1528758-1-antonio@mandelbit.com/
- Also bound the sendmsg() paths, which share the queue: zerocopy
  buffers are completed when dropped early, and the batched XDP buffers
  of tun_xdp_one() are covered too (Willem)
- Drop the IFF_NAPI_FRAGS exclusion (Willem)
- Recheck under the queue lock before queueing (Willem)
- Compare with > like enqueue_to_backlog() (Willem)
- Keep the includes sorted (Willem)
- Add the reproducer and a testing statement to the commit message

v2: https://lore.kernel.org/netdev/20261030152540.1409884-1-antonio@mandelbit.com/
- Cc netdev and the maintainers

Testing, in an x86-64 VM with 1 and 2 vCPUs:
- Reproducer from patch 1, 15 seconds, 500 and 3000 iptables rules:
  memory use stays flat, no OOM; forwarding rate unchanged (112962
  packets in 3 s without the patch, 113822 with it).
- tun_vhost (patch 2), with vhost_net experimental_zcopytx=0 and =1:
  passes with patch 1. Without it, every variant fails (nothing is
  dropped); removing the tun_xdp_one() check fails the batch variant,
  and removing the zerocopy completion fails the zerocopy one.
- tun kselftest: pass:91 fail:0 xfail:12, as without the patch.

Notes:
- Affected since 943170998b20 (v4.15). Based on net/main 94cea342e891.
- Mitigation: disallow unprivileged user namespaces or restrict
  access to /dev/net/tun.

Antonio Quartulli (2):
  tun: bound the NAPI receive queue
  selftests: net: add a vhost-net test for the tun NAPI queue bound

 drivers/net/tun.c                       |  82 +++++-
 tools/testing/selftests/net/Makefile    |   1 +
 tools/testing/selftests/net/config      |   1 +
 tools/testing/selftests/net/tun_vhost.c | 361 ++++++++++++++++++++++++
 4 files changed, 431 insertions(+), 14 deletions(-)
 create mode 100644 tools/testing/selftests/net/tun_vhost.c

-- 
2.56.0
Technical Details
Message-ID: <20261103142232.1869185-1-antonio@mandelbit.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355723-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355723-linux-kernel-netdev=dewy.ru
From: antonio@mandelbit.com (Antonio Quartulli)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4 0/2] tun: bound the NAPI receive queue
Date: Tue,  3 Nov 2026 15:22:28 +0100
Organization: Usenet Network
Message-ID: <20261103142232.1869185-1-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3187612"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tMplVbFcfaAtKo5/xcDlrXejxTE= sha256:NYmrvdEZIZ783vEDzU8+y6a1zBohlmTP9EWui9bkzc8=
	sha1:RWiVFI2EYx70LIx8u5T+Flkn7c4= sha256:CmdWDz5r2G2S/eyNzG9k0ywmr3GZ5zqh5WwU3ZGpFR0=
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 018EA1128F4; Tue,  3 Nov 2026 17:33:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[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]
	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 l9M-OJjwkmak;
	Tue,  3 Nov 2026 17:33:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-355723-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id BEA321128F2; Tue,  3 Nov 2026 17:33:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 1184B60DA75; Tue,  3 Nov 2026 14:23:23 +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=1793715775;
	b=cMtb/P5I1KpQ4ZjZQTT26PpqNZx57frKuqDF2cHZ/MgNBtg5V0eXJYchhbDvvjBhUr0a
	 Pd/r0d6EQDXkFYI/UH3OvdZZ4CmcpOLwckZw/IxdvdX1Y7Lleh+wgbAW3Cf4x07tlmVRC
	 kBiJRng0dqZwoqus9a55a07iBo8BF0oqh5HnxFZroAIdIKopJqauLyd48Ex3fAWehm/rZ
	 PB8/diWZ8R3bpIxROToPvSn+OXQPdacFePGppzfftLyeDDTgmpdfxe0pD54Op62U7T2hm
	 dE1hW2bMQUEng768DDwb1j01JLJXFEfvyeW9/d9DiYACNZf4jqEd63Ox4ufnMgfdQgA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793715775;
	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=UwIyMDhSrSKTyt+83psKeyoXfPEnExDxP5qigMbsr7I=;
	b=FAGuuNmzT1NELiS8tQVyG+cvTurkHm+9rT6ClNu9mIk0WTg/UIZ76PHklpINbpKZhus6
	 O7tY9CdevTieuKXnRTuo/1Ub0tGClV5KrA360NvF5T+PntrOpyeL2VlmSsnepUytrtr8D
	 sWZqbUPrxVbUBol7awhtwGg0FOAY1LLBNyNPhkwg1IJYuCoC8net8AgI/mJndsrwZqSDX
	 H+AmP1wcZNjGQjXINH/AQ3v3Z0KxBzkAXZEegbOYo8TDa+klhPn2auysLlLSeodyP93fW
	 wR6xxpyTPTaLCHLy8jmTqEaf6S6BsG4RkVZ9evlWK2Rd+R47HUBpJWLM+RXk91iV2+A==
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=0ZiGcmx+;
	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 2537F606EE84;
	Tue,  3 Nov 2026 14:22:55 +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=0ZiGcmx+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793715774;
	b=p9KChH74r3ZZyVesI2EgehVXZEaCgYj0JlLCNMuffi/QC7FT85DL1s1HaQ0QkpwRb7zz
	 streR6kF0GfootwNnpVs0SITCBqMa2Sq80+pvLIXYb10yPJ3T3bjduSv7GytLf8ECmsoD
	 6G1vzqLMhNcUK97113TMVSuc2JbaRMMvqQ3sqmteiz/UBsvIrA/3l+7UCwDzPBMyITUtx
	 /LMGp0zx7vtDCWL8e3Z9iw6I5UKgQVtEdlWqRGsLdNzdxemkoVNcwphPGyIJmy6cjeAtF
	 0RFiEszYfexDBy84SsuSpAITjf3no5hnKVcK829EKWAsEGsoGyd1s4loKBgcXShEdGg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793715774;
	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=UwIyMDhSrSKTyt+83psKeyoXfPEnExDxP5qigMbsr7I=;
	b=oOacMVPwAmBFYKv49h6iu0AXXW9CoOTm1perEjTF1AkXmK30nDXgTLV5dpeKty5vTxHe
	 NA/SvSjuFzyEEb0SLPfGYm9ccGKA0NMs+pV9N4ZZGe8bnWBLLmzdwd6RjGhFe6Sio6wKm
	 zM9cv6FwhYrfz+FZNBGSmyV5s7VzlOfd3MNaAoCMB282EvT2Cw4EmwFSRQWrAOjLHz0ZY
	 0inZKHO3IH/D+78k4SyN6q5ZJ8mMCr7Siqy0wkP1P2WAK/I2FGK6V9sCHkrRhvfxQk5Y3
	 EpDmhJSYcaNj7AWXROP+eHXULE/v6zztfoYT2zldpVuZmDGnJuq9KoRp3Sah1bdLnMQ==
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=0ZiGcmx+;
	arc=none smtp.remote-ip=195.10.208.50
X-Received: from mout-b-105.mailbox.org (mout-b-105.mailbox.org [195.10.208.50])
	(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 67EC8606D831;
	Tue,  3 Nov 2026 14:22:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67EC8606D831
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-105.mailbox.org (Postfix) with ESMTPS id 4jJrPs0rXMz9sQr;
	Tue, 03 Nov 2026 15:22:41 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
	s=MBO0001; t=1793715761;
	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=UwIyMDhSrSKTyt+83psKeyoXfPEnExDxP5qigMbsr7I=;
	b=0ZiGcmx+HoTGuhRSoPS/d3lLFVtKiratO5FO6+OLCUC6eYcoPrzzgJ36WVDGz5ojAFYpxV
	SkmdfBD7iFpP9dKnPjkrIZbWRtjrHEDbckU+eD01ELidi9pvXSASXRtJaUHGELLkKU9vrl
	89A/OrwHA2jhk3t6FUQ2rT9vt3G2j5r0TuvoGlS0D24v9trFNQpxoSFe6ITvSZ7OlEZPFn
	F5kV2+hqHNfq/DR/PNUbrckcdcshJBv9jpzhJBwsFTP9HCH4P62sxlYFOGsmtD80who8Bw
	n2LUfiQo8LTUXt8j9nn+A4VFPkTWG7KMhRkH8e2AdhvBVmJuVLkfbBTV1o/xiA==
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,
	shuah@kernel.org,
	ast@kernel.org,
	daniel@iogearbox.net,
	hawk@kernel.org,
	john.fastabend@gmail.com,
	sdf@fomichev.me,
	maheshb@google.com,
	peterpenkov96@gmail.com,
	netdev@vger.kernel.org,
	virtualization@lists.linux.dev,
	linux-kselftest@vger.kernel.org,
	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: 4jJrPs0rXMz9sQr