Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2266047imm; Mon, 28 May 2018 05:04:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLALrI8r2WqNrzK3kdb8ofqLbWtSGJyJ+18z1E/f1fljH5XTaZPDZSOfnf3I5L1LN18UcX0 X-Received: by 2002:a63:7a49:: with SMTP id j9-v6mr307171pgn.353.1527509085410; Mon, 28 May 2018 05:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527509085; cv=none; d=google.com; s=arc-20160816; b=ocU1RhOY18YOJL9wCLAr+hEQCqlqi9Auj7CTezHrN/yWQwaVsUDehoVTYd16r/ZoVN GfNIkmvTo5LNyADb873RkxxMZWOE8OtR1c+Hj5BFICJ8iHH3gfx3QUFu2R/7WgTKRdNG LQctbtdl1tHZ+AWqhTHfoZ/Y3eIMuzsNmBXkfbLWqG7MePF1zb6R/dC+8/OigSrmSsAt ZORdSI+NrWWmqxChx4QyuZqzgeiHgtp6yC+hH5NthNKMPnaUD1GFvDpy7M4Kvy6j+pV0 U6tjJU2bvEmvWBI1Eylpc2vrUX19T60HimCC8fas72ZNiUHq2FHDkYLohB+WfM8reBSY SibQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=GsqTefA7ZIKqsWoy1gqqidw1Awd7Pe04d6QA+SV6UN8=; b=HAI1SluaZtWo+blprrTI6lZc/bzBoNMAYezOLhEXcr+BSyePGRunE+9xym78mKiM6A ucP6iwNpJ+oSeqXUM2VvCbGWy8zjlP4zckwByEbIBeD652+LRvNu+z0BFS31AMUWxg4Q aMvvII6a6fVotePbFZZPaxlK3+1Q8zUYGwMF3Ic9u1nenUuI6Penm7GgvIZp5Ya++HBe 7v369hOlFxJs4qf5BixgQX5NSSjoWboTs8kcmCLv8Hrnpx+oCU2WlgjJLXmNZz/qahF+ RUjIXb4qd6oszGCIOBcacawuyOng0NdyRLNeoBohEFZpFxueMKbT/TByo8gKY5mGK1Rn 83UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wGdXN4us; 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 o1-v6si29611860pld.424.2018.05.28.05.04.30; Mon, 28 May 2018 05:04:45 -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=wGdXN4us; 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 S938572AbeE1MDe (ORCPT + 99 others); Mon, 28 May 2018 08:03:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:53388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423280AbeE1LGd (ORCPT ); Mon, 28 May 2018 07:06:33 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 8576D2089E; Mon, 28 May 2018 11:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505593; bh=qNhhoPl/d5mXd7Yj+ToBoJ5DjNJfjANp2fPRlwsXFW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wGdXN4usqDk5o1mFfcrcWEq97f5iryrNrF0kWmGcezR2nUy3cPpr0sMSH63/aiyDx +2+w/jSpZiK2HDcsmS6yYZBc4WfxuieMV6WfFS/0Uch1fEl0YDpJweLYTUfbyLvOtQ 3iMeGF/O5vD+g92hbfShaDSeerh9Bjtohvcgfi7I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carlos Maiolino , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 4.16 060/272] Force log to disk before reading the AGF during a fstrim Date: Mon, 28 May 2018 12:01:33 +0200 Message-Id: <20180528100245.937025017@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Carlos Maiolino [ Upstream commit 8c81dd46ef3c416b3b95e3020fb90dbd44e6140b ] Forcing the log to disk after reading the agf is wrong, we might be calling xfs_log_force with XFS_LOG_SYNC with a metadata lock held. This can cause a deadlock when racing a fstrim with a filesystem shutdown. The deadlock has been identified due a miscalculation bug in device-mapper dm-thin, which returns lack of space to its users earlier than the device itself really runs out of space, changing the device-mapper volume into an error state. The problem happened while filling the filesystem with a single file, triggering the bug in device-mapper, consequently causing an IO error and shutting down the filesystem. If such file is removed, and fstrim executed before the XFS finishes the shut down process, the fstrim process will end up holding the buffer lock, and going to sleep on the cil wait queue. At this point, the shut down process will try to wake up all the threads waiting on the cil wait queue, but for this, it will try to hold the same buffer log already held my the fstrim, locking up the filesystem. Signed-off-by: Carlos Maiolino Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_discard.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -50,19 +50,19 @@ xfs_trim_extents( pag = xfs_perag_get(mp, agno); - error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp); - if (error || !agbp) - goto out_put_perag; - - cur = xfs_allocbt_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_CNT); - /* * Force out the log. This means any transactions that might have freed - * space before we took the AGF buffer lock are now on disk, and the + * space before we take the AGF buffer lock are now on disk, and the * volatile disk cache is flushed. */ xfs_log_force(mp, XFS_LOG_SYNC); + error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp); + if (error || !agbp) + goto out_put_perag; + + cur = xfs_allocbt_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_CNT); + /* * Look up the longest btree in the AGF and start with it. */