From: Mikulas Patocka Date: Fri, 27 Feb 2015 19:04:27 +0000 (-0500) Subject: dm: hold suspend_lock while suspending device during device deletion X-Git-Tag: v3.16.35~2475 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e91439b8d6080ededdb8bfd8c7012574a065e47;p=thirdparty%2Fkernel%2Fstable.git dm: hold suspend_lock while suspending device during device deletion commit ab7c7bb6f4ab95dbca96fcfc4463cd69843e3e24 upstream. __dm_destroy() must take the suspend_lock so that its presuspend and postsuspend calls do not race with an internal suspend. Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer [ luis: backported to 3.16: adjusted context ] Signed-off-by: Luis Henriques --- diff --git a/drivers/md/dm.c b/drivers/md/dm.c index e705042a997ce..bd7c5c810214f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2405,10 +2405,16 @@ static void __dm_destroy(struct mapped_device *md, bool wait) set_bit(DMF_FREEING, &md->flags); spin_unlock(&_minor_lock); + /* + * Take suspend_lock so that presuspend and postsuspend methods + * do not race with internal suspend. + */ + mutex_lock(&md->suspend_lock); if (!dm_suspended_md(md)) { dm_table_presuspend_targets(map); dm_table_postsuspend_targets(map); } + mutex_unlock(&md->suspend_lock); /* dm_put_live_table must be before msleep, otherwise deadlock is possible */ dm_put_live_table(md, srcu_idx);