1 From a0873490660246db587849a9e172f2b7b21fa88a Mon Sep 17 00:00:00 2001
2 From: Filipe Manana <fdmanana@suse.com>
3 Date: Thu, 13 Dec 2018 21:16:56 +0000
4 Subject: Btrfs: setup a nofs context for memory allocation at __btrfs_set_acl
6 From: Filipe Manana <fdmanana@suse.com>
8 commit a0873490660246db587849a9e172f2b7b21fa88a upstream.
10 We are holding a transaction handle when setting an acl, therefore we can
11 not allocate the xattr value buffer using GFP_KERNEL, as we could deadlock
12 if reclaim is triggered by the allocation, therefore setup a nofs context.
14 Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
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>
23 fs/btrfs/acl.c | 9 +++++++++
24 1 file changed, 9 insertions(+)
29 #include <linux/posix_acl_xattr.h>
30 #include <linux/posix_acl.h>
31 #include <linux/sched.h>
32 +#include <linux/sched/mm.h>
33 #include <linux/slab.h>
36 @@ -72,8 +73,16 @@ static int __btrfs_set_acl(struct btrfs_
40 + unsigned int nofs_flag;
42 size = posix_acl_xattr_size(acl->a_count);
44 + * We're holding a transaction handle, so use a NOFS memory
45 + * allocation context to avoid deadlock if reclaim happens.
47 + nofs_flag = memalloc_nofs_save();
48 value = kmalloc(size, GFP_KERNEL);
49 + memalloc_nofs_restore(nofs_flag);