Received: by 10.223.176.5 with SMTP id f5csp1027505wra; Fri, 2 Feb 2018 09:57:49 -0800 (PST) X-Google-Smtp-Source: AH8x226AERcy6QsM+LysVOkUI+UWivcHmN07wDlJqunVxEUezcXS+9KjUqaODdm74GjY14lxHbxT X-Received: by 2002:a17:902:7897:: with SMTP id q23-v6mr14952767pll.166.1517594268948; Fri, 02 Feb 2018 09:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517594268; cv=none; d=google.com; s=arc-20160816; b=FjHYVhjwSlVCKejnEjRjbhYhLiWgu4Izqe3/WwTD6CCQMv7dymd/FdhUXm8f/0rNHh 386n1ITvNp5BaUOCiAPIFpY2vA1EGhpWt0nkQi45cSHvGZq8pSMLw5POccn4pM0Jqnwc gTfML5JPzuBS5rVVm16YmeslC1w/ui0BXvA9fgj0uvT6+aY1A1Dx5sqPZZpu/usYooJf 6VN/2umkTemSPzyG5lPUyVSZ43nBMBMYegrdYdw4IsRK4XvZHYavfo5tGctoWxZaN+bG W/z+dh4UaKIfgbiLKBPIMwaDcbmz/qsSGr1AZbf9mqrNsuFGCaYXmWmWyxYijo1zMbb/ PTdQ== 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 :arc-authentication-results; bh=0S9KoW8ZRO5lJLxbYTnnb04W2idS3aHkJYzzU5NvMC0=; b=fxIgeaa7Hd1Poyk2tS/SyehmM99+UF3wF1AzUJt90scLvk3OwCF6/rHfVlNE4DfxuP S7FqUwi65Ke6Xzn/MzrK3nzwcIpQyRHtx9W54ErAxKOWSl3IAeze910/83j9Zxi+QOz+ 93J2u+2+PNDOMfukMDYxlufqrflFIRRgpBrs8cbzGXGea51CLeiWxH4rUC5wJlsNraQG x0uExiF8LwcDRGkdJQ6buqEfvSCIxkyJ/fS01Di9D5poZapMUMpDJmxUBrfOeaVH+izb zmpGadFl8cpmugIAdJvDxL+3S802qKUhNxXPFA6MwyuBrmtHgIEY/u9tfTWB7nk3zinC N4fw== ARC-Authentication-Results: i=1; mx.google.com; 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 c6-v6si227884plr.681.2018.02.02.09.57.34; Fri, 02 Feb 2018 09:57:48 -0800 (PST) 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; 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 S1753802AbeBBRzV (ORCPT + 99 others); Fri, 2 Feb 2018 12:55:21 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38700 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753396AbeBBRLi (ORCPT ); Fri, 2 Feb 2018 12:11:38 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8E3BCEFA; Fri, 2 Feb 2018 17:11:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Omar Sandoval , Liu Bo , David Sterba , Sasha Levin Subject: [PATCH 4.14 071/156] btrfs: fix deadlock when writing out space cache Date: Fri, 2 Feb 2018 17:57:32 +0100 Message-Id: <20180202140843.498772658@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit b77000ed558daa3bef0899d29bf171b8c9b5e6a8 ] If we fail to prepare our pages for whatever reason (out of memory in our case) we need to make sure to drop the block_group->data_rwsem, otherwise hilarity ensues. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: Liu Bo Reviewed-by: David Sterba [ add label and use existing unlocking code ] Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/free-space-cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1264,7 +1264,7 @@ static int __btrfs_write_out_cache(struc /* Lock all pages first so we can lock the extent safely. */ ret = io_ctl_prepare_pages(io_ctl, inode, 0); if (ret) - goto out; + goto out_unlock; lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, &cached_state); @@ -1358,6 +1358,7 @@ out_nospc_locked: out_nospc: cleanup_write_cache_enospc(inode, io_ctl, &cached_state); +out_unlock: if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) up_write(&block_group->data_rwsem);