linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	Ming Lei <ming.lei@redhat.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, dm-devel@redhat.com,
	Song Liu <song@kernel.org>,
	linux-raid@vger.kernel.org, Mike Snitzer <snitzer@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Dave Kleikamp <shaggy@kernel.org>,
	jfs-discussion@lists.sourceforge.net, cluster-devel@redhat.com,
	Bob Peterson <rpeterso@redhat.com>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Mikulas Patocka <mpatocka@redhat.com>,
	gouhao@uniontech.com,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Damien Le Moal <damien.lemoal@opensource.wdc.com>
Subject: [PATCH v6 15/20] md: raid1: check if adding pages to resync bio fails
Date: Tue, 30 May 2023 08:49:18 -0700	[thread overview]
Message-ID: <c60c6f46b70c96b528b6c4746918ea87c2a01473.1685461490.git.johannes.thumshirn@wdc.com> (raw)
In-Reply-To: <cover.1685461490.git.johannes.thumshirn@wdc.com>

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.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid1-10.c | 11 ++++++-----
 drivers/md/raid10.c   | 20 ++++++++++----------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index e61f6cad4e08..cd349e69ed77 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -101,11 +101,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
 		struct page *page = resync_fetch_page(rp, idx);
 		int len = min_t(int, size, PAGE_SIZE);
 
-		/*
-		 * won't fail because the vec table is big
-		 * enough to hold all these pages
-		 */
-		bio_add_page(bio, page, len, 0);
+		if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+			bio->bi_status = BLK_STS_RESOURCE;
+			bio_endio(bio);
+			return;
+		}
+
 		size -= len;
 	} while (idx++ < RESYNC_PAGES && size > 0);
 }
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 4fcfcb350d2b..381c21f7fb06 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3819,11 +3819,11 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
 		for (bio= biolist ; bio ; bio=bio->bi_next) {
 			struct resync_pages *rp = get_resync_pages(bio);
 			page = resync_fetch_page(rp, page_idx);
-			/*
-			 * won't fail because the vec table is big enough
-			 * to hold all these pages
-			 */
-			bio_add_page(bio, page, len, 0);
+			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+				bio->bi_status = BLK_STS_RESOURCE;
+				bio_endio(bio);
+				goto giveup;
+			}
 		}
 		nr_sectors += len>>9;
 		sector_nr += len>>9;
@@ -4997,11 +4997,11 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,
 		if (len > PAGE_SIZE)
 			len = PAGE_SIZE;
 		for (bio = blist; bio ; bio = bio->bi_next) {
-			/*
-			 * won't fail because the vec table is big enough
-			 * to hold all these pages
-			 */
-			bio_add_page(bio, page, len, 0);
+			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+				bio->bi_status = BLK_STS_RESOURCE;
+				bio_endio(bio);
+				return sectors_done;
+			}
 		}
 		sector_nr += len >> 9;
 		nr_sectors += len >> 9;
-- 
2.40.1


WARNING: multiple messages have this Message-ID (diff)
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	Ming Lei <ming.lei@redhat.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, dm-devel@redhat.com,
	Song Liu <song@kernel.org>,
	linux-raid@vger.kernel.org, Mike Snitzer <snitzer@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Dave Kleikamp <shaggy@kernel.org>,
	jfs-discussion@lists.sourceforge.net, cluster-devel@redhat.com,
	Bob Peterson <rpeterso@redhat.com>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Mikulas Patocka <mpatocka@redhat.com>,
	gouha7@uniontech.com,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Damien Le Moal <damien.lemoal@opensource.wdc.com>
Subject: [PATCH v6 15/20] md: raid1: check if adding pages to resync bio fails
Date: Wed, 31 May 2023 04:37:57 -0700	[thread overview]
Message-ID: <c60c6f46b70c96b528b6c4746918ea87c2a01473.1685461490.git.johannes.thumshirn@wdc.com> (raw)
Message-ID: <20230531113757.SG1tHJbV1OcqRN5LCB2UAW43xbmM9NnF54hXZ1fDgno@z> (raw)
In-Reply-To: <cover.1685461490.git.johannes.thumshirn@wdc.com>

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.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/md/raid1-10.c | 11 ++++++-----
 drivers/md/raid10.c   | 20 ++++++++++----------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index e61f6cad4e08..cd349e69ed77 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -101,11 +101,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
 		struct page *page = resync_fetch_page(rp, idx);
 		int len = min_t(int, size, PAGE_SIZE);
 
-		/*
-		 * won't fail because the vec table is big
-		 * enough to hold all these pages
-		 */
-		bio_add_page(bio, page, len, 0);
+		if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+			bio->bi_status = BLK_STS_RESOURCE;
+			bio_endio(bio);
+			return;
+		}
+
 		size -= len;
 	} while (idx++ < RESYNC_PAGES && size > 0);
 }
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 4fcfcb350d2b..381c21f7fb06 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3819,11 +3819,11 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
 		for (bio= biolist ; bio ; bio=bio->bi_next) {
 			struct resync_pages *rp = get_resync_pages(bio);
 			page = resync_fetch_page(rp, page_idx);
-			/*
-			 * won't fail because the vec table is big enough
-			 * to hold all these pages
-			 */
-			bio_add_page(bio, page, len, 0);
+			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+				bio->bi_status = BLK_STS_RESOURCE;
+				bio_endio(bio);
+				goto giveup;
+			}
 		}
 		nr_sectors += len>>9;
 		sector_nr += len>>9;
@@ -4997,11 +4997,11 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,
 		if (len > PAGE_SIZE)
 			len = PAGE_SIZE;
 		for (bio = blist; bio ; bio = bio->bi_next) {
-			/*
-			 * won't fail because the vec table is big enough
-			 * to hold all these pages
-			 */
-			bio_add_page(bio, page, len, 0);
+			if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+				bio->bi_status = BLK_STS_RESOURCE;
+				bio_endio(bio);
+				return sectors_done;
+			}
 		}
 		sector_nr += len >> 9;
 		nr_sectors += len >> 9;
-- 
2.40.1


  parent reply	other threads:[~2023-05-30 15:51 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 15:49 [PATCH v6 00/20] bio: check return values of bio_add_page Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 01/20] swap: use __bio_add_page to add page to bio Johannes Thumshirn
2023-05-31  4:20   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 02/20] drbd: " Johannes Thumshirn
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 03/20] dm: dm-zoned: use __bio_add_page for adding single metadata page Johannes Thumshirn
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 04/20] fs: buffer: use __bio_add_page to add single page to bio Johannes Thumshirn
2023-05-31  1:20   ` Gou Hao
2023-05-31  4:20   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 05/20] md: use __bio_add_page to add single page Johannes Thumshirn
2023-05-31  4:21   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 06/20] md: raid5-log: " Johannes Thumshirn
2023-05-31  4:21   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 07/20] md: raid5: use __bio_add_page to add single page to new bio Johannes Thumshirn
2023-05-31  4:21   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 08/20] jfs: logmgr: use __bio_add_page to add single page to bio Johannes Thumshirn
2023-05-31  4:21   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 09/20] gfs2: use __bio_add_page for adding " Johannes Thumshirn
2023-05-31  4:22   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 10/20] zonefs: " Johannes Thumshirn
2023-05-31  4:22   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 11/20] zram: " Johannes Thumshirn
2023-05-31  4:22   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 12/20] floppy: " Johannes Thumshirn
2023-05-31  4:23   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 13/20] md: check for failure when adding pages in alloc_behind_master_bio Johannes Thumshirn
2023-05-30 20:40   ` Song Liu
2023-05-31  4:23   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 14/20] md: raid1: use __bio_add_page for adding single page to bio Johannes Thumshirn
2023-05-31  4:23   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` Johannes Thumshirn [this message]
2023-05-31  4:25   ` [PATCH v6 15/20] md: raid1: check if adding pages to resync bio fails Christoph Hellwig
2023-05-31  4:58     ` Song Liu
2023-05-31  7:54       ` Paul Menzel
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 16/20] dm-crypt: check if adding pages to clone " Johannes Thumshirn
2023-05-30 16:10   ` Mike Snitzer
2023-05-30 16:20     ` Johannes Thumshirn
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 17/20] block: mark bio_add_page as __must_check Johannes Thumshirn
2023-05-31  4:25   ` Christoph Hellwig
2023-05-31 11:37   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 18/20] block: add __bio_add_folio Johannes Thumshirn
2023-05-30 15:57   ` Matthew Wilcox
2023-05-31  4:26   ` Christoph Hellwig
2023-05-31 11:38   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 19/20] fs: iomap: use __bio_add_folio where possible Johannes Thumshirn
2023-05-30 15:58   ` Matthew Wilcox
2023-05-31  4:29   ` Christoph Hellwig
2023-05-31 11:38   ` Johannes Thumshirn
2023-05-30 15:49 ` [PATCH v6 20/20] block: mark bio_add_folio as __must_check Johannes Thumshirn
2023-05-30 15:58   ` Matthew Wilcox
2023-05-31  4:29   ` Christoph Hellwig
2023-05-31 11:38   ` Johannes Thumshirn
2023-05-31 11:37 ` [PATCH v6 00/20] bio: check return values of bio_add_page Johannes Thumshirn
2023-05-31 11:50 ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c60c6f46b70c96b528b6c4746918ea87c2a01473.1685461490.git.johannes.thumshirn@wdc.com \
    --to=johannes.thumshirn@wdc.com \
    --cc=agruenba@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=cluster-devel@redhat.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=damien.lemoal@wdc.com \
    --cc=dm-devel@redhat.com \
    --cc=gouhao@uniontech.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=mpatocka@redhat.com \
    --cc=rpeterso@redhat.com \
    --cc=shaggy@kernel.org \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).