]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Revert "btrfs: fix the file offset calculation inside btrfs_decompress_buf2page()"
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 22 May 2026 18:14:07 +0000 (19:14 +0100)
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 9 Jun 2026 16:22:44 +0000 (18:22 +0200)
It seems that af566bdaff54 was tested against a tree which did not
contain commit 12851bd921d4 ("fs: Turn page_offset() into a wrapper
around folio_pos()).  Unfortunately it has a bug of its own; on 32-bit
systems, shifting by PAGE_SHIFT will overflow on files larger than 4GiB.
Since page_offset() is now fixed, just revert af566bdaff54.

Fixes: af566bdaff54 (btrfs: fix the file offset calculation inside btrfs_decompress_buf2page())
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Tested-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c

index cce85eebf2beecd8fafdc58233c9cbbd8f0a3fc8..ffb6b52863a78dabb5e12f5359f487eff9053981 100644 (file)
@@ -1170,22 +1170,6 @@ void __cold btrfs_exit_compress(void)
        bioset_exit(&btrfs_compressed_bioset);
 }
 
-/*
- * The bvec is a single page bvec from a bio that contains folios from a filemap.
- *
- * Since the folio may be a large one, and if the bv_page is not a head page of
- * a large folio, then page->index is unreliable.
- *
- * Thus we need this helper to grab the proper file offset.
- */
-static u64 file_offset_from_bvec(const struct bio_vec *bvec)
-{
-       const struct page *page = bvec->bv_page;
-       const struct folio *folio = page_folio(page);
-
-       return (page_pgoff(folio, page) << PAGE_SHIFT) + bvec->bv_offset;
-}
-
 /*
  * Copy decompressed data from working buffer to pages.
  *
@@ -1238,7 +1222,7 @@ int btrfs_decompress_buf2page(const char *buf, u32 buf_len,
                 * cb->start may underflow, but subtracting that value can still
                 * give us correct offset inside the full decompressed extent.
                 */
-               bvec_offset = file_offset_from_bvec(&bvec) - cb->start;
+               bvec_offset = page_offset(bvec.bv_page) + bvec.bv_offset - cb->start;
 
                /* Haven't reached the bvec range, exit */
                if (decompressed + buf_len <= bvec_offset)