Article View: linux.kernel.netdev
Article #16017[PATCH net v6 0/2] tun: bound the NAPI receive queue
From: Antonio Quartulli
Date: Fri, 13 Nov 2026 21:22
Date: Fri, 13 Nov 2026 21:22
82 lines
12853 bytes
12853 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. v6: - Complete the zerocopy buffer of a dropped packet with net_zcopy_put(), as a success, so that vhost-net does not fall back to copying (Willem) - selftest: slim it down, and add a wrapper that loads vhost_net and also runs the zerocopy variant (Willem) - Rebase on net v5: https://lore.kernel.org/netdev/20261111014208.1795777-1-antonio@mandelbit.com/ - 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 7e1392a42ea2: - Reproducer from patch 1, 15 seconds: memory use stays flat, no OOM; forwarding rate unchanged (113755 packets in 3 s without the patch, 113990 with it). - tun_vhost (patch 2), through the wrapper and with vhost_net experimental_zcopytx=0 and =1: passes with patch 1. Without it, every variant fails; 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 | 55 +++++- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/tun_vhost.c | 222 +++++++++++++++++++++++ tools/testing/selftests/net/tun_vhost.sh | 23 +++ 6 files changed, 296 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/net/tun_vhost.c create mode 100755 tools/testing/selftests/net/tun_vhost.sh base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6 -- 2.56.0
Technical Details
Message-ID:
<20261113212237.1742984-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-362933-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-362933-linux-kernel-netdev=dewy.ru From: antonio@mandelbit.com (Antonio Quartulli) Newsgroups: linux.kernel.netdev Subject: [PATCH net v6 0/2] tun: bound the NAPI receive queue Date: Fri, 13 Nov 2026 22:22:32 +0100 Organization: Usenet Network Message-ID: <20261113212237.1742984-1-antonio@mandelbit.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1450007"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:JxOLLemWhbVcfSHE3oFOxyG3j1s= sha256:O1yQmLMeJTzQYuMu0yNwgZ7P/J/Z5cCxuPcAIClj/uU= sha1:eGnsFpTFpU7w+GuSZ9OmDnPQ0nY= sha256:2AeNsdIxa2ZPABIEfRGH30Bi3bSn1QcEM6Fi6w2g8ho= 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 48F8C1146AF; Sat, 14 Nov 2026 01:02:20 +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 Ic2xkHP5QW2I; Sat, 14 Nov 2026 01:02:16 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-362933-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 7FF2A1146B2; Sat, 14 Nov 2026 01:02:07 +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 ECD862A4EBF; Fri, 13 Nov 2026 21:23:00 +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=1794604977; b=AJW5XJiQO5Gb6lKQg2XgsySHG68u52fQmGZXeLaIoZxPZ1xYkVM68g/a7p8UHZl3afNd nJFaV8i6QBVhowTVyxs+5uhmPV4OiZpWFo+DaLHLG5Xff7cOq8yUyFFElcQ7U1W82ejBi SuFzWJ6znhrMGrgSIbie0PE82zpcr/TmTDXmvqnA8Eke+cSv46fwj1vfg9DHNP4TjKXVi WahFuHxFPiZKq8YVHK/oYtRPYm3ncZ2WeIhTLgOCKkvjjRA93L6QJX9Qek7reKvDzSSkX o0CgJaEz9SJX3bHdX/B1fRnofJ36I1baxpwlyU5X3ZUq//xkYOCzcy6MZAtWyjLoRMw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794604977; 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=VPnnnYLXSk8CSUf7R95OZDKV8BqykYO6+l1ofQyoXNU=; b=wgXfdhNzbLI9f/cZjhsCtDO6zO/B8/Cgs+IUJAD39vlJDSD9JJ0WEO2sPgThRjUeT2Mr QGEX95kbAly3Howwj15IFE5AW+R6Vgc6KjJi5MWdJv3GMJNvxCJhDPw/euovJsls9Qghs XFit+Q6rv4qYtGMlHPXDC7y4fg8cvrlrDx9IMLy62IwZPIFXRK/Y74cStcd3R8fS7E+jk fPUlopyGf4s7D2TOwYnMlK0XrUzwA4P2PMsHca4xW78vDET9Kp1g0m1ufS1jWyDoxmdOa CjVAnDIJjDZwRv0uw3l8zb4ChOAqdo0SAjlM/rs5kywGTa/Uo3zpOOdd8SX5CSzzN2A== 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=TOHTITDA; 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 8FFED606A882; Fri, 13 Nov 2026 21:22:57 +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=TOHTITDA X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.61 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794604971; b=1Qu7lXitJT34iUEW9BpiM/r45s8JZh2NpdfORgTm/nIkIebkSLSK8ySy9dVnXBLHOpKa LtWDgXz2v1DVWCmQvfQOz6HiMrTRHwfGyJfIi10T1qeC20BzdPfptzjrwALLqo0/VytxF w+3wvTLYpFBZ1dfwtbTyiP37ZfbXxCBhYRvUwU0/jMXOzKjvnv4WqvkvNECS/WfeMt9dj MbwtoMW3Kn+VcyOvo8jL8NZvqSEnLg0hAE0AgYznuYuTCTwO2ErEl08PuSgzQS4JnXMqh bHavw6CbecuagEd6p6/V+y3mHTy99aCCVjYkqMTDTa9eMaY5+VnR2hLEaJ0WAXuYYEQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794604971; 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=VPnnnYLXSk8CSUf7R95OZDKV8BqykYO6+l1ofQyoXNU=; b=Ss2xyO8Ror1T+znHxToV/L8IPDk8sSJdOt+OpmN2TyUVAJWPrxHG4jpUNybKO/+SuVo1 Lvyh6PttUydGTJ8mkwCpYsvlFz+Be3qo8D1fgivbJWgMcicW3358ZyjnKNdkicg1iBzOw /uPjOKMsSZa2ca0OsBd0wJp4k/VwfuTzkFuQRNIbW6p3aZc34CPBMU3yrEolsfy+fTMcW c+iCYY4X7NGwjA2cXfty+xvDeK2HqdIVdv4EXa0SOdEAwrPwa7rhv2KXa1fB7h4zLw7IZ X/tXX3QNWGFNYs7c7Y1qBq5sxgnjAJ4+IFUDccxyKM9TY2mPH4s8A0UaDG4aVw19v1Q== 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=TOHTITDA; arc=none smtp.remote-ip=195.10.208.61 X-Received: from mout-b-201.mailbox.org (mout-b-201.mailbox.org [195.10.208.61]) (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 92EA8606A32E; Fri, 13 Nov 2026 21:22:49 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92EA8606A32E 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-201.mailbox.org (Postfix) with ESMTPS id 4jR9Fx2mnWzLm2v; Fri, 13 Nov 2026 22:22:45 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794604965; 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=VPnnnYLXSk8CSUf7R95OZDKV8BqykYO6+l1ofQyoXNU=; b=TOHTITDA+0YVf69VA8D/rhN/UEIPkneY574BXqQzbCrfTQ5AhTQlJgrRyzTOAWWrVheLxN BtXjzQ4SYa3N+wPMIoB3MufE0o0P+eUqtPDovQOTUep1vIWkpL7EXV+QZb3JFXYo1PTDoI f/1Os9565bH6RN9CRh7fQ+c59f1t8Vlja/9zuzeN3PFcSvtHdiNRI6DF9Zj4pBnrokmEMj ruRFh9eMJ5nhMr+ZCmxUKsfq3655cdfvbmC6qKK+iwg5GdplWfdxyAQjkWqBFmafVWCRUa JTXRRjSi8OP7WoKlHUTTn+uUPeM6eR/6nrn2IZbmS7v2Id6SNsIoZTEVuAl0gw== 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: 4jR9Fx2mnWzLm2v