Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp675124ybh; Tue, 10 Mar 2020 06:16:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvViuWlq5M9uQQtXnjQSXrJRuANKcOC2A8i2HkZ3wDTJRd2jZ1Xh1PAn0TnbEPnwdlceaaw X-Received: by 2002:aca:a9d4:: with SMTP id s203mr1131619oie.106.1583846215190; Tue, 10 Mar 2020 06:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583846215; cv=none; d=google.com; s=arc-20160816; b=kcpTITK11LZeXuic3SQZB0blgS5B5XggKscH6gLHoLPx23bCnSX3tI89+WUceaMsLv jno33DS7+Wz1EZ3WbZyw19U5reayky06sNpNMYDMiZFqp7NaHJj5LA1asbLI2uEcJqn2 U+z1D0z1HHvo2MeUoH0ou435eGrFKyM6LH0KivLVWI91cI4U8NKLjvBArCxGr/0yVPVu Dh0HUGeE0oz7E/y6p7H7xfvw/5Fwx93222xo7jkTqSrfMCnpf61L0RV15qBjVolgk44D fK49/SyY3PrVFLs+F97xhXvbbV79W4b16njzrqYLUJ5wcFIyxxuCS2ujqkUqbLcEP9JY uabQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ASa5z796DczJ2rNpQkBSNaL1AU62QsyZ6uhNrAlphj4=; b=syqae3pWd5lm3qJDblw6fXL2Zanpd3dGUaong2VfXG7ZLBuLyK8gd08GKS4b4fPMY0 eDOHf6FbTU3+rXkS9F3SBGtWFL9/e9SWoEm1IXzrYxzGIVz1Rh5RySlMNX+qcbnf1B/B GOi9Jf1hmc0gMlJ5WoSirMasSZ1qglnDWH1mc60FU7Eko1p57lHF8V/tULd8HnuXcuQe Y/+pYDuBSkbhQc8kFbQygBTNfzACk1hGv3yAs1KyP1Nd4Dvtyn+xlVUvpBn2Cf7lu1EO SPKnJZ7SNizC1pn1kN0TVuoj6T5YQFVUiVLN1IY3uGI9DE1Ih4vFY0mgLseOxf+iPeqb oTcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gQ1YEQ5O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y13si7638658oto.33.2020.03.10.06.16.42; Tue, 10 Mar 2020 06:16:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gQ1YEQ5O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731743AbgCJNNm (ORCPT + 99 others); Tue, 10 Mar 2020 09:13:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:36696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731740AbgCJNNk (ORCPT ); Tue, 10 Mar 2020 09:13:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C5FF2468C; Tue, 10 Mar 2020 13:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583846018; bh=iaI8RigxyHBF2XyZTtdYdQc4C6phvCfJC38pluzMJT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gQ1YEQ5Oc1sXhU+EmFNHOAv2gIkpqFvEtwep4CTRVJnPdMu8q5UUszuYfr45fjtNr 2ix+4fH82oCzDFbYFM32+Xy9LoCUM1r2GAzD8JIjoBTkHvh5Z7DWyq8udgtlgRA8i0 HI0cz8TNENrzesQ6FuLujLgWO3ahoFvhYRgeBbn0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Corey Marthaler , Mikulas Patocka , Mike Snitzer Subject: [PATCH 4.19 56/86] dm: report suspended device during destroy Date: Tue, 10 Mar 2020 13:45:20 +0100 Message-Id: <20200310124533.817196498@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124530.808338541@linuxfoundation.org> References: <20200310124530.808338541@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit adc0daad366b62ca1bce3e2958a40b0b71a8b8b3 upstream. The function dm_suspended returns true if the target is suspended. However, when the target is being suspended during unload, it returns false. An example where this is a problem: the test "!dm_suspended(wc->ti)" in writecache_writeback is not sufficient, because dm_suspended returns zero while writecache_suspend is in progress. As is, without an enhanced dm_suspended, simply switching from flush_workqueue to drain_workqueue still emits warnings: workqueue writecache-writeback: drain_workqueue() isn't complete after 10 tries workqueue writecache-writeback: drain_workqueue() isn't complete after 100 tries workqueue writecache-writeback: drain_workqueue() isn't complete after 200 tries workqueue writecache-writeback: drain_workqueue() isn't complete after 300 tries workqueue writecache-writeback: drain_workqueue() isn't complete after 400 tries writecache_suspend calls flush_workqueue(wc->writeback_wq) - this function flushes the current work. However, the workqueue may re-queue itself and flush_workqueue doesn't wait for re-queued works to finish. Because of this - the function writecache_writeback continues execution after the device was suspended and then concurrently with writecache_dtr, causing a crash in writecache_writeback. We must use drain_workqueue - that waits until the work and all re-queued works finish. As a prereq for switching to drain_workqueue, this commit fixes dm_suspended to return true after the presuspend hook and before the postsuspend hook - just like during a normal suspend. It allows simplifying the dm-integrity and dm-writecache targets so that they don't have to maintain suspended flags on their own. With this change use of drain_workqueue() can be used effectively. This change was tested with the lvm2 testsuite and cryptsetup testsuite and the are no regressions. Fixes: 48debafe4f2f ("dm: add writecache target") Cc: stable@vger.kernel.org # 4.18+ Reported-by: Corey Marthaler Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-integrity.c | 12 +++++------- drivers/md/dm-writecache.c | 2 +- drivers/md/dm.c | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -186,12 +186,13 @@ struct dm_integrity_c { __u8 sectors_per_block; unsigned char mode; - int suspending; int failed; struct crypto_shash *internal_hash; + struct dm_target *ti; + /* these variables are locked with endio_wait.lock */ struct rb_root in_progress; struct list_head wait_list; @@ -2080,7 +2081,7 @@ static void integrity_writer(struct work unsigned prev_free_sectors; /* the following test is not needed, but it tests the replay code */ - if (READ_ONCE(ic->suspending) && !ic->meta_dev) + if (unlikely(dm_suspended(ic->ti)) && !ic->meta_dev) return; spin_lock_irq(&ic->endio_wait.lock); @@ -2139,7 +2140,7 @@ static void integrity_recalc(struct work next_chunk: - if (unlikely(READ_ONCE(ic->suspending))) + if (unlikely(dm_suspended(ic->ti))) goto unlock_ret; range.logical_sector = le64_to_cpu(ic->sb->recalc_sector); @@ -2411,8 +2412,6 @@ static void dm_integrity_postsuspend(str del_timer_sync(&ic->autocommit_timer); - WRITE_ONCE(ic->suspending, 1); - if (ic->recalc_wq) drain_workqueue(ic->recalc_wq); @@ -2426,8 +2425,6 @@ static void dm_integrity_postsuspend(str dm_integrity_flush_buffers(ic); } - WRITE_ONCE(ic->suspending, 0); - BUG_ON(!RB_EMPTY_ROOT(&ic->in_progress)); ic->journal_uptodate = true; @@ -3116,6 +3113,7 @@ static int dm_integrity_ctr(struct dm_ta } ti->private = ic; ti->per_io_data_size = sizeof(struct dm_integrity_io); + ic->ti = ti; ic->in_progress = RB_ROOT; INIT_LIST_HEAD(&ic->wait_list); --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -844,7 +844,7 @@ static void writecache_suspend(struct dm } wc_unlock(wc); - flush_workqueue(wc->writeback_wq); + drain_workqueue(wc->writeback_wq); wc_lock(wc); if (flush_on_suspend) --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2353,6 +2353,7 @@ static void __dm_destroy(struct mapped_d map = dm_get_live_table(md, &srcu_idx); if (!dm_suspended_md(md)) { dm_table_presuspend_targets(map); + set_bit(DMF_SUSPENDED, &md->flags); dm_table_postsuspend_targets(map); } /* dm_put_live_table must be before msleep, otherwise deadlock is possible */