Messages in this thread Patch in this message | | | From | Lai Jiangshan <> | Subject | [PATCH 1/9 V3] workqueue: ensure the wq_worker_sleeping() see the right flags | Date | Thu, 30 Aug 2012 00:51:52 +0800 |
| |
The compiler may compile this code into TWO write/modify instructions. worker->flags &= ~WORKER_UNBOUND; worker->flags |= WORKER_REBIND;
so the other CPU may see the temporary of worker->flags which has not WORKER_UNBOUND nor WORKER_REBIND, it will wrongly do local wake up.
so we use one write/modify instruction explicitly instead.
This bug will not occur on idle workers, because they have another WORKER_NOT_RUNNING flags.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> --- kernel/workqueue.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 692d976..4f252d0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1434,10 +1434,13 @@ retry: /* rebind busy workers */ for_each_busy_worker(worker, i, pos, gcwq) { struct work_struct *rebind_work = &worker->rebind_work; + unsigned long worker_flags = worker->flags; /* morph UNBOUND to REBIND */ - worker->flags &= ~WORKER_UNBOUND; - worker->flags |= WORKER_REBIND; + worker_flags &= ~WORKER_UNBOUND; + worker_flags |= WORKER_REBIND; + /* ensure the wq_worker_sleeping() see the right flags */ + ACCESS_ONCE(worker->flags) = worker_flags; if (test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(rebind_work))) -- 1.7.4.4
| |