* [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock
@ 2018-12-10 17:53 fdmanana
2018-12-11 8:00 ` Nikolay Borisov
2018-12-12 13:15 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2018-12-10 17:53 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
When initializing the security xattrs, we are holding a transaction handle
therefore we need to use a GFP_NOFS context in order to avoid a deadlock
with reclaim in case it's triggered.
Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/xattr.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index ea78c3d6dcfc..f141b45ce349 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -11,6 +11,7 @@
#include <linux/security.h>
#include <linux/posix_acl_xattr.h>
#include <linux/iversion.h>
+#include <linux/sched/mm.h>
#include "ctree.h"
#include "btrfs_inode.h"
#include "transaction.h"
@@ -422,9 +423,15 @@ static int btrfs_initxattrs(struct inode *inode,
{
const struct xattr *xattr;
struct btrfs_trans_handle *trans = fs_info;
+ unsigned int nofs_flag;
char *name;
int err = 0;
+ /*
+ * We're holding a transaction handle, so use a NOFS memory allocation
+ * context to avoid deadlock if reclaim happens.
+ */
+ nofs_flag = memalloc_nofs_save();
for (xattr = xattr_array; xattr->name != NULL; xattr++) {
name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
strlen(xattr->name) + 1, GFP_KERNEL);
@@ -440,6 +447,7 @@ static int btrfs_initxattrs(struct inode *inode,
if (err < 0)
break;
}
+ memalloc_nofs_restore(nofs_flag);
return err;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock
2018-12-10 17:53 [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock fdmanana
@ 2018-12-11 8:00 ` Nikolay Borisov
2018-12-12 13:15 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2018-12-11 8:00 UTC (permalink / raw)
To: fdmanana, linux-btrfs
On 10.12.18 г. 19:53 ч., fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> When initializing the security xattrs, we are holding a transaction handle
> therefore we need to use a GFP_NOFS context in order to avoid a deadlock
> with reclaim in case it's triggered.
>
> Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/xattr.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
> index ea78c3d6dcfc..f141b45ce349 100644
> --- a/fs/btrfs/xattr.c
> +++ b/fs/btrfs/xattr.c
> @@ -11,6 +11,7 @@
> #include <linux/security.h>
> #include <linux/posix_acl_xattr.h>
> #include <linux/iversion.h>
> +#include <linux/sched/mm.h>
> #include "ctree.h"
> #include "btrfs_inode.h"
> #include "transaction.h"
> @@ -422,9 +423,15 @@ static int btrfs_initxattrs(struct inode *inode,
> {
> const struct xattr *xattr;
> struct btrfs_trans_handle *trans = fs_info;
> + unsigned int nofs_flag;
> char *name;
> int err = 0;
>
> + /*
> + * We're holding a transaction handle, so use a NOFS memory allocation
> + * context to avoid deadlock if reclaim happens.
> + */
> + nofs_flag = memalloc_nofs_save();
> for (xattr = xattr_array; xattr->name != NULL; xattr++) {
> name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
> strlen(xattr->name) + 1, GFP_KERNEL);
> @@ -440,6 +447,7 @@ static int btrfs_initxattrs(struct inode *inode,
> if (err < 0)
> break;
> }
> + memalloc_nofs_restore(nofs_flag);
> return err;
> }
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock
2018-12-10 17:53 [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock fdmanana
2018-12-11 8:00 ` Nikolay Borisov
@ 2018-12-12 13:15 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2018-12-12 13:15 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Mon, Dec 10, 2018 at 05:53:35PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> When initializing the security xattrs, we are holding a transaction handle
> therefore we need to use a GFP_NOFS context in order to avoid a deadlock
> with reclaim in case it's triggered.
>
> Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-12-12 13:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 17:53 [PATCH] Btrfs: use nofs context when initializing security xattrs to avoid deadlock fdmanana
2018-12-11 8:00 ` Nikolay Borisov
2018-12-12 13:15 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).