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] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZG0YeeTZNox8YB25@slm.duckdns.org>
Date:   Tue, 23 May 2023 09:48:09 -1000
From:   Tejun Heo <tj@...nel.org>
To:     Zqiang <qiang.zhang1211@...il.com>
Cc:     jiangshanlai@...il.com, naresh.kamboju@...aro.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] workqueue: Fix warning triggered when nr_running is
 checked in worker_enter_idle()

Hello,

On Tue, May 23, 2023 at 09:40:16AM -1000, Tejun Heo wrote:
> On Tue, May 23, 2023 at 10:09:41PM +0800, Zqiang wrote:
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> > index 9c5c1cfa478f..329b84c42062 100644
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> > @@ -1144,13 +1144,12 @@ void wq_worker_tick(struct task_struct *task)
> >  	 * longer than wq_cpu_intensive_thresh_us, it's automatically marked
> >  	 * CPU_INTENSIVE to avoid stalling other concurrency-managed work items.
> >  	 */
> > -	if ((worker->flags & WORKER_NOT_RUNNING) ||
> > +	if ((worker->flags & WORKER_NOT_RUNNING) || worker->sleeping ||
> >  	    worker->task->se.sum_exec_runtime - worker->current_at <
> >  	    wq_cpu_intensive_thresh_us * NSEC_PER_USEC)
> >  		return;
> 
> Ah, right, this isn't just interrupted read-modify-write. It has to consider
> sleeping. This is subtle. We'll definitely need more comments. Will think
> more about it.

So, there already are enough barriers to make this safe but that's kinda
brittle because e.g. it'd depend on the barrier in preempt_disable() which
is there for an unrelated reason. Can you please change ->sleeping accesses
to use WRITE/READ_ONCE() and explain in wq_worker_tick() that the worker
doesn't contribute to ->nr_running while ->sleeping regardless of
NOT_RUNNING and thus the operation shouldn't proceed? We probably need to
make it prettier but I think that should do for now.

Thanks.

-- 
tejun

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ