Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2511569imm; Mon, 28 May 2018 09:28:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL2lZeXFBX7DPlnZPE/ty2JGK7cK6wDzSmbMoLOS7fc7f2nujIZv+okANPpAtkOUUmEyqpa X-Received: by 2002:a62:c4dd:: with SMTP id h90-v6mr5900202pfk.86.1527524882452; Mon, 28 May 2018 09:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524882; cv=none; d=google.com; s=arc-20160816; b=JCexXzX+5Hfn9gd6GVLDK4SdqJ7oW1SHq3R6+Ao1ZZweNLOJJVUFfyN5qjzTJGeLGl AvBar/Np8EfUMzRPWUDuv39f4qWPuBoYY3H3tbt3WrwHnWJoVzoyu41ZimmOtXyomawG A/59IkuKODuV58qSK4AusGymRamAk7DWb1LkDogT7sDqLeOc5YVlWFEOUf2uZxif+vEm nDBcHhr12gF14uNZqyK2Y7KiGwQYYAzg+ip8uLilQo4Pb7IeHb1x0lF3XBSIR6lt34Cj VMQXzNqeBfoiEQKphCzloC4AM9LCBnoP2mYJmv/YJYrb9b4UShViYqemaHvtlJUR+vy4 43lQ== 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=wRJuVE3zI+VJHfQ9zTkGLUGHH1TyvPIknWWc13ugQqg=; b=pDT09CDomDuWBr67mT0rmPN5UkCHB/a0yJN/f4R0hMuwfhbkABnnHrSKQ/kZXpsROC 4iTiGBUHkmgWI8BMuhg8jRMRIUdmhAvtdTiG2+2rOuQM3moHs4dUmoMtVjyUBVGcUbg8 abTHy2eJGNDsMF02+oIno2xIXY65I9xYtxrSOK15aSHchp3di7PQkLvbFVdd6DO2yNVO IcPZUMJEi3BxXxlr36AQJZg3F6JfDpFnQE2+9Gz3LzAYLl6AgW9+oYvgXW54dBtxok69 wDux62WFr1TktBK4nBiwAzR4nJheSgo9DVmm8Hm9yKOuriRsz82hRWg4TxDGAQNxDrY8 uA9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FjjqC8kq; 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 p91-v6si30550042plb.457.2018.05.28.09.27.47; Mon, 28 May 2018 09:28:02 -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=FjjqC8kq; 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 S936755AbeE1Q0M (ORCPT + 99 others); Mon, 28 May 2018 12:26:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:58828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936512AbeE1KKi (ORCPT ); Mon, 28 May 2018 06:10:38 -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 71047208AF; Mon, 28 May 2018 10:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502238; bh=qFff5FyL8T0qBZT6hTMK/stM2/Wkx4dE/1dhl3wvRNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FjjqC8kqwzZKQU0dRTAzGV6cIGb0QCDgFaPkp5PjA+umO6nN3VMOyGxHPhuldcqxq R46JCEfs2Kv3Mpbb68Zr1HVSmbDm91P44nd8Dvd1QlS+05OtT0iQoqjOzG1wShXSQ6 MAARCXYqwZ22t519ol0IdHskM8Ib/Ln5Qx01B1og= 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 3.18 113/185] Force log to disk before reading the AGF during a fstrim Date: Mon, 28 May 2018 12:02:34 +0200 Message-Id: <20180528100101.471049782@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -51,19 +51,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. */