Commit f152c392 authored by Lai Jiangshan's avatar Lai Jiangshan Committed by Ben Hutchings

workqueue: UNBOUND -> REBIND morphing in rebind_workers() should be atomic

commit 96e65306 upstream.

The compiler may compile the following code into TWO write/modify
instructions.

	worker->flags &= ~WORKER_UNBOUND;
	worker->flags |= WORKER_REBIND;

so the other CPU may temporarily see worker->flags which doesn't have
either WORKER_UNBOUND or WORKER_REBIND set and perform local wakeup
prematurely.

Fix it by using single explicit assignment via ACCESS_ONCE().

Because idle workers have another WORKER_NOT_RUNNING flag, this bug
doesn't exist for them; however, update it to use the same pattern for
consistency.

tj: Applied the change to idle workers too and updated comments and
    patch description a bit.

stable: Idle worker rebinding doesn't apply for -stable and
        WORKER_UNBOUND used to be WORKER_ROGUE.  Updated accordingly.
Signed-off-by: default avatarLai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent e8bf333a
...@@ -3437,14 +3437,17 @@ static int __cpuinit trustee_thread(void *__gcwq) ...@@ -3437,14 +3437,17 @@ static int __cpuinit trustee_thread(void *__gcwq)
for_each_busy_worker(worker, i, pos, gcwq) { for_each_busy_worker(worker, i, pos, gcwq) {
struct work_struct *rebind_work = &worker->rebind_work; struct work_struct *rebind_work = &worker->rebind_work;
unsigned long worker_flags = worker->flags;
/* /*
* Rebind_work may race with future cpu hotplug * Rebind_work may race with future cpu hotplug
* operations. Use a separate flag to mark that * operations. Use a separate flag to mark that
* rebinding is scheduled. * rebinding is scheduled. The morphing should
* be atomic.
*/ */
worker->flags |= WORKER_REBIND; worker_flags |= WORKER_REBIND;
worker->flags &= ~WORKER_ROGUE; worker_flags &= ~WORKER_ROGUE;
ACCESS_ONCE(worker->flags) = worker_flags;
/* queue rebind_work, wq doesn't matter, use the default one */ /* queue rebind_work, wq doesn't matter, use the default one */
if (test_and_set_bit(WORK_STRUCT_PENDING_BIT, if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment