public inbox for linux-raid@vger.kernel.org
 help / color / mirror / Atom feed
From: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
To: Li Nan <linan666@huaweicloud.com>,
	song@kernel.org, yukuai@fnnas.com, linan666@huaweicloud.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] md: use md_free_cloned_bio() in md_end_clone_io()
Date: Thu, 16 Apr 2026 09:39:09 +0200	[thread overview]
Message-ID: <m27bq72w2q.fsf@gmail.com> (raw)
In-Reply-To: <7f82e3ae-bb2b-96fc-af9c-632fa6ae07af@huaweicloud.com>

Hi Nan,

thank you for the feedback.

On Thu, Apr 16, 2026 at 14:47 +0800, Li Nan wrote:
> 在 2026/4/15 16:19, Abd-Alrhman Masalkhi 写道:
>> md_end_clone_io() and md_free_cloned_bio() share identical teardown
>> logic. Use md_free_cloned_bio() in md_end_clone_io() for cleanup and
>> call bio_endio() afterwards.
>> 
>> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
>> ---
>> Changes in v2:
>>   - Reuse md_free_cloned_bio() instead of introducing a new helper
>>   - Link to v1: https://lore.kernel.org/linux-raid/20260414103813.307601-1-abd.masalkhi@gmail.com
>> ---
>>   drivers/md/md.c | 13 +------------
>>   1 file changed, 1 insertion(+), 12 deletions(-)
>> 
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index ac71640ff3a8..8565566a447b 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -9212,20 +9212,9 @@ static void md_end_clone_io(struct bio *bio)
>>   {
>>   	struct md_io_clone *md_io_clone = bio->bi_private;
>>   	struct bio *orig_bio = md_io_clone->orig_bio;
>> -	struct mddev *mddev = md_io_clone->mddev;
>> -
>> -	if (bio_data_dir(orig_bio) == WRITE && md_bitmap_enabled(mddev, false))
>> -		md_bitmap_end(mddev, md_io_clone);
>> -
>> -	if (bio->bi_status && !orig_bio->bi_status)
>> -		orig_bio->bi_status = bio->bi_status;
>> -
>> -	if (md_io_clone->start_time)
>> -		bio_end_io_acct(orig_bio, md_io_clone->start_time);
>>   
>> -	bio_put(bio);
>> +	md_free_cloned_bio(bio);
>>   	bio_endio(orig_bio);
>
> Is it safe to end orig_bio after putting active_io?

As I understand it, active_io is primarily used to account for
in-flight bios, allowing the array to be safely suspended once no
bios are outstanding.

I have made a diagram, while i am reviewing the md driver:

mddev->active_io

md driver:
md_handle_request()
    mddev->active_io +1
	    pers->make_request()
            md_account_bio() +1
			    if (err)
				    md_free_cloned_bio -1
    mddev->active_io -1

lower driver:
bio_endio()
    md_end_clone_io -1

As shown, it incremented in two places, the first is before passing
orig_bio to pers->make_request(), and decremented after it returns
(regardless of what make_request() does with it). and the second
is when cloning the original bio, and it should be decremented after
the cloned bio is released.

In this context, it should not matter whether bio_endio(orig_bio) is
called before or after decrementing active_io, as long as the cloned
bio teardown is completed correctly.

Am I missing anything that would make this unsafe?

>
>> -	percpu_ref_put(&mddev->active_io);
>>   }
>>   
>>   static void md_clone_bio(struct mddev *mddev, struct bio **bio)
>
> -- 
> Thanks,
> Nan
>

-- 
Best Regards,
Abd-Alrhman

  reply	other threads:[~2026-04-16  7:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  8:19 [PATCH v2] md: use md_free_cloned_bio() in md_end_clone_io() Abd-Alrhman Masalkhi
2026-04-16  6:47 ` Li Nan
2026-04-16  7:39   ` Abd-Alrhman Masalkhi [this message]
2026-04-17  1:29     ` Li Nan

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=m27bq72w2q.fsf@gmail.com \
    --to=abd.masalkhi@gmail.com \
    --cc=linan666@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=yukuai@fnnas.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox