Skip to content

Commit

Permalink
dm-delay: fix workqueue delay_timer race
Browse files Browse the repository at this point in the history
delay_timer could be pending when delay_dtr() is called. It needs to be
shut down before kdelayd_wq is destroyed, so it won't try queueing more
work to kdelayd_wq while that's getting destroyed.

Also the del_timer_sync() call in delay_presuspend() doesn't protect
against the timer getting immediately rearmed by the queued call to
flush_delayed_bios(), but there's no real harm if that does happen.
timer_delete() is less work, and is basically just as likely to stop a
pointless call to flush_delayed_bios().

Fixes: 26b9f22 ("dm: delay target")
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
  • Loading branch information
bmarzins authored and Mike Snitzer committed May 9, 2024
1 parent 83637d9 commit 8d24790
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/md/dm-delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ static void delay_dtr(struct dm_target *ti)
{
struct delay_c *dc = ti->private;

if (dc->kdelayd_wq)
if (dc->kdelayd_wq) {
timer_shutdown_sync(&dc->delay_timer);
destroy_workqueue(dc->kdelayd_wq);
}

if (dc->read.dev)
dm_put_device(ti, dc->read.dev);
Expand Down Expand Up @@ -335,7 +337,7 @@ static void delay_presuspend(struct dm_target *ti)
mutex_unlock(&delayed_bios_lock);

if (!delay_is_fast(dc))
del_timer_sync(&dc->delay_timer);
timer_delete(&dc->delay_timer);
flush_delayed_bios(dc, true);
}

Expand Down

0 comments on commit 8d24790

Please sign in to comment.