public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/2] xfs: xfs_reflink_convert_cow() memory allocation deadlock
Date: Thu, 7 Jun 2018 07:41:40 -0400	[thread overview]
Message-ID: <20180607114140.GB7798@bfoster> (raw)
In-Reply-To: <20180607052132.6207-3-david@fromorbit.com>

On Thu, Jun 07, 2018 at 03:21:32PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> xfs_reflink_convert_cow() manipulates the incore extent list
> in GFP_KERNEL context in the IO submission path whilst holding
> locked pages under writeback. This is a memory reclaim deadlock
> vector. This code is not in a transaction, so any memory allocations
> it makes aren't protected via the memalloc_nofs_save() context that
> transactions carry.
> 
> Hence we need to run this call under memalloc_nofs_save() context to
> prevent potential memory allocations from being run as GFP_KERNEL
> and deadlocking.
> 
> Signed-Off-By: Dave Chinner <dchinner@redhat.com>
> ---

Looks fine modulo the header thing Allison already pointed out:

Reviewed-by: Brian Foster <bfoster@redhat.com>

BTW, shouldn't we also be using XFS_TRANS_NOFS in
xfs_iomap_write_allocate()?

Brian

>  fs/xfs/xfs_aops.c  | 11 +++++++++++
>  fs/xfs/xfs_buf.c   |  1 -
>  fs/xfs/xfs_linux.h |  1 +
>  3 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> index 767d53222f31..1eb625fdcb1e 100644
> --- a/fs/xfs/xfs_aops.c
> +++ b/fs/xfs/xfs_aops.c
> @@ -531,8 +531,19 @@ xfs_submit_ioend(
>  {
>  	/* Convert CoW extents to regular */
>  	if (!status && ioend->io_type == XFS_IO_COW) {
> +		/*
> +		 * Yuk. This can do memory allocation, but is not a
> +		 * transactional operation so everything is done in GFP_KERNEL
> +		 * context. That can deadlock, because we hold pages in
> +		 * writeback state and GFP_KERNEL allocations can block on them.
> +		 * Hence we must operate in nofs conditions here.
> +		 */
> +		unsigned nofs_flag;
> +
> +		nofs_flag = memalloc_nofs_save();
>  		status = xfs_reflink_convert_cow(XFS_I(ioend->io_inode),
>  				ioend->io_offset, ioend->io_size);
> +		memalloc_nofs_restore(nofs_flag);
>  	}
>  
>  	/* Reserve log space if we might write beyond the on-disk inode size. */
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index 980bc48979e9..e9c058e3761c 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -21,7 +21,6 @@
>  #include <linux/migrate.h>
>  #include <linux/backing-dev.h>
>  #include <linux/freezer.h>
> -#include <linux/sched/mm.h>
>  
>  #include "xfs_format.h"
>  #include "xfs_log_format.h"
> diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
> index ae1e66fa3f61..1631cf4546f2 100644
> --- a/fs/xfs/xfs_linux.h
> +++ b/fs/xfs/xfs_linux.h
> @@ -26,6 +26,7 @@ typedef __u32			xfs_nlink_t;
>  
>  #include <linux/semaphore.h>
>  #include <linux/mm.h>
> +#include <linux/sched/mm.h>
>  #include <linux/kernel.h>
>  #include <linux/blkdev.h>
>  #include <linux/slab.h>
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-06-07 11:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07  5:21 [PATCH 0/2] xfs: fix a couple of potential deadlocks Dave Chinner
2018-06-07  5:21 ` [PATCH 1/2] xfs: setup VFS i_rwsem lockdep state correctly Dave Chinner
2018-06-07  5:32   ` Dave Chinner
2018-06-07 11:41     ` Brian Foster
2018-06-07  5:50   ` Allison Henderson
2018-06-07 14:53   ` Darrick J. Wong
2018-06-07  5:21 ` [PATCH 2/2] xfs: xfs_reflink_convert_cow() memory allocation deadlock Dave Chinner
2018-06-07  5:56   ` Allison Henderson
2018-06-07 14:46     ` Darrick J. Wong
2018-06-07 22:08       ` Dave Chinner
2018-06-07 11:41   ` Brian Foster [this message]
2018-06-07 14:48     ` Darrick J. Wong
2018-06-08  0:48     ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180607114140.GB7798@bfoster \
    --to=bfoster@redhat.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox