Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3468720imu; Sun, 11 Nov 2018 15:48:46 -0800 (PST) X-Google-Smtp-Source: AJdET5fLJZcldBRNFbqrLMdvcYcd/k3/avRjVLIANNJ+FFw5xBv3O99VsOGpxU4LviM1q7/dOfyf X-Received: by 2002:a63:fc22:: with SMTP id j34-v6mr15725792pgi.434.1541980126142; Sun, 11 Nov 2018 15:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980126; cv=none; d=google.com; s=arc-20160816; b=ehEpIoXoK1vhFWQGH3PG2xsHuqidIv/zHdoRI66BWMSXcUHKKJpuFvt62+9bKRL5Tq lrQPgaUQVD1fy7J1BWYhobGMjCKOmeCFr6EWuwxeGBoosQb5GBNEoHihRUVruQO/kIWV OfseWDSMZRcjx8T9ay/7mo2matyztD0s2Z/4Yrkr1s0v0FqytekedtlcXTS5whyg129H XLzHu4VMsOJO2kcXgt1t9AuKPZXyR3caosbK5gN5vYYZp0fa3KTYj4MutVuEYiEI3RYa hJGbN1naLufZpWOmHOYYqVqYbDLiqohMDsgU+QVnZsEq3d6EjDbp68MpvEhuslxFVCFB svpA== 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=OFy3TV99QqDUCwX6B/qgH1XgdhgUNzNz41TtHGSNr5g=; b=VKXnU8JJqOpzwVeZYqp6EfMkSwYETqlHGVFAVLt01M17QDQqlJhZx9JpEIFR/4vuSQ aYfdrl38b+sz6PXnJjqb90WtTMl8hkb33tWMhDFlkjmrAXq8bNZctEj9Xw3ftTtQnpyA 3GVIPhCngLlZz8tVKPQyLwl5E95ntCWk1iJ/ZoZbnMjrZkP8d5UK/TSUs16pMURymktt 81HYqPT+aooklyBRfU93arlw6PxEvlWpcw3vuiac/z7QbQxzf0t6yYCdtQmx2hzUAKL1 nFjQFanU53hh+yBPp21bshXb1Jf+nakhDQM7pQu8nHm8OIQi+UND9C+BDH45GR0ingKp /J2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vslPSAMX; 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 b24-v6si13207698pgb.50.2018.11.11.15.48.30; Sun, 11 Nov 2018 15:48:46 -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=@kernel.org header.s=default header.b=vslPSAMX; 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 S2387422AbeKLJia (ORCPT + 99 others); Mon, 12 Nov 2018 04:38:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:38130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733105AbeKLISo (ORCPT ); Mon, 12 Nov 2018 03:18:44 -0500 Received: from localhost (unknown [206.108.79.134]) (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 0DE60223AE; Sun, 11 Nov 2018 22:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975328; bh=d9u/X+kOl+R8X3EMYLLZb+nupN2pzRBZhD8DA/veUsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vslPSAMXWSMlLQtOMZR2mELD/jh3Fcqr/qbWhkYEc4RUc4sVuG8RHw2RmTqt1+y9p BLI+MbdeM4alvRkFsoLWjcuEulwFd2U55/gmRNTSvJkgjVbRUc8FeKv7QtTfXmJU0i Kcz6+SkVMCxDcjlP2gXNhY8tdojGodKDnx+YWEZ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omar Sandoval , Josef Bacik , David Sterba Subject: [PATCH 4.19 339/361] btrfs: protect space cache inode alloc with GFP_NOFS Date: Sun, 11 Nov 2018 14:21:26 -0800 Message-Id: <20181111221700.567181738@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 84de76a2fb217dc1b6bc2965cc397d1648aa1404 upstream. If we're allocating a new space cache inode it's likely going to be under a transaction handle, so we need to use memalloc_nofs_save() in order to avoid deadlocks, and more importantly lockdep messages that make xfstests fail. CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Omar Sandoval Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/free-space-cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "ctree.h" #include "free-space-cache.h" #include "transaction.h" @@ -47,6 +48,7 @@ static struct inode *__lookup_free_space struct btrfs_free_space_header *header; struct extent_buffer *leaf; struct inode *inode = NULL; + unsigned nofs_flag; int ret; key.objectid = BTRFS_FREE_SPACE_OBJECTID; @@ -68,7 +70,13 @@ static struct inode *__lookup_free_space btrfs_disk_key_to_cpu(&location, &disk_key); btrfs_release_path(path); + /* + * We are often under a trans handle at this point, so we need to make + * sure NOFS is set to keep us from deadlocking. + */ + nofs_flag = memalloc_nofs_save(); inode = btrfs_iget(fs_info->sb, &location, root, NULL); + memalloc_nofs_restore(nofs_flag); if (IS_ERR(inode)) return inode;