Skip to content

Commit e1889fc

Browse files
Ming Leipopcornmix
authored andcommitted
block: fix adding folio to bio
commit 26064d3 upstream. >4GB folio is possible on some ARCHs, such as aarch64, 16GB hugepage is supported, then 'offset' of folio can't be held in 'unsigned int', cause warning in bio_add_folio_nofail() and IO failure. Fix it by adjusting 'page' & trimming 'offset' so that `->bi_offset` won't be overflow, and folio can be added to bio successfully. Fixes: ed9832b ("block: introduce folio awareness and add a bigger size from folio") Cc: Kundan Kumar <kundan.kumar@samsung.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Gavin Shan <gshan@redhat.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> Link: https://lore.kernel.org/r/20250312145136.2891229-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk> [ The follow-up fix fbecd73 ("xfs: fix zoned GC data corruption due to wrong bv_offset") addresses issues in the file fs/xfs/xfs_zone_gc.c. This file was first introduced in version v6.15-rc1. So don't backport the follow up fix to 6.12.y. ] Signed-off-by: Alva Lan <alvalan9@foxmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0c20720 commit e1889fc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

block/bio.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,10 @@ EXPORT_SYMBOL(bio_add_page);
11561156
void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
11571157
size_t off)
11581158
{
1159+
unsigned long nr = off / PAGE_SIZE;
1160+
11591161
WARN_ON_ONCE(len > UINT_MAX);
1160-
WARN_ON_ONCE(off > UINT_MAX);
1161-
__bio_add_page(bio, &folio->page, len, off);
1162+
__bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE);
11621163
}
11631164
EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
11641165

@@ -1179,9 +1180,11 @@ EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
11791180
bool bio_add_folio(struct bio *bio, struct folio *folio, size_t len,
11801181
size_t off)
11811182
{
1182-
if (len > UINT_MAX || off > UINT_MAX)
1183+
unsigned long nr = off / PAGE_SIZE;
1184+
1185+
if (len > UINT_MAX)
11831186
return false;
1184-
return bio_add_page(bio, &folio->page, len, off) > 0;
1187+
return bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE) > 0;
11851188
}
11861189
EXPORT_SYMBOL(bio_add_folio);
11871190

0 commit comments

Comments
 (0)