Commit de2491fd authored by David Sterba's avatar David Sterba

btrfs: scrub: add memalloc_nofs protection around init_ipath

init_ipath is called from a safe ioctl context and from scrub when
printing an error.  The protection is added for three reasons:

* init_data_container calls vmalloc and this does not work as expected
  in the GFP_NOFS context, so this silently does GFP_KERNEL and might
  deadlock in some cases
* keep the context constraint of GFP_NOFS, used by scrub
* we want to use GFP_KERNEL unconditionally inside init_ipath or its
  callees
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent f11f7441
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
#include <linux/sched/mm.h>
#include "ctree.h" #include "ctree.h"
#include "volumes.h" #include "volumes.h"
#include "disk-io.h" #include "disk-io.h"
...@@ -733,6 +734,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, ...@@ -733,6 +734,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
u32 nlink; u32 nlink;
int ret; int ret;
int i; int i;
unsigned nofs_flag;
struct extent_buffer *eb; struct extent_buffer *eb;
struct btrfs_inode_item *inode_item; struct btrfs_inode_item *inode_item;
struct scrub_warning *swarn = warn_ctx; struct scrub_warning *swarn = warn_ctx;
...@@ -771,7 +773,14 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, ...@@ -771,7 +773,14 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
nlink = btrfs_inode_nlink(eb, inode_item); nlink = btrfs_inode_nlink(eb, inode_item);
btrfs_release_path(swarn->path); btrfs_release_path(swarn->path);
/*
* init_path might indirectly call vmalloc, or use GFP_KERNEL. Scrub
* uses GFP_NOFS in this context, so we keep it consistent but it does
* not seem to be strictly necessary.
*/
nofs_flag = memalloc_nofs_save();
ipath = init_ipath(4096, local_root, swarn->path); ipath = init_ipath(4096, local_root, swarn->path);
memalloc_nofs_restore(nofs_flag);
if (IS_ERR(ipath)) { if (IS_ERR(ipath)) {
ret = PTR_ERR(ipath); ret = PTR_ERR(ipath);
ipath = NULL; ipath = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment