From: Daejun Park An AIO direct write drops the iolock before its bios complete. XFS_IOC_SWAPEXT does not wait for it. The write can land in blocks that the swap moved to the temporary file. Once xfs_fsr frees them, the write corrupts whatever reuses them. Wait for direct I/O first, as exchange-range does. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Daejun Park --- Tested with an AIO direct write held back by cgroup io.max. Before, the write reached files that reused the freed blocks in 7 of 7 runs. After, those files were intact. The new fstests case "xfs: test that swapext waits for in-flight direct I/O" fails before and passes after. Running fstests -g fsr shows no change. Applies with or without "xfs: break layouts before swapping extents". --- fs/xfs/xfs_bmap_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 865aec3ae5a..4d214708f9c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1257,6 +1257,7 @@ xfs_swap_extent_flush( { int error; + inode_dio_wait(VFS_I(ip)); error = filemap_write_and_wait(VFS_I(ip)->i_mapping); if (error) return error; --- base-commit: 1e17fc56469d62d1c1ac45c137a2456d14456f1d change-id: 20261109-xfs-swapext-dio-wait-6b700c2a981e Best regards, -- Daejun Park