Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2907396iog; Mon, 27 Jun 2022 05:32:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWz4PSJsqoHYpTAsKsJ0dydMJ7prQqo+aZPWa788uTYV7TcCoUIbF9kLq6BtdMbhBxPQ8J X-Received: by 2002:a17:902:d54b:b0:16b:7ea9:a765 with SMTP id z11-20020a170902d54b00b0016b7ea9a765mr4715872plf.4.1656333127485; Mon, 27 Jun 2022 05:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333127; cv=none; d=google.com; s=arc-20160816; b=0wH/Xh3ExDSL32t45LkQkvOCCAyCw3PCBuMk8+T30qGG1OUsBZyQ25KsXEVNP7DC6R H/0C6HPcj9EnZYpB7ktlg+voYERxqyufOMg8qvFBQ76bez8DDL7wlex5oTbxqF/KQ3Fr jzWVF8mpWq7DCQHwplKlY3q0jnsEKwRo9007PFzcjoDkPnyQkpRf+g+0kiD2/PVhUlLU Cm9c7oyFkFc9HK0mLApC0xxFQfl5a59y1GfaMJLlttC6stBfVed3gKauQo5Ut0dMO7eT xVC1hv2/m5Pt7v6G8wNy6v3MFnjNO4VgtxM5OAQbL5C5w5BZL27U1yJUdW1wQARW2R4Y tV8w== 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=q7gbQmQjiMAC9Ms3eKQwy6F+QNHa/dbgi48mKKS7b9k=; b=CQN069/vfgm7LZYCkBMNxGlNWxWDGBx0yYoF4dxS0ExeaBerX4oDpkGfs+L00FJ8g9 LPVIaCecPHRjXVOlJo9zY2USBzCsqnUlbuamX5jrFNzsc1DqX7NhjENOxt196cMPsXt2 ADAf2uddlCbVFYorouQarb1FkaK3dBxdL+pmnq0AcEhNYcIn5X5caxN/9eO6Y8g79jbD tJxC7cWyq746O+AiH2XxKiL1NA0SZtLiQayk+CPJGzxX/hflk+g+XkcHOvossupeCqjv 4Gw/dmZwIUMEMasVZpq/MGdX6FBMyHeP6wofYdzu5RZPZaoo3Np2MkK0YticGhjgYzkl CDnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=msKQhhZZ; 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 r17-20020a634411000000b00408d94d8198si13433582pga.119.2022.06.27.05.31.55; Mon, 27 Jun 2022 05:32:07 -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=msKQhhZZ; 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 S235916AbiF0Leq (ORCPT + 99 others); Mon, 27 Jun 2022 07:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236092AbiF0LdK (ORCPT ); Mon, 27 Jun 2022 07:33:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B19FBE2B; Mon, 27 Jun 2022 04:30:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5969E61510; Mon, 27 Jun 2022 11:30:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68236C3411D; Mon, 27 Jun 2022 11:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329414; bh=cuO2nTisTqBS0cLwTF9hisxzJeuL2o6+A2Rz7bYaU/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=msKQhhZZfmwNbaPw/bts5dgyCB2ZJKJ3ljYK5i5cN9kdYHUq5CYtEPpC6oo4O9W1L p3Cn0VIZ44oknn/RmKAW7KPOX6oZqnHAgviot11fcndA/YmO1YxSHic+xXpWDrRrSk GZUZ/SQW/N0G9kBqzUXMkox2o3wTLg2DQs4xBcXo= 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.4 11/60] dm era: commit metadata in postsuspend after worker stops Date: Mon, 27 Jun 2022 13:21:22 +0200 Message-Id: <20220627111927.985048485@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111927.641837068@linuxfoundation.org> References: <20220627111927.641837068@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 @@ -1397,7 +1397,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); } /*---------------------------------------------------------------- @@ -1581,6 +1581,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)