Received: by 10.223.176.46 with SMTP id f43csp281374wra; Tue, 23 Jan 2018 20:59:34 -0800 (PST) X-Google-Smtp-Source: AH8x2273C3QDcyjnySUVSnJO2Fpfm28/oIYtTifRq5OCY9BynUUTzRowsK2vnJo9vqy9wFP50yQh X-Received: by 10.99.185.2 with SMTP id z2mr6097719pge.299.1516769974762; Tue, 23 Jan 2018 20:59:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769974; cv=none; d=google.com; s=arc-20160816; b=qwVtEsrlIhSJ6EKeLh574Ih7zOTURtV9UNfJcCMXhqkC9untK7gQxzIe6PlgXKWhpA Tc2uU+g4tJFwdfWMVzf3EeakHDicVkbkv+bfzSlclu2em7G4nil/J+/GZSmbBRvbzR1Q 5iWenkiMqCcSLdqYYqdGzFFtUT0cci5HFZtAiRt8ucdwE/mva4tY29Fc8tHGw6uB9ra/ ynksz1uedtb3NPJ5W7oBDo28TeItYb0qmanF7p5Qj2XMKDaSFSnWuiMkRMSwqmCnk7an WN9RHBsrLHG+hBp3DbpaIkqD4rZeB7G2fTFb5jz/YRM9O7HG9kQrdScFZ8x8lrtUvuZQ p2Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=I7bGhLkvjZvxK6cnYgVn/buia1RNbisw+zWZgraY0uE=; b=w+3hCTjRx2hCbBA3uT/uztWleftN4CioN2Wn61k2DF4ucdg2PPBV4ZEVegr8P5Tgzg 6eyYc8ugRTwcvlD2cMCt9X95JSlNnNErnxF2rXt0SGWhYEuzj0cHDUWUlQb4cwY7z3gx bbPET9+FDNZZUKYbOgkDZGVkqalIN3VHpZfP1TTNbKXFo+W4mktA05hTMO5LaQoYCf8n SF1v1FrRCzE4i6Dtgrlh2iEdzNJe9YZBOt+BZSxh5qKURppZynNXNabunsA+oY6mkGAc +su6MvF9VF6fUbCClXhJkF4DtoJZAt+H69GKlAPtdywfu+NNuVza2gQh6amLiuv2tBOm aYWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=l1dzb8BL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z66si2350906pfj.156.2018.01.23.20.59.21; Tue, 23 Jan 2018 20:59:34 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=l1dzb8BL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932512AbeAXE66 (ORCPT + 99 others); Tue, 23 Jan 2018 23:58:58 -0500 Received: from mail-cys01nam02on0117.outbound.protection.outlook.com ([104.47.37.117]:59166 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752749AbeAXEPQ (ORCPT ); Tue, 23 Jan 2018 23:15:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=I7bGhLkvjZvxK6cnYgVn/buia1RNbisw+zWZgraY0uE=; b=l1dzb8BLxnUI1WWV1lkiZBnKmaILTfHjeYv+JW+WglbLsC1BEIjtynpYeqghn7BElm9GGvRGIykPjeZTHU1DkSsBY6CLMK3G4Nd1PPKHLQ4qinXsjZfcmFardKvwGkyI+u4yIivpsdbsbL99TfKoath226zZXXkQRon1f8H+Y44= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1080.namprd21.prod.outlook.com (52.132.130.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:15:14 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:14 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 042/100] btrfs: fix deadlock when writing out space cache Thread-Topic: [PATCH AUTOSEL for 4.14 042/100] btrfs: fix deadlock when writing out space cache Thread-Index: AQHTlMndgV94JOjCkkefdoeC+rmYwQ== Date: Wed, 24 Jan 2018 04:14:45 +0000 Message-ID: <20180124041414.32065-42-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1080;7:Yc3BbldHquxnY5ZvC77uPEvno8YQuyeXrCPHjWL0t5YfgldYLXEV4OpfFGyg73eB2OSrbvejNX0Iu7uI3iKfN8w/MCjXvfUf/faL3a6Wj7iuakwpcskIfeYv5S4bLE/BAU06deGL2ul3zKM8lOpIUrJcFr3fTeHGnLrRRxJ1ts102uRkdBPkN0/ecu4oZtHGg0GMhryJZSUdkhfe+bnQifAYgFJ/QykhrUin13aX5qX+aPHWL1FvhQT5BLwO8SPY x-ms-office365-filtering-correlation-id: ded42404-8457-41ea-6290-08d562e1116a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1080; x-ms-traffictypediagnostic: DM5PR2101MB1080: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(67672495146484)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1080;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1080; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(346002)(39860400002)(39380400002)(366004)(189003)(199004)(72206003)(110136005)(316002)(5250100002)(6346003)(2900100001)(54906003)(1076002)(6116002)(3846002)(22452003)(36756003)(53936002)(99286004)(6512007)(68736007)(2501003)(3660700001)(14454004)(3280700002)(86362001)(102836004)(7736002)(5660300001)(305945005)(107886003)(6486002)(6506007)(2906002)(81156014)(26005)(25786009)(4326008)(81166006)(105586002)(8936002)(59450400001)(106356001)(478600001)(10290500003)(6436002)(8676002)(2950100002)(86612001)(97736004)(76176011)(6666003)(10090500001)(66066001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1080;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: GpTwXYxM4opZVGpay4d2bGPOkyS9+dQhmm4ML9PIUDc6btj8gqLzKRGkZOdaircq/Z1T8/JCCJI8O+r21SStGQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ded42404-8457-41ea-6290-08d562e1116a X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:45.0444 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- fs/btrfs/free-space-cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cdc9f4015ec3..4426d1c73e50 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1264,7 +1264,7 @@ static int __btrfs_write_out_cache(struct btrfs_root = *root, struct inode *inode, /* Lock all pages first so we can lock the extent safely. */ ret =3D io_ctl_prepare_pages(io_ctl, inode, 0); if (ret) - goto out; + goto out_unlock; =20 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); =20 +out_unlock: if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) up_write(&block_group->data_rwsem); =20 --=20 2.11.0