Skip to content

Commit

Permalink
workqueue: add missing smp_wmb() in process_one_work()
Browse files Browse the repository at this point in the history
commit 959d1af8cffc8fd38ed53e8be1cf4ab8782f9c00 upstream.

WORK_STRUCT_PENDING is used to claim ownership of a work item and
process_one_work() releases it before starting execution.  When
someone else grabs PENDING, all pre-release updates to the work item
should be visible and all updates made by the new owner should happen
afterwards.

Grabbing PENDING uses test_and_set_bit() and thus has a full barrier;
however, clearing doesn't have a matching wmb.  Given the preceding
spin_unlock and use of clear_bit, I don't believe this can be a
problem on an actual machine and there hasn't been any related report
but it still is theretically possible for clear_pending to permeate
upwards and happen before work->entry update.

Add an explicit smp_wmb() before work_clear_pending().

Signed-off-by: Tejun Heo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

Signed-off-by: franciscofranco <[email protected]>
  • Loading branch information
htejun authored and airend committed Mar 8, 2016
1 parent 7f93460 commit 0f07f95
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,9 @@ __acquires(&gcwq->lock)

spin_unlock_irq(&gcwq->lock);

smp_wmb(); /* paired with test_and_set_bit(PENDING) */
work_clear_pending(work);

lock_map_acquire_read(&cwq->wq->lockdep_map);
lock_map_acquire(&lockdep_map);
trace_workqueue_execute_start(work);
Expand Down

0 comments on commit 0f07f95

Please sign in to comment.