fix ->run failure handling
Hi Song, hi Yu,
this series fixes problems I found when testing how md handles trying to creat an array with disks that support incompatible protection information or a mix of protection information and not protection information.
Note that this only fixes the oops due to the double frees. After the attempt to at the incompatible device the /dev/md0 node is still around with zero blocks and linked to the the previous devices in sysfs which is a bit confusing, but unrelated to the resource cleanup touched here.
raid10 and raid5 also free conf on failure in their ->run handle, but set mddev->private to NULL which prevents the double free as well (but requires more code)
Diffstat:
raid0.c | 21 +++++---------------- raid1.c | 14 +++----------- 2 files changed, 8 insertions(+), 27 deletions(-)
PATCH 1/2 md/raid0: don't free conf on raid0_run failure
The core md code calls the ->free method which already frees conf.
--- drivers/md/raid0.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/md/raid0.c +5 -16
@@ -365,18 +365,13 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } -static void free_conf (struct mddev *mddev,struct r0conf *conf) -{ -kfree (conf->strip_zone); -kfree (conf->devlist); -kfree (conf); -} -static void raid0_free (struct mddev *mddev,void *priv) {struct r0conf *conf = priv; -free_conf (mddev, conf); +kfree (conf->strip_zone); +kfree (conf->devlist); +kfree (conf); }static int raid0_set_limits (struct mddev *mddev)
@@ -415,7 +410,7 @@ static int raid0_run(struct mddev *mddev)if (!mddev_is_dm (mddev)) { ret =raid0_set_limits (mddev);if (ret) - goto out_free_conf; +return ret; }/* calculate array device size */
@@ -427,13 +422,7 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); - ret =md_integrity_register (mddev); -if (ret) - goto out_free_conf; -return 0 ; -out_free_conf: -free_conf (mddev, conf); -return ret; +return md_integrity_register (mddev); }/*
Signature · 1 line
2.43.0
Re: [PATCH 1/2] md/raid0: don't free conf on raid0_run failure
Quoted 4 lines · Christoph Hellwig
The core md code calls the ->free method which already frees conf.
Fixes 0c031fd37f69 ("md: Move alloc/free acct bioset in to personality")Signed-off-by Christoph Hellwig <[email protected]>
LGTM
Quoted 55 lines
--- drivers/md/raid0.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)drivers/md/raid0.c +5
-16@@ -365,18 +365,13 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disksreturn array_sectors; } -static void free_conf (struct mddev *mddev,struct r0conf *conf) -{ -kfree (conf->strip_zone); -kfree (conf->devlist); -kfree (conf); -} -static void raid0_free (struct mddev *mddev,void *priv) {struct r0conf *conf = priv; -free_conf (mddev, conf); +kfree (conf->strip_zone); +kfree (conf->devlist); +kfree (conf); }static int raid0_set_limits (struct mddev *mddev)@@ -415,7 +410,7 @@ static int raid0_run(struct mddev *mddev)if (!mddev_is_dm (mddev)) { ret =raid0_set_limits (mddev);if (ret) - goto out_free_conf; +return ret; }/* calculate array device size */ @@ -427,13 +422,7 @@ static int raid0_run(struct mddev *mddev)dump_zones (mddev); - ret =md_integrity_register (mddev); -if (ret) - goto out_free_conf; -return 0 ; -out_free_conf: -free_conf (mddev, conf); -return ret; +return md_integrity_register (mddev); }/*
Re: [PATCH 1/2] md/raid0: don't free conf on raid0_run failure
Hi,
Quoted 8 lines · Yu Kuai
Quoted 4 lines · Christoph Hellwig
The core md code calls the ->free method which already frees conf.
Fixes 0c031fd37f69 ("md: Move alloc/free acct bioset in to personality")Signed-off-by Christoph Hellwig <[email protected]>LGTM
Reviewed-by Yu Kuai <[email protected]>
Sorry that I just noticed that the sysfs api level_store() calls the pers->run() as well, and it didn't handle failure by pers->free(). It's weried that the api will return success in this case, and after this patch, it will require __md_stop() to free the conf.
Can you also fix the level_store()? By checking pers->run() and if it failed, call pers->free() and return error.
Thanks,
Kuai
Quoted 53 lines
Quoted 40 lines
---
drivers/md/raid0.c| 21 +++++----------------1 file changed, 5 insertions(+), 16 deletions(-)drivers/md/raid0.c +0
-0@@ -365,18 +365,13 @@ static sector_t raid0_size(struct mddev *mddev,
sector_tsectors, intraid_disks
returnarray_sectors;
}drivers/md/raid0.c +0
-7-static void free_conf (struct mddev *mddev,struct r0conf *conf) -{ - kfree(conf->strip_zone); - kfree(conf->devlist); - kfree(conf); -} -static void
raid0_free(struct mddev *mddev, void *priv){
struct r0conf *conf = priv;
-free_conf(mddev, conf);
+kfree(conf->strip_zone);
+kfree(conf->devlist);
+ kfree(conf);
}
static intraid0_set_limits(struct mddev *mddev)drivers/md/raid0.c +1
-2@@ -415,7 +410,7 @@ static int raid0_run(struct mddev *mddev) if (!mddev_is_dm(mddev)) { ret = raid0_set_limits(mddev); if (ret) - goto out_free_conf; + return ret; } /* calculate array device size */@@ -427,13 +422,7 @@ static int raid0_run(struct mddev *mddev) dump_zones(mddev); - ret = md_integrity_register(mddev);drivers/md/raid0.c static int raid0_run(struct mddev *mddev) · line 426
Quoted 10 lines
drivers/md/raid0.c +1
-6- if (ret) - goto out_free_conf; - return 0; -out_free_conf: - free_conf(mddev, conf); - return ret; + return md_integrity_register(mddev); } /*.
Re: [PATCH 1/2] md/raid0: don't free conf on raid0_run failure
Quoted 7 lines · Yu Kuai
Sorry that I just noticed that the sysfs api
level_store()calls thepers->run()as well, and it didn't handle failure bypers->free(). It's weried that the api will return success in this case, and after this patch, it will require__md_stop()to free the conf.Can you also fix the
level_store()? By checkingpers->run()and if it failed, callpers->free()and return error.
I can look into it. But if we don't have consistent callers anyway I'd be tempted to not call ->free on ->run failure, as that is a rather unusual convention.
PATCH 2/2 md/raid1: don't free conf on raid0_run failure
In reply to Christoph HellwigThe core md code calls the ->free method which already frees conf.
--- drivers/md/raid1.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/md/raid1.c +3 -11
@@ -3204,7 +3204,6 @@ static int raid1_set_limits(struct mddev *mddev)return queue_limits_set (mddev->gendisk->queue, &lim); } -static void raid1_free (struct mddev *mddev,void *priv);static int raid1_run (struct mddev *mddev) {struct r1conf *conf;
@@ -3238,7 +3237,7 @@ static int raid1_run(struct mddev *mddev)if (!mddev_is_dm (mddev)) { ret =raid1_set_limits (mddev);if (ret) - goto abort; +return ret; } mddev->degraded =0 ;
@@ -3252,8 +3251,7 @@ static int raid1_run(struct mddev *mddev)*/ if (conf->raid_disks - mddev->degraded <1 ) {md_unregister_thread (mddev, &conf->thread); - ret = -EINVAL ; - goto abort; +return -EINVAL ; }if (conf->raid_disks - mddev->degraded ==1 )
@@ -3277,14 +3275,8 @@ static int raid1_run(struct mddev *mddev)md_set_array_sectors (mddev,raid1_size (mddev,0 ,0 )); ret =md_integrity_register (mddev); -if (ret) { +if (ret)md_unregister_thread (mddev, &mddev->thread); - goto abort; - } -return 0 ; - -abort: -raid1_free (mddev, conf);return ret; }
Signature · 1 line
2.43.0
Song Liu
maintainerHi Christoph,
Quoted 14 lines · Christoph Hellwig
Hi Song, hi Yu,
this series fixes problems I found when testing how md handles trying to creat an array with disks that support incompatible protection information or a mix of protection information and not protection information.
Note that this only fixes the oops due to the double frees. After the attempt to at the incompatible device the
/dev/md0node is still around with zero blocks and linked to the the previous devices in sysfs which is a bit confusing, but unrelated to the resource cleanup touched here.
Quoted 8 lines
raid10 and raid5 also free conf on failure in their ->run handle, but set
mddev->privateto NULL which prevents the double free as well (but requires more code)Diffstat:
raid0.c | 21 +++++---------------- raid1.c | 14 +++----------- 2 files changed, 8 insertions(+), 27 deletions(-)
Thanks for the patchset. I applied it to the md-6.11 branch.
Song
Quoted 10 lines · Song Liu
Quoted 8 lines
raid10 and raid5 also free conf on failure in their ->run handle, but set
mddev->privateto NULL which prevents the double free as well (but requires more code)Diffstat:
raid0.c | 21 +++++---------------- raid1.c | 14 +++----------- 2 files changed, 8 insertions(+), 27 deletions(-)Thanks for the patchset. I applied it to the md-6.11 branch.
I was planning to respin this to also handle failures in the takeover path.
Song Liu
maintainerHi Christoph,
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Song Liu
Quoted 8 lines
raid10 and raid5 also free conf on failure in their ->run handle, but set
mddev->privateto NULL which prevents the double free as well (but requires more code)Diffstat:
raid0.c | 21 +++++---------------- raid1.c | 14 +++----------- 2 files changed, 8 insertions(+), 27 deletions(-)
Quoted 4 lines
Quoted 1 line
Thanks for the patchset. I applied it to the md-6.11 branch.
I was planning to respin this to also handle failures in the takeover path.
How about we do that in a follow up patch?
Thanks for fixing these issues!
Song