From nobody Fri Dec 19 10:50:32 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3041715350B; Fri, 14 Mar 2025 07:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741938278; cv=none; b=sxFRjlo+hoGFlmqOhVXSYrUN3u9Xm1m+pbTm49UI8Ifx5slDvArQ6zN2JCw4z02XVcry70gNi7qQudnmO0usdcXqWpoRnzRE4osUMySX82zw5EPO+z7CUz77rM41GrpEEo742W3r0GTUOXd5qFCnS35TlvPOAuC2YZJ5NyBsC/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741938278; c=relaxed/simple; bh=XPhEZgZVhi3XbjMujJuvrYrqXR4THiKCRiorg6BtSJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JPbonaj4Hjqh1YhmaCuzf7EHeDYKbd43V3cX/L7G8mTqxfnln8YLzBi2XXpBoZn7x9bzdI6vAyzcD5PaiqS4T8OpRlHCysth8lWkWIQv3ksKkwGPmmVq80r2cv4IjlSz1V1UyfUO1eA+EZuxP5oKzUBSuG3Sd+q5qB3KQn5ilLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ax/01A6c; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ax/01A6c" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DNPANW032481; Fri, 14 Mar 2025 07:44:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=KMW5jMY7RmYyG8F2N 1NffrMddU+AWRHw8CPczXyW4iQ=; b=ax/01A6cCMv43HoAKS8JPuap2hh2mSdAh VNjNtDsrmX+H/InPiIBiU0dRMLF4F1LtPhfGmJ+fi6wbCWJP24vlqexNuMdWmO9Z SngZvJVJtfFAhpb+A4zWnY3cAXwz30h7N9Uuv6tGP/KFdK9vIQsno48VD+nY9ObN 7ZGDwbVxw5u0wFDQ9bOeLEFALW7SLPjdMWZjqT45kH26Opa4jPEnhD85mSTz3xxG 8GbpSzvK81pdhYCIPmGqOHOwC3CRB0OQvrnmmI9QpBuDF9XyUpl28tS2UypwvCWw hhCxH4N8378HaqCk4g4q2pVdkaN5EN5Nmm7+D/UQCHLnu071HwKtg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hptbgn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 07:44:28 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52E7fLh0009928; Fri, 14 Mar 2025 07:44:27 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hptbgk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 07:44:27 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E48Fe2012311; Fri, 14 Mar 2025 07:44:27 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45atsrnuat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 07:44:26 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52E7iPvt45810106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 07:44:25 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0453B20043; Fri, 14 Mar 2025 07:44:25 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA99E2004B; Fri, 14 Mar 2025 07:44:21 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.24.194]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 07:44:21 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Jan Kara , Baokun Li , Ritesh Harjani , linux-kernel@vger.kernel.org, Mahesh Kumar Subject: [PATCH v3 2/3] ext4: avoid journaling sb update on error if journal is destroying Date: Fri, 14 Mar 2025 13:14:10 +0530 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DUS-CeE-yyLaUWcnezMoMshJf2_twk2H X-Proofpoint-ORIG-GUID: OSynhhKYz7sTrI0z0Gt_oGVuN9Hu0yAB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_03,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140058 Content-Type: text/plain; charset="utf-8" Presently we always BUG_ON if trying to start a transaction on a journal ma= rked with JBD2_UNMOUNT, since this should never happen. However, while ltp runni= ng stress tests, it was observed that in case of some error handling paths, it= is possible for update_super_work to start a transaction after the journal is destroyed eg: (umount) ext4_kill_sb kill_block_super generic_shutdown_super sync_filesystem /* commits all txns */ evict_inodes /* might start a new txn */ ext4_put_super flush_work(&sbi->s_sb_upd_work) /* flush the workqueue */ jbd2_journal_destroy journal_kill_thread journal->j_flags |=3D JBD2_UNMOUNT; jbd2_journal_commit_transaction jbd2_journal_get_descriptor_buffer jbd2_journal_bmap ext4_journal_bmap ext4_map_blocks ... ext4_inode_error ext4_handle_error schedule_work(&sbi->s_sb_upd_work) /* work queue kicks in */ update_super_work jbd2_journal_start start_this_handle BUG_ON(journal->j_flag= s & JBD2_UNMOUNT) Hence, introduce a new mount flag to indicate journal is destroying and onl= y do a journaled (and deferred) update of sb if this flag is not set. Otherwise,= just fallback to an un-journaled commit. Further, in the journal destroy path, we have the following sequence: 1. Set mount flag indicating journal is destroying 2. force a commit and wait for it 3. flush pending sb updates This sequence is important as it ensures that, after this point, there is n= o sb update that might be journaled so it is safe to update the sb outside the journal. (To avoid race discussed in 2d01ddc86606) Also, we don't need a similar check in ext4_grp_locked_error since it is on= ly called from mballoc and AFAICT it would be always valid to schedule work he= re. Fixes: 2d01ddc86606 ("ext4: save error info to sb through journal if availa= ble") Reported-by: Mahesh Kumar Signed-off-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 1 + fs/ext4/ext4_jbd2.h | 15 +++++++++++++++ fs/ext4/super.c | 12 ++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2b7d781bfcad..ee54b8510791 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1179,6 +1179,7 @@ struct ext4_inode_info { #define EXT4_ERROR_FS 0x0002 /* Errors detected */ #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ #define EXT4_FC_REPLAY 0x0020 /* Fast commit replay ongoing */ +#define EXT4_JOURNAL_DESTORY 0x0040 /* Journal is in process of destroyin= g */ =20 /* * Misc. filesystem flags diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 9b3c9df02a39..f054db9fa9e1 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -437,6 +437,21 @@ static inline int ext4_journal_destroy(struct ext4_sb_= info *sbi, journal_t *jour { int err =3D 0; =20 + /* + * At this point only two things can be operating on the journal. + * JBD2 thread performing transaction commit and s_sb_upd_work + * issuing sb update through the journal. Once we set + * EXT4_JOURNAL_DESTROY, new ext4_handle_error() calls will not + * queue s_sb_upd_work and ext4_force_commit() makes sure any + * ext4_handle_error() calls from the running transaction commit are + * finished. Hence no new s_sb_upd_work can be queued after we + * flush it here. + */ + ext4_set_mount_flag(sbi->s_sb, EXT4_JOURNAL_DESTORY); + + ext4_force_commit(sbi->s_sb); + flush_work(&sbi->s_sb_upd_work); + err =3D jbd2_journal_destroy(journal); sbi->s_journal =3D NULL; =20 diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 8ad664d47806..54ef0cc566a4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -704,9 +704,13 @@ static void ext4_handle_error(struct super_block *sb, = bool force_ro, int error, * In case the fs should keep running, we need to writeout * superblock through the journal. Due to lock ordering * constraints, it may not be safe to do it right here so we - * defer superblock flushing to a workqueue. + * defer superblock flushing to a workqueue. We just need to be + * careful when the journal is already shutting down. If we get + * here in that case, just update the sb directly as the last + * transaction won't commit anyway. */ - if (continue_fs && journal) + if (continue_fs && journal && + !ext4_test_mount_flag(sb, EXT4_JOURNAL_DESTORY)) schedule_work(&EXT4_SB(sb)->s_sb_upd_work); else ext4_commit_super(sb); @@ -4957,8 +4961,6 @@ static int ext4_load_and_init_journal(struct super_bl= ock *sb, return 0; =20 out: - /* flush s_sb_upd_work before destroying the journal. */ - flush_work(&sbi->s_sb_upd_work); ext4_journal_destroy(sbi, sbi->s_journal); return -EINVAL; } @@ -5648,8 +5650,6 @@ failed_mount8: __maybe_unused sbi->s_ea_block_cache =3D NULL; =20 if (sbi->s_journal) { - /* flush s_sb_upd_work before journal destroy. */ - flush_work(&sbi->s_sb_upd_work); ext4_journal_destroy(sbi, sbi->s_journal); } failed_mount3a: --=20 2.48.1