Skip to content

Commit 7eb8ff0

Browse files
Li Lingfengliu-song-6
authored andcommitted
md: Hold mddev->reconfig_mutex when trying to get mddev->sync_thread
Commit ba9d9f1a707f ("Revert "md: unlock mddev before reap sync_thread in action_store"") removed the scenario of calling md_unregister_thread() without holding mddev->reconfig_mutex, so add a lock holding check before acquiring mddev->sync_thread by passing mdev to md_unregister_thread(). Signed-off-by: Li Lingfeng <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Song Liu <[email protected]>
1 parent 892da88 commit 7eb8ff0

File tree

7 files changed

+15
-14
lines changed

7 files changed

+15
-14
lines changed

drivers/md/md-cluster.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,8 @@ static int join(struct mddev *mddev, int nodes)
952952
return 0;
953953
err:
954954
set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
955-
md_unregister_thread(&cinfo->recovery_thread);
956-
md_unregister_thread(&cinfo->recv_thread);
955+
md_unregister_thread(mddev, &cinfo->recovery_thread);
956+
md_unregister_thread(mddev, &cinfo->recv_thread);
957957
lockres_free(cinfo->message_lockres);
958958
lockres_free(cinfo->token_lockres);
959959
lockres_free(cinfo->ack_lockres);
@@ -1015,8 +1015,8 @@ static int leave(struct mddev *mddev)
10151015
resync_bitmap(mddev);
10161016

10171017
set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
1018-
md_unregister_thread(&cinfo->recovery_thread);
1019-
md_unregister_thread(&cinfo->recv_thread);
1018+
md_unregister_thread(mddev, &cinfo->recovery_thread);
1019+
md_unregister_thread(mddev, &cinfo->recv_thread);
10201020
lockres_free(cinfo->message_lockres);
10211021
lockres_free(cinfo->token_lockres);
10221022
lockres_free(cinfo->ack_lockres);

drivers/md/md.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6258,7 +6258,7 @@ static void mddev_detach(struct mddev *mddev)
62586258
mddev->pers->quiesce(mddev, 1);
62596259
mddev->pers->quiesce(mddev, 0);
62606260
}
6261-
md_unregister_thread(&mddev->thread);
6261+
md_unregister_thread(mddev, &mddev->thread);
62626262
if (mddev->queue)
62636263
blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
62646264
}
@@ -7990,9 +7990,10 @@ struct md_thread *md_register_thread(void (*run) (struct md_thread *),
79907990
}
79917991
EXPORT_SYMBOL(md_register_thread);
79927992

7993-
void md_unregister_thread(struct md_thread __rcu **threadp)
7993+
void md_unregister_thread(struct mddev *mddev, struct md_thread __rcu **threadp)
79947994
{
7995-
struct md_thread *thread = rcu_dereference_protected(*threadp, true);
7995+
struct md_thread *thread = rcu_dereference_protected(*threadp,
7996+
lockdep_is_held(&mddev->reconfig_mutex));
79967997

79977998
if (!thread)
79987999
return;
@@ -9484,7 +9485,7 @@ void md_reap_sync_thread(struct mddev *mddev)
94849485
bool is_reshaped = false;
94859486

94869487
/* resync has finished, collect result */
9487-
md_unregister_thread(&mddev->sync_thread);
9488+
md_unregister_thread(mddev, &mddev->sync_thread);
94889489
atomic_inc(&mddev->sync_seq);
94899490

94909491
if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&

drivers/md/md.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ extern struct md_thread *md_register_thread(
761761
void (*run)(struct md_thread *thread),
762762
struct mddev *mddev,
763763
const char *name);
764-
extern void md_unregister_thread(struct md_thread __rcu **threadp);
764+
extern void md_unregister_thread(struct mddev *mddev, struct md_thread __rcu **threadp);
765765
extern void md_wakeup_thread(struct md_thread __rcu *thread);
766766
extern void md_check_recovery(struct mddev *mddev);
767767
extern void md_reap_sync_thread(struct mddev *mddev);

drivers/md/raid1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ static int raid1_run(struct mddev *mddev)
31563156
* RAID1 needs at least one disk in active
31573157
*/
31583158
if (conf->raid_disks - mddev->degraded < 1) {
3159-
md_unregister_thread(&conf->thread);
3159+
md_unregister_thread(mddev, &conf->thread);
31603160
ret = -EINVAL;
31613161
goto abort;
31623162
}
@@ -3183,7 +3183,7 @@ static int raid1_run(struct mddev *mddev)
31833183

31843184
ret = md_integrity_register(mddev);
31853185
if (ret) {
3186-
md_unregister_thread(&mddev->thread);
3186+
md_unregister_thread(mddev, &mddev->thread);
31873187
goto abort;
31883188
}
31893189
return 0;

drivers/md/raid10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4320,7 +4320,7 @@ static int raid10_run(struct mddev *mddev)
43204320
return 0;
43214321

43224322
out_free_conf:
4323-
md_unregister_thread(&mddev->thread);
4323+
md_unregister_thread(mddev, &mddev->thread);
43244324
raid10_free_conf(conf);
43254325
mddev->private = NULL;
43264326
out:

drivers/md/raid5-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@ void r5l_exit_log(struct r5conf *conf)
31683168
{
31693169
struct r5l_log *log = conf->log;
31703170

3171-
md_unregister_thread(&log->reclaim_thread);
3171+
md_unregister_thread(conf->mddev, &log->reclaim_thread);
31723172

31733173
/*
31743174
* 'reconfig_mutex' is held by caller, set 'confg->log' to NULL to

drivers/md/raid5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8107,7 +8107,7 @@ static int raid5_run(struct mddev *mddev)
81078107

81088108
return 0;
81098109
abort:
8110-
md_unregister_thread(&mddev->thread);
8110+
md_unregister_thread(mddev, &mddev->thread);
81118111
print_raid5_conf(conf);
81128112
free_conf(conf);
81138113
mddev->private = NULL;

0 commit comments

Comments
 (0)