Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp490891pxu; Thu, 3 Dec 2020 05:39:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHXWgNPn987zkcXdzeZMTg8eFP2778p8o/NxWPIGqB8KBUc1N0rXPghGYruRjZF4fBeWmT X-Received: by 2002:aa7:d1c2:: with SMTP id g2mr2959395edp.8.1607002771988; Thu, 03 Dec 2020 05:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607002771; cv=none; d=google.com; s=arc-20160816; b=F6GW68uLJq2NkmTMW7jA+gs6qiBbgc4IhcG6Go1RFhFL30l3z4SoJAPodvT6Qphb5C hlY+JM8Ke+uJ2wrnBJtWpcRC7Ua/qE+9z7HfyDSiB+E7xqo5Yn5dK8F6z00rNvDPvgL+ uDWXxBudtQ49U/KPggAzsx1m9kR6UVFp7J3ROfbyL/sbpjOQf6WTAhNKem/HrbZbSxs7 l1kcu8a5gv6ANKmpPKFi0Pjz+KwdX+AHkx73PwN/n/OVsb+P9Z+0JxdtGwcVgoGqV776 W5Fx/iOJHg15N3nweDfe60Eo0ZVsyAp9JAxaGc+I9f7tsaWJs+LhYFK48LbGgfnDg6la wTyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/daueLAQlzbSeS8dpg2DjjJ5aRN+6GlqCQpj1SvtP4I=; b=Nb1NrQ7LPVN0NZnlndJdymk1YsN1pHZwhZdgyi5R3rojhfhQEcqt0nKkpm/4UkS0tM AXTH3Vc/X+/fw0zTDTv8jqdL2iUT3qPGDsWthh9QufzIMzGplmA/kpwKXAa32YxFdaU9 UDdKCZXwhpXAwLjagrouUnvsu8sx/ZX0zaFGXmC3OcCG0tYuuihrpcIPPGX8zVIGTRGH AwrLyQrYJ+82LoVwI0WUJTKzOYrbTyDiXqpE6oP/zWRYbmoKFskc52gs/iUBADLNaWCj dENj+dr66zEhtG3a2TTs+pWaxeYJ/6IW5QJUKJBykPBJW8xDagTii1ew9fqwCeac0QWc q31Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s28si886919edw.412.2020.12.03.05.39.04; Thu, 03 Dec 2020 05:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436602AbgLCNa3 (ORCPT + 99 others); Thu, 3 Dec 2020 08:30:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:47922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436466AbgLCNaX (ORCPT ); Thu, 3 Dec 2020 08:30:23 -0500 From: Sasha Levin Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Filipe Manana , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.9 24/39] btrfs: do nofs allocations when adding and removing qgroup relations Date: Thu, 3 Dec 2020 08:28:18 -0500 Message-Id: <20201203132834.930999-24-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201203132834.930999-1-sashal@kernel.org> References: <20201203132834.930999-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana [ Upstream commit 7aa6d359845a9dbf7ad90b0b1b6347ef4764621f ] When adding or removing a qgroup relation we are doing a GFP_KERNEL allocation which is not safe because we are holding a transaction handle open and that can make us deadlock if the allocator needs to recurse into the filesystem. So just surround those calls with a nofs context. Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/qgroup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 9205a88f2a881..15c38803576ce 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "ctree.h" #include "transaction.h" @@ -1324,13 +1325,17 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, u64 src, struct btrfs_qgroup *member; struct btrfs_qgroup_list *list; struct ulist *tmp; + unsigned int nofs_flag; int ret = 0; /* Check the level of src and dst first */ if (btrfs_qgroup_level(src) >= btrfs_qgroup_level(dst)) return -EINVAL; + /* We hold a transaction handle open, must do a NOFS allocation. */ + nofs_flag = memalloc_nofs_save(); tmp = ulist_alloc(GFP_KERNEL); + memalloc_nofs_restore(nofs_flag); if (!tmp) return -ENOMEM; @@ -1387,10 +1392,14 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src, struct btrfs_qgroup_list *list; struct ulist *tmp; bool found = false; + unsigned int nofs_flag; int ret = 0; int ret2; + /* We hold a transaction handle open, must do a NOFS allocation. */ + nofs_flag = memalloc_nofs_save(); tmp = ulist_alloc(GFP_KERNEL); + memalloc_nofs_restore(nofs_flag); if (!tmp) return -ENOMEM; -- 2.27.0