Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1161890ybi; Fri, 2 Aug 2019 10:18:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUweLB6BPXQX76yuuHi080m7moHWomVRd+9ATzETpotYr77JhMKwSDYuUWk0vehhdW6C0O X-Received: by 2002:a63:1d2:: with SMTP id 201mr91793521pgb.307.1564766299944; Fri, 02 Aug 2019 10:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564766299; cv=none; d=google.com; s=arc-20160816; b=J5ChTxWa/CgoJV7HPl1yVVv5vhJpve776arHTDWJBQXJMvza8lvrlXsjTV+m8xvYR0 ZY+ZoYJLiDiu59+O5Qr6fZbHkrs0dwY1yst24x7yGVFu6DQ9chA2Zv174g5Uqu/Df28j mDnVSdG+IN9e7m7JJjpmG8ei8D009YVXyUe/J/Gf5G+k+pn59z4c3QwSiMWqjR/3FjFR Bh3EE0wUpu/3ybNtUk60nKB4qRyCLpqBLXPZb7xoHmdgK3AvVE0cTg6/mMKSBX0kxS+G plr845RToeYZn3pFrovjWlW3U0ZUTtdoBZwNkDOJ70j9hY1+viJEfEDMkbocEDORZWkr abRg== 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=80tkQEpOsB56C/53re86PEBZEVUAv7hGPod3Ey+UrIk=; b=iFr26ei2FDHs7IsfDgI9KXwiKgyZUyDUg02PhT7UUGIywKwx8ZDoV35EetekHzYvwD jpSHzvE8y4lLHx6ypz5jpybkCGkml7fsUGj4P+Ct6HKLaPunc9A5Hc1McrDxet3yYpyL jAF/8Jg5ETcbfFQPUMJZvwdy39p1WxRl0kOrQI3Mtl4TDOlBlwNcAE1wruVB4+V8G7oU V5S8rVUaGEie9CEXAp8pJJXYy5ridvXZqJNrdubO4Axz5GDDBgFOzRIQB+f/ZuteM+WH D1+KBGSiugQMzDeiu1P4akrQhaulMviNaQ/ROpZPWe6NUhJWeTanUtutylRFqIhcRIbx WBqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RyVItj12; 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 k143si37920075pfd.212.2019.08.02.10.18.01; Fri, 02 Aug 2019 10:18:19 -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=RyVItj12; 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 S2391966AbfHBJpd (ORCPT + 99 others); Fri, 2 Aug 2019 05:45:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:49258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405370AbfHBJp3 (ORCPT ); Fri, 2 Aug 2019 05:45:29 -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 B800720679; Fri, 2 Aug 2019 09:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739129; bh=SipdAuyC52gfeobWDnLZNj0rO8IMaAtTeLAVQJI1mFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RyVItj122ALPHJ3/LZR3rNOTM+28FfOEh5yvRGIWNjFMO0JXmmapTTOnTQSzTr87q X1dRInHXsiETxM6I1exttu6p0joZ0EdCY9hMUnyCpPrFpa1XCQpvD1E2R8yuwbTIJt M1Nsm5RQQ3cshNh4FEhSHqr56+xv5F4Vj/QLFy+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junxiao Bi , Mike Snitzer Subject: [PATCH 4.9 124/223] dm bufio: fix deadlock with loop device Date: Fri, 2 Aug 2019 11:35:49 +0200 Message-Id: <20190802092247.153499892@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 @@ -1585,9 +1585,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);