Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10430436ybi; Wed, 24 Jul 2019 23:05:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCiPZ6FfvAJmE+4ZE7IkX4WsEmhLOjXP+AaGYGcY5Ob3I9wM9MvvCwmtqh3KNyz43gRT64 X-Received: by 2002:a17:90a:220a:: with SMTP id c10mr92763211pje.33.1564034700976; Wed, 24 Jul 2019 23:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034700; cv=none; d=google.com; s=arc-20160816; b=XB7t8be2fOIUEm9P3P3YZrDLgWn1J7LkFZQl9YwQfL3DPbYQ54cflWCRs00ozwBe/n C30H07mf+ILdtYlrY1kHiJHUP2C+DEFLuaLluNDL+7pa3JBFRbLt/VVvEHOw50v8bxU3 RN3SNC4U8brWfCN3D8CIcSOMF6ia8Sjcg95BJqChkVpnAql8w8jzdJzeVzadXJp+D22c D4kOCEuRuTDcUl5TZQyPHUT7GQ/yEwRkzTEATNe3uOoHnxi4Uy2+fKQMPLL9rUltLjCW yXSuKcvy/ab+5NamPPoA0iQmP8vXqOz6W2zpW9IUDqgouylqLoNe8OOJQe/Kk7sylhcL uV6Q== 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=OYtqQvwlfKc1clOIuqJbrTlfOstELOEyuhXj2aXK+p8=; b=SLnAZPSXchLWYft0Y506taoVGqOKVm6f9XGbno0HxARCbsKo3hMj1hjK9pdXvcIqMw K8gaRRZQpWg66RiDl3tKTq1PUb14KbgGJqcnMbKwhHc9EfNWQg6V2F9I0SmH2zH2wG9i aku3BSTI1rxpEmrHbGRwXPDVykWHKDxLQDZIZkCsN8MMKcxy09BPLayHDlYoy28UWo/4 d3Q79W6UlvjrFqWpGlgp03QGqWRFmoCWkb17+9nFUZdUqX31JIw/TvV5L64PgjvIZNO6 adoBD6j8yqrp2hSvHSQog1Xlm4vMFa305qbvOMG5Qsyd9j+OdMUb/LMhcusWrckmM++K lH3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kKxpZ74h; 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 h189si15797239pgc.236.2019.07.24.23.04.46; Wed, 24 Jul 2019 23:05:00 -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=kKxpZ74h; 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 S1727811AbfGYFrC (ORCPT + 99 others); Thu, 25 Jul 2019 01:47:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:34866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391505AbfGYFq7 (ORCPT ); Thu, 25 Jul 2019 01:46:59 -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 BEFA42147A; Thu, 25 Jul 2019 05:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033618; bh=gr+fh92xGUPJDzZvbxxX5CaJ2QI9hu3dRDLsBqNr1g0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKxpZ74hSrxRBGYhUsD9NdPZwteDg/l+JeP2r+AlTyEofxrxQkvSkQkAOG1LKPNWX gY2UQia/WFQ14Jz3ebjFfstcrP4d3lZv7BPjjZlo0gci0rOs2G+P73lSzUP1Br5gKn Rw/gFBubUdefqGjDpJsz/F2SeryUkXKLYEZXQnt8= 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.19 271/271] dm bufio: fix deadlock with loop device Date: Wed, 24 Jul 2019 21:22:20 +0200 Message-Id: <20190724191718.479146711@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 @@ -1602,9 +1602,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);