From: "Chen Cheng" <chencheng@fnnas.com>
To: <yukuai@fygo.io>, <linux-raid@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 3/3] md/raid10: free r10bio before ending master_bio in raid_end_bio_io() and raid_end_discard_bio()
Date: Sat, 11 Jul 2026 16:38:04 +0800 [thread overview]
Message-ID: <e3d981c9-19b4-4e7c-b9e6-c6831710e7cb@fnnas.com> (raw)
In-Reply-To: <fb8b048b-3912-44e8-9f56-a25989cd80ee@fygo.io>
在 2026/7/5 15:48, yu kuai 写道:
> Hi,
>
> 在 2026/6/23 20:38, Chen Cheng 写道:
>> From: Chen Cheng <chencheng@fnnas.com>
>>
>> origin flow:
>>
>> bio_endio(master_bio); /* may drop active_io to zero */
>> allow_barrier(conf);
>> free_r10bio(r10_bio); /* reads conf->geo, returns to pool */
>>
>> one scenario is:
>>
>> CPU A (softirq, raid_end_bio_io) CPU B (action_store) --> reshape
>> ================================ ===============================
>> bio_endio(master_bio)
>> md_end_clone_io
>> percpu_ref_put -> 0
>> wait_event wakeup, and,
>> mddev_suspend return
>> raid10_start_reshape:
>> setup_geo(&conf->geo, new)
>> ...
>> mempool_destroy(old_pool)
>> conf->r10bio_pool = new_pool
>> allow_barrier(conf)
>> free_r10bio(r10_bio)
>> put_all_bios:
>> for (i=0; i<conf->geo.raid_disks; i++)
>> ==> old obj, new geo, OOB
>> mempool_free(r10_bio, conf->r10bio_pool)
>> ==> old-geometry obj freed into new pool
>>
>> so .. fix by reorder the flow:
>>
>> free_r10bio(r10_bio)
>> allow_barrier(conf)
>> bio_endio(master_io)
>>
>> raid_end_discard_bio() is exactly the same.
>>
>> Signed-off-by: Chen Cheng <chencheng@fnnas.com>
>> ---
>> drivers/md/raid10.c | 17 ++++++++++-------
>> 1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
>> index d740744a9746..e44a9b6e95c7 100644
>> --- a/drivers/md/raid10.c
>> +++ b/drivers/md/raid10.c
>> @@ -330,24 +330,25 @@ static void reschedule_retry(struct r10bio *r10_bio)
>> */
>> static void raid_end_bio_io(struct r10bio *r10_bio)
>> {
>> struct bio *bio = r10_bio->master_bio;
>> struct r10conf *conf = r10_bio->mddev->private;
>> + unsigned long state = r10_bio->state;
>>
>> - if (!test_and_set_bit(R10BIO_Returned, &r10_bio->state)) {
>> - if (!test_bit(R10BIO_Uptodate, &r10_bio->state))
>> - bio->bi_status = BLK_STS_IOERR;
>> - bio_endio(bio);
>> - }
>> + free_r10bio(r10_bio);
>>
>> /*
>> * Wake up any possible resync thread that waits for the device
>> * to go idle.
>> */
>> allow_barrier(conf);
>>
>> - free_r10bio(r10_bio);
>> + if (!test_and_set_bit(R10BIO_Returned, &state)) {
>> + if (!test_bit(R10BIO_Uptodate, &state))
>> + bio->bi_status = BLK_STS_IOERR;
>> + bio_endio(bio);
>> + }
>
> Why is this moved to the end? I feel it's not necessary.
>
yes, point is let endio after free r10bio.
free_r10bio(r10_bio) -> allow_barrier(conf) -> bio_endio(master_io) or
free_r10bio(r10_bio) -> bio_endio(master_io) -> allow_barrier(conf)
both order is correct to fix the bug.
>> }
>>
>> /*
>> * Update disk head position estimator based on IRQ completion info.
>> */
>> @@ -1580,13 +1581,15 @@ static void raid_end_discard_bio(struct r10bio *r10bio)
>> if (!test_bit(R10BIO_Discard, &r10bio->state)) {
>> first_r10bio = (struct r10bio *)r10bio->master_bio;
>> free_r10bio(r10bio);
>> r10bio = first_r10bio;
>> } else {
>> + struct bio *master_bio = r10bio->master_bio;
>> +
>> md_write_end(r10bio->mddev);
>> - bio_endio(r10bio->master_bio);
>> free_r10bio(r10bio);
>> + bio_endio(master_bio);
>> break;
>> }
>> }
>> }
>>
>
prev parent reply other threads:[~2026-07-11 8:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 12:38 [PATCH v6 0/3] md/raid10: fix r10bio width mismatches across reshape Chen Cheng
2026-06-23 12:38 ` [PATCH v6 1/3] md: suspend array when sync_action=reshape Chen Cheng
2026-07-05 7:43 ` yu kuai
2026-06-23 12:38 ` [PATCH v6 2/3] md/raid10: resize r10bio_pool for reshape Chen Cheng
2026-06-23 12:38 ` [PATCH v6 3/3] md/raid10: free r10bio before ending master_bio in raid_end_bio_io() and raid_end_discard_bio() Chen Cheng
2026-07-05 7:48 ` yu kuai
2026-07-11 8:38 ` Chen Cheng [this message]
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=e3d981c9-19b4-4e7c-b9e6-c6831710e7cb@fnnas.com \
--to=chencheng@fnnas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=yukuai@fygo.io \
/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