Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp621551img; Fri, 22 Mar 2019 05:19:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsDyGXPcJLCX5o3xfuJ1XXxc9o9EY5DrIkm4fTy1Yl1F9v28R+4KvS5MKqKTweYWHNZYwC X-Received: by 2002:a17:902:407:: with SMTP id 7mr9324046ple.62.1553257193014; Fri, 22 Mar 2019 05:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257193; cv=none; d=google.com; s=arc-20160816; b=sLBEKGX1jJ1uOXLgtOZUvaaUtAQ56AMEBdgRdJaGpZdVucOTkX6EfRb32Imue/sCHW E1GmzsHzjytoGl62IqRmg/uc5MQjr62a2H7D8B0oR+byXdCeGDUER9ccgEM2oT0qy3NG 4SM3/gJBM0ffX6VuF6k10UPKajY5miInYn4V2w3cn2ppVWn4R+3ITilKXeRzEdKPKE28 C0dA0PCu1+UJWpre5BroaDyfA2BFqZAmz5ACHJ0MeEpKH/4MxRBxKEePNVz9wV7nAsIi PXgjsLfCrzx6AxCZieQbIo5WdOC8zB7RijW7hTlR7mdpMnAuwcBi9R5THsK+LHAvLZkh Hk5A== 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=5d1lHfF7ZNwYkMW3+YeYa7Bz+g6KJfGzKJuI+tPVcpg=; b=Hhf3xNFlmaDmghnvj35xqqEQZmc7IZlVSZFG79jjwj+Ooit7iN6Xtoq789ytVzUfUI n2iKIcC1HEa+zvgC+9sNT2kYhnUmQ6zU9Mn/TV2UmbyxsANxwjyVFRBTroh1RiHb19+Z izNoaqyUDx6Dv9UyGYQa7x/C2OPKJ44toJLfgDaqT678KUqh0FEUC70nn+pHxQpvdgjQ d2YJZyFrxziotGsbOnV0U4fr+92I8m02RdyqkYL7jY1MZTsfKSQIFow9UR25J+UFXYd1 aUYhSft6MM1SXEh1GAPeIpl5G10cKBIY4A76G6Q9wdhmZ7P4+Y8z+e/F1x9hFepTbfCd B4WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QrnfMl4J; 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 y66si6744481pgy.34.2019.03.22.05.19.37; Fri, 22 Mar 2019 05:19:53 -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=QrnfMl4J; 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 S2390180AbfCVMRk (ORCPT + 99 others); Fri, 22 Mar 2019 08:17:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:56534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390362AbfCVMRh (ORCPT ); Fri, 22 Mar 2019 08:17:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 E9C5921900; Fri, 22 Mar 2019 12:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257056; bh=/Y8+6BJoF4i6jbTVWQRKSNBBsn5ti+nwZAQW/9zlU4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QrnfMl4JmhMZev+TX3tmdz7IfpLVGvJbQfJy6ifoxcF94hkjFCLveB5En+ztwzcWm UuhXENzChusy3JrsesPutuVElCH8ORHE4BQSyMj2Ryg1cWRxXr7MnlAtE7L0f93utn UBn63AnIDHzYV3Thq60zsgfXHfnllEyM0+5QG60Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Filipe Manana , David Sterba Subject: [PATCH 5.0 091/238] Btrfs: setup a nofs context for memory allocation at btrfs_create_tree() Date: Fri, 22 Mar 2019 12:15:10 +0100 Message-Id: <20190322111303.949671429@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit b89f6d1fcb30a8cbdc18ce00c7d93792076af453 upstream. We are holding a transaction handle when creating a tree, therefore we can not allocate the root using GFP_KERNEL, as we could deadlock if reclaim is triggered by the allocation, therefore setup a nofs context. Fixes: 74e4d82757f74 ("btrfs: let callers of btrfs_alloc_root pass gfp flags") CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Nikolay Borisov Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "ctree.h" #include "disk-io.h" @@ -1258,10 +1259,17 @@ struct btrfs_root *btrfs_create_tree(str struct btrfs_root *tree_root = fs_info->tree_root; struct btrfs_root *root; struct btrfs_key key; + unsigned int nofs_flag; int ret = 0; uuid_le uuid = NULL_UUID_LE; + /* + * We're holding a transaction handle, so use a NOFS memory allocation + * context to avoid deadlock if reclaim happens. + */ + nofs_flag = memalloc_nofs_save(); root = btrfs_alloc_root(fs_info, GFP_KERNEL); + memalloc_nofs_restore(nofs_flag); if (!root) return ERR_PTR(-ENOMEM);