Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: fcarli@gmail.com
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
Subject: Re: [PATCH net] veth: disable preemption between the NAPI mark and its wake-up
Date: Sat, 05 Dec 2026 08:09:25 +0000	[thread overview]
Message-ID: <179645816504.3146.9790849691773053454@kernel.org> (raw)
In-Reply-To: <20261204-veth-napi-rt-v1-1-02b900f75067@gmail.com>

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

  parent reply	other threads:[~2026-12-05  8:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  7:51 [PATCH net] veth: disable preemption between the NAPI mark and its wake-up Florent Carli via B4 Relay
2026-12-04  9:20 ` Sebastian Andrzej Siewior
2026-12-04 10:38   ` Florent Carli
2026-12-05  8:09 ` netdev-bot+sashiko [this message]
2026-12-05  8:20   ` Florent Carli

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=179645816504.3146.9790849691773053454@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bpf@vger.kernel.org \
    --cc=clrkwllms@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fcarli@gmail.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sdf@fomichev.me \
    --cc=stable@vger.kernel.org \
    --cc=toshiaki.makita1@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