bio: check return values of bio_add_page
Subsystems (13)
v7 cover bio: check return values of bio_add_page
We have two functions for adding a page to a bio, __bio_add_page() which is used to add a single page to a freshly created bio and bio_add_page() which is used to add a page to an existing bio.
While __bio_add_page() is expected to succeed, bio_add_page() can fail.
This series converts the callers of bio_add_page() which can easily use __bio_add_page() to using it and checks the return of bio_add_page() for callers that don't work on a freshly created bio.
Lastly it marks bio_add_page() as __must_check so we don't have to go again and audit all callers.
Changes to v6:
- Incorporated comments from Mike and Christoph
- Collected Reviewed-bys
Changes to v5:
- Rebased onto latest Linus' master
- Removed now superfluous BUG_ON() in fs/buffer.c (Gou)
- Removed dead cleanup code in dm-crypt.c (Mikulas)
Changes to v4:
- Rebased onto latest Linus' master
- Dropped already merged patches
- Added Sergey's Reviewed-by
Changes to v3:
- Added __bio_add_folio and use it in iomap (Willy)
- Mark bio_add_folio must check (Willy)
- s/GFS/GFS2/ (Andreas)
Changes to v2:
- Removed 'wont fail' comments pointed out by Song
Changes to v1:
- Removed pointless comment pointed out by Willy
- Changed commit messages pointed out by Damien
- Colledted Damien's Reviews and Acks
Johannes Thumshirn (20):
swap: use __bio_add_page to add page to bio
drbd: use __bio_add_page to add page to bio
dm: dm-zoned: use __bio_add_page for adding single metadata page
fs: buffer: use __bio_add_page to add single page to bio
md: use __bio_add_page to add single page
md: raid5-log: use __bio_add_page to add single page
md: raid5: use __bio_add_page to add single page to new bio
jfs: logmgr: use __bio_add_page to add single page to bio
gfs2: use __bio_add_page for adding single page to bio
zonefs: use __bio_add_page for adding single page to bio
zram: use __bio_add_page for adding single page to bio
floppy: use __bio_add_page for adding single page to bio
md: check for failure when adding pages in alloc_behind_master_bio
md: raid1: use __bio_add_page for adding single page to bio
md: raid1: check if adding pages to resync bio fails
dm-crypt: use __bio_add_page to add single page to clone bio
block: mark bio_add_page as __must_check
block: add bio_add_folio_nofail
fs: iomap: use bio_add_folio_nofail where possible
block: mark bio_add_folio as __must_check
block/bio.c | 8 ++++++++ drivers/block/drbd/drbd_bitmap.c | 4 +--- drivers/block/floppy.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/dm-crypt.c | 3 +-- drivers/md/dm-zoned-metadata.c | 6 +++--- drivers/md/md.c | 4 ++-- drivers/md/raid1-10.c | 11 ++++++----- drivers/md/raid1.c | 7 +++++-- drivers/md/raid10.c | 20 ++++++++++---------- drivers/md/raid5-cache.c | 2 +- drivers/md/raid5-ppl.c | 4 ++-- fs/buffer.c | 3 +-- fs/gfs2/ops_fstype.c | 2 +- fs/iomap/buffered-io.c | 6 +++--- fs/jfs/jfs_logmgr.c | 4 ++-- fs/zonefs/super.c | 2 +- include/linux/bio.h | 8 ++++++-- mm/page_io.c | 8 ++++---- 19 files changed, 59 insertions(+), 47 deletions(-)
base-commit: 48b1320a674e1ff5de2fad8606bee38f724594dc
Signature · 1 line
2.40.1
PATCH v7 1/20 swap: use __bio_add_page to add page to bio
The swap code only adds a single page to a newly created bio. So use __bio_add_page() to add the page which is guaranteed to succeed in this case.
This brings us closer to marking bio_add_page() as __must_check.
--- mm/page_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page_io.c +4 -4
@@ -338,7 +338,7 @@ static void swap_writepage_bdev_sync(struct page *page,bio_init (&bio, sis->bdev, &bv,1 ,REQ_OP_WRITE |REQ_SWAP |wbc_to_write_flags (wbc)); bio.bi_iter.bi_sector =swap_page_sector (page); -bio_add_page (&bio, page,thp_size (page),0 ); +__bio_add_page (&bio, page,thp_size (page),0 );bio_associate_blkg_from_page (&bio, page);count_swpout_vm_event (page);
@@ -360,7 +360,7 @@ static void swap_writepage_bdev_async(struct page *page, GFP_NOIO); bio->bi_iter.bi_sector =swap_page_sector (page); bio->bi_end_io = end_swap_bio_write; -bio_add_page (bio, page,thp_size (page),0 ); +__bio_add_page (bio, page,thp_size (page),0 );bio_associate_blkg_from_page (bio, page);count_swpout_vm_event (page);
@@ -468,7 +468,7 @@ static void swap_readpage_bdev_sync(struct page *page,bio_init (&bio, sis->bdev, &bv,1 ,REQ_OP_READ ); bio.bi_iter.bi_sector =swap_page_sector (page); -bio_add_page (&bio, page,thp_size (page),0 ); +__bio_add_page (&bio, page,thp_size (page),0 );/* * Keep this task valid during swap readpage because the oom killer may * attempt to access it in the page fault retry time check.
@@ -488,7 +488,7 @@ static void swap_readpage_bdev_async(struct page *page, bio =bio_alloc (sis->bdev,1 ,REQ_OP_READ ,GFP_KERNEL ); bio->bi_iter.bi_sector =swap_page_sector (page); bio->bi_end_io = end_swap_bio_read; -bio_add_page (bio, page,thp_size (page),0 ); +__bio_add_page (bio, page,thp_size (page),0 );count_vm_event (PSWPIN );submit_bio (bio); }
Signature · 1 line
2.40.1
PATCH v7 2/20 drbd: use __bio_add_page to add page to bio
In reply to Johannes ThumshirnThe drbd code only adds a single page to a newly created bio. So use __bio_add_page() to add the page which is guaranteed to succeed in this case.
This brings us closer to marking bio_add_page() as __must_check.
--- drivers/block/drbd/drbd_bitmap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/drbd/drbd_bitmap.c +1 -3
@@ -1043,9 +1043,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho bio =bio_alloc_bioset (device->ldev->md_bdev,1 , op,GFP_NOIO , &drbd_md_io_bio_set); bio->bi_iter.bi_sector = on_disk_sector; -/* bio_add_page of a single page to an empty bio will always succeed, -* according to api. Do we want to assert that? */ -bio_add_page (bio, page, len,0 ); +__bio_add_page (bio, page, len,0 ); bio->bi_private = ctx; bio->bi_end_io = drbd_bm_endio;
Signature · 1 line
2.40.1
PATCH v7 3/20 dm: dm-zoned: use __bio_add_page for adding single metadata page
In reply to Johannes Thumshirndm-zoned uses bio_add_page() for adding a single page to a freshly created metadata bio.
Use __bio_add_page() instead as adding a single page to a new bio is always guaranteed to succeed.
This brings us a step closer to marking bio_add_page() __must_check
--- drivers/md/dm-zoned-metadata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-zoned-metadata.c +3 -3
@@ -577,7 +577,7 @@ static struct dmz_mblock *dmz_get_mblock_slow(struct dmz_metadata *zmd, bio->bi_iter.bi_sector =dmz_blk2sect (block); bio->bi_private = mblk; bio->bi_end_io = dmz_mblock_bio_end_io; -bio_add_page (bio, mblk->page,DMZ_BLOCK_SIZE ,0 ); +__bio_add_page (bio, mblk->page,DMZ_BLOCK_SIZE ,0 );submit_bio (bio);return mblk;
@@ -728,7 +728,7 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, struct dmz_mblock *mblk, bio->bi_iter.bi_sector =dmz_blk2sect (block); bio->bi_private = mblk; bio->bi_end_io = dmz_mblock_bio_end_io; -bio_add_page (bio, mblk->page,DMZ_BLOCK_SIZE ,0 ); +__bio_add_page (bio, mblk->page,DMZ_BLOCK_SIZE ,0 );submit_bio (bio);return 0 ;
@@ -752,7 +752,7 @@ static int dmz_rdwr_block(struct dmz_dev *dev, enum req_op op, bio =bio_alloc (dev->bdev,1 , op |REQ_SYNC |REQ_META |REQ_PRIO ,GFP_NOIO ); bio->bi_iter.bi_sector =dmz_blk2sect (block); -bio_add_page (bio, page,DMZ_BLOCK_SIZE ,0 ); +__bio_add_page (bio, page,DMZ_BLOCK_SIZE ,0 ); ret =submit_bio_wait (bio);bio_put (bio);
Signature · 1 line
2.40.1
PATCH v7 4/20 fs: buffer: use __bio_add_page to add single page to bio
In reply to Johannes ThumshirnThe buffer_head submission code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- fs/buffer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/buffer.c +1 -2
@@ -2760,8 +2760,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >>9 ); -bio_add_page (bio, bh->b_page, bh->b_size,bh_offset (bh)); -BUG_ON (bio->bi_iter.bi_size != bh->b_size); +__bio_add_page (bio, bh->b_page, bh->b_size,bh_offset (bh)); bio->bi_end_io = end_bio_bh_io_sync; bio->bi_private = bh;
Signature · 1 line
2.40.1
PATCH v7 5/20 md: use __bio_add_page to add single page
In reply to Johannes ThumshirnThe md-raid superblock writing code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/md/md.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.c +2 -2
@@ -938,7 +938,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,atomic_inc (&rdev->nr_pending); bio->bi_iter.bi_sector = sector; -bio_add_page (bio, page, size,0 ); +__bio_add_page (bio, page, size,0 ); bio->bi_private = rdev; bio->bi_end_io = super_written;
@@ -979,7 +979,7 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size, bio.bi_iter.bi_sector = sector + rdev->new_data_offset; else bio.bi_iter.bi_sector = sector + rdev->data_offset; -bio_add_page (&bio, page, size,0 ); +__bio_add_page (&bio, page, size,0 );submit_bio_wait (&bio);
Signature · 1 line
2.40.1
PATCH v7 6/20 md: raid5-log: use __bio_add_page to add single page
In reply to Johannes ThumshirnThe raid5 log metadata submission code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/md/raid5-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid5-cache.c +1 -1
@@ -792,7 +792,7 @@ static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log) io->current_bio =r5l_bio_alloc (log); io->current_bio->bi_end_io = r5l_log_endio; io->current_bio->bi_private = io; -bio_add_page (io->current_bio, io->meta_page,PAGE_SIZE ,0 ); +__bio_add_page (io->current_bio, io->meta_page,PAGE_SIZE ,0 );r5_reserve_log_entry (log, io);
Signature · 1 line
2.40.1
PATCH v7 7/20 md: raid5: use __bio_add_page to add single page to new bio
In reply to Johannes ThumshirnThe raid5-ppl submission code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked. For adding consecutive pages, the return is actually checked and a new bio is allocated if adding the page fails.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/md/raid5-ppl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid5-ppl.c +2 -2
@@ -465,7 +465,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io) bio->bi_end_io = ppl_log_endio; bio->bi_iter.bi_sector = log->next_io_sector; -bio_add_page (bio, io->header_page,PAGE_SIZE ,0 ); +__bio_add_page (bio, io->header_page,PAGE_SIZE ,0 );pr_debug ("%s: log->current_io_sector: %llu\n" , __func__, (unsigned long long )log->next_io_sector);
@@ -496,7 +496,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io) prev->bi_opf,GFP_NOIO , &ppl_conf->bs); bio->bi_iter.bi_sector =bio_end_sector (prev); -bio_add_page (bio, sh->ppl_page,PAGE_SIZE ,0 ); +__bio_add_page (bio, sh->ppl_page,PAGE_SIZE ,0 );bio_chain (bio, prev);ppl_submit_iounit_bio (io, prev);
Signature · 1 line
2.40.1
PATCH v7 8/20 jfs: logmgr: use __bio_add_page to add single page to bio
In reply to Johannes ThumshirnThe JFS IO code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- fs/jfs/jfs_logmgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/jfs/jfs_logmgr.c +2 -2
@@ -1974,7 +1974,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) bio =bio_alloc (log->bdev,1 ,REQ_OP_READ ,GFP_NOFS ); bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize -9 ); -bio_add_page (bio, bp->l_page,LOGPSIZE , bp->l_offset); +__bio_add_page (bio, bp->l_page,LOGPSIZE , bp->l_offset);BUG_ON (bio->bi_iter.bi_size !=LOGPSIZE ); bio->bi_end_io = lbmIODone;
@@ -2115,7 +2115,7 @@ static void lbmStartIO(struct lbuf * bp) bio =bio_alloc (log->bdev,1 ,REQ_OP_WRITE |REQ_SYNC ,GFP_NOFS ); bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize -9 ); -bio_add_page (bio, bp->l_page,LOGPSIZE , bp->l_offset); +__bio_add_page (bio, bp->l_page,LOGPSIZE , bp->l_offset);BUG_ON (bio->bi_iter.bi_size !=LOGPSIZE ); bio->bi_end_io = lbmIODone;
Signature · 1 line
2.40.1
PATCH v7 9/20 gfs2: use __bio_add_page for adding single page to bio
In reply to Johannes ThumshirnThe GFS2 superblock reading code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- fs/gfs2/ops_fstype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/ops_fstype.c +1 -1
@@ -254,7 +254,7 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent) bio =bio_alloc (sb->s_bdev,1 ,REQ_OP_READ |REQ_META ,GFP_NOFS ); bio->bi_iter.bi_sector = sector * (sb->s_blocksize >>9 ); -bio_add_page (bio, page,PAGE_SIZE ,0 ); +__bio_add_page (bio, page,PAGE_SIZE ,0 ); bio->bi_end_io = end_bio_io_page; bio->bi_private = page;
Signature · 1 line
2.40.1
PATCH v7 10/20 zonefs: use __bio_add_page for adding single page to bio
In reply to Johannes ThumshirnThe zonefs superblock reading code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- fs/zonefs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/zonefs/super.c +1 -1
@@ -1128,7 +1128,7 @@ static int zonefs_read_super(struct super_block *sb)bio_init (&bio, sb->s_bdev, &bio_vec,1 ,REQ_OP_READ ); bio.bi_iter.bi_sector =0 ; -bio_add_page (&bio, page,PAGE_SIZE ,0 ); +__bio_add_page (&bio, page,PAGE_SIZE ,0 ); ret =submit_bio_wait (&bio);if (ret)
Signature · 1 line
2.40.1
PATCH v7 11/20 zram: use __bio_add_page for adding single page to bio
In reply to Johannes ThumshirnThe zram writeback code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/zram/zram_drv.c +1 -1
@@ -700,7 +700,7 @@ static ssize_t writeback_store(struct device *dev,bio_init (&bio, zram->bdev, &bio_vec,1 ,REQ_OP_WRITE |REQ_SYNC ); bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >>9 ); -bio_add_page (&bio, page,PAGE_SIZE ,0 ); +__bio_add_page (&bio, page,PAGE_SIZE ,0 );/* * XXX: A single page IO would be inefficient for write
Signature · 1 line
2.40.1
PATCH v7 12/20 floppy: use __bio_add_page for adding single page to bio
In reply to Johannes ThumshirnThe floppy code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/block/floppy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/floppy.c +1 -1
@@ -4147,7 +4147,7 @@ static int __floppy_read_block_0(struct block_device *bdev, int drive) cbdata.drive = drive;bio_init (&bio, bdev, &bio_vec,1 ,REQ_OP_READ ); -bio_add_page (&bio, page,block_size (bdev),0 ); +__bio_add_page (&bio, page,block_size (bdev),0 ); bio.bi_iter.bi_sector =0 ; bio.bi_flags |= (1 <<BIO_QUIET );
Signature · 1 line
2.40.1
PATCH v7 13/20 md: check for failure when adding pages in alloc_behind_master_bio
In reply to Johannes Thumshirnalloc_behind_master_bio() can possibly add multiple pages to a bio, but it is not checking for the return value of bio_add_page() if adding really succeeded.
Check if the page adding succeeded and if not bail out.
--- drivers/md/raid1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/raid1.c +4 -1
@@ -1147,7 +1147,10 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,if (unlikely (!page)) goto free_pages; -bio_add_page (behind_bio, page, len,0 ); +if (!bio_add_page (behind_bio, page, len,0 )) { +free_page (page); + goto free_pages; + } size -= len; i++;
Signature · 1 line
2.40.1
PATCH v7 14/20 md: raid1: use __bio_add_page for adding single page to bio
In reply to Johannes ThumshirnThe sync request code uses bio_add_page() to add a page to a newly created bio. bio_add_page() can fail, but the return value is never checked.
Use __bio_add_page() as adding a single page to a newly created bio is guaranteed to succeed.
This brings us a step closer to marking bio_add_page() as __must_check.
--- drivers/md/raid1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid1.c +1 -1
@@ -2917,7 +2917,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,* won't fail because the vec table is big * enough to hold all these pages */ -bio_add_page (bio, page, len,0 ); +__bio_add_page (bio, page, len,0 ); } } nr_sectors += len>>9 ;
Signature · 1 line
2.40.1
PATCH v7 15/20 md: raid1: check if adding pages to resync bio fails
In reply to Johannes ThumshirnCheck if adding pages to resync bio fails and if bail out.
As the comment above suggests this cannot happen, WARN if it actually happens. Technically __bio_add_pages() would be sufficient here, but asserting the pages actually get added to the bio is preferred.
This way we can mark bio_add_pages as __must_check.
--- drivers/md/raid1-10.c | 11 ++++++----- drivers/md/raid10.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-)
drivers/md/raid1-10.c +6 -5
@@ -101,11 +101,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,struct page *page =resync_fetch_page (rp, idx);int len =min_t (int, size,PAGE_SIZE ); -/* -* won't fail because the vec table is big -* enough to hold all these pages -*/ -bio_add_page (bio, page, len,0 ); +if (WARN_ON (!bio_add_page (bio, page, len,0 ))) { + bio->bi_status =BLK_STS_RESOURCE ; +bio_endio (bio); +return ; + } + size -= len; }while (idx++ <RESYNC_PAGES && size >0 ); }
drivers/md/raid10.c +10 -10
@@ -3819,11 +3819,11 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,for (bio= biolist ; bio ; bio=bio->bi_next) {struct resync_pages *rp =get_resync_pages (bio); page =resync_fetch_page (rp, page_idx); -/* -* won't fail because the vec table is big enough -* to hold all these pages -*/ -bio_add_page (bio, page, len,0 ); +if (WARN_ON (!bio_add_page (bio, page, len,0 ))) { + bio->bi_status =BLK_STS_RESOURCE ; +bio_endio (bio); + goto giveup; + } } nr_sectors += len>>9 ; sector_nr += len>>9 ;
@@ -4997,11 +4997,11 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,if (len >PAGE_SIZE ) len =PAGE_SIZE ;for (bio = blist; bio ; bio = bio->bi_next) { -/* -* won't fail because the vec table is big enough -* to hold all these pages -*/ -bio_add_page (bio, page, len,0 ); +if (WARN_ON (!bio_add_page (bio, page, len,0 ))) { + bio->bi_status =BLK_STS_RESOURCE ; +bio_endio (bio); +return sectors_done; + } } sector_nr += len >>9 ; nr_sectors += len >>9 ;
Signature · 1 line
2.40.1
PATCH v7 16/20 dm-crypt: use __bio_add_page to add single page to clone bio
In reply to Johannes Thumshirncrypt_alloc_buffer() already allocates enough entries in the clone bio's vector, so adding a page to the bio can't fail. Use __bio_add_page() to reflect this.
--- drivers/md/dm-crypt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-crypt.c +1 -2
@@ -1693,8 +1693,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned int size) len = (remaining_size >PAGE_SIZE ) ?PAGE_SIZE : remaining_size; -bio_add_page (clone, page, len,0 ); - +__bio_add_page (clone, page, len,0 ); remaining_size -= len; }
Signature · 1 line
2.40.1
PATCH v7 17/20 block: mark bio_add_page as __must_check
In reply to Johannes ThumshirnNow that all users of bio_add_page check for the return value, mark bio_add_page as __must_check.
--- include/linux/bio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/bio.h +2 -1
@@ -465,7 +465,8 @@ extern void bio_uninit(struct bio *);void bio_reset (struct bio *bio,struct block_device *bdev,blk_opf_t opf);void bio_chain (struct bio *,struct bio *); -int bio_add_page (struct bio *,struct page *,unsigned len,unsigned off); +int __must_check bio_add_page (struct bio *bio,struct page *page,unsigned len, +unsigned off);bool bio_add_folio (struct bio *,struct folio *,size_t len,size_t off);extern int bio_add_pc_page (struct request_queue *,struct bio *,struct page *,unsigned int ,unsigned int );
Signature · 1 line
2.40.1
Re: [PATCH v7 17/20] block: mark bio_add_page as __must_check
Looks good:
PATCH v7 18/20 block: add bio_add_folio_nofail
In reply to Johannes ThumshirnJust like for bio_add_pages() add a no-fail variant for bio_add_folio().
--- block/bio.c | 8 ++++++++ include/linux/bio.h | 2 ++ 2 files changed, 10 insertions(+)
block/bio.c +8 -0
@@ -1138,6 +1138,14 @@ int bio_add_page(struct bio *bio, struct page *page, }EXPORT_SYMBOL (bio_add_page); +void bio_add_folio_nofail (struct bio *bio,struct folio *folio,size_t len, +size_t off) +{ +WARN_ON_ONCE (len >UINT_MAX ); +WARN_ON_ONCE (off >UINT_MAX ); +__bio_add_page (bio, &folio->page, len, off); +} +/** * bio_add_folio - Attempt to add part of a folio to a bio. * @bio: BIO to add to.
include/linux/bio.h +2 -0
@@ -474,6 +474,8 @@ int bio_add_zone_append_page(struct bio *bio, struct page *page, unsigned int len, unsigned int offset);void __bio_add_page (struct bio *bio,struct page *page,unsigned int len,unsigned int off); +void bio_add_folio_nofail (struct bio *bio,struct folio *folio,size_t len, +size_t off);int bio_iov_iter_get_pages (struct bio *bio,struct iov_iter *iter);void bio_iov_bvec_set (struct bio *bio,struct iov_iter *iter);void __bio_release_pages (struct bio *bio,bool mark_dirty);
Signature · 1 line
2.40.1
Re: [PATCH v7 18/20] block: add bio_add_folio_nofail
Looks good:
PATCH v7 19/20 fs: iomap: use bio_add_folio_nofail where possible
In reply to Johannes ThumshirnWhen the iomap buffered-io code can't add a folio to a bio, it allocates a new bio and adds the folio to that one. This is done using bio_add_folio(), but doesn't check for errors.
As adding a folio to a newly created bio can't fail, use the newly introduced bio_add_folio_nofail() function.
--- fs/iomap/buffered-io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/iomap/buffered-io.c +3 -3
@@ -312,7 +312,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, ctx->bio->bi_opf |=REQ_RAHEAD ; ctx->bio->bi_iter.bi_sector = sector; ctx->bio->bi_end_io = iomap_read_end_io; -bio_add_folio (ctx->bio, folio, plen, poff); +bio_add_folio_nofail (ctx->bio, folio, plen, poff); } done:
@@ -539,7 +539,7 @@ static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,bio_init (&bio, iomap->bdev, &bvec,1 ,REQ_OP_READ ); bio.bi_iter.bi_sector =iomap_sector (iomap, block_start); -bio_add_folio (&bio, folio, plen, poff); +bio_add_folio_nofail (&bio, folio, plen, poff);return submit_bio_wait (&bio); }
@@ -1582,7 +1582,7 @@ iomap_add_to_ioend(struct inode *inode, loff_t pos, struct folio *folio,if (!bio_add_folio (wpc->ioend->io_bio, folio, len, poff)) { wpc->ioend->io_bio =iomap_chain_bio (wpc->ioend->io_bio); -bio_add_folio (wpc->ioend->io_bio, folio, len, poff); +bio_add_folio_nofail (wpc->ioend->io_bio, folio, len, poff); }if (iop)
Signature · 1 line
2.40.1
Re: [PATCH v7 19/20] fs: iomap: use bio_add_folio_nofail where possible
Quoted 37 lines · Johannes Thumshirn
When the iomap buffered-io code can't add a folio to a bio, it allocates a new bio and adds the folio to that one. This is done using
bio_add_folio(), but doesn't check for errors.As adding a folio to a newly created bio can't fail, use the newly introduced
bio_add_folio_nofail()function.Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Matthew Wilcox (Oracle) <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>--- fs/iomap/buffered-io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/iomap/buffered-io.c +2
-2@@ -312,7 +312,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, ctx->bio->bi_opf |=REQ_RAHEAD ; ctx->bio->bi_iter.bi_sector = sector; ctx->bio->bi_end_io = iomap_read_end_io; -bio_add_folio (ctx->bio, folio, plen, poff); +bio_add_folio_nofail (ctx->bio, folio, plen, poff); } done:@@ -539,7 +539,7 @@ static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,bio_init (&bio, iomap->bdev, &bvec,1 ,REQ_OP_READ ); bio.bi_iter.bi_sector =iomap_sector (iomap, block_start); -bio_add_folio (&bio, folio, plen, poff); +bio_add_folio_nofail (&bio, folio, plen, poff);return submit_bio_wait (&bio); }
fs/iomap/buffered-io.c iomap_add_to_ioend(struct inode *inode, loff_t pos, struct folio *folio, · line 1586
Quoted 6 lines
fs/iomap/buffered-io.c +1
-1@@ -1582,7 +1582,7 @@ iomap_add_to_ioend(struct inode *inode, loff_t pos, struct folio *folio,if (!bio_add_folio (wpc->ioend->io_bio, folio, len, poff)) { wpc->ioend->io_bio =iomap_chain_bio (wpc->ioend->io_bio); -bio_add_folio (wpc->ioend->io_bio, folio, len, poff); +bio_add_folio_nofail (wpc->ioend->io_bio, folio, len, poff); }
We lose adjacent page merging with this change.
We've had performance regressions in the past that have been attributed to either the page allocator not handing out sequential adjacent pages for sequential writes and/or bios not merging adjacent pages. Some hardware is much more performant when it only has to do a single large DMA instead of (potentially) hundreds of single page DMAs for the same amount of data...
What performance regression testing has been done on this change?
-Dave.
Signature · 2 lines
Dave Chinner david at fromorbit.com
Re: [PATCH v7 19/20] fs: iomap: use bio_add_folio_nofail where possible
Quoted 1 line · Dave Chinner
We lose adjacent page merging with this change.
This is only used for adding the first folio to a brand new bio, so there is nothing to merge with yet at this point.
Re: [PATCH v7 19/20] fs: iomap: use bio_add_folio_nofail where possible
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Dave Chinner
We lose adjacent page merging with this change.
This is only used for adding the first folio to a brand new bio, so there is nothing to merge with yet at this point.
Ah, sorry, missed that. Carry on. :)
-Dave.
Signature · 2 lines
Dave Chinner david at fromorbit.com
PATCH v7 20/20 block: mark bio_add_folio as __must_check
In reply to Johannes ThumshirnNow that all callers of bio_add_folio() check the return value, mark it as __must_check.
--- include/linux/bio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/bio.h +2 -1
@@ -467,7 +467,8 @@ void bio_chain(struct bio *, struct bio *);int __must_check bio_add_page (struct bio *bio,struct page *page,unsigned len,unsigned off); -bool bio_add_folio (struct bio *,struct folio *,size_t len,size_t off); +bool __must_check bio_add_folio (struct bio *bio,struct folio *folio, +size_t len,size_t off);extern int bio_add_pc_page (struct request_queue *,struct bio *,struct page *,unsigned int ,unsigned int ); int bio_add_zone_append_page(struct bio *bio, struct page *page,
Signature · 1 line
2.40.1
Re: [PATCH v7 20/20] block: mark bio_add_folio as __must_check
Looks good:
Quoted 11 lines · Johannes Thumshirn
We have two functions for adding a page to a bio,
__bio_add_page()which is used to add a single page to a freshly created bio andbio_add_page()which is used to add a page to an existing bio.While
__bio_add_page()is expected to succeed,bio_add_page()can fail.This series converts the callers of
bio_add_page()which can easily use__bio_add_page()to using it and checks the return ofbio_add_page()for callers that don't work on a freshly created bio.[...]
Applied, thanks!
[01/20] swap: use __bio_add_page to add page to bio
commit: cb58bf91b138c1a8b18cca9503308789e26e3522
[02/20] drbd: use __bio_add_page to add page to bio
commit: 8f11f79f193c935da617375ba5ea4e768a73a094
[03/20] dm: dm-zoned: use __bio_add_page for adding single metadata page
commit: fc8ac3e539561aff1c0a255d701d9412d425373c
[04/20] fs: buffer: use __bio_add_page to add single page to bio
commit: 741af75d4027b1229fc6e62f4e3c4378dfe04897
[05/20] md: use __bio_add_page to add single page
commit: 3c383235c51dcd6198d37ac3ac06e2acad79f981
[06/20] md: raid5-log: use __bio_add_page to add single page
commit: b0a2f17cad9d3fa564d67c543f5d19343401fefd
[07/20] md: raid5: use __bio_add_page to add single page to new bio
commit: 6eea4ff8528d6a5b9f0eeb47992e48a8f44b5b8f
[08/20] jfs: logmgr: use __bio_add_page to add single page to bio
commit: 2896db174ced7a800863223f9e74543b98271ba0
[09/20] gfs2: use __bio_add_page for adding single page to bio
commit: effa7ddeeba782406c81b572791a142fbdaf6b05
[10/20] zonefs: use __bio_add_page for adding single page to bio
commit: 0fa5b08cf6e17b0a64ffcc5894d8efe186691ab8
[11/20] zram: use __bio_add_page for adding single page to bio
commit: 34848c910b911838e1e83e1370cb988b578c8860
[12/20] floppy: use __bio_add_page for adding single page to bio
commit: 5225229b8fdfb3e65520c43547ecf9a737161c3f
[13/20] md: check for failure when adding pages in alloc_behind_master_bio
commit: 6473bc325644b9c8473e6c92bfb520a68dce1e12
[14/20] md: raid1: use __bio_add_page for adding single page to bio
commit: 2f9848178cfa4ac68a5b46e63e5163a09b8bd80f
[15/20] md: raid1: check if adding pages to resync bio fails
commit: 33332be32fe91ff54ff326b3a1608973544e835a
[16/20] dm-crypt: use __bio_add_page to add single page to clone bio
commit: 9be63ecfdd63f957b9ed25eaf85666d22a02d7a5
[17/20] block: mark bio_add_page as __must_check
commit: 5b3e39c1cc8e1cf31a398830dd665eb15546b4f7
[18/20] block: add bio_add_folio_nofail
commit: 42205551d1d43b1b42942fb7ef023cf954136cea
[19/20] fs: iomap: use bio_add_folio_nofail where possible
commit: f31c58ab3ddaf64503d7988197602d7443d5be37
[20/20] block: mark bio_add_folio as __must_check
commit: 9320744e4dbe10df6059b2b6531946c200a0ba3bBest regards,
Signature · 1 line
Jens Axboe