]>
Commit | Line | Data |
---|---|---|
df1bfe5f GKH |
1 | From b89f6d1fcb30a8cbdc18ce00c7d93792076af453 Mon Sep 17 00:00:00 2001 |
2 | From: Filipe Manana <fdmanana@suse.com> | |
3 | Date: Thu, 13 Dec 2018 21:16:45 +0000 | |
4 | Subject: Btrfs: setup a nofs context for memory allocation at btrfs_create_tree() | |
5 | ||
6 | From: Filipe Manana <fdmanana@suse.com> | |
7 | ||
8 | commit b89f6d1fcb30a8cbdc18ce00c7d93792076af453 upstream. | |
9 | ||
10 | We are holding a transaction handle when creating a tree, therefore we can | |
11 | not allocate the root using GFP_KERNEL, as we could deadlock if reclaim is | |
12 | triggered by the allocation, therefore setup a nofs context. | |
13 | ||
14 | Fixes: 74e4d82757f74 ("btrfs: let callers of btrfs_alloc_root pass gfp flags") | |
15 | CC: stable@vger.kernel.org # 4.9+ | |
16 | Reviewed-by: Nikolay Borisov <nborisov@suse.com> | |
17 | Signed-off-by: Filipe Manana <fdmanana@suse.com> | |
18 | Reviewed-by: David Sterba <dsterba@suse.com> | |
19 | Signed-off-by: David Sterba <dsterba@suse.com> | |
20 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
21 | ||
22 | --- | |
23 | fs/btrfs/disk-io.c | 8 ++++++++ | |
24 | 1 file changed, 8 insertions(+) | |
25 | ||
26 | --- a/fs/btrfs/disk-io.c | |
27 | +++ b/fs/btrfs/disk-io.c | |
28 | @@ -17,6 +17,7 @@ | |
29 | #include <linux/semaphore.h> | |
30 | #include <linux/error-injection.h> | |
31 | #include <linux/crc32c.h> | |
32 | +#include <linux/sched/mm.h> | |
33 | #include <asm/unaligned.h> | |
34 | #include "ctree.h" | |
35 | #include "disk-io.h" | |
36 | @@ -1236,10 +1237,17 @@ struct btrfs_root *btrfs_create_tree(str | |
37 | struct btrfs_root *tree_root = fs_info->tree_root; | |
38 | struct btrfs_root *root; | |
39 | struct btrfs_key key; | |
40 | + unsigned int nofs_flag; | |
41 | int ret = 0; | |
42 | uuid_le uuid = NULL_UUID_LE; | |
43 | ||
44 | + /* | |
45 | + * We're holding a transaction handle, so use a NOFS memory allocation | |
46 | + * context to avoid deadlock if reclaim happens. | |
47 | + */ | |
48 | + nofs_flag = memalloc_nofs_save(); | |
49 | root = btrfs_alloc_root(fs_info, GFP_KERNEL); | |
50 | + memalloc_nofs_restore(nofs_flag); | |
51 | if (!root) | |
52 | return ERR_PTR(-ENOMEM); | |
53 |