Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2901860iog; Mon, 27 Jun 2022 05:24:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTtoox/YnIlFB/eQyrHXL7mYAX7ciUXIcQwzmbjpH5I5U/iYWB1bMbgRQjAqgy6oVSfAg+ X-Received: by 2002:a17:902:f34a:b0:16a:e2d:3e9 with SMTP id q10-20020a170902f34a00b0016a0e2d03e9mr14597226ple.95.1656332699244; Mon, 27 Jun 2022 05:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656332699; cv=none; d=google.com; s=arc-20160816; b=h0NV83/FZKtJV4U0CmriMtpAFxgvUHzUBO7nNf/YLW7wiY4HMN6yRASA2qfgbkQC7k Y7UoVBBMW/LY7oX0MSTgnmA4q/a2XNh894zVCw2E9nixSms9p3/gDvtdK6HK3ZPDiKyu 3kSXe0UauzvOBVhSVckRGk8klJ/ZwAzpQW0xiHhAsaWAnQrqMgqKGj34zHHY20RGQ5G8 WHdiRay2LhkHcKs6YyyLO8m12F0B7BZGCdcgMb8wkBCnPiPsP+svcT6vQGjDdaSggBD/ Wi7qRpUSJVRsh3roBtSgFXYGJDPWs2nkAVbCFnIIveBxzbez4Ro3z9iAbCb2TazSPgdo Wqbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dxqcpE1W7ebSpJugi9us2nr6Z8G4saUP+rroV631Jsw=; b=jOrj0NcYi6Y0aTFe5KJcJAi1/VI2Mj0VLxrpI07X+u2QQEfD4VXcMThwrJcG33SfWT pLcegCfpXdAAeIlTPu+ZfN0tldVPX6DIAuatiQlUBiRe7OVf7VNBDE7Z1/+IGilbqHDL BpMZ4gDzVmfSW/PgWPdJitSx3EnSGfnsbvCjdF9/XMkqPwUlpFkSSF0niEgJTYV3XRGS jnKJHTbdWDghXZri79mQ9JjsILFknfjz6UuSI9SKthJaarG+eH20o2eYE10CEnkoccp/ PmwaXg4xKNuLheZApvyxAIuroT9ppNQ0hT5d0+fmhHEjKbs4HHxBCgDpL3sKhI6kesFB uBtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhsirJPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a63f253000000b0040c9e0a1ef5si13726303pgk.516.2022.06.27.05.24.47; Mon, 27 Jun 2022 05:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhsirJPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232654AbiF0LXW (ORCPT + 99 others); Mon, 27 Jun 2022 07:23:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234580AbiF0LXT (ORCPT ); Mon, 27 Jun 2022 07:23:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4442DE8; Mon, 27 Jun 2022 04:23:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 960DFB81116; Mon, 27 Jun 2022 11:23:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08591C3411D; Mon, 27 Jun 2022 11:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656328994; bh=AJWxeXAUJ3DsLHyvcz2cfrvPxmBjAzdfm0WYVN/6l6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhsirJPmCPZ6to68vChJ1bb3WEDv/EsDakPgrAwxd5GVG4K6LopZysFvTAoXecwdV a9G00YrFhCBWBRKmuLe1jd7gUAm9LOq9xwsSTQrofWWuYSxLaU9BmkyG84KbAGUWvY brfN15zvNxLLDCmLLv3D04+NpmIQayRH0NHSNNCE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikos Tsironis , Mike Snitzer Subject: [PATCH 5.10 016/102] dm era: commit metadata in postsuspend after worker stops Date: Mon, 27 Jun 2022 13:20:27 +0200 Message-Id: <20220627111933.946926694@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111933.455024953@linuxfoundation.org> References: <20220627111933.455024953@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikos Tsironis commit 9ae6e8b1c9bbf6874163d1243e393137313762b7 upstream. During postsuspend dm-era does the following: 1. Archives the current era 2. Commits the metadata, as part of the RPC call for archiving the current era 3. Stops the worker Until the worker stops, it might write to the metadata again. Moreover, these writes are not flushed to disk immediately, but are cached by the dm-bufio client, which writes them back asynchronously. As a result, the committed metadata of a suspended dm-era device might not be consistent with the in-core metadata. In some cases, this can result in the corruption of the on-disk metadata. Suppose the following sequence of events: 1. Load a new table, e.g. a snapshot-origin table, to a device with a dm-era table 2. Suspend the device 3. dm-era commits its metadata, but the worker does a few more metadata writes until it stops, as part of digesting an archived writeset 4. These writes are cached by the dm-bufio client 5. Load the dm-era table to another device. 6. The new instance of the dm-era target loads the committed, on-disk metadata, which don't include the extra writes done by the worker after the metadata commit. 7. Resume the new device 8. The new dm-era target instance starts using the metadata 9. Resume the original device 10. The destructor of the old dm-era target instance is called and destroys the dm-bufio client, which results in flushing the cached writes to disk 11. These writes might overwrite the writes done by the new dm-era instance, hence corrupting its metadata. Fix this by committing the metadata after the worker stops running. stop_worker uses flush_workqueue to flush the current work. However, the work item may re-queue itself and flush_workqueue doesn't wait for re-queued works to finish. This could result in the worker changing the metadata after they have been committed, or writing to the metadata concurrently with the commit in the postsuspend thread. Use drain_workqueue instead, which waits until the work and all re-queued works finish. Fixes: eec40579d8487 ("dm: add era target") Cc: stable@vger.kernel.org # v3.15+ Signed-off-by: Nikos Tsironis Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-era-target.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -1396,7 +1396,7 @@ static void start_worker(struct era *era static void stop_worker(struct era *era) { atomic_set(&era->suspended, 1); - flush_workqueue(era->wq); + drain_workqueue(era->wq); } /*---------------------------------------------------------------- @@ -1566,6 +1566,12 @@ static void era_postsuspend(struct dm_ta } stop_worker(era); + + r = metadata_commit(era->md); + if (r) { + DMERR("%s: metadata_commit failed", __func__); + /* FIXME: fail mode */ + } } static int era_preresume(struct dm_target *ti)