Re: [PATCH net] net: fix premature exit from NAPI state polling in napi_disable()

From: Jakub Kicinski
Date: Wed Nov 10 2021 - 20:44:58 EST


On Wed, 10 Nov 2021 17:44:07 -0800 Jakub Kicinski wrote:
> On Wed, 10 Nov 2021 20:43:37 +0100 Alexander Lobakin wrote:
> > > What about replacing the error prone do {...} while (cmpxchg(..)) by
> > > something less confusing ?
> > >
> > > This way, no need for a label.
> > >
> > > diff --git a/net/core/dev.c b/net/core/dev.c
> > > index 5e37d6809317fb3c54686188a908bfcb0bfccdab..9327141892cdaaf0282e082e0c6746abae0f12a7
> > > 100644
> > > --- a/net/core/dev.c
> > > +++ b/net/core/dev.c
> > > @@ -6264,7 +6264,7 @@ void napi_disable(struct napi_struct *n)
> > > might_sleep();
> > > set_bit(NAPI_STATE_DISABLE, &n->state);
> > >
> > > - do {
> > > + for (;;) {
> > > val = READ_ONCE(n->state);
> > > if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
> > > usleep_range(20, 200);
> > > @@ -6273,7 +6273,9 @@ void napi_disable(struct napi_struct *n)
> > >
> > > new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
> > > new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);
> > > - } while (cmpxchg(&n->state, val, new) != val);
> > > + if (cmpxchg(&n->state, val, new) == val)
> > > + break;
> > > + }
> > >
> > > hrtimer_cancel(&n->timer);
> >
> > LFTM, I'l queue v2 in a moment with you in Suggested-by.
>
> Ouch.
>
> Feel free to put
>
> Acked-by: Jakub Kicinski <kuba@xxxxxxxxxx>

Or I'll do it myself since it's already out...