[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250521152147.077f1cb0@kernel.org>
Date: Wed, 21 May 2025 15:21:47 -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 12:51:33 -0700 Samiullah Khawaja wrote:
> > This might suffer from the problem you highlighted earlier,
> > CPU 0 (IRQ) CPU 1 (NAPI thr) CPU 2 (config)
> >
> > ____napi_schedule()
> > if (test_bit(NAPI_STATE_THREADED))
> > if (thread) {
> >
> > kthread_stop()
> > if (state & SCHED_THREADED || !(state & SCHED)) {
> > state &= ~THREADED;
> > if (try_cmp_xchg())
> > break
> >
> > set_bit(NAPI_STATE_SCHED_THREADED)
> > wake_up_process(thread);
This got a bit line wrapped for me so can't judge :(
> > This would happen without the try_cmp_xchg logic that I added in my
> > patch in the __napi_schedule (in the fast path). __napi_schedule would
> > have to make sure that the kthread is not stopping while it is trying
> > to do SCHED. This is similar to the logic we have in
> > napi_schedule_prep that handles the STATE_DISABLE, STATE_SCHED and
> > STATE_MISSED scenarios. Also if it falls back to normal softirq, it
> > needs to make sure that the kthread is not polling at the same time.
> Discard this as the SCHED would be set in napi_schedule_prepare before
> __napi_schedule is called in IRQ, so try_cmp_xchg would return false.
> I think if the thread stops if the napi is idle(SCHED is not) set then
> it should do. This should make sure any pending SCHED_THREADED are
> also done. The existing logic in napi_schedulle_prep should handle all
> the cases.
I think we're on the same page. We're clearing the THREADED bit
(not SCHED_THREADED). Only napi_schedule() path looks at that bit,
after setting SCHED. So if we cmpxchg on a state where SCHED was
clear - we can't race with anything that cares about THREADED bit.
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.
And FWIW my understanding is that we don't need any barriers on the
fast path (SCHED vs checking THREADED) because memory ordering is
a thing which exists only between distinct memory words.
Powered by blists - more mailing lists