Re: [PATCH] workqueue: Don't double assign worker->sleeping

From: Sebastian Andrzej Siewior
Date: Thu Apr 02 2020 - 03:31:14 EST


On 2020-04-02 08:07:35 [+0800], Lai Jiangshan wrote:
> > > would be *increased* twice
> > >
> > > I just saw the V2 patch, this issue is not listed, but need to be fixed too.
> >
> > | void wq_worker_running(struct task_struct *task)
> > | {
> > | struct worker *worker = kthread_data(task);
> > |
> > | if (!worker->sleeping)
> > | return;
> > | if (!(worker->flags & WORKER_NOT_RUNNING))
> > | atomic_inc(&worker->pool->nr_running);
> > *0
> > | worker->sleeping = 0;
> > *1
> > | }
> >
> > So an interrupt
> > - before *0, the preempting caller drop early in wq_worker_sleeping(), only one
> > atomic_inc()
>
> If it is preempted on *0, the preempting caller drop early in
> wq_worker_sleeping()
> so there is no atomic decreasing, only one atomic_inc() in the
> preempting caller.
> The preempted point here, wq_worker_running(), has already just done
> atomic_inc(),
> the total number of atomic_inc() is two, while the number of atomic decreasing
> is one.

But in order to look at the same worker->sleeping it has to be same
`task'. This can not happen because the `worker' assignment is
per-thread.

Sebastian