From: Denis V. Lunev An rpc reaches the worker in two steps: the caller puts it on the rpc list, then wake_worker() queues the work unless the target is suspended. stop_worker() raises that flag and drains the workqueue with no ordering against either step, so an rpc can land on both sides of the drain. An rpc queued before the flag is raised, whose wake_worker() runs after it, is never served. The caller waits for a completion that only the next resume can deliver, and it waits holding the table srcu, so a reload blocks in dm_swap_table() and the device can no longer be reloaded or removed. An rpc whose wake_worker() read the flag as clear can instead queue the work after drain_workqueue() has returned. The worker then commits the metadata beside the commit era_postsuspend() runs in its own thread. Both commits allocate from the same space map and take the same block, which corrupts it, and every commit after that fails: device-mapper: space map common: unable to decrement block device-mapper: era: metadata_commit: pre commit failed Add the rpc and queue the work under the rpc lock, take that lock to raise the flag, and refuse an rpc that arrives once it is raised. An rpc that made it onto the list is then queued before the drain waits for it. Userspace sees one change. A status query on a suspended era device used to block until the device was resumed, and now reports the target in error. Fixes: eec40579d848 ("dm: add era target") Cc: stable@vger.kernel.org Signed-off-by: Denis V. Lunev --- drivers/md/dm-era-target.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c index ea499adca4ce..29b0602e7849 100644 --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -1389,10 +1389,14 @@ static int perform_rpc(struct era *era, struct rpc *rpc) init_completion(&rpc->complete); spin_lock(&era->rpc_lock); + if (atomic_read(&era->suspended)) { + spin_unlock(&era->rpc_lock); + return -EBUSY; + } list_add(&rpc->list, &era->rpc_calls); + queue_work(era->wq, &era->worker); spin_unlock(&era->rpc_lock); - wake_worker(era); wait_for_completion(&rpc->complete); return rpc->result; @@ -1427,7 +1431,10 @@ static void start_worker(struct era *era) static void stop_worker(struct era *era) { + spin_lock(&era->rpc_lock); atomic_set(&era->suspended, 1); + spin_unlock(&era->rpc_lock); + drain_workqueue(era->wq); } -- 2.55.0