lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250528170442.160f6f99@kernel.org>
Date: Wed, 28 May 2025 17:04:42 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Samiullah Khawaja <skhawaja@...gle.com>
Cc: Wei Wang <weiwan@...gle.com>, "David S . Miller" <davem@...emloft.net>,
 Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>,
 almasrymina@...gle.com, willemb@...gle.com, jdamato@...tly.com,
 mkarsten@...terloo.ca, netdev@...r.kernel.org
Subject: Re: [PATCH net-next v2] net: stop napi kthreads when THREADED napi
 is disabled

On Wed, 21 May 2025 15:50:19 -0700 Samiullah Khawaja wrote:
> > Just to be clear - the stopping of the thread has to be after the
> > proposed loop, so kthread_should_stop() does not come into play.  
> Wait, the thread will unset STATE_THREADED if kthread_should_stop is
> true. right? Otherwise how would thread know that it has to unset the
> bit and stop?
> 
> As I understand, we should be doing something like following:
> 
> while (true) {
>    state = READ_ONCE()
>    can_stop = false;
> 
>    if (kthread_should_stop) {
>        if (SCHED_THREADED || !SCHED) {
>            state &= !THREADED
>        } else {
>            msleep(1);
>            continue;
>        }
> 
>         if (try_cmpxchg) {
>             can_stop = true;
>             if (!SCHED_THREADED)
>                 break;
>         }
>    }
> 
>    if (SCHED_THREADED)
>        poll()
> 
>    if (can_stop))
>        break;
> }

So moving the stopping logic into the polling thread? I don't think this
helps anything. 

Once we unset the THREADED bit we should wait for the thread to clear
SCHED_THREADED (before trying to stop it). SCHED_THREADED going away
is our signal that it's safe to reap the thread.

If you're afraid that the thread will not terminate (because packets
continue to flow in) - we probably want something like:

diff --git a/net/core/dev.c b/net/core/dev.c
index 2b514d95c528..33d4b726395b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7548,6 +7548,13 @@ static void napi_threaded_poll_loop(struct napi_struct *napi)
                if (!repoll)
                        break;
 
+               /* Thread is going away, give up the ownership */
+               if (!likely(READ_ONCE(napi->state) & NAPIF_STATE_THREADED)) {
+                       clear_bit(NAPI_STATE_SCHED_THREADED, &napi->state);
+                       __napi_schedule(napi);
+                       break;
+               }
+
                rcu_softirq_qs_periodic(last_qs);
                cond_resched();
        }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ