Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3427163imu; Sun, 11 Nov 2018 14:51:30 -0800 (PST) X-Google-Smtp-Source: AJdET5fTHRvjEPJoYaQ7IrKNIAO2o2u+gzGTp8rV22osBJpulAhif3QpDTWhqdTfh3N7qFeeZvQF X-Received: by 2002:a63:b4c:: with SMTP id a12mr15659972pgl.131.1541976690611; Sun, 11 Nov 2018 14:51:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976690; cv=none; d=google.com; s=arc-20160816; b=ZCjwijmpDD33KXcWGyYVXiD1mglrAhSSv3YJ0Px+Wc/mJoHeBObU3BlB45WmgAlk3h d5t0K0chuZG2+SqNJxEFV8JFAQcsH0+tRL79TLnVCSuh2Rue1aAIW/GJuWJh8AtPjTde yCLhSjp3RkOdG0m9bfYYbiieTG+iC6JoroPe9s5ggcq0t077ncCbKSlqMYYoUvwXc6eI 3DKS97mTvhIPTejSFIHkwp9zmUBHJ6n+pD5n4+6HgodeqZCzMC0UGaj1uNF1vovCG8qL M4cCJmKVzQbsMnT4kAMTItbI9VtnN1CDWW7aD5j4WFb/Ub7BO6u8RI0I03kTBWexp5Qa MhgQ== 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=aAnf6vyptUW+JAfWhKTKtE53uUCsQfCHkMGaMA9mNa8=; b=He5fANrlzDHPVe9Bz+3LNjCUjC30k36ZykVtXMWJcH+WhEwfPfUWIf9JkU6yzjdm6v zjolsxyaqq6FU4sYbLvxnJjV8xVk53CQ1MnnQ6sEXVuJl4YKewTa+6uNNDJ4XyxldlGG GcpSxKe4bWEiRUXF8GtM0/8Knq6wQswWZsStMrgJqWYYmOlqk8PuVYoIUV7PKBPesFji GTeh+DhMlgcShb6+Iq1XbUePikJEzYBHkwXRMkEB9Mw3HtWT7Y8REg17rIJ6HW2RpFi2 TryHNW9L+SA5E1MSv6Mnlo22JwiShPwl2y0KFDedBt46M4GALwS9T1oS6ja4vT+FVd8h cBlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FRNhmaKW; 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 z33-v6si11101371plb.91.2018.11.11.14.51.15; Sun, 11 Nov 2018 14:51:30 -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=FRNhmaKW; 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 S2404141AbeKLIk7 (ORCPT + 99 others); Mon, 12 Nov 2018 03:40:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:54772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404201AbeKLIXJ (ORCPT ); Mon, 12 Nov 2018 03:23:09 -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 D833221582; Sun, 11 Nov 2018 22:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975591; bh=L4Zg47B0QCU1A/Guvj7bKOCxZ3sciwlqUn9V8d46LTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRNhmaKW9AObOiHRIpbS6yWJ/akynvco01/SDpf8DDiGpo/RNx59k0tm4NxfMaYye zMwKFQybIu2Lkhl8pH3lAjEp+afzz84mwaGYRItIDfOzxv78jT6COxSEnzWC5WWOqR xvMoEi7V+Qzze07kwFaDxDvSEpjM7QCvGTgCF+EE= 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.14 205/222] btrfs: protect space cache inode alloc with GFP_NOFS Date: Sun, 11 Nov 2018 14:25:02 -0800 Message-Id: <20181111221705.004966247@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -22,6 +22,7 @@ #include #include #include +#include #include "ctree.h" #include "free-space-cache.h" #include "transaction.h" @@ -59,6 +60,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; @@ -80,7 +82,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; if (is_bad_inode(inode)) {