All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents
@ 2021-03-25 14:03 Chandan Babu R
  2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chandan Babu R @ 2021-03-25 14:03 UTC (permalink / raw)
  To: linux-xfs; +Cc: Chandan Babu R, djwong

xfs/538 can cause the following call trace to be printed when executing on a
multi-block directory configuration,

 WARNING: CPU: 1 PID: 2578 at fs/xfs/libxfs/xfs_bmap.c:717 xfs_bmap_extents_to_btree+0x520/0x5d0
 Call Trace:
  ? xfs_buf_rele+0x4f/0x450
  xfs_bmap_add_extent_hole_real+0x747/0x960
  xfs_bmapi_allocate+0x39a/0x440
  xfs_bmapi_write+0x507/0x9e0
  xfs_da_grow_inode_int+0x1cd/0x330
  ? up+0x12/0x60
  xfs_dir2_grow_inode+0x62/0x110
  ? xfs_trans_log_inode+0x234/0x2d0
  xfs_dir2_sf_to_block+0x103/0x940
  ? xfs_dir2_sf_check+0x8c/0x210
  ? xfs_da_compname+0x19/0x30
  ? xfs_dir2_sf_lookup+0xd0/0x3d0
  xfs_dir2_sf_addname+0x10d/0x910
  xfs_dir_createname+0x1ad/0x210
  xfs_create+0x404/0x620
  xfs_generic_create+0x24c/0x320
  path_openat+0xda6/0x1030
  do_filp_open+0x88/0x130
  ? kmem_cache_alloc+0x50/0x210
  ? __cond_resched+0x16/0x40
  ? kmem_cache_alloc+0x50/0x210
  do_sys_openat2+0x97/0x150
  __x64_sys_creat+0x49/0x70
  do_syscall_64+0x33/0x40
  entry_SYSCALL_64_after_hwframe+0x44/0xae

This occurs because xfs_bmap_exact_minlen_extent_alloc() initializes
xfs_alloc_arg->total to xfs_bmalloca->minlen. In the context of
xfs_bmap_exact_minlen_extent_alloc(), xfs_bmalloca->minlen has a value of 1
and hence the space allocator could choose an AG which has less than
xfs_bmalloca->total number of free blocks available. As the transaction
proceeds, one of the future space allocation requests could fail due to
non-availability of free blocks in the AG that was originally chosen.

This commit fixes the bug by assigning xfs_alloc_arg->total to the value of
xfs_bmalloca->total.

Fixes: 301519674699 ("xfs: Introduce error injection to allocate only minlen size extents for files")
Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
 fs/xfs/libxfs/xfs_bmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index e0905ad171f0..585f7e795023 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3586,7 +3586,8 @@ xfs_bmap_exact_minlen_extent_alloc(
 	args.fsbno = ap->blkno;
 	args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
 	args.type = XFS_ALLOCTYPE_FIRST_AG;
-	args.total = args.minlen = args.maxlen = ap->minlen;
+	args.minlen = args.maxlen = ap->minlen;
+	args.total = ap->total;
 
 	args.alignment = 1;
 	args.minalignslop = 0;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent
  2021-03-25 14:03 [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Chandan Babu R
@ 2021-03-25 14:03 ` Chandan Babu R
  2021-03-25 18:53   ` Darrick J. Wong
  2021-04-02  6:45   ` Christoph Hellwig
  2021-03-25 18:54 ` [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Darrick J. Wong
  2021-04-02  6:44 ` Christoph Hellwig
  2 siblings, 2 replies; 6+ messages in thread
From: Chandan Babu R @ 2021-03-25 14:03 UTC (permalink / raw)
  To: linux-xfs; +Cc: Chandan Babu R, djwong

With dax enabled filesystems, a direct write operation into an existing
unwritten extent results in xfs_iomap_write_direct() zero-ing and converting
the extent into a normal extent before the actual data is copied from the
userspace buffer.

The inode extent count can increase by 2 if the extent range being written to
maps to the middle of the existing unwritten extent range. Hence this commit
uses XFS_IEXT_WRITE_UNWRITTEN_CNT as the extent count delta when such a write
operation is being performed.

Fixes: 727e1acd297c ("xfs: Check for extent overflow when trivally adding a new extent")
Reported-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
 fs/xfs/xfs_iomap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index e17ab7f42928..8b27c10a3d08 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -198,6 +198,7 @@ xfs_iomap_write_direct(
 	bool			force = false;
 	int			error;
 	int			bmapi_flags = XFS_BMAPI_PREALLOC;
+	int			nr_exts = XFS_IEXT_ADD_NOSPLIT_CNT;
 
 	ASSERT(count_fsb > 0);
 
@@ -232,6 +233,7 @@ xfs_iomap_write_direct(
 		bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
 		if (imap->br_state == XFS_EXT_UNWRITTEN) {
 			force = true;
+			nr_exts = XFS_IEXT_WRITE_UNWRITTEN_CNT;
 			dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
 		}
 	}
@@ -241,8 +243,7 @@ xfs_iomap_write_direct(
 	if (error)
 		return error;
 
-	error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
-			XFS_IEXT_ADD_NOSPLIT_CNT);
+	error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, nr_exts);
 	if (error)
 		goto out_trans_cancel;
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent
  2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
@ 2021-03-25 18:53   ` Darrick J. Wong
  2021-04-02  6:45   ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2021-03-25 18:53 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: linux-xfs

On Thu, Mar 25, 2021 at 07:33:39PM +0530, Chandan Babu R wrote:
> With dax enabled filesystems, a direct write operation into an existing
> unwritten extent results in xfs_iomap_write_direct() zero-ing and converting
> the extent into a normal extent before the actual data is copied from the
> userspace buffer.
> 
> The inode extent count can increase by 2 if the extent range being written to
> maps to the middle of the existing unwritten extent range. Hence this commit
> uses XFS_IEXT_WRITE_UNWRITTEN_CNT as the extent count delta when such a write
> operation is being performed.
> 
> Fixes: 727e1acd297c ("xfs: Check for extent overflow when trivally adding a new extent")
> Reported-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>

Pretty much what I was expecting,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_iomap.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index e17ab7f42928..8b27c10a3d08 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -198,6 +198,7 @@ xfs_iomap_write_direct(
>  	bool			force = false;
>  	int			error;
>  	int			bmapi_flags = XFS_BMAPI_PREALLOC;
> +	int			nr_exts = XFS_IEXT_ADD_NOSPLIT_CNT;
>  
>  	ASSERT(count_fsb > 0);
>  
> @@ -232,6 +233,7 @@ xfs_iomap_write_direct(
>  		bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
>  		if (imap->br_state == XFS_EXT_UNWRITTEN) {
>  			force = true;
> +			nr_exts = XFS_IEXT_WRITE_UNWRITTEN_CNT;
>  			dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
>  		}
>  	}
> @@ -241,8 +243,7 @@ xfs_iomap_write_direct(
>  	if (error)
>  		return error;
>  
> -	error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
> -			XFS_IEXT_ADD_NOSPLIT_CNT);
> +	error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, nr_exts);
>  	if (error)
>  		goto out_trans_cancel;
>  
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents
  2021-03-25 14:03 [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Chandan Babu R
  2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
@ 2021-03-25 18:54 ` Darrick J. Wong
  2021-04-02  6:44 ` Christoph Hellwig
  2 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2021-03-25 18:54 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: linux-xfs

On Thu, Mar 25, 2021 at 07:33:38PM +0530, Chandan Babu R wrote:
> xfs/538 can cause the following call trace to be printed when executing on a
> multi-block directory configuration,
> 
>  WARNING: CPU: 1 PID: 2578 at fs/xfs/libxfs/xfs_bmap.c:717 xfs_bmap_extents_to_btree+0x520/0x5d0
>  Call Trace:
>   ? xfs_buf_rele+0x4f/0x450
>   xfs_bmap_add_extent_hole_real+0x747/0x960
>   xfs_bmapi_allocate+0x39a/0x440
>   xfs_bmapi_write+0x507/0x9e0
>   xfs_da_grow_inode_int+0x1cd/0x330
>   ? up+0x12/0x60
>   xfs_dir2_grow_inode+0x62/0x110
>   ? xfs_trans_log_inode+0x234/0x2d0
>   xfs_dir2_sf_to_block+0x103/0x940
>   ? xfs_dir2_sf_check+0x8c/0x210
>   ? xfs_da_compname+0x19/0x30
>   ? xfs_dir2_sf_lookup+0xd0/0x3d0
>   xfs_dir2_sf_addname+0x10d/0x910
>   xfs_dir_createname+0x1ad/0x210
>   xfs_create+0x404/0x620
>   xfs_generic_create+0x24c/0x320
>   path_openat+0xda6/0x1030
>   do_filp_open+0x88/0x130
>   ? kmem_cache_alloc+0x50/0x210
>   ? __cond_resched+0x16/0x40
>   ? kmem_cache_alloc+0x50/0x210
>   do_sys_openat2+0x97/0x150
>   __x64_sys_creat+0x49/0x70
>   do_syscall_64+0x33/0x40
>   entry_SYSCALL_64_after_hwframe+0x44/0xae
> 
> This occurs because xfs_bmap_exact_minlen_extent_alloc() initializes
> xfs_alloc_arg->total to xfs_bmalloca->minlen. In the context of
> xfs_bmap_exact_minlen_extent_alloc(), xfs_bmalloca->minlen has a value of 1
> and hence the space allocator could choose an AG which has less than
> xfs_bmalloca->total number of free blocks available. As the transaction
> proceeds, one of the future space allocation requests could fail due to
> non-availability of free blocks in the AG that was originally chosen.
> 
> This commit fixes the bug by assigning xfs_alloc_arg->total to the value of
> xfs_bmalloca->total.
> 
> Fixes: 301519674699 ("xfs: Introduce error injection to allocate only minlen size extents for files")
> Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>

Sounds resonable to me, I guess I'll give it a try...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/libxfs/xfs_bmap.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index e0905ad171f0..585f7e795023 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -3586,7 +3586,8 @@ xfs_bmap_exact_minlen_extent_alloc(
>  	args.fsbno = ap->blkno;
>  	args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
>  	args.type = XFS_ALLOCTYPE_FIRST_AG;
> -	args.total = args.minlen = args.maxlen = ap->minlen;
> +	args.minlen = args.maxlen = ap->minlen;
> +	args.total = ap->total;
>  
>  	args.alignment = 1;
>  	args.minalignslop = 0;
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents
  2021-03-25 14:03 [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Chandan Babu R
  2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
  2021-03-25 18:54 ` [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Darrick J. Wong
@ 2021-04-02  6:44 ` Christoph Hellwig
  2 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-04-02  6:44 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: linux-xfs, djwong

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent
  2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
  2021-03-25 18:53   ` Darrick J. Wong
@ 2021-04-02  6:45   ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-04-02  6:45 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: linux-xfs, djwong

On Thu, Mar 25, 2021 at 07:33:39PM +0530, Chandan Babu R wrote:
> With dax enabled filesystems, a direct write operation into an existing
> unwritten extent results in xfs_iomap_write_direct() zero-ing and converting
> the extent into a normal extent before the actual data is copied from the
> userspace buffer.
> 
> The inode extent count can increase by 2 if the extent range being written to
> maps to the middle of the existing unwritten extent range. Hence this commit
> uses XFS_IEXT_WRITE_UNWRITTEN_CNT as the extent count delta when such a write
> operation is being performed.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-02  6:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 14:03 [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Chandan Babu R
2021-03-25 14:03 ` [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Chandan Babu R
2021-03-25 18:53   ` Darrick J. Wong
2021-04-02  6:45   ` Christoph Hellwig
2021-03-25 18:54 ` [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Darrick J. Wong
2021-04-02  6:44 ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.