Netdev List
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@mandelbit.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>, jasowangio@gmail.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org
Subject: Re: [PATCH net v2] tun: bound the NAPI receive queue
Date: Sat, 31 Oct 2026 23:15:04 +0100	[thread overview]
Message-ID: <790874fd-0c02-4e70-9aa6-4fa0bb2857f2@mandelbit.com> (raw)
In-Reply-To: <willemdebruijn.kernel.1805eb8882e13@gmail.com>

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


      reply	other threads:[~2026-10-31 22:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 15:25 [PATCH net v2] tun: bound the NAPI receive queue Antonio Quartulli
2026-10-30 21:52 ` Willem de Bruijn
2026-10-31 22:15   ` Antonio Quartulli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=790874fd-0c02-4e70-9aa6-4fa0bb2857f2@mandelbit.com \
    --to=antonio@mandelbit.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox