]> www.infradead.org Git - users/jedix/linux-maple.git/commit
dm bufio: fix deadlock with loop device
authorJunxiao Bi <junxiao.bi@oracle.com>
Wed, 10 Jul 2019 00:17:19 +0000 (17:17 -0700)
committerBrian Maly <brian.maly@oracle.com>
Wed, 4 Sep 2019 01:13:37 +0000 (21:13 -0400)
commitcfd20f2eb1cfb5fa5b0f9d3fa29cc620c18fb3ba
treef8c4ed897c82b70f1a79242b4e15ca4034ab0022
parentfc0a715f628e9ff8338477007903531106171f2f
dm bufio: fix deadlock with loop device

When thin-volume is built on loop device, if available memory is low,
the following deadlock can be triggered:

One process P1 allocates memory with GFP_FS flag, direct alloc fails,
memory reclaim invokes memory shrinker in dm_bufio, dm_bufio_shrink_scan()
runs, mutex dm_bufio_client->lock is acquired, then P1 waits for dm_buffer
IO to complete in __try_evict_buffer().

But this IO may never complete if issued to an underlying loop device
that forwards it using direct-IO, which allocates memory using
GFP_KERNEL (see: do_blockdev_direct_IO()).  If allocation fails, memory
reclaim will invoke memory shrinker in dm_bufio, dm_bufio_shrink_scan()
will be invoked, and since the mutex is already held by P1 the loop
thread will hang, and IO will never complete.  Resulting in ABBA
deadlock.

Cc: stable@vger.kernel.org
Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
(cherry picked from commit bd293d071ffe65e645b4d8104f9d8fe15ea13862)

Orabug: 29964645
Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Reviewed-by: Shuning Zhang <sunny.s.zhang@oracle.com>
Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/md/dm-bufio.c