btrfs: subpage: access correct object when reading bitmap start in subpage_calc_start...
authorQu Wenruo <wqu@suse.com>
Wed, 26 Mar 2025 04:11:13 +0000 (14:41 +1030)
committerDavid Sterba <dsterba@suse.com>
Thu, 17 Apr 2025 09:55:17 +0000 (11:55 +0200)
Inside the macro, subpage_calc_start_bit(), we need to calculate the
offset to the beginning of the folio.

But we're using offset_in_page(), on systems with 4K page size and 4K fs
block size, this means we will always return offset 0 for a large folio,
causing all kinds of errors.

Fix it by using offset_in_folio() instead.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/subpage.c

index 11dbd7be6a3b3be830e3383de143a15913ffa680..bd252c78a261d407d5957f9d7984e1dfc169b90f 100644 (file)
@@ -204,7 +204,7 @@ static void btrfs_subpage_assert(const struct btrfs_fs_info *fs_info,
                           btrfs_blocks_per_folio(fs_info, folio);      \
                                                                        \
        btrfs_subpage_assert(fs_info, folio, start, len);               \
-       __start_bit = offset_in_page(start) >> fs_info->sectorsize_bits; \
+       __start_bit = offset_in_folio(folio, start) >> fs_info->sectorsize_bits; \
        __start_bit += blocks_per_folio * btrfs_bitmap_nr_##name;       \
        __start_bit;                                                    \
 })