🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9207

Re: [PATCH net v2] tun: bound the NAPI receive queue

#9207
From: Antonio Quartulli
Date: Sat, 31 Oct 2026 22:15
88 lines
11532 bytes
Hi Willem,

thanks a lot for the review. See below:

On 30/10/2026 22:52, Willem de Bruijn wrote:
> Antonio Quartulli wrote:
[...]>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index 770b8fe085c3..1ace0c1f22f2 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -60,6 +60,7 @@
>>   #include <linux/rcupdate.h>
>>   #include <net/net_namespace.h>
>>   #include <net/netns/generic.h>
>> +#include <net/hotdata.h>
>>   #include <net/rtnetlink.h>
>>   #include <net/sock.h>
>>   #include <net/xdp.h>
> 
> Keep alphebetical order

ACK, will fix in v3.

> 
> 
>> @@ -1856,6 +1857,17 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>>   			zerocopy = true;
>>   	}
>>   
>> +	/* In NAPI mode packets are queued here and processed by the NAPI
>> +	 * poll, possibly in a kthread or ksoftirqd. Bound that queue like
>> +	 * the per-CPU backlog, and drop before allocating and copying.
>> +	 */
>> +	if (tfile->napi_enabled && !frags && !msg_control &&
> 
> Why disable if frags? That is still using NAPI scheduling.

Right, the exclusion doesn't help much.
In frags mode tun_get_user() processes the packet synchronously
with napi_gro_frags() and never queues to sk_write_queue, so the
check could only fire if something else filled that queue.
tun_xdp_one() can, on the same tfile, therefore I'll drop the
exclusion and also bounds tun_xdp_one() in v3.

> 
> Same for msg_control. tun_chr_write_iter calls with NULL msg_control.
> 
>> +	    unlikely(skb_queue_len_lockless(&tfile->sk.sk_write_queue) >=
>> +		     READ_ONCE(net_hotdata.max_backlog))) {
> 
> Nit: consider > instead of >=, same as enqueue_to_backlog
> 

ACK

>> +		dev_core_stats_rx_dropped_inc(tun->dev);
>> +		return total_len;
>> +	}
> 
> also best effort: more robust would require retesting once holding
> the lock.

I see.
In v3 I'll keep the lockless check before allocating and copying, and
recheck under the queue lock before __skb_queue_tail(), in both
tun_get_user() and tun_xdp_one().
Similarly to what enqueue_to_backlog() does.


Regards,

> 
>> +
>>   	if (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {
>>   		/* For the packet that is not easy to be processed
>>   		 * (e.g gso or jumbo packet), we will do it at after
>> -- 
>> 2.56.0
>>
> 

-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
Technical Details
Message-ID: <790874fd-0c02-4e70-9aa6-4fa0bb2857f2@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-354158-linux-kernel-netdev=dewy.ru
References: <20261030152540.1409884-1-antonio@mandelbit.com> <willemdebruijn.kernel.1805eb8882e13@gmail.com>

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-354158-linux-kernel-netdev=dewy.ru
From: antonio@mandelbit.com (Antonio Quartulli)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tun: bound the NAPI receive queue
Date: Sat, 31 Oct 2026 23:15:04 +0100
Organization: Usenet Network
Message-ID: <790874fd-0c02-4e70-9aa6-4fa0bb2857f2@mandelbit.com>
References: <20261030152540.1409884-1-antonio@mandelbit.com>
 <willemdebruijn.kernel.1805eb8882e13@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2565404"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:D0HKmjGS9Sjo1IwJuVStdamEBrM= sha256:9ZSnsZKcLhpRU6F1nI0oWYHCPXzgjOMeRLwjojrhPBo=
	sha1:vt1uhZFlUVG9koxdS9AMCpDBG9c= sha256:B8jrVG6FC8PmswM0O+1+koP+0cklR5ZkaJbrDQrIOws=
Content-Language: en-US
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 CD16A1122B9; Sun,  1 Nov 2026 01:15:40 +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.25,
	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 h-UG-7NmpE44;
	Sun,  1 Nov 2026 01:15:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354158-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 2838D112280; Sun,  1 Nov 2026 01:15:29 +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 00B2229486; Sat, 31 Oct 2026 22:15:21 +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=1793484920;
	b=d6wAEiW2pZtgq3D2q5IhSyGFI4wxQQYrL7IX/GU/xpdqo8mIl8V7dbwKZh6V8XajYy9N
	 9TzKN/T0lnSGUP20JbweG0Bu9qBVc2avkS5m/DThc4bbvADmBJ5KjnHpLo1zRXFgON2Cg
	 yuF6sXgPGlXHxpi4CHL2XQX1UrHtkg+TdyEb6aosGlbSHUsthqGe88J7GPVJmF22O0d5z
	 nE7o7jOuO6/hHnmZO5ZLg58utea9fhPErHobzCPAacvTg9gtO0TDTnwi3aMd8xHdCYJ69
	 wGl+dVSXy2cuDwp8obNmg4CRN+d8GVI5AsvROspLC3WT5oGer4r/Mt1wIF3lAZcfqCA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793484920;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 User-Agent:Subject:To:Cc:References:Content-Language:From:
	 Organization:In-Reply-To:Content-Type:Content-Transfer-Encoding:
	 X-Rspamd-Queue-Id;
	bh=eEDZVJa6rECx46xFFyMmTNRNAdijfZTVObHJQWnV0yk=;
	b=C9/bVvxPAOKfDaqPLIkgJXyjEBISmvd0kn+hu7Kt7AcqbiSBSNTDbqJp9zU+GXaisi+R
	 7mH02OWFDVzw2x5qgb3SjmGos3lzx1h2sSYGLDDjkovfBAhpn2MhlaZfK0Db1PdzQ9zMt
	 jOA85Lc+yAIGE6CDuFGhBod9kh6opFso7fTq3dEoglAfZKIITZ/mR3Crb0kvxhfI/8cRN
	 JehWquI4CDOgsy41uHf5hwe6tfKoRMcsfQrcxNTsVRPFF07+HYb5DyIJp9QXXJlj9Czfl
	 hXtn3j3nLNIxSkZUtq3XcQq8Joh6JqH9hGaVc4W2DNO64/wxM/1ZKJ8LUYUr3K3oGeQ==
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=XwUhQb+D;
	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 CBE64606A321;
	Sat, 31 Oct 2026 22:15:20 +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=XwUhQb+D
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.51
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793484919;
	b=tYgGweDwEumIts+pZFxTbOGo+/xR2ADRj1ROaAmm5Gw2f2pHhM+YvMZiaYSYw+FasNmg
	 MpBPhQYjwKqp8KW/10OlBZSaSADyUrRs3V0ub9Zlps5WBBN0rqGqIDIn9augcJWbmAhJi
	 BW7VRbMLWiuIUL7wOHggN0y4OkSgAwWtHihhmxIGgQ4AUG+SLwRkjVBHCwTFBCdtNy842
	 +IrAC7EGm8sDGOsF/m3gj8e5JFLFruftETN3JzoWqFG7+bc5Ud/RtBZ35DYepVzPLLzcC
	 vSJbdT7D1XrK+iHSOiSkG+ytjOWOQNHSf9iYd83zLZNAAiZWBZrA4P1KMW/110XX6Fw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793484919;
	h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Date:MIME-Version:
	 User-Agent:Subject:To:Cc:References:Content-Language:From:
	 Organization:In-Reply-To:Content-Type:Content-Transfer-Encoding:
	 X-Rspamd-Queue-Id;
	bh=eEDZVJa6rECx46xFFyMmTNRNAdijfZTVObHJQWnV0yk=;
	b=4y3Ckx4c/1h/T7egpi5IC43H+6kqj68/meBLUfeMle5EO0RhWdR2I1X0rYona/SlmRX/
	 MR4g0WSfp7KiIHwyGSVeU6jvnLHnDVwGp3yjdGpTAvntCDvkrnb4x2vv0tEPQmJhMXWRR
	 Dw2DRUhS3i2ziELYLhoAclU4MjgIVoAI+oBK8kiR27gXDVCnkeAw6bs5vEb07LblHQ4nq
	 +w6GpnOkYXEPrYScp+3yanm2TjfUQTAnWt8hpKw9p0iact68PAUITgXbQSozP2kkGHxoh
	 uqnKgulz9Bqxd8chu3klT3wc7T440a/pA/+SQLxAl4e5RZvgnFlT2f/8xyDEozl9LaA==
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=XwUhQb+D;
	arc=none smtp.remote-ip=195.10.208.51
X-Received: from mout-b-206.mailbox.org (mout-b-206.mailbox.org [195.10.208.51])
	(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 DC69A606A31A
	for <netdev@vger.kernel.org>; Sat, 31 Oct 2026 22:15:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC69A606A31A
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-206.mailbox.org (Postfix) with ESMTPS id 4jHC2L56h0zbv;
	Sat, 31 Oct 2026 23:15:06 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
	s=MBO0001; t=1793484906;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=eEDZVJa6rECx46xFFyMmTNRNAdijfZTVObHJQWnV0yk=;
	b=XwUhQb+D1UyAxEn5cnnh1lrDGtdXr9HkAQogoDodQLIBfIA+5SrZ/AdUvWUtrpaRq1fia2
	HIv8cVtQ1XjTZepbqmIdzPB6QHHoIBeqaNXPJOL1nTUQQI17iW+NXYl6o1MinslbpK1kOx
	lTe6TX8ox/zdSJVlCMBG1qKfwTt6IsLCMV9bud3FbgmrpcRXnvq1Ohtxx6Uy3fujh8HiWK
	WSKHDfFiKro8sVni7ayq6SYK7oHYZtbHZDefwI6WFIknaToYj0vJzdCLXDL2vU92LdFr0R
	cGua8UtaGeP+T+pyE3AMDbfST+5JS/mM7+OPVdJkVeVVTKzD4/04n5sLkzxPbw==
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-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-User-Agent: Mozilla Thunderbird
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org
X-Organization: Mandelbit SRL
X-In-Reply-To: <willemdebruijn.kernel.1805eb8882e13@gmail.com>
X-Rspamd-Queue-Id: 4jHC2L56h0zbv