All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junxiao Bi <junxiao.bi@oracle.com>
To: dm-devel@redhat.com
Cc: honglei.wang@oracle.com, mpatocka@redhat.com, agk@redhat.com,
	snitzer@redhat.com, junxiao.bi@oracle.com
Subject: [PATCH v2] dm-bufio: fix deadlock with loop device
Date: Tue,  9 Jul 2019 17:17:19 -0700	[thread overview]
Message-ID: <20190710001719.2504-1-junxiao.bi@oracle.com> (raw)

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

One process P1 was allocating memory with GFP_FS flag, direct alloc fail,
memory reclaim invoked memory shrinker in dm_bufio, dm_bufio_shrink_scan()
run, mutex dm_bufio_client->lock was acquired, then P1 wait for dm_buffer
io done in __try_evict_buffer->()__try_evict_buffer().

But this io may never done as it was issued to the underlying loop device
who forward it using fs direct-io, there some memory allocation were using
GFP_FS(like do_blockdev_direct_IO()), if direct alloc fail, memory reclaim
will invoke memory shrinker in dm_bufio, where dm_bufio_shrink_scan()
will be invoked, since the mutex was already hold by P1, the loop thread
will hung, io will never done. ABBA deadlock.

Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
---
Changes in v2:
  - refine the commit log

 drivers/md/dm-bufio.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 2a48ea3f1b30..b6b5acc92ca2 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1599,9 +1599,7 @@ dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 	unsigned long freed;
 
 	c = container_of(shrink, struct dm_bufio_client, shrinker);
-	if (sc->gfp_mask & __GFP_FS)
-		dm_bufio_lock(c);
-	else if (!dm_bufio_trylock(c))
+	if (!dm_bufio_trylock(c))
 		return SHRINK_STOP;
 
 	freed  = __scan(c, sc->nr_to_scan, sc->gfp_mask);
-- 
2.17.1

             reply	other threads:[~2019-07-10  0:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10  0:17 Junxiao Bi [this message]
2019-07-10 17:48 ` [PATCH v2] dm-bufio: fix deadlock with loop device Mike Snitzer
2019-07-10 21:08   ` Junxiao Bi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190710001719.2504-1-junxiao.bi@oracle.com \
    --to=junxiao.bi@oracle.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=honglei.wang@oracle.com \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.