]> git.baikalelectronics.ru Git - kernel.git/commit
block: don't use un-ordered __set_current_state(TASK_UNINTERRUPTIBLE)
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 2 Jan 2019 18:46:03 +0000 (10:46 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 2 Jan 2019 18:46:03 +0000 (10:46 -0800)
commitaf5d6e56effd9b60766580059fd75d274ea63509
tree8d2cb4d087b6e6c1acc7303cfe336f9f67247b53
parentbdfbb3c9a01a8b0f4a0359b4d40a85a957dc780c
block: don't use un-ordered __set_current_state(TASK_UNINTERRUPTIBLE)

This mostly reverts commit b6f2f3ce33c0 ("block: avoid ordered task
state change for polled IO").  It was wrongly claiming that the ordering
wasn't necessary.  The memory barrier _is_ necessary.

If something is truly polling and not going to sleep, it's the whole
state setting that is unnecessary, not the memory barrier.  Whenever you
set your state to a sleeping state, you absolutely need the memory
barrier.

Note that sometimes the memory barrier can be elsewhere.  For example,
the ordering might be provided by an external lock, or by setting the
process state to sleeping before adding yourself to the wait queue list
that is used for waking up (where the wait queue lock itself will
guarantee that any wakeup will correctly see the sleeping state).

But none of those cases were true here.

NOTE! Some of the polling paths may indeed be able to drop the state
setting entirely, at which point the memory barrier also goes away.

(Also note that this doesn't revert the TASK_RUNNING cases: there is no
race between a wakeup and setting the process state to TASK_RUNNING,
since the end result doesn't depend on ordering).

Cc: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/block_dev.c
fs/iomap.c
mm/page_io.c