From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11E32C4332B for ; Wed, 30 Dec 2020 13:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0781221FA for ; Wed, 30 Dec 2020 13:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbgL3NFQ (ORCPT ); Wed, 30 Dec 2020 08:05:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:53802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727368AbgL3NFN (ORCPT ); Wed, 30 Dec 2020 08:05:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3702F22573; Wed, 30 Dec 2020 13:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609333461; bh=61+iNcBDie/n0PCMCDmOO2PTfNTL/z08B+iuTNZh3GY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NfHuT8694daaJlepzn9o6xSbhRTws276RhGAaoNg+F6JPWeP9G2MSVXQrQZqzrQSF 2FokDsDC/Dao5p3qQ1eV9ib120Ji2yGo6oBp2cuBWTHwLXWvDmjTRsDSKp+odsM7SA O6oiO9vLRa+WfLtvg1IWZwUHfaQgNA+P8i+Et9b1kjjxJ5s5gSjPnmO0f6bru7oPSP STlavt9xONhsveWRMWOZPDoypDxJEk71gCZh9IwZJ3K2onoEdw8D9OD5chRAOTeaii +ebkBVQ1ejIc9raiq1SSz/ikcHViw5BlVAzUWi5bZyT8oPTVDiv/ArGIV1pOH3XnQg 8cqnqnvuIbUbg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hyeongseok Kim , Sami Tolvanen , Mike Snitzer , Sasha Levin , dm-devel@redhat.com Subject: [PATCH AUTOSEL 5.4 17/17] dm verity: skip verity work if I/O error when system is shutting down Date: Wed, 30 Dec 2020 08:03:57 -0500 Message-Id: <20201230130357.3637261-17-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201230130357.3637261-1-sashal@kernel.org> References: <20201230130357.3637261-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hyeongseok Kim [ Upstream commit 252bd1256396cebc6fc3526127fdb0b317601318 ] If emergency system shutdown is called, like by thermal shutdown, a dm device could be alive when the block device couldn't process I/O requests anymore. In this state, the handling of I/O errors by new dm I/O requests or by those already in-flight can lead to a verity corruption state, which is a misjudgment. So, skip verity work in response to I/O error when system is shutting down. Signed-off-by: Hyeongseok Kim Reviewed-by: Sami Tolvanen Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-verity-target.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 4fb33e7562c52..2aeb922e2365c 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -533,6 +533,15 @@ static int verity_verify_io(struct dm_verity_io *io) return 0; } +/* + * Skip verity work in response to I/O error when system is shutting down. + */ +static inline bool verity_is_system_shutting_down(void) +{ + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF + || system_state == SYSTEM_RESTART; +} + /* * End one "io" structure with a given error. */ @@ -560,7 +569,8 @@ static void verity_end_io(struct bio *bio) { struct dm_verity_io *io = bio->bi_private; - if (bio->bi_status && !verity_fec_is_enabled(io->v)) { + if (bio->bi_status && + (!verity_fec_is_enabled(io->v) || verity_is_system_shutting_down())) { verity_finish_io(io, bio->bi_status); return; } -- 2.27.0