]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.108/btrfs-setup-a-nofs-context-for-memory-allocation-at-__btrfs_set_acl.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / releases / 4.14.108 / btrfs-setup-a-nofs-context-for-memory-allocation-at-__btrfs_set_acl.patch
CommitLineData
2705b78f
GKH
1From a0873490660246db587849a9e172f2b7b21fa88a Mon Sep 17 00:00:00 2001
2From: Filipe Manana <fdmanana@suse.com>
3Date: Thu, 13 Dec 2018 21:16:56 +0000
4Subject: Btrfs: setup a nofs context for memory allocation at __btrfs_set_acl
5
6From: Filipe Manana <fdmanana@suse.com>
7
8commit a0873490660246db587849a9e172f2b7b21fa88a upstream.
9
10We are holding a transaction handle when setting an acl, therefore we can
11not allocate the xattr value buffer using GFP_KERNEL, as we could deadlock
12if reclaim is triggered by the allocation, therefore setup a nofs context.
13
14Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
15CC: stable@vger.kernel.org # 4.9+
16Reviewed-by: Nikolay Borisov <nborisov@suse.com>
17Signed-off-by: Filipe Manana <fdmanana@suse.com>
18Reviewed-by: David Sterba <dsterba@suse.com>
19Signed-off-by: David Sterba <dsterba@suse.com>
20Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21
22---
23 fs/btrfs/acl.c | 9 +++++++++
24 1 file changed, 9 insertions(+)
25
26--- a/fs/btrfs/acl.c
27+++ b/fs/btrfs/acl.c
28@@ -22,6 +22,7 @@
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>
34
35 #include "ctree.h"
36@@ -89,8 +90,16 @@ static int __btrfs_set_acl(struct btrfs_
37 }
38
39 if (acl) {
40+ unsigned int nofs_flag;
41+
42 size = posix_acl_xattr_size(acl->a_count);
43+ /*
44+ * We're holding a transaction handle, so use a NOFS memory
45+ * allocation context to avoid deadlock if reclaim happens.
46+ */
47+ nofs_flag = memalloc_nofs_save();
48 value = kmalloc(size, GFP_KERNEL);
49+ memalloc_nofs_restore(nofs_flag);
50 if (!value) {
51 ret = -ENOMEM;
52 goto out;