From: Guillaume Morin <guillaume@morinfr.org>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Guillaume Morin <guillaume@morinfr.org>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
song@kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [BUG] possible race between md_free_disk and md_notify_reboot
Date: Thu, 20 Feb 2025 14:39:07 +0100 [thread overview]
Message-ID: <Z7cwexr7tLRIOlNx@bender.morinfr.org> (raw)
In-Reply-To: <6748f138-ad52-b7c5-ac53-1c7fa6fab9b7@huaweicloud.com>
On 20 Feb 19:55, Yu Kuai wrote:
>
> > I just take a quick look, the problem looks obviously to me, see how
> > md_seq_show() handle the iteration.
> >
> > diff --git a/drivers/md/md.c b/drivers/md/md.c
> > index 465ca2af1e6e..7c7a58f618c1 100644
> > --- a/drivers/md/md.c
> > +++ b/drivers/md/md.c
> > @@ -9911,8 +9911,11 @@ static int md_notify_reboot(struct notifier_block
> > *this,
> > mddev_unlock(mddev);
> > }
> > need_delay = 1;
> > - mddev_put(mddev);
> > - spin_lock(&all_mddevs_lock);
> > +
> > + spin_lock(&all_mddevs_lock)
> > + if (atomic_dec_and_test(&mddev->active))
> > + __mddev_put(mddev);
> > +
> > }
> > spin_unlock(&all_mddevs_lock);
>
> While cooking the patch, this is not enough, list_for_each_entry_safe()
> should be replaced with list_for_each_entry() as well.
>
> Will send the patch soon, with:
>
> Reported-by: Guillaume Morin <guillaume@morinfr.org>
Thank you! I just saw the patch and we are going to test it and let you
know.
The issue with the next pointer seems to be fixed with your change.
Though I am still unclear how the 2nd potential issue I mentioned -
where the current item would be freed concurrently by mddev_free() - is
prevented. I am not finding anything in the code that seems to prevent a
concurrent call to mddev_free() for the current item in the
list_for_each_entry() loop (and therefore accessing mddev after the
kfree()).
I understand that we are getting a reference through the active atomic
in mddev_get() under the lock in md_notify_reboot() but how is that
preventing mddev_free() from freeing the mddev as soon as we release the
all_mddevs_lock in the loop?
I am not not familiar with this code so I am most likely missing
osmething but if you had the time to explain, that would be very
helpful.
TIA
Guillaume.
--
Guillaume Morin <guillaume@morinfr.org>
next prev parent reply other threads:[~2025-02-20 13:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 19:43 Guillaume Morin
2025-02-20 1:26 ` Yu Kuai
2025-02-20 3:05 ` Guillaume Morin
2025-02-20 3:19 ` Yu Kuai
2025-02-20 3:45 ` Guillaume Morin
2025-02-20 4:06 ` Yu Kuai
2025-02-20 11:55 ` Yu Kuai
2025-02-20 13:39 ` Guillaume Morin [this message]
2025-02-21 1:27 ` Yu Kuai
2025-02-21 15:19 ` Guillaume Morin
2025-02-22 1:08 ` 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=Z7cwexr7tLRIOlNx@bender.morinfr.org \
--to=guillaume@morinfr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=yukuai1@huaweicloud.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®