dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page
@ 2023-03-29 17:05 Johannes Thumshirn
  2023-03-29 17:05 ` [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio Johannes Thumshirn
                   ` (18 more replies)
  0 siblings, 19 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

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.

Johannes Thumshirn (19):
  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
  btrfs: repair: use __bio_add_page for adding single page
  btrfs: raid56: use __bio_add_page to add single page
  jfs: logmgr: use __bio_add_page to add single page to bio
  gfs: 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: check if adding pages to clone bio fails
  block: mark bio_add_page as __must_check

 drivers/block/drbd/drbd_bitmap.c |  8 +++++---
 drivers/block/floppy.c           |  2 +-
 drivers/block/zram/zram_drv.c    |  2 +-
 drivers/md/dm-crypt.c            |  9 ++++++++-
 drivers/md/dm-zoned-metadata.c   |  6 +++---
 drivers/md/md.c                  |  4 ++--
 drivers/md/raid1-10.c            |  7 ++++++-
 drivers/md/raid1.c               |  5 +++--
 drivers/md/raid10.c              | 12 ++++++++++--
 drivers/md/raid5-cache.c         |  2 +-
 drivers/md/raid5-ppl.c           |  4 ++--
 fs/btrfs/bio.c                   |  2 +-
 fs/btrfs/raid56.c                |  2 +-
 fs/buffer.c                      |  2 +-
 fs/gfs2/ops_fstype.c             |  2 +-
 fs/jfs/jfs_logmgr.c              |  4 ++--
 fs/zonefs/super.c                |  2 +-
 include/linux/bio.h              |  2 +-
 mm/page_io.c                     |  8 ++++----
 19 files changed, 54 insertions(+), 31 deletions(-)

-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:29   ` Damien Le Moal
       [not found]   ` <CGME20230331122046eucas1p247e0cd2d06229a6b7cae9cb26ea43d5b@eucas1p2.samsung.com>
  2023-03-29 17:05 ` [dm-devel] [PATCH 02/19] drbd: " Johannes Thumshirn
                   ` (17 subsequent siblings)
  18 siblings, 2 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 mm/page_io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 87b682d18850..684cd3c7b59b 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -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);
 }
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 02/19] drbd: use __bio_add_page to add page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
  2023-03-29 17:05 ` [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 17:48   ` Matthew Wilcox
  2023-03-29 23:29   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page Johannes Thumshirn
                   ` (16 subsequent siblings)
  18 siblings, 2 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/block/drbd/drbd_bitmap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 289876ffbc31..c542dcf8c457 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -1043,9 +1043,11 @@ 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 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->bi_private = ctx;
 	bio->bi_end_io = drbd_bm_endio;
 
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
  2023-03-29 17:05 ` [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio Johannes Thumshirn
  2023-03-29 17:05 ` [dm-devel] [PATCH 02/19] drbd: " Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:30   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio Johannes Thumshirn
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

dm-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

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/dm-zoned-metadata.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index cf9402064aba..8dbe102ab271 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -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);
 
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (2 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:31   ` Damien Le Moal
       [not found]   ` <CGME20230331122235eucas1p2208286ce210d9b01ea36a26bd3897b72@eucas1p2.samsung.com>
  2023-03-29 17:05 ` [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page Johannes Thumshirn
                   ` (14 subsequent siblings)
  18 siblings, 2 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 9e1e2add541e..855dc41fe162 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2733,7 +2733,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));
+	__bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh));
 	BUG_ON(bio->bi_iter.bi_size != bh->b_size);
 
 	bio->bi_end_io = end_bio_bh_io_sync;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (3 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:31   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 06/19] md: raid5-log: " Johannes Thumshirn
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-of_-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/md.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 39e49e5d7182..e730c3627d00 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -958,7 +958,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;
 
@@ -999,7 +999,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);
 
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 06/19] md: raid5-log: use __bio_add_page to add single page
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (4 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:32   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio Johannes Thumshirn
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid5-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 46182b955aef..852b265c5db4 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -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);
 
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (5 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 06/19] md: raid5-log: " Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:32   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page Johannes Thumshirn
                   ` (11 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid5-ppl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c
index e495939bb3e0..eaea57aee602 100644
--- a/drivers/md/raid5-ppl.c
+++ b/drivers/md/raid5-ppl.c
@@ -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);
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (6 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:33   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add " Johannes Thumshirn
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The btrfs repair bio 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 726592868e9c..73220a219c91 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -224,7 +224,7 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
 	repair_bio = bio_alloc_bioset(NULL, 1, REQ_OP_READ, GFP_NOFS,
 				      &btrfs_repair_bioset);
 	repair_bio->bi_iter.bi_sector = failed_bbio->saved_iter.bi_sector;
-	bio_add_page(repair_bio, bv->bv_page, bv->bv_len, bv->bv_offset);
+	__bio_add_page(repair_bio, bv->bv_page, bv->bv_len, bv->bv_offset);
 
 	repair_bbio = btrfs_bio(repair_bio);
 	btrfs_bio_init(repair_bbio, failed_bbio->inode, NULL, fbio);
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add single page
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (7 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:33   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio Johannes Thumshirn
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The btrfs raid58 sector 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/raid56.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 642828c1b299..c8173e003df6 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1108,7 +1108,7 @@ static int rbio_add_io_sector(struct btrfs_raid_bio *rbio,
 	bio->bi_iter.bi_sector = disk_start >> 9;
 	bio->bi_private = rbio;
 
-	bio_add_page(bio, sector->page, sectorsize, sector->pgoff);
+	__bio_add_page(bio, sector->page, sectorsize, sector->pgoff);
 	bio_list_add(bio_list, bio);
 	return 0;
 }
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (8 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add " Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:34   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding " Johannes Thumshirn
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/jfs/jfs_logmgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 695415cbfe98..15c645827dec 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -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;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (9 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:34   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 12/19] zonefs: " Johannes Thumshirn
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The GFS 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/gfs2/ops_fstype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6de901c3b89b..e0cd0d43b12f 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -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;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 12/19] zonefs: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (10 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding " Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:35   ` Damien Le Moal
  2023-03-29 17:05 ` [dm-devel] [PATCH 13/19] zram: " Johannes Thumshirn
                   ` (6 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/zonefs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 23b8b299c64e..9350221abfc5 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -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)
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 13/19] zram: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (11 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 12/19] zonefs: " Johannes Thumshirn
@ 2023-03-29 17:05 ` Johannes Thumshirn
  2023-03-29 23:36   ` Damien Le Moal
       [not found]   ` <CGME20230331122828eucas1p18e0bbbda45a6955f59fc82b29f42a8bb@eucas1p1.samsung.com>
  2023-03-29 17:06 ` [dm-devel] [PATCH 14/19] floppy: " Johannes Thumshirn
                   ` (5 subsequent siblings)
  18 siblings, 2 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:05 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/block/zram/zram_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index aa490da3cef2..9179bd0f248c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -760,7 +760,7 @@ static ssize_t writeback_store(struct device *dev,
 			 REQ_OP_WRITE | REQ_SYNC);
 		bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);
 
-		bio_add_page(&bio, bvec.bv_page, bvec.bv_len,
+		__bio_add_page(&bio, bvec.bv_page, bvec.bv_len,
 				bvec.bv_offset);
 		/*
 		 * XXX: A single page IO would be inefficient for write
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 14/19] floppy: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (12 preceding siblings ...)
  2023-03-29 17:05 ` [dm-devel] [PATCH 13/19] zram: " Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:36   ` Damien Le Moal
  2023-03-29 17:06 ` [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio Johannes Thumshirn
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/block/floppy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 487840e3564d..6f46a30f7c36 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -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);
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (13 preceding siblings ...)
  2023-03-29 17:06 ` [dm-devel] [PATCH 14/19] floppy: " Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:38   ` Damien Le Moal
  2023-03-29 17:06 ` [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio Johannes Thumshirn
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

alloc_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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 68a9e2d9985b..bd7c339a84a1 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1147,7 +1147,8 @@ 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))
+			goto free_pages;
 
 		size -= len;
 		i++;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (14 preceding siblings ...)
  2023-03-29 17:06 ` [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:38   ` Damien Le Moal
  2023-03-29 17:06 ` [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails Johannes Thumshirn
                   ` (2 subsequent siblings)
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

The 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.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index bd7c339a84a1..c226d293992f 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2915,7 +2915,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;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (15 preceding siblings ...)
  2023-03-29 17:06 ` [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:44   ` Damien Le Moal
  2023-03-29 17:06 ` [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone " Johannes Thumshirn
  2023-03-29 17:06 ` [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check Johannes Thumshirn
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

Check if adding pages to resync bio fails and if bail out.

As the comment above suggests this cannot happen, WARN if it actually
happens.

This way we can mark bio_add_pages as __must_check.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid1-10.c |  7 ++++++-
 drivers/md/raid10.c   | 12 ++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index e61f6cad4e08..c21b6c168751 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -105,7 +105,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
 		 * 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);
 }
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 6c66357f92f5..5682dba52fd3 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3808,7 +3808,11 @@ static sector_t raid10_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);
+			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;
@@ -4989,7 +4993,11 @@ static sector_t reshape_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);
+			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+				bio->bi_status = BLK_STS_RESOURCE;
+				bio_endio(bio);
+				return sectors_done; /* XXX: is this correct? */
+			}
 		}
 		sector_nr += len >> 9;
 		nr_sectors += len >> 9;
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone bio fails
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (16 preceding siblings ...)
  2023-03-29 17:06 ` [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:49   ` Damien Le Moal
  2023-03-29 17:06 ` [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check Johannes Thumshirn
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

Check if adding pages to clone bio fails and if bail out.

This way we can mark bio_add_pages as __must_check.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/dm-crypt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 3ba53dc3cc3f..19f7e087c6df 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1693,7 +1693,14 @@ 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);
+		if (!bio_add_page(clone, page, len, 0)) {
+			mempool_free(page, &cc->page_pool);
+			crypt_free_buffer_pages(cc, clone);
+			bio_put(clone);
+			gfp_mask |= __GFP_DIRECT_RECLAIM;
+			goto retry;
+
+		}
 
 		remaining_size -= len;
 	}
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check
  2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
                   ` (17 preceding siblings ...)
  2023-03-29 17:06 ` [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone " Johannes Thumshirn
@ 2023-03-29 17:06 ` Johannes Thumshirn
  2023-03-29 23:58   ` Damien Le Moal
  18 siblings, 1 reply; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-29 17:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Johannes Thumshirn,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

Now that all users of bio_add_page check for the return value, mark
bio_add_page as __must_check.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 include/linux/bio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bio.h b/include/linux/bio.h
index d766be7152e1..0f8a8d7a6384 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -465,7 +465,7 @@ 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 *, struct 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);
-- 
2.39.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 02/19] drbd: use __bio_add_page to add page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 02/19] drbd: " Johannes Thumshirn
@ 2023-03-29 17:48   ` Matthew Wilcox
  2023-03-29 23:29   ` Damien Le Moal
  1 sibling, 0 replies; 47+ messages in thread
From: Matthew Wilcox @ 2023-03-29 17:48 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Jens Axboe, linux-raid, Damien Le Moal, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Mike Snitzer, jfs-discussion, Ming Lei, linux-block, linux-mm,
	dm-devel, David Sterba, linux-fsdevel, Christoph Hellwig,
	linux-btrfs, Bob Peterson

On Wed, Mar 29, 2023 at 10:05:48AM -0700, Johannes Thumshirn wrote:
> +++ b/drivers/block/drbd/drbd_bitmap.c
> @@ -1043,9 +1043,11 @@ 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 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);

Surely the comment should just be deleted?  With no return value to
check, what would you assert?

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio Johannes Thumshirn
@ 2023-03-29 23:29   ` Damien Le Moal
       [not found]   ` <CGME20230331122046eucas1p247e0cd2d06229a6b7cae9cb26ea43d5b@eucas1p2.samsung.com>
  1 sibling, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:29 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	jfs-discussion, Matthew Wilcox, Ming Lei, linux-block, linux-mm,
	dm-devel, David Sterba, linux-fsdevel, Christoph Hellwig,
	linux-btrfs, Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 02/19] drbd: use __bio_add_page to add page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 02/19] drbd: " Johannes Thumshirn
  2023-03-29 17:48   ` Matthew Wilcox
@ 2023-03-29 23:29   ` Damien Le Moal
  1 sibling, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:29 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	jfs-discussion, Matthew Wilcox, Ming Lei, linux-block, linux-mm,
	dm-devel, David Sterba, linux-fsdevel, Christoph Hellwig,
	linux-btrfs, Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

With Matthew comment addressed,

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page
  2023-03-29 17:05 ` [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page Johannes Thumshirn
@ 2023-03-29 23:30   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:30 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> dm-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
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio Johannes Thumshirn
@ 2023-03-29 23:31   ` Damien Le Moal
       [not found]   ` <CGME20230331122235eucas1p2208286ce210d9b01ea36a26bd3897b72@eucas1p2.samsung.com>
  1 sibling, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:31 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page
  2023-03-29 17:05 ` [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page Johannes Thumshirn
@ 2023-03-29 23:31   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:31 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-of_-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 06/19] md: raid5-log: use __bio_add_page to add single page
  2023-03-29 17:05 ` [dm-devel] [PATCH 06/19] md: raid5-log: " Johannes Thumshirn
@ 2023-03-29 23:32   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:32 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio Johannes Thumshirn
@ 2023-03-29 23:32   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:32 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page
  2023-03-29 17:05 ` [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page Johannes Thumshirn
@ 2023-03-29 23:33   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:33 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The btrfs repair bio 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add single page
  2023-03-29 17:05 ` [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add " Johannes Thumshirn
@ 2023-03-29 23:33   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:33 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The btrfs raid58 sector 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio Johannes Thumshirn
@ 2023-03-29 23:34   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:34 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding " Johannes Thumshirn
@ 2023-03-29 23:34   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:34 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The GFS 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 12/19] zonefs: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 12/19] zonefs: " Johannes Thumshirn
@ 2023-03-29 23:35   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:35 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 13/19] zram: use __bio_add_page for adding single page to bio
  2023-03-29 17:05 ` [dm-devel] [PATCH 13/19] zram: " Johannes Thumshirn
@ 2023-03-29 23:36   ` Damien Le Moal
       [not found]   ` <CGME20230331122828eucas1p18e0bbbda45a6955f59fc82b29f42a8bb@eucas1p1.samsung.com>
  1 sibling, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:36 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	jfs-discussion, Matthew Wilcox, Ming Lei, linux-block, linux-mm,
	dm-devel, David Sterba, linux-fsdevel, Christoph Hellwig,
	linux-btrfs, Bob Peterson

On 3/30/23 02:05, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 14/19] floppy: use __bio_add_page for adding single page to bio
  2023-03-29 17:06 ` [dm-devel] [PATCH 14/19] floppy: " Johannes Thumshirn
@ 2023-03-29 23:36   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:36 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio
  2023-03-29 17:06 ` [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio Johannes Thumshirn
@ 2023-03-29 23:38   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:38 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, Damien Le Moal, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	jfs-discussion, Matthew Wilcox, Ming Lei, linux-block, linux-mm,
	dm-devel, David Sterba, linux-fsdevel, Christoph Hellwig,
	linux-btrfs, Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> alloc_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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio
  2023-03-29 17:06 ` [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio Johannes Thumshirn
@ 2023-03-29 23:38   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:38 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails
  2023-03-29 17:06 ` [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails Johannes Thumshirn
@ 2023-03-29 23:44   ` Damien Le Moal
  2023-03-30 10:38     ` Johannes Thumshirn
  0 siblings, 1 reply; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:44 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> Check if adding pages to resync bio fails and if bail out.
> 
> As the comment above suggests this cannot happen, WARN if it actually
> happens.
> 
> This way we can mark bio_add_pages as __must_check.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  drivers/md/raid1-10.c |  7 ++++++-
>  drivers/md/raid10.c   | 12 ++++++++++--
>  2 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
> index e61f6cad4e08..c21b6c168751 100644
> --- a/drivers/md/raid1-10.c
> +++ b/drivers/md/raid1-10.c
> @@ -105,7 +105,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
>  		 * 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))) {

Not sure we really need the WARN_ON here...
Nevertheless,

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>


> +			bio->bi_status = BLK_STS_RESOURCE;
> +			bio_endio(bio);
> +			return;
> +		}
> +
>  		size -= len;
>  	} while (idx++ < RESYNC_PAGES && size > 0);
>  }
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 6c66357f92f5..5682dba52fd3 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -3808,7 +3808,11 @@ static sector_t raid10_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);
> +			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;
> @@ -4989,7 +4993,11 @@ static sector_t reshape_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);
> +			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
> +				bio->bi_status = BLK_STS_RESOURCE;
> +				bio_endio(bio);
> +				return sectors_done; /* XXX: is this correct? */
> +			}
>  		}
>  		sector_nr += len >> 9;
>  		nr_sectors += len >> 9;

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone bio fails
  2023-03-29 17:06 ` [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone " Johannes Thumshirn
@ 2023-03-29 23:49   ` Damien Le Moal
  2023-03-30  0:17     ` Yang Shi
  0 siblings, 1 reply; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:49 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> Check if adding pages to clone bio fails and if bail out.

Nope. The code retries with direct reclaim until it succeeds. Which is very
suspicious...

> 
> This way we can mark bio_add_pages as __must_check.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

With the commit message fixed,

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>


-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check
  2023-03-29 17:06 ` [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check Johannes Thumshirn
@ 2023-03-29 23:58   ` Damien Le Moal
  0 siblings, 0 replies; 47+ messages in thread
From: Damien Le Moal @ 2023-03-29 23:58 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 3/30/23 02:06, Johannes Thumshirn wrote:
> Now that all users of bio_add_page check for the return value, mark
> bio_add_page as __must_check.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone bio fails
  2023-03-29 23:49   ` Damien Le Moal
@ 2023-03-30  0:17     ` Yang Shi
  2023-03-30  0:24       ` Damien Le Moal
  0 siblings, 1 reply; 47+ messages in thread
From: Yang Shi @ 2023-03-30  0:17 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: Jens Axboe, linux-raid, jfs-discussion, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Johannes Thumshirn, Mike Snitzer, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

On Wed, Mar 29, 2023 at 4:49 PM Damien Le Moal
<damien.lemoal@opensource.wdc.com> wrote:
>
> On 3/30/23 02:06, Johannes Thumshirn wrote:
> > Check if adding pages to clone bio fails and if bail out.
>
> Nope. The code retries with direct reclaim until it succeeds. Which is very
> suspicious...

It is not related to bio_add_page() failure. It is used to avoid a
race condition when two processes are depleting the mempool
simultaneously.

IIUC I don't think page merge may happen for dm-crypt, so is
__bio_add_page() good enough? I'm working on this code too, using
__bio_add_page() would make my patch easier.

>
> >
> > This way we can mark bio_add_pages as __must_check.
> >
> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>
> With the commit message fixed,
>
> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
>
>
> --
> Damien Le Moal
> Western Digital Research
>
>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone bio fails
  2023-03-30  0:17     ` Yang Shi
@ 2023-03-30  0:24       ` Damien Le Moal
  2023-03-30 22:29         ` Yang Shi
  0 siblings, 1 reply; 47+ messages in thread
From: Damien Le Moal @ 2023-03-30  0:24 UTC (permalink / raw)
  To: Yang Shi
  Cc: Jens Axboe, linux-raid, jfs-discussion, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Johannes Thumshirn, Mike Snitzer, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

On 3/30/23 09:17, Yang Shi wrote:
> On Wed, Mar 29, 2023 at 4:49 PM Damien Le Moal
> <damien.lemoal@opensource.wdc.com> wrote:
>>
>> On 3/30/23 02:06, Johannes Thumshirn wrote:
>>> Check if adding pages to clone bio fails and if bail out.
>>
>> Nope. The code retries with direct reclaim until it succeeds. Which is very
>> suspicious...
> 
> It is not related to bio_add_page() failure. It is used to avoid a
> race condition when two processes are depleting the mempool
> simultaneously.
> 
> IIUC I don't think page merge may happen for dm-crypt, so is
> __bio_add_page() good enough? I'm working on this code too, using
> __bio_add_page() would make my patch easier.

If the BIO was allocated with enough bvecs, we could use that function. But page
merging reduces overhead, so if it can happen, let's use it.

> 
>>
>>>
>>> This way we can mark bio_add_pages as __must_check.
>>>
>>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>>
>> With the commit message fixed,
>>
>> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
>>
>>
>> --
>> Damien Le Moal
>> Western Digital Research
>>
>>

-- 
Damien Le Moal
Western Digital Research

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails
  2023-03-29 23:44   ` Damien Le Moal
@ 2023-03-30 10:38     ` Johannes Thumshirn
  0 siblings, 0 replies; 47+ messages in thread
From: Johannes Thumshirn @ 2023-03-30 10:38 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe
  Cc: linux-raid, jfs-discussion, cluster-devel, Chaitanya Kulkarni,
	Andreas Gruenbacher, Song Liu, Dave Kleikamp, Mike Snitzer,
	Matthew Wilcox, Ming Lei, linux-block, linux-mm, dm-devel,
	David Sterba, linux-fsdevel, Christoph Hellwig, linux-btrfs,
	Bob Peterson

On 30.03.23 01:44, Damien Le Moal wrote:
> On 3/30/23 02:06, Johannes Thumshirn wrote:
>> Check if adding pages to resync bio fails and if bail out.
>>
>> As the comment above suggests this cannot happen, WARN if it actually
>> happens.
>>
>> This way we can mark bio_add_pages as __must_check.
>>
>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>> ---
>>  drivers/md/raid1-10.c |  7 ++++++-
>>  drivers/md/raid10.c   | 12 ++++++++++--
>>  2 files changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
>> index e61f6cad4e08..c21b6c168751 100644
>> --- a/drivers/md/raid1-10.c
>> +++ b/drivers/md/raid1-10.c
>> @@ -105,7 +105,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
>>  		 * 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))) {
> Not sure we really need the WARN_ON here...
> Nevertheless,
> 

I see it as a kind of assert(). It shouldn't fail but in theory it can.

> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

Thanks

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone bio fails
  2023-03-30  0:24       ` Damien Le Moal
@ 2023-03-30 22:29         ` Yang Shi
  0 siblings, 0 replies; 47+ messages in thread
From: Yang Shi @ 2023-03-30 22:29 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: Jens Axboe, linux-raid, jfs-discussion, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Johannes Thumshirn, Mike Snitzer, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

On Wed, Mar 29, 2023 at 5:24 PM Damien Le Moal
<damien.lemoal@opensource.wdc.com> wrote:
>
> On 3/30/23 09:17, Yang Shi wrote:
> > On Wed, Mar 29, 2023 at 4:49 PM Damien Le Moal
> > <damien.lemoal@opensource.wdc.com> wrote:
> >>
> >> On 3/30/23 02:06, Johannes Thumshirn wrote:
> >>> Check if adding pages to clone bio fails and if bail out.
> >>
> >> Nope. The code retries with direct reclaim until it succeeds. Which is very
> >> suspicious...
> >
> > It is not related to bio_add_page() failure. It is used to avoid a
> > race condition when two processes are depleting the mempool
> > simultaneously.
> >
> > IIUC I don't think page merge may happen for dm-crypt, so is
> > __bio_add_page() good enough? I'm working on this code too, using
> > __bio_add_page() would make my patch easier.
>
> If the BIO was allocated with enough bvecs, we could use that function. But page
> merging reduces overhead, so if it can happen, let's use it.

It does allocate BIO with enough bvecs. IIUC it will merge the
adjacent pages? If so page merging may happen. Since dm-crypt does
allocate BIO with enough bvces, so it can't fail if I read the code
correctly. I'm wondering whether we could have a never fail variant.

>
> >
> >>
> >>>
> >>> This way we can mark bio_add_pages as __must_check.
> >>>
> >>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> >>
> >> With the commit message fixed,
> >>
> >> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> >>
> >>
> >> --
> >> Damien Le Moal
> >> Western Digital Research
> >>
> >>
>
> --
> Damien Le Moal
> Western Digital Research
>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio
       [not found]   ` <CGME20230331122046eucas1p247e0cd2d06229a6b7cae9cb26ea43d5b@eucas1p2.samsung.com>
@ 2023-03-31 12:12     ` Pankaj Raghav
  0 siblings, 0 replies; 47+ messages in thread
From: Pankaj Raghav @ 2023-03-31 12:12 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Jens Axboe, linux-raid, Damien Le Moal, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

On Wed, Mar 29, 2023 at 10:05:47AM -0700, Johannes Thumshirn wrote:
> 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio
       [not found]   ` <CGME20230331122235eucas1p2208286ce210d9b01ea36a26bd3897b72@eucas1p2.samsung.com>
@ 2023-03-31 12:14     ` Pankaj Raghav
  0 siblings, 0 replies; 47+ messages in thread
From: Pankaj Raghav @ 2023-03-31 12:14 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Dave Kleikamp, jfs-discussion, Song Liu, dm-devel,
	Christoph Hellwig, Andreas Gruenbacher, Matthew Wilcox,
	cluster-devel, p.raghav, Chaitanya Kulkarni, Mike Snitzer,
	Ming Lei, linux-raid, Bob Peterson, David Sterba, Jens Axboe,
	linux-block, Damien Le Moal, linux-mm, linux-fsdevel,
	linux-btrfs

On Wed, Mar 29, 2023 at 10:05:50AM -0700, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dm-devel] [PATCH 13/19] zram: use __bio_add_page for adding single page to bio
       [not found]   ` <CGME20230331122828eucas1p18e0bbbda45a6955f59fc82b29f42a8bb@eucas1p1.samsung.com>
@ 2023-03-31 12:20     ` Pankaj Raghav
  0 siblings, 0 replies; 47+ messages in thread
From: Pankaj Raghav @ 2023-03-31 12:20 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Jens Axboe, linux-raid, Damien Le Moal, cluster-devel,
	Chaitanya Kulkarni, Andreas Gruenbacher, Song Liu, Dave Kleikamp,
	Mike Snitzer, jfs-discussion, Matthew Wilcox, Ming Lei,
	linux-block, linux-mm, dm-devel, David Sterba, linux-fsdevel,
	Christoph Hellwig, linux-btrfs, Bob Peterson

On Wed, Mar 29, 2023 at 10:05:59AM -0700, Johannes Thumshirn wrote:
> The 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.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2023-03-31 12:29 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 17:05 [dm-devel] [PATCH 00/19] bio: check return values of bio_add_page Johannes Thumshirn
2023-03-29 17:05 ` [dm-devel] [PATCH 01/19] swap: use __bio_add_page to add page to bio Johannes Thumshirn
2023-03-29 23:29   ` Damien Le Moal
     [not found]   ` <CGME20230331122046eucas1p247e0cd2d06229a6b7cae9cb26ea43d5b@eucas1p2.samsung.com>
2023-03-31 12:12     ` Pankaj Raghav
2023-03-29 17:05 ` [dm-devel] [PATCH 02/19] drbd: " Johannes Thumshirn
2023-03-29 17:48   ` Matthew Wilcox
2023-03-29 23:29   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 03/19] dm: dm-zoned: use __bio_add_page for adding single metadata page Johannes Thumshirn
2023-03-29 23:30   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 04/19] fs: buffer: use __bio_add_page to add single page to bio Johannes Thumshirn
2023-03-29 23:31   ` Damien Le Moal
     [not found]   ` <CGME20230331122235eucas1p2208286ce210d9b01ea36a26bd3897b72@eucas1p2.samsung.com>
2023-03-31 12:14     ` Pankaj Raghav
2023-03-29 17:05 ` [dm-devel] [PATCH 05/19] md: use __bio_add_page to add single page Johannes Thumshirn
2023-03-29 23:31   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 06/19] md: raid5-log: " Johannes Thumshirn
2023-03-29 23:32   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 07/19] md: raid5: use __bio_add_page to add single page to new bio Johannes Thumshirn
2023-03-29 23:32   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 08/19] btrfs: repair: use __bio_add_page for adding single page Johannes Thumshirn
2023-03-29 23:33   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 09/19] btrfs: raid56: use __bio_add_page to add " Johannes Thumshirn
2023-03-29 23:33   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 10/19] jfs: logmgr: use __bio_add_page to add single page to bio Johannes Thumshirn
2023-03-29 23:34   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 11/19] gfs: use __bio_add_page for adding " Johannes Thumshirn
2023-03-29 23:34   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 12/19] zonefs: " Johannes Thumshirn
2023-03-29 23:35   ` Damien Le Moal
2023-03-29 17:05 ` [dm-devel] [PATCH 13/19] zram: " Johannes Thumshirn
2023-03-29 23:36   ` Damien Le Moal
     [not found]   ` <CGME20230331122828eucas1p18e0bbbda45a6955f59fc82b29f42a8bb@eucas1p1.samsung.com>
2023-03-31 12:20     ` Pankaj Raghav
2023-03-29 17:06 ` [dm-devel] [PATCH 14/19] floppy: " Johannes Thumshirn
2023-03-29 23:36   ` Damien Le Moal
2023-03-29 17:06 ` [dm-devel] [PATCH 15/19] md: check for failure when adding pages in alloc_behind_master_bio Johannes Thumshirn
2023-03-29 23:38   ` Damien Le Moal
2023-03-29 17:06 ` [dm-devel] [PATCH 16/19] md: raid1: use __bio_add_page for adding single page to bio Johannes Thumshirn
2023-03-29 23:38   ` Damien Le Moal
2023-03-29 17:06 ` [dm-devel] [PATCH 17/19] md: raid1: check if adding pages to resync bio fails Johannes Thumshirn
2023-03-29 23:44   ` Damien Le Moal
2023-03-30 10:38     ` Johannes Thumshirn
2023-03-29 17:06 ` [dm-devel] [PATCH 18/19] dm-crypt: check if adding pages to clone " Johannes Thumshirn
2023-03-29 23:49   ` Damien Le Moal
2023-03-30  0:17     ` Yang Shi
2023-03-30  0:24       ` Damien Le Moal
2023-03-30 22:29         ` Yang Shi
2023-03-29 17:06 ` [dm-devel] [PATCH 19/19] block: mark bio_add_page as __must_check Johannes Thumshirn
2023-03-29 23:58   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).