Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9942813ybi; Wed, 24 Jul 2019 12:45:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIO9QxtvuWQbunWrNCs62rE5x7H7wKhyK5O08b0dcuWzrsE2QZRaVmNl+GcTjcVMmLnAO3 X-Received: by 2002:a17:90a:f498:: with SMTP id bx24mr90471515pjb.91.1563997536479; Wed, 24 Jul 2019 12:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563997536; cv=none; d=google.com; s=arc-20160816; b=z+CyLXmwkMWdE63GWRXZFWe943i+w7NlAp8HD3TmlYQueiSAZphCB43XGkDJJeiMAb o6s2C3l8l8WuAeUTy0vh860lamuOxASw90OS7RLglRulFdmXjOzVjOMclUwOkDqd9nFX HKFblgmGEV0W0XFgK4W2w1mlLEgKzYPIDV659UORV8SXoE5Ncw5DK/AHS+o4leyMQjwI 07hwBK8hkItso7qfDC3H3lyUWrWXPRyUafxyDfHVGPmYTO6pdAzR2nWGG6NRQKtLPONp PJJ/27vtsSR8kuegD8kibtNdsRlv0Usu1FF7DyJId73oedXLVWVhYB1aREXIMtlvTGKT YwSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KO9cxB4QMVGelXkKoAFimbyZJ4Z3SQxI91RLQMOqCdw=; b=lBeYYVPmXzMQJXOQjrvSajQMjM+Yya/ZP3rJPmTDtAxQY1EGjblKl3XXumpaG8LN08 8qTBWc9SAjgcR+KYx0laDiUNMPKcXD4uRpoDp1KCCrKtgTDn8MRTaVBu8VOHDYIihOyA MKqjR1ubqNymVBLWNxHbJYr28fA1efRXS02UwPmUjNVkxLz6QEJE5odVc9JcYzqUEgIS dE3iOoBd+yeYim6jcQcrP6QJefbxl0tTNRy+l/rVZ70bfoR/2bqXBCHtTGMxOGBAezzC 4snUFGpgIOmdYIy8g8W7VzRyhHxROcojWYq4527a6Rs2/fo76KpMQ1SFt6zYJ8SFew42 Jiww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=09ID5DDz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si14587940pgp.435.2019.07.24.12.45.22; Wed, 24 Jul 2019 12:45:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=09ID5DDz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390425AbfGXTmx (ORCPT + 99 others); Wed, 24 Jul 2019 15:42:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:44700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389203AbfGXTmv (ORCPT ); Wed, 24 Jul 2019 15:42:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3DAF920665; Wed, 24 Jul 2019 19:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997370; bh=GHmAGkLOrHLzPUBhHXMeYPkixSMgbRwCjktYV+PyNWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=09ID5DDzGpd4269YO+75JzNPAq5s+d0tIIjj1ndGrUdsEZ4LEvzljHSjU+8DeqkG3 397YZ8rbxBsQ2OnqoZZW0uwEyQeoN5nw5zHoKatwfc54GbsRelwX+yBKb6/w46CYkq 7Wen/6RNWBw21WquukaRZdwjlV+f/2zApOKdW1xg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junxiao Bi , Mike Snitzer Subject: [PATCH 5.2 413/413] dm bufio: fix deadlock with loop device Date: Wed, 24 Jul 2019 21:21:44 +0200 Message-Id: <20190724191804.013853130@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Junxiao Bi commit bd293d071ffe65e645b4d8104f9d8fe15ea13862 upstream. 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 Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-bufio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -1599,9 +1599,7 @@ dm_bufio_shrink_scan(struct shrinker *sh 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);