dm io: fix a race condition in the wake up code for sync_io
authorJoe Thornber <thornber@redhat.com>
Fri, 27 Jun 2014 19:29:04 +0000 (15:29 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2014 23:21:05 +0000 (16:21 -0700)
commit7d63157cc8e0272e910c2e155000288d34eca589
tree4d9215eb5c2562adb0e1413334dba97bb5e2e4e9
parent3acebd3e8140619f5093b8a70d1d9affcc634cab
dm io: fix a race condition in the wake up code for sync_io

commit 10f1d5d111e8aed46a0f1179faf9a3cf422f689e upstream.

There's a race condition between the atomic_dec_and_test(&io->count)
in dec_count() and the waking of the sync_io() thread.  If the thread
is spuriously woken immediately after the decrement it may exit,
making the on stack io struct invalid, yet the dec_count could still
be using it.

Fix this race by using a completion in sync_io() and dec_count().

Reported-by: Minfei Huang <huangminfei@ucloud.cn>
Signed-off-by: Joe Thornber <thornber@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-io.c