All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: guoqing.jiang@linux.dev, song@kernel.org, jgq516@gmail.com,
	neilb@suse.de, shli@fb.com, lzhong@suse.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com,
	yangerkun@huawei.com
Subject: [PATCH v2 4/6] md/radi10: fix leak of 'r10bio->remaining' for recovery
Date: Fri, 10 Mar 2023 15:38:53 +0800	[thread overview]
Message-ID: <20230310073855.1337560-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20230310073855.1337560-1-yukuai1@huaweicloud.com>

From: Yu Kuai <yukuai3@huawei.com>

raid10_sync_request() will add 'r10bio->remaining' for both rdev and
replacement rdev. However, if the read io fails, recovery_request_write()
returns without issuing the write io, in this case, end_sync_request()
is only called once and 'remaining' is leaked, cause an io hang.

Fix the problem by decreasing 'remaining' according to if 'bio' and
'repl_bio' is valid.

Fixes: 24afd80d99f8 ("md/raid10: handle recovery of replacement devices.")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/raid10.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a8b5fecef136..f7002a1aa9cf 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2611,11 +2611,22 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio)
 {
 	struct r10conf *conf = mddev->private;
 	int d;
-	struct bio *wbio, *wbio2;
+	struct bio *wbio = r10_bio->devs[1].bio;
+	struct bio *wbio2 = r10_bio->devs[1].repl_bio;
+
+	/* Need to test wbio2->bi_end_io before we call
+	 * submit_bio_noacct as if the former is NULL,
+	 * the latter is free to free wbio2.
+	 */
+	if (wbio2 && !wbio2->bi_end_io)
+		wbio2 = NULL;
 
 	if (!test_bit(R10BIO_Uptodate, &r10_bio->state)) {
 		fix_recovery_read_error(r10_bio);
-		end_sync_request(r10_bio);
+		if (wbio->bi_end_io)
+			end_sync_request(r10_bio);
+		if (wbio2)
+			end_sync_request(r10_bio);
 		return;
 	}
 
@@ -2624,14 +2635,6 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio)
 	 * and submit the write request
 	 */
 	d = r10_bio->devs[1].devnum;
-	wbio = r10_bio->devs[1].bio;
-	wbio2 = r10_bio->devs[1].repl_bio;
-	/* Need to test wbio2->bi_end_io before we call
-	 * submit_bio_noacct as if the former is NULL,
-	 * the latter is free to free wbio2.
-	 */
-	if (wbio2 && !wbio2->bi_end_io)
-		wbio2 = NULL;
 	if (wbio->bi_end_io) {
 		atomic_inc(&conf->mirrors[d].rdev->nr_pending);
 		md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio));
-- 
2.31.1


  parent reply	other threads:[~2023-03-10  7:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  7:38 [PATCH v2 0/6] md/raid10: several simple obvious bugfix Yu Kuai
2023-03-10  7:38 ` [PATCH v2 1/6] md/raid10: don't call bio_start_io_acct twice for bio which experienced read error Yu Kuai
2023-03-13 22:08   ` Song Liu
2023-03-14  1:16     ` Yu Kuai
2023-03-14  1:22     ` [PATCH v3] " Yu Kuai
2023-03-14 20:43       ` Song Liu
2023-03-10  7:38 ` [PATCH v2 2/6] md: fix soft lockup in status_resync Yu Kuai
2023-03-13 22:24   ` Song Liu
2023-03-10  7:38 ` [PATCH v2 3/6] md/raid10: don't BUG_ON() in raise_barrier() Yu Kuai
2023-03-10  7:38 ` Yu Kuai [this message]
2023-03-10  7:38 ` [PATCH v2 5/6] md/raid10: fix memleak for 'conf->bio_split' Yu Kuai
2023-03-10  7:38 ` [PATCH v2 6/6] md/raid10: fix memleak of md thread Yu Kuai
2023-03-13 22:37 ` [PATCH v2 0/6] md/raid10: several simple obvious bugfix Song Liu
2023-03-14 12:02   ` Yu Kuai

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=20230310073855.1337560-5-yukuai1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=guoqing.jiang@linux.dev \
    --cc=jgq516@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=lzhong@suse.com \
    --cc=neilb@suse.de \
    --cc=shli@fb.com \
    --cc=song@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.