Skip to content

Commit 6e24f5a

Browse files
fdmananagregkh
authored andcommitted
Btrfs: setup a nofs context for memory allocation at __btrfs_set_acl
commit a087349 upstream. We are holding a transaction handle when setting an acl, therefore we can not allocate the xattr value buffer using GFP_KERNEL, as we could deadlock if reclaim is triggered by the allocation, therefore setup a nofs context. Fixes: 39a27ec ("btrfs: use GFP_KERNEL for xattr and acl allocations") CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 61f9209 commit 6e24f5a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎fs/btrfs/acl.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/posix_acl_xattr.h>
1010
#include <linux/posix_acl.h>
1111
#include <linux/sched.h>
12+
#include <linux/sched/mm.h>
1213
#include <linux/slab.h>
1314

1415
#include "ctree.h"
@@ -72,8 +73,16 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
7273
}
7374

7475
if (acl) {
76+
unsigned int nofs_flag;
77+
7578
size = posix_acl_xattr_size(acl->a_count);
79+
/*
80+
* We're holding a transaction handle, so use a NOFS memory
81+
* allocation context to avoid deadlock if reclaim happens.
82+
*/
83+
nofs_flag = memalloc_nofs_save();
7684
value = kmalloc(size, GFP_KERNEL);
85+
memalloc_nofs_restore(nofs_flag);
7786
if (!value) {
7887
ret = -ENOMEM;
7988
goto out;

0 commit comments

Comments
 (0)