Skip to content

Commit

Permalink
block: ensure that bio_add_page() always accepts a page for an empty bio
Browse files Browse the repository at this point in the history
With commit 762380a added support for chunk sizes and no merging
across them, it broke the rule of always allowing adding of a single
page to an empty bio. So relax the restriction a bit to allow for that,
similarly to what we have always done.

This fixes a crash with mkfs.xfs and 512b sector sizes on NVMe.

Reported-by: Keith Busch <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Jun 10, 2014
1 parent 2b8393b commit 58a4915
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,13 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
unsigned int offset)
{
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
unsigned int max_sectors;

return __bio_add_page(q, bio, page, len, offset, blk_max_size_offset(q, bio->bi_iter.bi_sector));
max_sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector);
if ((max_sectors < (len >> 9)) && !bio->bi_iter.bi_size)
max_sectors = len >> 9;

return __bio_add_page(q, bio, page, len, offset, max_sectors);
}
EXPORT_SYMBOL(bio_add_page);

Expand Down
5 changes: 4 additions & 1 deletion block/blk-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ EXPORT_SYMBOL(blk_queue_max_hw_sectors);
* Description:
* If a driver doesn't want IOs to cross a given chunk size, it can set
* this limit and prevent merging across chunks. Note that the chunk size
* must currently be a power-of-2 in sectors.
* must currently be a power-of-2 in sectors. Also note that the block
* layer must accept a page worth of data at any offset. So if the
* crossing of chunks is a hard limitation in the driver, it must still be
* prepared to split single page bios.
**/
void blk_queue_chunk_sectors(struct request_queue *q, unsigned int chunk_sectors)
{
Expand Down

0 comments on commit 58a4915

Please sign in to comment.