Skip to contentSkip to conversation

xfs: fix livelock in delayed allocation at ENOSPC

PATCH In review Dave Chinner 3 participants 3 messages May 27, 2023 – May 28, 2023 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix livelock in delayed allocation at ENOSPC

Hi Greg,

A regression in 6.3.0 has been identified in XFS that causes filesystem corruption. It has been seen in the wild by a number of users, and bisected down to an issued we'd already fixed in 6.4-rc1 with commit:

9419092fb263 ("xfs: fix livelock in delayed allocation at ENOSPC")

This was reported with much less harmful symptoms (alloctor livelock) and it wasn't realised that it could have other, more impactful symptoms. A reproducer for the corruption was found yesterday and, soon after than, the cause of the corruption reports was identified.

The commit applies cleanly to a 6.3.0 kernel here, so it should also apply cleanly to a current 6.3.x kernel. I've included the entire commit below in case that's easier for you.

Can you please pull this commit into the next 6.3.x release as a matter of priority?

Cheers,

Dave.

Signature · 38 lines
Dave Chinner
[email protected]

xfs: fix livelock in delayed allocation at ENOSPC

From: Dave Chinner <[email protected]>

On a filesystem with a non-zero stripe unit and a large sequential
write, delayed allocation will set a minimum allocation length of
the stripe unit. If allocation fails because there are no extents
long enough for an aligned minlen allocation, it is supposed to
fall back to unaligned allocation which allows single block extents
to be allocated.

When the allocator code was rewritting in the 6.3 cycle, this
fallback was broken - the old code used args->fsbno as the both the
allocation target and the allocation result, the new code passes the
target as a separate parameter. The conversion didn't handle the
aligned->unaligned fallback path correctly - it reset args->fsbno to
the target fsbno on failure which broke allocation failure detection
in the high level code and so it never fell back to unaligned
allocations.

This resulted in a loop in writeback trying to allocate an aligned
block, getting a false positive success, trying to insert the result
in the BMBT. This did nothing because the extent already was in the
BMBT (merge results in an unchanged extent) and so it returned the
prior extent to the conversion code as the current iomap.

Because the iomap returned didn't cover the offset we tried to map,
xfs_convert_blocks() then retries the allocation, which fails in the
same way and now we have a livelock.

Reported-and-tested-by: Brian Foster <[email protected]>
Fixes: 85843327094f ("xfs: factor xfs_bmap_btalloc()")
Signed-off-by: Dave Chinner <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
---
fs/xfs/libxfs/xfs_bmap.c +0 -1
index 1a4e446194dd..b512de0540d5 100644
@@ -3540,7 +3540,6 @@ xfs_bmap_btalloc_at_eof(
 	 * original non-aligned state so the caller can proceed on allocation
 	 * failure as if this function was never called.
 	 */
-	args->fsbno = ap->blkno;
 	args->alignment = 1;
 	return 0;
 }
#1 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

Rule: 'Cc: [email protected]' or 'commit <sha1> upstream.'
Subject: [PATCH, STABLE 6.3.x] xfs: fix livelock in delayed allocation at ENOSPC

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#2 lore raw
In reply to Dave Chinner
Quoted 15 lines · Dave Chinner

Hi Greg,

A regression in 6.3.0 has been identified in XFS that causes filesystem corruption. It has been seen in the wild by a number of users, and bisected down to an issued we'd already fixed in 6.4-rc1 with commit:

9419092fb263 ("xfs: fix livelock in delayed allocation at ENOSPC")

This was reported with much less harmful symptoms (alloctor livelock) and it wasn't realised that it could have other, more impactful symptoms. A reproducer for the corruption was found yesterday and, soon after than, the cause of the corruption reports was identified.

Quoted 6 lines

The commit applies cleanly to a 6.3.0 kernel here, so it should also apply cleanly to a current 6.3.x kernel. I've included the entire commit below in case that's easier for you.

Can you please pull this commit into the next 6.3.x release as a matter of priority?

Now queued up, thanks.

greg k-h