]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix wrong block mapping for multi-devices
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 20 Oct 2025 21:52:17 +0000 (17:52 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:03:15 +0000 (14:03 +0100)
[ Upstream commit 9d5c4f5c7a2c7677e1b3942772122b032c265aae ]

Assuming the disk layout as below,

disk0: 0            --- 0x00035abfff
disk1: 0x00035ac000 --- 0x00037abfff
disk2: 0x00037ac000 --- 0x00037ebfff

and we want to read data from offset=13568 having len=128 across the block
devices, we can illustrate the block addresses like below.

0 .. 0x00037ac000 ------------------- 0x00037ebfff, 0x00037ec000 -------
          |          ^            ^                                ^
          |   fofs   0            13568                            13568+128
          |       ------------------------------------------------------
          |   LBA    0x37e8aa9    0x37ebfa9                        0x37ec029
          --- map    0x3caa9      0x3ffa9

In this example, we should give the relative map of the target block device
ranging from 0x3caa9 to 0x3ffa9 where the length should be calculated by
0x37ebfff + 1 - 0x37ebfa9.

In the below equation, however, map->m_pblk was supposed to be the original
address instead of the one from the target block address.

 - map->m_len = min(map->m_len, dev->end_blk + 1 - map->m_pblk);

Cc: stable@vger.kernel.org
Fixes: 71f2c8206202 ("f2fs: multidevice: support direct IO")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
[ applied fix to f2fs_map_blocks() instead of f2fs_map_blocks_cached() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/data.c

index 8843f2bd613d5b15931af82c7d3f5c972bd745e0..6798efda7d0d335747a3346384a48ae5195307a0 100644 (file)
@@ -1505,9 +1505,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
                        bidx = f2fs_target_device_index(sbi, map->m_pblk);
 
                        map->m_bdev = FDEV(bidx).bdev;
-                       map->m_pblk -= FDEV(bidx).start_blk;
                        map->m_len = min(map->m_len,
                                FDEV(bidx).end_blk + 1 - map->m_pblk);
+                       map->m_pblk -= FDEV(bidx).start_blk;
 
                        if (map->m_may_create)
                                f2fs_update_device_state(sbi, inode->i_ino,