Skip to content

Commit 26064d3

Browse files
Ming Leiaxboe
authored andcommitted
block: fix adding folio to bio
>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 <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Gavin Shan <[email protected]> Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 61667cb commit 26064d3

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
@@ -1026,9 +1026,10 @@ EXPORT_SYMBOL(bio_add_page);
10261026
void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
10271027
size_t off)
10281028
{
1029+
unsigned long nr = off / PAGE_SIZE;
1030+
10291031
WARN_ON_ONCE(len > UINT_MAX);
1030-
WARN_ON_ONCE(off > UINT_MAX);
1031-
__bio_add_page(bio, &folio->page, len, off);
1032+
__bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE);
10321033
}
10331034
EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
10341035

@@ -1049,9 +1050,11 @@ EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
10491050
bool bio_add_folio(struct bio *bio, struct folio *folio, size_t len,
10501051
size_t off)
10511052
{
1052-
if (len > UINT_MAX || off > UINT_MAX)
1053+
unsigned long nr = off / PAGE_SIZE;
1054+
1055+
if (len > UINT_MAX)
10531056
return false;
1054-
return bio_add_page(bio, &folio->page, len, off) > 0;
1057+
return bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE) > 0;
10551058
}
10561059
EXPORT_SYMBOL(bio_add_folio);
10571060

0 commit comments

Comments
 (0)