Commit fedbb16e authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Kelsey Skunberg

dm cache: fix a crash due to incorrect work item cancelling

BugLink: https://bugs.launchpad.net/bugs/1868628

commit 7cdf6a0a upstream.

The crash can be reproduced by running the lvm2 testsuite test
lvconvert-thin-external-cache.sh for several minutes, e.g.:
  while :; do make check T=shell/lvconvert-thin-external-cache.sh; done

The crash happens in this call chain:
do_waker -> policy_tick -> smq_tick -> end_hotspot_period -> clear_bitset
-> memset -> __memset -- which accesses an invalid pointer in the vmalloc
area.

The work entry on the workqueue is executed even after the bitmap was
freed. The problem is that cancel_delayed_work doesn't wait for the
running work item to finish, so the work item can continue running and
re-submitting itself even after cache_postsuspend. In order to make sure
that the work item won't be running, we must use cancel_delayed_work_sync.

Also, change flush_workqueue to drain_workqueue, so that if some work item
submits itself or another work item, we are properly waiting for both of
them.

Fixes: c6b4fcba ("dm: add cache target")
Cc: stable@vger.kernel.org # v3.9
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent b21fada7
......@@ -2193,8 +2193,8 @@ static void wait_for_migrations(struct cache *cache)
static void stop_worker(struct cache *cache)
{
cancel_delayed_work(&cache->waker);
flush_workqueue(cache->wq);
cancel_delayed_work_sync(&cache->waker);
drain_workqueue(cache->wq);
}
static void requeue_deferred_cells(struct cache *cache)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment