Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3906778ybi; Mon, 29 Jul 2019 15:05:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXaA6I3oQ/MnkwoRC1SZBok4GQcJfGTY6nyXvAE2Q/YZwHUJgZ5yQbHTEGSRHO8+nMb6zx X-Received: by 2002:a17:902:9897:: with SMTP id s23mr111346685plp.47.1564437926387; Mon, 29 Jul 2019 15:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564437926; cv=none; d=google.com; s=arc-20160816; b=F+DnCX7+vqmDInP66F02/wDG2F2pYHXI0IkEO8CQhUgbrfepe4phSjH5KdoXVRghVE 1BEaOLjhF66W8brivbNMiJZhQPmeeh9Z7N2rs13oormRnROWIIi3FPixlD/YrixhP7Mx avC5ABajBskb4wRNb6WpuA4/AzijpGwadv/gUR5or8I5AjFqi3FGyNzZOAk5GUbtw3yS gtCLjvu7ZDM5sYBDe1UQen7B/EPw/MTlYkcWS3WJ3T9nkqg6jvUkq36Ol7McyVEKvAg9 +/Bd5HH1ZuZArYHS4kMGlpAGKUwzD1qLYPTWCPQIYNSJvMTTwB6lqTzmBrLGkipeWvDk pr8A== 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=9uIajdki5FFMKAeUwdrPVtbCUc0LOvRHcNVjJ7P7v/c=; b=ebbr40Qudy40sK3ks+OSWGdAaZH8x3A+0ElDDVmdVHFT8uheQUNSzs9pp49tWWvr4A t7lH47pF9SktaLyjmrUDcGTfct7rUl3VJcmW4xQdSaDa6LQjyGj3VQLwv8b0UZ0Cn+MN Iq19Ry64yvOEh1/JJCGrG8FwRNhIcQCl5Scma/BPVgzvCAU9rlIhV9zXg7mZiey7ltSE R0gfMG0hvBBMYFq3e5Ew7kKvQcsVhoW0N0mkWQLlaPFLN+i3eI8/Wo1+6hbypjXovlpH vb7BRoGSQVrJwsYaJmdvcu68Bqy3Knl4yPHSO6tEh4my5fPD8yJyoUkGu5jKc8uU90gP K+ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2lhmOhKp; 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 bh8si25528251plb.175.2019.07.29.15.05.11; Mon, 29 Jul 2019 15:05:26 -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=2lhmOhKp; 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 S1729672AbfG2Tcq (ORCPT + 99 others); Mon, 29 Jul 2019 15:32:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729647AbfG2Tcn (ORCPT ); Mon, 29 Jul 2019 15:32:43 -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 4A4DE217D6; Mon, 29 Jul 2019 19:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428761; bh=QbL9JCURI8IT0HneOsq6UcX7QVgG1PIUGLeYwf0lED4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2lhmOhKpm0i6WptHkgAFHP223C4/1iwi5Fs7VkFPgnKyhtcwGOGFjEb5JsTK7zSc/ DJU/oZCDfgD/ejwTwTmvvydJEI/MvRWf7oXjujl/+3SgQ2ibKmwA0q9CZAsNFBDizt AiKdjkR3gxQesmp4vRTDs6EorxPHhdAxznwDWvF0= 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.14 177/293] dm bufio: fix deadlock with loop device Date: Mon, 29 Jul 2019 21:21:08 +0200 Message-Id: <20190729190838.077796168@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 @@ -1630,9 +1630,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);