Article View: linux.kernel.netdev
Article #14360[PATCH net v5 0/2] tun: bound the NAPI receive queue
From: Antonio Quartulli
Date: Wed, 11 Nov 2026 01:42
Date: Wed, 11 Nov 2026 01:42
72 lines
12358 bytes
12358 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. v5: - Take at most budget packets in the NAPI poll instead of keeping the leftovers on a separate queue (Willem) - Keep only the lockless check, before allocating, also in tun_xdp_one() (Willem) - Say that an OOM is still possible with large packets and many queues, if hard to reach in practice (Sashiko) - selftest: little-endian ring, buffers returned in any order, lower netdev_max_backlog only after setup and restore it first, any non-zero experimental_zcopytx, .gitignore entry (Sashiko) - Rebase on net, which conflicted in selftests/net/config v4: https://lore.kernel.org/netdev/20261103142232.1869185-1-antonio@mandelbit.com/ - 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, on net ead744fd1ce0: - Reproducer from patch 1, 15 seconds, 500 and 3000 iptables rules, 1400 to 65000-byte packets: memory use stays flat, no OOM; forwarding rate unchanged (152577 packets in 3 s without the patch, 151277 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, removing the zerocopy completion fails the zerocopy one, and removing the NAPI scheduling on drop fails the copy and zerocopy ones. - tun kselftest: pass:91 fail:0 xfail:12, as without the patch. Notes: - Affected since 943170998b20 (v4.15). - 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 | 59 +++- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/tun_vhost.c | 409 ++++++++++++++++++++++++ 5 files changed, 463 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/net/tun_vhost.c -- 2.56.0
Technical Details
Message-ID:
<20261111014208.1795777-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-360816-linux-kernel-netdev=dewy.ruShow 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-360816-linux-kernel-netdev=dewy.ru From: antonio@mandelbit.com (Antonio Quartulli) Newsgroups: linux.kernel.netdev Subject: [PATCH net v5 0/2] tun: bound the NAPI receive queue Date: Wed, 11 Nov 2026 02:42:01 +0100 Organization: Usenet Network Message-ID: <20261111014208.1795777-1-antonio@mandelbit.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="751748"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:DdBysRk1co5eKm7Cq8mtMCe3eks= sha256:lCSctrxpmF7IsEJsriaZBwQa7SkrdBlzpYKUX9TgywY= sha1:MAUOfwSEdNqAFJ7pDU3nnP+/D90= sha256:Bk+jVznnuXg0DdVY34YoMJp2zvt9iYhpbnqT1ZjuyME= 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 606E4113DAF; Wed, 11 Nov 2026 04:43:05 +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 82xujvmVo-es; Wed, 11 Nov 2026 04:43:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360816-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 088FE113DFE; Wed, 11 Nov 2026 04:42:50 +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 8276946822; Wed, 11 Nov 2026 01:42:26 +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=1794361345; b=dXxsuquVfsibOVmeoAhrF79Af7I4rSmBXz7IeRfQVq/tZOTEQWsWVRK+lnh3P6/WTiL8 2vrVOOTwlxIwV7Pd/tnrzGL0dQmn4Ovz67gEbT9zK1bKDqBtowyXlJTLGaF0/aTt7Dgh0 XqA61nQCq7OChR1Vg9LJyg1/k6OR02YqrLj0arPXiwqXTlVidSI2cKH6oXbAPzK1CAHQi VlhLeUt5img4HH96eT1ghmQJIStzSqlZu3QoHYynT/leO1SURGWDXfC7xTXbVbQS6iP2P uaJ0WG2CtCox+tloZJRE9MntkeC5SetNV0wsQ2yny5hPTNO/7aCpgBaF3PoJNFOu3sw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794361345; 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=g3YMKqL7Zig4N1u5uNQ3udwfmaIwcfVBjpYpAiJaW48=; b=q07uwKzos31TBYN65/W2Igkg6M2NP5UJPgvTr1Th9+OFy+kwBnNsCe+2iD4Inj2KetiS mhyZOhJ7zkOJrZfch0yqF+/eahL92KZHzyQu+4wKaIGe4ijgwB8b/jnKntnG6jMD2c5ii SXdDD9bpPV5gU7gIVKXVAfVFAVbM252Ycv+pa851pwVcleKu58E9eWxK96FOT4m2S1myO ygbc3olHkZB+LQYkC0K2rCwb9HsmrYt9qTeMzLJM7lIiMwllaqTfhjQ9CyV3z66FthMDR Qef23/t89XLM3Pt+Bt4r0wcQB47jjm8DFENEdOHkOdqJBuFI94rav0ek/zqehrS5JCg== 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=jcbc3NCE; 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 2DC3E60A2600; Wed, 11 Nov 2026 01:42:25 +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=jcbc3NCE X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.40 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794361344; b=QXSP2aQsvDTVfoQQiE/d4n5l4cE3xgrnlABSOVASd0gfXlRCwlunU0BACJDTSnGIqTd3 OXTns+78IyIYq6YlhkFrh9fxgAw46qOgxfulfyC9DOm2wyEFyIFY3Wf2TQME82886PU/B MK1e0H8XVGcSBC8auhg5w4BYH/oPF2oxeZP1L7ylbdQEruDV+zc6YafnjHxvmRs4RpJMe QZ328BLuXhKiD+k703k6TNU8pWJOvHrCOMSmk+zXu8Fh28ywEuIOn/XRrykRXOxehFK66 lnzxWSsDqmd1xDodKjUSP/RwIT1KyN44ezZYcY5Hnfki2yDgWUPeZSidm/pj5rZEUxw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794361344; 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=g3YMKqL7Zig4N1u5uNQ3udwfmaIwcfVBjpYpAiJaW48=; b=k6yfz8TYtO0wu+GP6EM2lIf3heg5EurTOvmyGsCAh340O/eEPpHz0OMeaGy8jZ6Bpy4G im5zgeRmQmOuhMR/FBqOnDhbf5MqMUlhC3mlnhqVryPfuCExDmlORSEGxQyP3xklO6JxM 9EExIPXXma57Z90p/VqoiKPicyFW+ebLeE5XzI/hJE9NEJ4HD4pMZygF4eEVkQmr59JmT XigZn1TsjiFWl1ADIVAuzLwvKyGLM8OFomVHs6VwihS4P751tta5TiIhg1Ht6d4OHAQLZ zDpyf69iM1/E6Ae3v2d2UBnAI8yyAUzFzBrCB9dLjs5+thkCTX8plO9mGMvjGN8/J/g== 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=jcbc3NCE; arc=none smtp.remote-ip=195.10.208.40 X-Received: from mout-b-210.mailbox.org (mout-b-210.mailbox.org [195.10.208.40]) (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 8941F606A326; Wed, 11 Nov 2026 01:42:23 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8941F606A326 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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-210.mailbox.org (Postfix) with ESMTPS id 4jPR8k6g8tzFq3n; Wed, 11 Nov 2026 02:42:14 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794361335; 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=g3YMKqL7Zig4N1u5uNQ3udwfmaIwcfVBjpYpAiJaW48=; b=jcbc3NCE1+Oc8wULKs2CBF/KuPayvlqKhR4DOPiHiYjyzllL+uijry5Kv8lBl9D4e7MPyi aHXPrkPhtA4dwzBYNPLj3hMQdrOfi1kIfLzr2pjfEW5On/xL8HQQi7qp15Qet7TBtSAXqE UtVe/HzvYMqvlNnd8Wttq5vwshTz3Hsft+HkJHYcATsHZyMuMON2S9MK3tQrDJROpmyQ/+ ULdYk5K4VMC1kscFTJmDGJX8Yo6GMOTTAsbXXP0BajQ3y3rJINBpo3RbLT8ETgC7BM5AQQ bGPFJbk72UowPJcNqyHftxU2UGZDueJvrNJFqTRLp5wzMRImKfk6Yvu4o11TdA== X-Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of antonio@mandelbit.com designates 2001:67c:2050:b231:465::2 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: 4jPR8k6g8tzFq3n