md: it panic after reshape from raid1 to raid5
cover md: it panic after reshape from raid1 to raid5
Hi all
After reshape from raid1 to raid5, it can panice when there are I/Os
The steps can reproduce this:
mdadm -CR /dev/md0 -l1 -n2 /dev/loop0 /dev/loop1
mdadm --wait /dev/md0
mkfs.xfs /dev/md0
mdadm /dev/md0 --grow -l5
mount /dev/md0 /mnt
These two patches fix this problem.
Xiao Ni (2):
Free r0conf memory when register integrity failed Move alloc/free acct bioset in to personality
drivers/md/md.c | 27 +++++++++++++++++---------- drivers/md/md.h | 2 ++ drivers/md/raid0.c | 28 ++++++++++++++++++++++++---- drivers/md/raid5.c | 41 ++++++++++++++++++++++++++++++----------- 4 files changed, 73 insertions(+), 25 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 md/raid0: Free r0conf memory when register integrity failed
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/md/raid0.c +15 -3
@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)
@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;return ret; + +free: +free_conf (conf); +return ret; } -static void raid0_free (struct mddev *mddev,void *priv) +static void free_conf (struct r0conf *conf) { -struct r0conf *conf = priv; -kfree (conf->strip_zone);kfree (conf->devlist);kfree (conf); } +static void raid0_free (struct mddev *mddev,void *priv) +{ +struct r0conf *conf = priv; + +free_conf (conf); +} +static void raid0_handle_discard (struct mddev *mddev,struct bio *bio) {struct r0conf *conf = mddev->private;
Signature · 1 line
2.31.1
PATCH 2/2 md: Move alloc/free acct bioset in to personality
In reply to Xiao NiNow it alloc acct bioset in md_run and only raid0/raid5 need acct bioset. For example, it doesn't create acct bioset when creating raid1. Then reshape from raid1 to raid0/raid5, it will access acct bioset after reshaping. It can panic because of NULL pointer reference.
We can move alloc/free jobs to personality. pers->run alloc acct bioset and pers->clean free it.
--- drivers/md/md.c | 27 +++++++++++++++++---------- drivers/md/md.h | 2 ++ drivers/md/raid0.c | 10 +++++++++- drivers/md/raid5.c | 41 ++++++++++++++++++++++++++++++----------- 4 files changed, 58 insertions(+), 22 deletions(-)
drivers/md/md.c +17 -10
@@ -5878,13 +5878,6 @@ int md_run(struct mddev *mddev)if (err) goto exit_bio_set; } -if (mddev->level !=1 && mddev->level !=10 && - !bioset_initialized (&mddev->io_acct_set)) { - err =bioset_init (&mddev->io_acct_set,BIO_POOL_SIZE , - offsetof(struct md_io_acct , bio_clone),0 ); -if (err) - goto exit_sync_set; - }spin_lock (&pers_lock); pers =find_pers (mddev->level, mddev->clevel);
@@ -6061,9 +6054,6 @@ int md_run(struct mddev *mddev)module_put (pers->owner);md_bitmap_destroy (mddev); abort: -if (mddev->level !=1 && mddev->level !=10 ) -bioset_exit (&mddev->io_acct_set); -exit_sync_set:bioset_exit (&mddev->sync_set); exit_bio_set:bioset_exit (&mddev->bio_set);
@@ -8596,6 +8586,23 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev, }EXPORT_SYMBOL_GPL (md_submit_discard_bio); +int acct_bioset_init (struct mddev *mddev) +{ +int err =0 ; + +if (!bioset_initialized (&mddev->io_acct_set)) + err =bioset_init (&mddev->io_acct_set,BIO_POOL_SIZE , + offsetof(struct md_io_acct , bio_clone),0 ); +return err; +} +EXPORT_SYMBOL_GPL (acct_bioset_init); + +void acct_bioset_exit (struct mddev *mddev) +{ +bioset_exit (&mddev->io_acct_set); +} +EXPORT_SYMBOL_GPL (acct_bioset_exit); +static void md_end_io_acct (struct bio *bio) {struct md_io_acct *md_io_acct = bio->bi_private;
drivers/md/md.h +2 -0
@@ -721,6 +721,8 @@ extern void md_error(struct mddev *mddev, struct md_rdev *rdev);extern void md_finish_reshape (struct mddev *mddev);void md_submit_discard_bio (struct mddev *mddev,struct md_rdev *rdev,struct bio *bio,sector_t start,sector_t size); +int acct_bioset_init (struct mddev *mddev); +void acct_bioset_exit (struct mddev *mddev);void md_account_bio (struct mddev *mddev,struct bio **bio);extern bool __must_check md_flush_request (struct mddev *mddev,struct bio *bio);
drivers/md/raid0.c +9 -1
@@ -371,11 +371,16 @@ static int raid0_run(struct mddev *mddev)if (md_check_no_bitmap (mddev))return -EINVAL ; +if (acct_bioset_init (mddev)) { +pr_err ("md/raid0:%s: alloc acct bioset failed.\n" ,mdname (mddev)); +return -ENOMEM ; + } +/* if private is not null, we are here after takeover */ if (mddev->private ==NULL ) { ret =create_strip_zones (mddev, &conf);if (ret <0 ) -return ret; + goto exit_acct_set; mddev->private = conf; } conf = mddev->private;
@@ -421,6 +426,8 @@ static int raid0_run(struct mddev *mddev) free:free_conf (conf); +exit_acct_set: +acct_bioset_exit (mddev);return ret; }
@@ -436,6 +443,7 @@ static void raid0_free(struct mddev *mddev, void *priv)struct r0conf *conf = priv;free_conf (conf); +acct_bioset_exit (mddev); }static void raid0_handle_discard (struct mddev *mddev,struct bio *bio)
drivers/md/raid5.c +30 -11
104 lines not on this page · raw message
Signature · 1 line
2.31.1
Song Liu
maintainerRe: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Xiao NiQuoted 22 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +1
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 10 lines
drivers/md/raid0.c +5
-0@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;return ret; + +free: +free_conf (conf);
Can we just use raid0_free() here? Also, after freeing conf, we should set mddev->private to NULL.
Thanks,
Song
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
Quoted 30 lines · Song Liu
Quoted 28 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;
Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf,
At first I used raid0_free too. But it looks strange after adding acct_bioset_exit
in raid0_free. Because if creating stripe zones failed, it doesn't need to free conf,
although it doesn't have problems that passes NULL to kfree.
But I'm ok if you want me to use raid0_free here. I'll send the next version.
Quoted 2 lines
we should set
mddev->privateto NULL.
Yes.
Regards
Xiao
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Song LiuQuoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni<[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;
Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf, we should setmddev->privateto NULL.
Agree, like what raid1_run did. And we might need to check the return value of pers->run in level_store as well.
Thanks,
Guoqing
Re: [PATCH 2/2] md: Move alloc/free acct bioset in to personality
In reply to Xiao NiQuoted 5 lines · Xiao Ni
Now it alloc acct bioset in
md_runand only raid0/raid5 need acct bioset. For example, it doesn't create acct bioset when creating raid1. Then reshape from raid1 to raid0/raid5, it will access acct bioset after reshaping. It can panic because of NULL pointer reference.
Thanks, I think the previous commit didn't think of the reshape scenario. Could you paste the relevant info into commit header?
Quoted 2 lines
We can move alloc/free jobs to personality.
pers->runalloc acct bioset andpers->cleanfree it.
In the reshape case, the caller of pers->run is level_store, so.
Thanks,
Guoqing
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Guoqing JiangQuoted 39 lines · Guoqing Jiang
Quoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni<[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf, we should setmddev->privateto NULL.
Quoted 2 lines
Agree, like what
raid1_rundid. And we might need to check the return value ofpers->runinlevel_storeas well.
Yes. It needs to check the return value and try to reback to the original state. I planed to fix this in the following days not this patch. This patch only fix the NULL reference problem after reshape.
In fact, no only we need to check pers->run in level_store, we also need to check integrity during reshape. Now integrity only supports raid0/raid1/raid10,
so it needs to do some jobs related with integrity (unregister/register)
I plan to fix these two problems in the next patches. Is it OK?
Regards
Xiao
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
Quoted 44 lines · Xiao Ni
Quoted 31 lines · Guoqing Jiang
Quoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni<[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 8 lines
Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf, we should setmddev->privateto NULL.Agree, like what
raid1_rundid. And we might need to check the return value ofpers->runinlevel_storeas well.Yes. It needs to check the return value and try to reback to the original state. I planed to fix this in the following days not this patch. This patch only fix the NULL reference problem after reshape.
Quoted 6 lines
In fact, no only we need to check
pers->runinlevel_store, we also need to check integrity during reshape. Now integrity only supports raid0/raid1/raid10,
so it needs to do some jobs related with integrity (unregister/register)I plan to fix these two problems in the next patches. Is it OK?
Yes, fine from my side and thanks for your time.
Thanks,
Guoqing
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Guoqing JiangQuoted 39 lines · Guoqing Jiang
Quoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni<[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf, we should setmddev->privateto NULL.
Quoted 2 lines
Agree, like what
raid1_rundid. And we might need to check the return value ofpers->runinlevel_storeas well.
Hi Guoqing
By the way, you agree with using raid1_run here? I just replied to Song in an email.
Could you have a look at it? I explained why I wrote a new function free_conf here.
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Xiao NiQuoted 34 lines · Xiao Ni
Quoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 5 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf,
Quoted 5 lines
At first I used
raid0_freetoo. But it looks strange after addingacct_bioset_exit
inraid0_free. Because if creating stripe zones failed, it doesn't need to free conf,
although it doesn't have problems that passes NULL to kfree.
Maybe something like this, just FYI.
drivers/md/raid0.c +0 -0
@@ -377,6 +377,12 @@ static int raid0_run(struct mddev *mddev)
return ret;
mddev->private = conf;
}
+
+ if (acct_bioset_init(mddev)) {
+ pr_err("md/raid0:%s: alloc acct bioset failed.\n", mdname(mddev)); + return -ENOMEM;
+ }
+
conf = mddev->private;
if (mddev->queue) {
struct md_rdev *rdev;
@@ -413,6 +419,11 @@ static int raid0_run(struct mddev *mddev) dump_zones(mddev);
ret = md_integrity_register(mddev); + if (ret) {
+ raid0_free(mddev, mddev->private); + mddev->private = NULL;
+ acct_bioset_exit(mddev);
+ }
return ret;
}
Thanks,
Guoqing
Re: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
Quoted 34 lines · Guoqing Jiang
Maybe something like this, just FYI.
drivers/md/raid0.c +6
-0@@ -377,6 +377,12 @@ static int raid0_run(struct mddev *mddev)return ret; mddev->private = conf; } + +if (acct_bioset_init (mddev)) { +pr_err ("md/raid0:%s: alloc acct bioset failed.\n" ,mdname (mddev)); +return -ENOMEM ; + } + conf = mddev->private;if (mddev->queue) {struct md_rdev *rdev;drivers/md/raid0.c +5
-0@@ -413,6 +419,11 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) { +raid0_free (mddev, mddev->private); + mddev->private =NULL ; +acct_bioset_exit (mddev); + }return ret; }
Quoted 3 lines
Thanks,
Guoqing
This should not work. The way to fix the original problem is that we need to clean acct bio set of old
level raid in pers->free and create acct bio set for new level raid in pers->run. So it doesn't need to
change any codes in level_store. So it needs to put acct_bioset_init/acct_bioset_exit in pers->run/free.
Regards
Xiao
Song Liu
maintainerRe: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Xiao NiQuoted 39 lines · Xiao Ni
Quoted 30 lines · Song Liu
Quoted 28 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf,
Quoted 6 lines
At first I used
raid0_freetoo. But it looks strange after addingacct_bioset_exit
inraid0_free. Because if creating stripe zones failed, it doesn't need to free conf,
although it doesn't have problems that passes NULL to kfree.
I see. Let's add free_conf() then. Maybe we can move both free_conf() and raid0_free() ahead to avoid the extra declaration?
Thanks,
Song
Song Liu
maintainerRe: [PATCH 1/2] md/raid0: Free r0conf memory when register integrity failed
In reply to Xiao NiQuoted 48 lines · Xiao Ni
Quoted 39 lines · Guoqing Jiang
Quoted 28 lines · Song Liu
Quoted 27 lines · Xiao Ni
It doesn't free memory when register integrity failed. And move free conf codes into a single function.
Signed-off-by Xiao Ni<[email protected]>--- drivers/md/raid0.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/md/raid0.c +3
-0@@ -356,6 +356,7 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } +static void free_conf (struct r0conf *conf);static void raid0_free (struct mddev *mddev,void *priv);static int raid0_run (struct mddev *mddev)@@ -413,19 +414,30 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); ret =md_integrity_register (mddev); +if (ret) + goto free;Quoted 6 lines
drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 423
Quoted 4 lines
drivers/md/raid0.c +3
-0return ret; + +free: +free_conf (conf);Can we just use
raid0_free()here? Also, after freeing conf, we should setmddev->privateto NULL.Quoted 2 lines
Agree, like what
raid1_rundid. And we might need to check the return value ofpers->runinlevel_storeas well.Yes. It needs to check the return value and try to reback to the original state. I planed to fix this in the following days not this patch. This patch only fix the NULL reference problem after reshape.
Quoted 6 lines
In fact, no only we need to check
pers->runinlevel_store, we also need to check integrity during reshape. Now integrity only supports raid0/raid1/raid10,
so it needs to do some jobs related with integrity (unregister/register)I plan to fix these two problems in the next patches. Is it OK?
Yes, that works. We don't have to fix all the issues in one set. :)
Song