Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp908942yba; Thu, 18 Apr 2019 11:36:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpVgqIxXYL0+7oIn4bBFnmitJ3p/vMyRoe+MYNTInTxebB/aoJcHLG4s0MLYzQ+litLVeN X-Received: by 2002:a17:902:8a81:: with SMTP id p1mr98110346plo.106.1555612594844; Thu, 18 Apr 2019 11:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555612594; cv=none; d=google.com; s=arc-20160816; b=AQNlm+ROjmqrs3wQElG7m5Q3qsMaDes7fQJM+6Giqhm1gAz0jlV5bX1hfInVIzhJd4 7Dlq9prrKb9Mhmrirf0Pm4cjGqrSQO97ALZ9mmbnrTLprCEarVPPm+TDdqcxNplUUpKm DdIM0F8S5lWkjzl2hV7TwEdCDlWF71PB3MsNoFmazPBPFP1semB49kJ/qrGaP9q1lzNf 9eK+WTsMYY1nRvXDfak+b2C3s0FY0TKedmcOwoHF5d/Rgz5CBfaOGhXCl01L2VFmcW44 WKhO/AdBJSGLGQA0/OlSeAGuf1fpbnwYnPx5y8Ce/wdWd5v9F/wcBaPYS7dawhtlRro0 rSsg== 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=+b2+qL+E8dZZDCKdY8OYIsP6/usT0CkDiV87oLjP7bY=; b=d+q6NsJ5alamSt92L/pCqm3JEDt957wfOBcHolzaYj9mK5VfTTMyC793fSQXXNFwF+ GsU/vvn8nE9kyE06oaSlxuQzva4u8z5Sz1IcBlxCF2VEmA9Ygc2X2oEd3YdIELj7h+ac uahIPfvR23PXF5gIAXLlpwNfHSa5XKpjeeIbKpltPrIOM+H2BMpJTAInD7RWFlAymhzp Wlh7+pRgzaYmCgg8BIeRUZuRzo6yiNvlDmcPiIeWBSMFqufD/sT/QCbV16AKefHI9Tmi IRRFZweObynaKNQppby/tF6mZJVtBessmJPOnJYwNQ6WzEGw8vEuhZrqClbN1N4DkfYn ni1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ss/Nqm1B"; 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 x30si2540076pgl.477.2019.04.18.11.36.19; Thu, 18 Apr 2019 11:36:34 -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="ss/Nqm1B"; 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 S2390012AbfDRR67 (ORCPT + 99 others); Thu, 18 Apr 2019 13:58:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:53260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389970AbfDRR6y (ORCPT ); Thu, 18 Apr 2019 13:58:54 -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 90D88206B6; Thu, 18 Apr 2019 17:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610334; bh=5etP62I2jgDL9zKcS21vh6Zxa5k2fwu2FFN3zO6pnFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ss/Nqm1B/ti5cpBIM6ifAV0rDSEew2Cmqa8GalLUkX518P31VS+lUypCaRRWEAR+n PhiZ4NHJ7sF6ZZhV4p6vmQ2YG6mz3VIZOP0LoZNAoAAoiJnSbFoyKYa/+t4ZuR+UoS 7A7ag2On8V+SD0rPDtR+9xou96rZR8CGfxpjnmNA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 4.19 006/110] ext4: avoid panic during forced reboot Date: Thu, 18 Apr 2019 19:55:55 +0200 Message-Id: <20190418160438.046449277@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160437.484158340@linuxfoundation.org> References: <20190418160437.484158340@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 [ Upstream commit 1dc1097ff60e4105216da7cd0aa99032b039a994 ] When admin calls "reboot -f" - i.e., does a hard system reboot by directly calling reboot(2) - ext4 filesystem mounted with errors=panic can panic the system. This happens because the underlying device gets disabled without unmounting the filesystem and thus some syscall running in parallel to reboot(2) can result in the filesystem getting IO errors. This is somewhat surprising to the users so try improve the behavior by switching to errors=remount-ro behavior when the system is running reboot(2). Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/super.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index a1cf7d68b4f0..abba7ece78e9 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -430,6 +430,12 @@ static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn) spin_unlock(&sbi->s_md_lock); } +static bool system_going_down(void) +{ + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF + || system_state == SYSTEM_RESTART; +} + /* Deal with the reporting of failure conditions on a filesystem such as * inconsistencies detected or read IO failures. * @@ -460,7 +466,12 @@ static void ext4_handle_error(struct super_block *sb) if (journal) jbd2_journal_abort(journal, -EIO); } - if (test_opt(sb, ERRORS_RO)) { + /* + * We force ERRORS_RO behavior when system is rebooting. Otherwise we + * could panic during 'reboot -f' as the underlying device got already + * disabled. + */ + if (test_opt(sb, ERRORS_RO) || system_going_down()) { ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); /* * Make sure updated value of ->s_mount_flags will be visible @@ -468,8 +479,7 @@ static void ext4_handle_error(struct super_block *sb) */ smp_wmb(); sb->s_flags |= SB_RDONLY; - } - if (test_opt(sb, ERRORS_PANIC)) { + } else if (test_opt(sb, ERRORS_PANIC)) { if (EXT4_SB(sb)->s_journal && !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR)) return; -- 2.19.1