๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27286

Re: [PATCH net] veth: disable preemption between the NAPI mark and its wake-up

#27286
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 08:09
133 lines
12898 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] With non-threaded NAPI on PREEMPT_RT, the veth fix does not
  remove the priority inversion the commit message describes.

--

veth: disable preemption between the NAPI mark and its wake-up

This patch adds a veth_napi_schedule() helper. The helper calls
napi_schedule_prep() and __napi_schedule() with preemption disabled.
__veth_xdp_flush() and the re-schedule at the end of veth_poll() now use
it. The aim is to stop a preempted low priority producer on PREEMPT_RT
from holding back the NAPI wake-up for every other producer of the same
veth.

> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index faa837acea7b7..a67a608e9ed1a 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -299,15 +299,26 @@ static void veth_ptr_free(void *ptr)
>  		kfree_skb(ptr);
>  }
>  
> -static void __veth_xdp_flush(struct veth_rq *rq)
> +/* Mark the NAPI scheduled and wake it up. Once it is marked, the other
> + * producers leave the wake-up to this caller. On PREEMPT_RT the callers
> + * are preemptible: do not let a preemption hold the wake-up back.
> + */
> +static void veth_napi_schedule(struct veth_rq *rq)
>  {
> -	/* Write ptr_ring before reading rx_notify_masked */
> -	smp_mb();
> -	if (!READ_ONCE(rq->rx_notify_masked) &&
> -	    napi_schedule_prep(&rq->xdp_napi)) {
> +	preempt_disable();
> +	if (napi_schedule_prep(&rq->xdp_napi)) {
>  		WRITE_ONCE(rq->rx_notify_masked, true);
>  		__napi_schedule(&rq->xdp_napi);
>  	}
> +	preempt_enable();
> +}

[Severity: High]

Does this close the window when the peer NAPI is not threaded? That is
the default for veth, which registers its NAPI with plain
netif_napi_add().

In that mode __napi_schedule() does not wake a task.
____napi_schedule() only queues the NAPI on the local CPU and raises the
softirq:

net/core/dev.c:____napi_schedule() {
    ...
	list_add_tail(&napi->poll_list, &sd->poll_list);
	WRITE_ONCE(napi->list_owner, smp_processor_id());
	if (!sd->in_net_rx_action)
		raise_softirq_irqoff(NET_RX_SOFTIRQ);
}

On PREEMPT_RT, in_interrupt() is true while the current task has BH
disabled, because softirq_count() there comes from
current->softirq_disable_cnt. So raise_softirq_irqoff() skips
wakeup_softirqd():

kernel/softirq.c:raise_softirq_irqoff() {
    ...
	if (!in_interrupt() && should_wake_ksoftirqd())
		wakeup_softirqd();
}

The pending NET_RX softirq then runs only when the same producer
reaches its own local_bh_enable().

Take a nice 19 sender on CPU3 and a high priority sender on CPU1:

CPU3 (nice 19)
veth_xmit()
  __veth_xdp_flush()
    veth_napi_schedule()
      napi_schedule_prep()     /* sets NAPI_STATE_SCHED */
      rx_notify_masked = true
      __napi_schedule()        /* only queued on CPU3 poll_list */
      preempt_enable()
  <preempted by a SCHED_FIFO task before local_bh_enable()>

CPU1 (SCHED_FIFO)
veth_xmit()
  __veth_xdp_flush()
    READ_ONCE(rq->rx_notify_masked) == true, return

Wouldn't CPU1's packets then stay in xdp_ring until the nice 19 task
runs again? That is the same stall the commit message describes.

The veth_poll() hunk seems to have the same problem. The commit message
says:

  "and the re-schedule at the end of veth_poll(), which without threaded
  NAPI runs in whatever task processes the softirq and has the same
  window on PREEMPT_RT."

In non-threaded mode, veth_poll() runs inside that task's
net_rx_action(). It already owns NAPI_STATE_SCHED for the whole poll,
and the poll can be preempted. The re-scheduled NAPI goes back on the
same CPU's poll_list with in_net_rx_action set. So it is only served
when that task resumes, whether it was preempted before or after
__napi_schedule().

In threaded mode, veth_poll() runs in the NAPI thread and re-schedules
itself. There doesn't seem to be a cross-task inversion there for
preempt_disable() to fix.

As far as I can tell, this only fixes the threaded NAPI producer case
that the reproducer used. Could the comment on veth_napi_schedule() and
the commit message be limited to that case? Or does the non-threaded
case need a different approach, such as covering the whole BH-disabled
section, or requiring threaded NAPI on PREEMPT_RT?

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-veth-napi-rt-v1-1-02b900f75067%40gmail.com
Technical Details
Message-ID: <179645816504.3146.9790849691773053454@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377874-linux-kernel-netdev=dewy.ru
References: <20261204-veth-napi-rt-v1-1-02b900f75067@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377874-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] veth: disable preemption between the NAPI mark and
 its wake-up
Date: Sat, 05 Dec 2026 08:09:25 +0000
Organization: Usenet Network
Message-ID: <179645816504.3146.9790849691773053454@kernel.org>
References: <20261204-veth-napi-rt-v1-1-02b900f75067@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2982675"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Q6G+VcmGbXbBs1j9fMMwCR/NthU= sha256:NhfxgI61gr2YbIoeTX/Hvuu/Ru2XgdOtG2QyOBeZoEE=
	sha1:KhDU2fHsrobCQo/DzPIt3z6FJZ0= sha256:EYyRZtPTVCr9szLCgnE9o12cxkK1LZd53m0W1tjMLPI=
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 05DA3117D9C; Sat,  5 Dec 2026 11:09:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=kernel.org
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 mR1rv69LrAKw;
	Sat,  5 Dec 2026 11:09:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377874-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 8135C117D4A; Sat,  5 Dec 2026 11:09:36 +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 5E9EF356D9; Sat,  5 Dec 2026 08:09:28 +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=1796458167;
	b=tyLtKO8UJQz6/tYOkBPOJtpRrO1Ve8L2t5O7mFj5LU74uKCcTJySmRvwQxRgjBZ5HTXF
	 NrAydtkCxPNyjNT2clIPesSaw0ohRaa0GU71yaS78RKF0KFT8dSHeuYTpEZz/wyM6B5s1
	 6C/Tg4UwmL60TU8DzELMYBIAbC4cBDHUB0THzUFt/S1NyrPyaVmZfLqbLMkd+iWgBuZpq
	 +5Yw/aXH/a+Kf9HbuGXp5Lba/P5KOKpeGIP4s4xzJ4GRgbxUx98w3ZVz2awqi1Rr01s7O
	 BzW8FjfyVrGw3SxasGnYmRKPKuiTHvKjiDqK7xBGnRq6Jaq47hGThiiDFtHVU31kvlA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796458167;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=YrLF2PdYC1LzZvhxxtK8aW2K75WBEceru/gwOlaI8LA=;
	b=pxKPvMbPwo949TGqQU1vggM2hq4AkxqgKGvy0qREVZrvwuU5gp/H+Ob26rKtfHIYsK6j
	 LvRcTfNlCQrSF0m06gzdl6Z3gDAYo7nGK60q5NQI5OfhIZkTiOMmGvNfisclNUF7s2Le0
	 vzLvmveDKatLWU1v0lqNO4yQZje6B81qVMDOIs1O0X7PnjC3J+CkXrOqjQER2Rx3KM20a
	 NLO9bqJknS2KDgso+dKhPMhbIlAnbLUtmyNh+QiAD1AV9Dwm49Y03zRlL9jcjYeP1kOQa
	 /PCE8B6suaCXNHC30qmjjKEHHkPdbk3WzfMM3ZawR90w16qbv+agidP7CEVA+xfNp9Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMVXRpEd;
	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 BE134606A33F;
	Sat,  5 Dec 2026 08:09:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMVXRpEd
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796458166;
	b=jwP8rx+H9CKDq/mlKLlVSa4HqzMOeW6R076D8QovHxmTSVgqXEFDcDlDnK2H9UIpisEZ
	 RunuNmA2xxqkJTKoWH/ojAtTQDjq4j04HanThx6OagfmIspCC9nD9dh0a0mMlJdgmvZSh
	 y2UeeDhxXiZ8gm78m/FUWqBwNbVRT8sxDoUlwcfCJCcFO16Ag08mnGoYn874i3FZqy0K1
	 zX9WREjoP1Z3bm0hgT1mlQO0KM6gTuaOv7WMQ+VR5ynD+FL3y4id4y0J5R2WVxdjO5gTw
	 5vGBSbYSWJW/2HY/Yl4xVcBPEyWBRTDZbq4J8xTdOKKT7XwOBJPlyosI+zG7K9jx71A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796458166;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=YrLF2PdYC1LzZvhxxtK8aW2K75WBEceru/gwOlaI8LA=;
	b=zmKsxlBm0p36qcX4ED193cpcGcFJWT60BT+Otb1OIiqyo8SCz9yQIhqC3Sb4CzZflF6t
	 skSu0XUPvt3v7wnrZN9bPShpqUzwan6cwmnciHixiYZxJsQ3QaJk7KHjrOFdaRdRGqPIK
	 AutrO9drKTy8UDFHEsB6dsZ1kt8F3nBfJ1EI3ddDHM0ou7ubFVexfbYmwjS+lkMkd3RKc
	 4n6MnjzriMFIgeu0SG/kOTmgYjNYYUtAZBXiYutpug1N8HMKczYf+LZb2GcS71263LuXJ
	 lldKgP/xjHmQ23XmVnbadLmunINDcED5LLFgs18cVl96JogytYzEwggKp/Ze2FuXRYw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMVXRpEd;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD74D606A332;
	Sat,  5 Dec 2026 08:09:26 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DC591F0092B;
	Sat,  5 Dec 2026 08:09:25 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796458166;
	bh=YrLF2PdYC1LzZvhxxtK8aW2K75WBEceru/gwOlaI8LA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=FMVXRpEdYUwVBAtCkyTrvbGpA24NpD4Ai/tXiGo2lxnLa+evYtRol6alm1qOpDnw5
	 bwMKu1zoUoQVE8baFqe93EtCbW8p3M5BG6FLdzGZ81OIwSsSbdV6vNpGzOVURgJpFO
	 lyunfhZ72OPgZEl+O6c4GcbbOUIm77IfQpQJGyqL6AZrqAS2spkkgr282KAl9JHGa+
	 zMejtPFNot7yDpmj7AtixxcXZqFZBidBccdCJZnDYBetHkLsC5S1B6lUt3s5DIbaex
	 rY4fcEhS+twpOIGlLE72uaNhSUPvbXG2mx/zEMEz0nBOaR8TANDNF8JXY0KSklEOk8
	 w3io0ppz0xh8g==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, bigeasy@linutronix.de,
 clrkwllms@kernel.org, rostedt@goodmis.org, ast@kernel.org,
 daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
 sdf@fomichev.me, netdev@vger.kernel.org, linux-rt-devel@lists.linux.dev,
 bpf@vger.kernel.org, toshiaki.makita1@gmail.com, stable@vger.kernel.org
X-In-Reply-To: <20261204-veth-napi-rt-v1-1-02b900f75067@gmail.com>
X-sashiko-severity: High
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