2023-08-30 22:05:52

by Yu Kuai

[permalink] [raw]
Subject: [PATCH -next 0/2] md: fix potential hang for mddev_suspend()

From: Yu Kuai <[email protected]>

Yu Kuai (2):
md: factor out helpers to grab and put 'active_io'
md: fix potential hang for mddev_suspend()

drivers/md/md.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)

--
2.39.2



2023-08-31 00:11:06

by Yu Kuai

[permalink] [raw]
Subject: [PATCH -next 2/2] md: fix potential hang for mddev_suspend()

From: Yu Kuai <[email protected]>

Commit 72adae23a72c ("md: Change active_io to percpu") drop that if
'active_io' is decreased to 0 and array is suspended, 'sb_wait' will be
woke up. This is wrong, however, there is no regression reported and I
think this is probably because 'sb_wait' is used in many scenarios and
it's woke up from other context.

Anyway, fix this potential problem by waking up 'sb_wait' in this case.

Fixes: 72adae23a72c ("md: Change active_io to percpu")
Signed-off-by: Yu Kuai <[email protected]>
---
drivers/md/md.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0d69b1a2e2d5..1c7eb3cfadb4 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -399,6 +399,9 @@ static bool md_array_enter(struct mddev *mddev, struct bio *bio)
static void md_array_exit(struct mddev *mddev)
{
percpu_ref_put(&mddev->active_io);
+ if (percpu_ref_is_zero(&mddev->active_io) &&
+ wq_has_sleeper(&mddev->sb_wait))
+ wake_up(&mddev->sb_wait);
}

void md_handle_request(struct mddev *mddev, struct bio *bio)
--
2.39.2


2023-09-22 21:47:00

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] md: fix potential hang for mddev_suspend()

On Wed, Aug 30, 2023 at 2:33 AM Yu Kuai <[email protected]> wrote:
>
> From: Yu Kuai <[email protected]>
>
> Yu Kuai (2):
> md: factor out helpers to grab and put 'active_io'
> md: fix potential hang for mddev_suspend()

Applied to md-next. Thanks!

Song

>
> drivers/md/md.c | 36 ++++++++++++++++++++++++++++++------
> 1 file changed, 30 insertions(+), 6 deletions(-)
>
> --
> 2.39.2
>

2023-09-25 09:07:56

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] md: fix potential hang for mddev_suspend()

Hi,

在 2023/09/25 15:58, Xiao Ni 写道:
> On Sat, Sep 23, 2023 at 5:33 AM Song Liu <[email protected]> wrote:
>>
>> On Wed, Aug 30, 2023 at 2:33 AM Yu Kuai <[email protected]> wrote:
>>>
>>> From: Yu Kuai <[email protected]>
>>>
>>> Yu Kuai (2):
>>> md: factor out helpers to grab and put 'active_io'
>>> md: fix potential hang for mddev_suspend()
>>
>> Applied to md-next. Thanks!
>>
>> Song
>>
>>>
>>> drivers/md/md.c | 36 ++++++++++++++++++++++++++++++------
>>> 1 file changed, 30 insertions(+), 6 deletions(-)
>>>
>>> --
>>> 2.39.2
>>>
>>
>
> Hi all
>
> For the second patch, active_io_release does this job. So it doesn't
> need to do this in md_array_exit again.

Yes, this is correct, I missed this while reviewing related code.

Song, can you revert this patchset for now? Sorry for the trouble.

Thanks,
Kuai

>
> Best Regards
> Xiao
>
> .
>

2023-09-25 11:12:25

by Xiao Ni

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] md: fix potential hang for mddev_suspend()

On Sat, Sep 23, 2023 at 5:33 AM Song Liu <[email protected]> wrote:
>
> On Wed, Aug 30, 2023 at 2:33 AM Yu Kuai <[email protected]> wrote:
> >
> > From: Yu Kuai <[email protected]>
> >
> > Yu Kuai (2):
> > md: factor out helpers to grab and put 'active_io'
> > md: fix potential hang for mddev_suspend()
>
> Applied to md-next. Thanks!
>
> Song
>
> >
> > drivers/md/md.c | 36 ++++++++++++++++++++++++++++++------
> > 1 file changed, 30 insertions(+), 6 deletions(-)
> >
> > --
> > 2.39.2
> >
>

Hi all

For the second patch, active_io_release does this job. So it doesn't
need to do this in md_array_exit again.

Best Regards
Xiao