Skip to contentSkip to conversation

md: Use pers->quiesce in mddev_suspend

RFC PATCH In review Xiao Ni 3 participants 8 messages Nov 5, 2024 MD RAID

lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

RFC PATCH 1/1 md: Use pers->quiesce in mddev_suspend

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
 drivers/md/md.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/md/md.c +6 -0
index 67108c397c5a..7409ecb2df68 100644
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
 		return err;
 	}
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 1);
+
 	/*
 	 * For raid456, io might be waiting for reshape to make progress,
 	 * allow new reshape to start while waiting for io to be done to
@@ -514,6 +517,9 @@ static void __mddev_resume(struct mddev *mddev, bool recovery_needed)
 	percpu_ref_resurrect(&mddev->active_io);
 	wake_up(&mddev->sb_wait);
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 0);
+
 	if (recovery_needed)
 		set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
 	md_wakeup_thread(mddev->thread);
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw

Hi,

Quoted 8 lines · Xiao Ni

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Do you mean that other than normal IO, raid5 expects sync IO to be done as well by mddev_suspend()? If so, we'd better add some comments as well.

Thanks,
Kuai

Quoted 32 lines
Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
  drivers/md/md.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/md/md.c +6 -0
index 67108c397c5a..7409ecb2df68 100644
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
  		return err;
  	}
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 1);
+
  	/*
  	 * For raid456, io might be waiting for reshape to make progress,
  	 * allow new reshape to start while waiting for io to be done to
@@ -514,6 +517,9 @@ static void __mddev_resume(struct mddev *mddev, bool recovery_needed)
  	percpu_ref_resurrect(&mddev->active_io);
  	wake_up(&mddev->sb_wait);
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 0);
+
  	if (recovery_needed)
  		set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  	md_wakeup_thread(mddev->thread);
author
#2 lore raw
Quoted 8 lines · Yu Kuai

Hi,

Quoted 4 lines · Xiao Ni

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Quoted 8 lines
Quoted 4 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Do you mean that other than normal IO, raid5 expects sync IO to be done as well by mddev_suspend()? If so, we'd better add some comments as well.

Hi Kuai

Yes, before patch b39f35ebe86d, mddev suspend can guarantee all io (normal io from filesystem and sync requests) finish. And raid5 conf->handle_list have normal io and sync io, so it should wait all these io finish in suspend operation. I'll add more comments.

Regards
Xiao

Quoted 37 lines

Thanks,
Kuai

Quoted 32 lines
Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
  drivers/md/md.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/md/md.c +6 -0
index 67108c397c5a..7409ecb2df68 100644
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
              return err;
      }
 
+     if (mddev->pers)
+             mddev->pers->quiesce(mddev, 1);
+
      /*
       * For raid456, io might be waiting for reshape to make progress,
       * allow new reshape to start while waiting for io to be done to
@@ -514,6 +517,9 @@ static void __mddev_resume(struct mddev *mddev, bool recovery_needed)
      percpu_ref_resurrect(&mddev->active_io);
      wake_up(&mddev->sb_wait);
 
+     if (mddev->pers)
+             mddev->pers->quiesce(mddev, 0);
+
      if (recovery_needed)
              set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
      md_wakeup_thread(mddev->thread);
#3 lore raw
In reply to Xiao Ni
Quoted 3 lines · On Tue, 5 Nov 2024 15:57:33 +0800 Xiao Ni <[email protected]> wrote:

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Is issue fixed with this patch? Is is missing here :)

Quoted 18 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
 drivers/md/md.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/md/md.c +0 -0
index 67108c397c5a..7409ecb2df68 100644

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 6 lines
drivers/md/md.c +3 -0
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
 		return err;
 	}
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 1);
+

Shouldn't it be implemented as below? According to b39f35ebe86d, some levels are not implementing this?

+ if (mddev->pers && mddev->pers->quiesce)
+ mddev->pers->quiesce(mddev, 1);

Is it reproducible with upstream kernel?

Thanks,
Mariusz

#4 lore raw

Hi,

Quoted 36 lines · Mariusz Tkaczyk
Quoted 3 lines · On Tue, 5 Nov 2024 15:57:33 +0800 Xiao Ni <[email protected]> wrote:

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Is issue fixed with this patch? Is is missing here :)

Quoted 18 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
  drivers/md/md.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/md/md.c +0 -0
index 67108c397c5a..7409ecb2df68 100644

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 6 lines
drivers/md/md.c +3 -0
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
  		return err;
  	}
 
+	if (mddev->pers)
+		mddev->pers->quiesce(mddev, 1);
+

Shouldn't it be implemented as below? According to b39f35ebe86d, some levels are not implementing this?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (mddev->pers && mddev->pers->quiesce)
+		mddev->pers->quiesce(mddev, 1);

It's fine, the fops is never NULL, just some levels points to an empty function.

The tricky part here is that accessing "mddev->pers" is not safe here, 'reconfig_mutex' is not held in mddev_suspend(), and can concurrent with, for example, change levels. :(

Thanks,
Kuai

Quoted 8 lines

Is it reproducible with upstream kernel?

Thanks,
Mariusz

.

author
#5 lore raw
Quoted 43 lines · Yu Kuai

Hi,

Quoted 36 lines · Mariusz Tkaczyk
Quoted 3 lines · On Tue, 5 Nov 2024 15:57:33 +0800 Xiao Ni <[email protected]> wrote:

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Is issue fixed with this patch? Is is missing here :)

Quoted 18 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
  drivers/md/md.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/md/md.c +0 -0
index 67108c397c5a..7409ecb2df68 100644

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 6 lines
drivers/md/md.c +3 -0
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
             return err;
     }
 
+    if (mddev->pers)
+            mddev->pers->quiesce(mddev, 1);
+

Shouldn't it be implemented as below? According to b39f35ebe86d, some levels are not implementing this?

Review

Quoted 2 lines
(quoted diff) +2 -0
+     if (mddev->pers && mddev->pers->quiesce)
+             mddev->pers->quiesce(mddev, 1);
Quoted 6 lines

It's fine, the fops is never NULL, just some levels points to an empty function.

The tricky part here is that accessing "mddev->pers" is not safe here, 'reconfig_mutex' is not held in mddev_suspend(), and can concurrent with, for example, change levels. :(

Hi Kuai

Now mddev->suspended is protected by mddev->suspend_mutex. It should can avoid the problem you mentioned above? level_store calls mddev_suspend and mddev->suspended is set to mddev->suspended+1. So other paths will return because mddev->suspended is not 0.

Regards
Xiao

Quoted 13 lines

Thanks,
Kuai

Quoted 8 lines

Is it reproducible with upstream kernel?

Thanks,
Mariusz

.

#6 lore raw

Hi,

Quoted 51 lines · Xiao Ni
Quoted 43 lines · Yu Kuai

Hi,

Quoted 36 lines · Mariusz Tkaczyk
Quoted 3 lines · On Tue, 5 Nov 2024 15:57:33 +0800 Xiao Ni <[email protected]> wrote:

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Is issue fixed with this patch? Is is missing here :)

Quoted 18 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
   drivers/md/md.c | 6 ++++++
   1 file changed, 6 insertions(+)
drivers/md/md.c +0 -0
index 67108c397c5a..7409ecb2df68 100644

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 6 lines
drivers/md/md.c +3 -0
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
              return err;
      }
 
+    if (mddev->pers)
+            mddev->pers->quiesce(mddev, 1);
+

Shouldn't it be implemented as below? According to b39f35ebe86d, some levels are not implementing this?

Review

Quoted 2 lines
(quoted diff) +2 -0
+     if (mddev->pers && mddev->pers->quiesce)
+             mddev->pers->quiesce(mddev, 1);
Quoted 6 lines

It's fine, the fops is never NULL, just some levels points to an empty function.

The tricky part here is that accessing "mddev->pers" is not safe here, 'reconfig_mutex' is not held in mddev_suspend(), and can concurrent with, for example, change levels. :(

Quoted 6 lines

Hi Kuai

Now mddev->suspended is protected by mddev->suspend_mutex. It should can avoid the problem you mentioned above? level_store calls mddev_suspend and mddev->suspended is set to mddev->suspended+1. So other paths will return because mddev->suspended is not 0.

Yeah, level store is just an wrong example, key point here is that mddev->pers is not protected by 'suspend_mutex'. Other places are md_run() and md_stop(), these path doesn't hold 'suspend_mutex' right? And they look like can concurrent with suspend, for example, suspend_lo_store()

Did you consider just fail raid5_store_group_thread_cnt() if sync_thread is active?

Or call ->quiesce() directly here with 'reconfig_mutex' held before suspend?

Thanks,
Kuai

Quoted 20 lines

Regards
Xiao

Quoted 13 lines

Thanks,
Kuai

Quoted 8 lines

Is it reproducible with upstream kernel?

Thanks,
Mariusz

.

.

author
#7 lore raw
Quoted 62 lines · Yu Kuai

Hi,

Quoted 51 lines · Xiao Ni
Quoted 43 lines · Yu Kuai

Hi,

Quoted 36 lines · Mariusz Tkaczyk
Quoted 3 lines · On Tue, 5 Nov 2024 15:57:33 +0800 Xiao Ni <[email protected]> wrote:

One customer reports a bug: raid5 is hung when changing thread cnt while resync is running. The stripes are all in conf->handle_list and new threads can't handle them.

Is issue fixed with this patch? Is is missing here :)

Quoted 18 lines

Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removes pers->quiesce from mddev_suspend/resume, then we can't guarantee sync requests finish in suspend operation. One personality knows itself the best. So pers->quiesce is a proper way to let personality quiesce.

Fixes b39f35ebe86d ("md: don't quiesce in mddev_suspend()")
---
   drivers/md/md.c | 6 ++++++
   1 file changed, 6 insertions(+)
drivers/md/md.c +0 -0
index 67108c397c5a..7409ecb2df68 100644

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 6 lines
drivers/md/md.c +3 -0
@@ -482,6 +482,9 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
              return err;
      }
 
+    if (mddev->pers)
+            mddev->pers->quiesce(mddev, 1);
+

Shouldn't it be implemented as below? According to b39f35ebe86d, some levels are not implementing this?

Review

Quoted 2 lines
(quoted diff) +2 -0
+     if (mddev->pers && mddev->pers->quiesce)
+             mddev->pers->quiesce(mddev, 1);
Quoted 6 lines

It's fine, the fops is never NULL, just some levels points to an empty function.

The tricky part here is that accessing "mddev->pers" is not safe here, 'reconfig_mutex' is not held in mddev_suspend(), and can concurrent with, for example, change levels. :(

Quoted 6 lines

Hi Kuai

Now mddev->suspended is protected by mddev->suspend_mutex. It should can avoid the problem you mentioned above? level_store calls mddev_suspend and mddev->suspended is set to mddev->suspended+1. So other paths will return because mddev->suspended is not 0.

Quoted 5 lines

Yeah, level store is just an wrong example, key point here is that mddev->pers is not protected by 'suspend_mutex'. Other places are md_run() and md_stop(), these path doesn't hold 'suspend_mutex' right? And they look like can concurrent with suspend, for example, suspend_lo_store()

Yes, thanks for pointing out this. I need to think more about this.

Quoted 3 lines

Did you consider just fail raid5_store_group_thread_cnt() if sync_thread is active?

It's one method, but not a good one.

Quoted 3 lines

Or call ->quiesce() directly here with 'reconfig_mutex' held before suspend?

I'll think this way. Thanks!

Regards
Xiao

Quoted 25 lines

Thanks,
Kuai

Quoted 20 lines

Regards
Xiao

Quoted 13 lines

Thanks,
Kuai

Quoted 8 lines

Is it reproducible with upstream kernel?

Thanks,
Mariusz

.

.