]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: fix an off-by-one issue during moving extents
authorZhang Yi <yi.zhang@huawei.com>
Fri, 12 Sep 2025 10:58:41 +0000 (18:58 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:33:59 +0000 (16:33 +0200)
commit 12e803c8827d049ae8f2c743ef66ab87ae898375 upstream.

During the movement of a written extent, mext_page_mkuptodate() is
called to read data in the range [from, to) into the page cache and to
update the corresponding buffers. Therefore, we should not wait on any
buffer whose start offset is >= 'to'. Otherwise, it will return -EIO and
fail the extents movement.

 $ for i in `seq 3 -1 0`; \
   do xfs_io -fs -c "pwrite -b 1024 $((i * 1024)) 1024" /mnt/foo; \
   done
 $ umount /mnt && mount /dev/pmem1s /mnt  # drop cache
 $ e4defrag /mnt/foo
   e4defrag 1.47.0 (5-Feb-2023)
   ext4 defragmentation for /mnt/foo
   [1/1]/mnt/foo:    0%    [ NG ]
   Success:                       [0/1]

Cc: stable@kernel.org
Fixes: a40759fb16ae ("ext4: remove array of buffer_heads from mext_page_mkuptodate()")
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Message-ID: <20250912105841.1886799-1-yi.zhang@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/move_extent.c

index 898443e98efc9e81d9db67a7d000eea2533d0ad8..a4c94eabc78ec6f2b1f6556a01cf3c5a0a59d11b 100644 (file)
@@ -225,7 +225,7 @@ static int mext_page_mkuptodate(struct folio *folio, size_t from, size_t to)
        do {
                if (bh_offset(bh) + blocksize <= from)
                        continue;
-               if (bh_offset(bh) > to)
+               if (bh_offset(bh) >= to)
                        break;
                wait_on_buffer(bh);
                if (buffer_uptodate(bh))