From nobody Mon Feb 9 01:51:31 2026 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FBD61CD39; Fri, 23 Aug 2024 01:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724376842; cv=none; b=TydT+6nMfE1VB7zvCx3kSk1iqzSzya025LKHy8piuaZbo9hJIk+KGV/I85MUxXNcK0bjKr0CIGO+Bq6HP3BQrMD+zgQegBYQsI+iooXookgRAGAMeCJ4RqfWCtRi/+tFA91P6ww65HXJzrf2EvgSlnlhL+Fwbe1bR1G49RIZ/Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724376842; c=relaxed/simple; bh=wdiNS1NVUsFCdpAPH1x17L4nOv4E184Rt48nedcpfLc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=HMdacdXsfq3XPA1zFy1r125fnjIJXpd1r5UFxI8emlLQkvP9qxDgkPWjazwt4icpsjPMM03YRAYbB0va/qoFhxjdINK8pxV9ECl9dx9zT/Q9JVbuWf8a83uCfq4dTm6xbcki5GOd2qsq9xN8l/Zt5zKr6IFDYyUwVPhe4fT8XUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KOId8Pzq; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KOId8Pzq" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7cd830e0711so1396639a12.0; Thu, 22 Aug 2024 18:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724376840; x=1724981640; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OfkinVOCRqqx14ba0QNxtd1YpB4MXEXYboXHawxHb8w=; b=KOId8PzqKqijKvPpWLRd4UA69dmQGShiOdv8T4u1CMEiQ/Cp1ktkxuW37QKHY7e2BD xIDd3oXPsZnqjvZLZDB0a8M+f/v1HDFReS2fnZd6Y/OQdXkb5MrgERENvcht0lCbMrcp KRncyIQ93wuWVa2FSuZ26U7vh6yBiA1MqfLC6uz+JwTXELfcSQzy0vO9IhHeCtzilrO5 UVRv+reI3Qb/EVHVbbV5CwsNl9C2TD0GzkgsSx2bwD56EnIkKGOihMca9onINuZlZT/T A7bBX4rMuMmG8irt+45CwyET0xjHTyZtiFR5rVv86HsJNr5/UaT1DgN9yMEbe0Pgxxvp 0QqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724376840; x=1724981640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OfkinVOCRqqx14ba0QNxtd1YpB4MXEXYboXHawxHb8w=; b=GnvXJuuvptNTFrpLhAfZ/81kMOEY+mU9dE1aV2ySaY6AJAJ2sJFQhdUAQr2QjnbjtU tZzV1hCFvywLxVMhvGbfToJ4avEh6wfJShNw3LC5txs3PudEd4o1tShlV8a+SWvKE8i1 Uz+AnG+3697z6QHHx42LnfV+uhMLYHAhhaR8cMkMxjlgVn9FLB+0LOhExR+D/kMcn+Ft gEePKZkxNQQClFeKsqQWjuXZ+q8ET9gAAS3Ya5gBdcG75vR9HG2kUl9FbBRl2Tfvq+Hz iHo1yGu1nJSVJ0XzA/EVGXRKQ/66DcJSWxMLCjCd0Tve49tiHCPeM6HLeuxJA78H8K7r 9zHA== X-Forwarded-Encrypted: i=1; AJvYcCVU2lvEJG78FwUl77ipZ1ja3WruJj3/HmdSqEV1zMeEyPDQ+mk2XVOL1k7uIb8aslilgfi/dLGzeJuSCdw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzsqsa5k+cH0yqzt0OueWw3zEehYvisNoPcR2cE5viJkITvQxJh WguJOrpB7cjS8Cp+Mn3OsgykqbLNRXFCTOa0MFTVoko5tmdJuQv2 X-Google-Smtp-Source: AGHT+IEg2d7kQadVufNNOb92yEl6EjDz6nSaIh2etUdOnHIJkwXGrTEsu12juGse41XEXkBJMkcuIA== X-Received: by 2002:a05:6a20:2586:b0:1c4:8694:6be8 with SMTP id adf61e73a8af0-1cae51ad0a6mr7541533637.3.1724376839370; Thu, 22 Aug 2024 18:33:59 -0700 (PDT) Received: from localhost.localdomain ([163.53.18.10]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad6e334sm1735781a12.84.2024.08.22.18.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 18:33:59 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Jan Kara Subject: [PATCH 1/2] ext4: hoist ext4_block_write_begin and replace the __block_write_begin Date: Fri, 23 Aug 2024 09:33:28 +0800 Message-Id: <20240823013329.1996741-2-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823013329.1996741-1-zhangshida@kylinos.cn> References: <20240823013329.1996741-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Shida Zhang Using __block_write_begin() make it inconvenient to journal the user data dirty process. We can't tell the block layer maintainer, =E2=80=98Hey, we want to trace the dirty user data in ext4, can we add some special code for ext4 in __block_write_begin?=E2=80=99:P So use ext4_block_write_begin() instead. The two functions are basically doing the same thing except for the fscrypt related code. Narrow the scope of CONFIG_FS_ENCRYPTION so as to allow ext4_block_write_begin() to function like __block_write_begin when the config is disabled. And hoist the ext4_block_write_begin so that it can be used in other files. Suggested-by: Jan Kara Signed-off-by: Shida Zhang Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 2 ++ fs/ext4/inline.c | 10 +++++----- fs/ext4/inode.c | 23 ++++++----------------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 08acd152261e..5f8257b68190 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3851,6 +3851,8 @@ static inline int ext4_buffer_uptodate(struct buffer_= head *bh) return buffer_uptodate(bh); } =20 +extern int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigne= d len, + get_block_t *get_block); #endif /* __KERNEL__ */ =20 #define EFSBADCRC EBADMSG /* Bad CRC detected */ diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index e7a09a99837b..0a1a8431e281 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -601,10 +601,10 @@ static int ext4_convert_inline_data_to_extent(struct = address_space *mapping, goto out; =20 if (ext4_should_dioread_nolock(inode)) { - ret =3D __block_write_begin(&folio->page, from, to, - ext4_get_block_unwritten); + ret =3D ext4_block_write_begin(folio, from, to, + ext4_get_block_unwritten); } else - ret =3D __block_write_begin(&folio->page, from, to, ext4_get_block); + ret =3D ext4_block_write_begin(folio, from, to, ext4_get_block); =20 if (!ret && ext4_should_journal_data(inode)) { ret =3D ext4_walk_page_buffers(handle, inode, @@ -856,8 +856,8 @@ static int ext4_da_convert_inline_data_to_extent(struct= address_space *mapping, goto out; } =20 - ret =3D __block_write_begin(&folio->page, 0, inline_size, - ext4_da_get_block_prep); + ret =3D ext4_block_write_begin(folio, 0, inline_size, + ext4_da_get_block_prep); if (ret) { up_read(&EXT4_I(inode)->xattr_sem); folio_unlock(folio); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 941c1c0d5c6e..6b15805ca88b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1041,9 +1041,8 @@ int do_journal_get_write_access(handle_t *handle, str= uct inode *inode, return ret; } =20 -#ifdef CONFIG_FS_ENCRYPTION -static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigne= d len, - get_block_t *get_block) +int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, + get_block_t *get_block) { unsigned from =3D pos & (PAGE_SIZE - 1); unsigned to =3D from + len; @@ -1119,7 +1118,9 @@ static int ext4_block_write_begin(struct folio *folio= , loff_t pos, unsigned len, } if (unlikely(err)) { folio_zero_new_buffers(folio, from, to); - } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { + } +#ifdef CONFIG_FS_ENCRYPTION + else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { for (i =3D 0; i < nr_wait; i++) { int err2; =20 @@ -1131,10 +1132,10 @@ static int ext4_block_write_begin(struct folio *fol= io, loff_t pos, unsigned len, } } } +#endif =20 return err; } -#endif =20 /* * To preserve ordering, it is essential that the hole instantiation and @@ -1216,19 +1217,11 @@ static int ext4_write_begin(struct file *file, stru= ct address_space *mapping, /* In case writeback began while the folio was unlocked */ folio_wait_stable(folio); =20 -#ifdef CONFIG_FS_ENCRYPTION if (ext4_should_dioread_nolock(inode)) ret =3D ext4_block_write_begin(folio, pos, len, ext4_get_block_unwritten); else ret =3D ext4_block_write_begin(folio, pos, len, ext4_get_block); -#else - if (ext4_should_dioread_nolock(inode)) - ret =3D __block_write_begin(&folio->page, pos, len, - ext4_get_block_unwritten); - else - ret =3D __block_write_begin(&folio->page, pos, len, ext4_get_block); -#endif if (!ret && ext4_should_journal_data(inode)) { ret =3D ext4_walk_page_buffers(handle, inode, folio_buffers(folio), from, to, @@ -2961,11 +2954,7 @@ static int ext4_da_write_begin(struct file *file, st= ruct address_space *mapping, if (IS_ERR(folio)) return PTR_ERR(folio); =20 -#ifdef CONFIG_FS_ENCRYPTION ret =3D ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep); -#else - ret =3D __block_write_begin(&folio->page, pos, len, ext4_da_get_block_pre= p); -#endif if (ret < 0) { folio_unlock(folio); folio_put(folio); --=20 2.33.0 From nobody Mon Feb 9 01:51:31 2026 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CAB720314; Fri, 23 Aug 2024 01:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724376847; cv=none; b=JdjYmxjBJBsjslK5fqvOJQ3Zxkp4DnH8oQWuyE/hkgJ5b5+uGzRxAynhaHWsOzAuP/JZP3bis2SKuHgq9t/LGc3591ijkRKGpkroT9jWuiD6vQJvHcpX84RwsPLIVIuAA7QooXwVR2L6gct6/L8vQDLXHEw50qptPt5ldjHiNl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724376847; c=relaxed/simple; bh=RkuvIMkclvFPD0SfbQ0lukE1nGNH6KOgpTMJO2EH9vE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tv5MRQvVdH4mR83M4/+aG3BDwacDWhtg/DTALXTxg/CzdcEtOLthvRUDX3c2ValR2LeF09b4BKOPr08/sajx+RsRyOO9g86YZeAfIqz6WkMqNwhL5NVVva7Wo/OxxOtW6vmXO2xfK9QloVKE0Vgxy1DOD8OPmEBX/ei8b7zOBUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EnIgDhby; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EnIgDhby" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5dcad9845b4so1089858eaf.2; Thu, 22 Aug 2024 18:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724376844; x=1724981644; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z1fH1Ho4GcX3EGjEBqcsALQduBlTVXsfPzay7ElzmRk=; b=EnIgDhbycdT4gl+M+Xak78AzvDOiZ6cuele4jXfR+aluAIcFwxcWtNdkAHLbaPA9wL bqx8w2tgajChhduUPfsgBZ7CN9KlkG4H1CJC7HR6xiGMdMoFLhSSuYO21RXT6cskUPKh U8mr7PSGUewVbo2yEvlb7GynON00JTqKoXGuUJd8W/K1sFyrRxz24Iaxfg67cFSG/I5R yQKC1uagtVkJ2gV9J2Vwsdqnw19rgMkIPxefGyU1bn5UcdCFwz+Ha5zx42pQt6+TURnO Pfcn2iA/nRteqIEdTZNZlfglN04tro4W+UoxHT1JPRQcSwngWjp1BUMl/P2shJ47rFby ag+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724376844; x=1724981644; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z1fH1Ho4GcX3EGjEBqcsALQduBlTVXsfPzay7ElzmRk=; b=gHPTUSxe++AN0FTZyUDFvnz5O/P8WbqwXuEsE0NXhv3sgLKAARQblP/vKWio8KuV1s hA3IYX2am9W3ZFghmwgOIAGvO4vlSZUavVDcUYmZLWbhI6f8/G2UH/C8nyMgPz50ZL5o 9PZJqi6I0UucYhC+2nmayZnsnXNt/lE7VYUqnRoY97YHyNfKW4vMJu9gvUbxVZxsBVeK BidCZYGxsxZdpjPV2aCZMh5tL8Q3InqjsUikxFsn3b1pPxfFJ42PUUrEgkT7SSy/p5wn Nd/txo1xEf0cZ3s9zyBitDZgwUlQT/GCltFVD9mhWY4YCfKMo6pIn9955N36JHMWNqY0 vrtA== X-Forwarded-Encrypted: i=1; AJvYcCVH/Q26qsb9hM+99NUnvMvsQe9s+KtjMYKA70RHq2NDOC85H2yBfWv9xUIQuq8ugFy8gEI9ipVfVc6+P/M=@vger.kernel.org X-Gm-Message-State: AOJu0YywtRF+HROfFqNeEI6cL2b3tekjSDxhYFe9F6hKwsP0rk1yVou2 xjdjfJPsgCHwTZSZ5iGq8tgJstkMCn2WPFoCZleBeqgF6Db1AnX/ X-Google-Smtp-Source: AGHT+IEJUd/FoXCyRCHI7KTlM3uspFbNook0Fyprx5/XcBi2eKFkl+xtVR4pOYOY5o+3pBQ6IR9NXQ== X-Received: by 2002:a05:6358:7e53:b0:1a6:7e01:e4f4 with SMTP id e5c5f4694b2df-1b5c22e99e2mr110823955d.28.1724376844083; Thu, 22 Aug 2024 18:34:04 -0700 (PDT) Received: from localhost.localdomain ([163.53.18.10]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad6e334sm1735781a12.84.2024.08.22.18.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 18:34:03 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Baolin Liu , Jan Kara Subject: [PATCH 2/2] ext4: fix a potential assertion failure due to improperly dirtied buffer Date: Fri, 23 Aug 2024 09:33:29 +0800 Message-Id: <20240823013329.1996741-3-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823013329.1996741-1-zhangshida@kylinos.cn> References: <20240823013329.1996741-1-zhangshida@kylinos.cn> 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 Content-Type: text/plain; charset="utf-8" From: Shida Zhang On an old kernel version(4.19, ext3, data=3Djournal, pagesize=3D64k), an assertion failure will occasionally be triggered by the line below: Reported-by: Baolin Liu Suggested-by: Jan Kara ----------- jbd2_journal_commit_transaction { ... J_ASSERT_BH(bh, !buffer_dirty(bh)); /* * The buffer on BJ_Forget list and not jbddirty means ... } ----------- The same condition may also be applied to the lattest kernel version. When blocksize < pagesize and we truncate a file, there can be buffers in the mapping tail page beyond i_size. These buffers will be filed to transaction's BJ_Forget list by ext4_journalled_invalidatepage() during truncation. When the transaction doing truncate starts committing, we can grow the file again. This calls __block_write_begin() which allocates new blocks under these buffers in the tail page we go through the branch: if (buffer_new(bh)) { clean_bdev_bh_alias(bh); if (folio_test_uptodate(folio)) { clear_buffer_new(bh); set_buffer_uptodate(bh); mark_buffer_dirty(bh); continue; } ... } Hence buffers on BJ_Forget list of the committing transaction get marked dirty and this triggers the jbd2 assertion. Teach ext4_block_write_begin() to properly handle files with data journalling by avoiding dirtying them directly. Instead of folio_zero_new_buffers() we use ext4_journalled_zero_new_buffers() which takes care of handling journalling. We also don't need to mark new uptodate buffers as dirty in ext4_block_write_begin(). That will be either done either by block_commit_write() in case of success or by folio_zero_new_buffers() in case of failure. Reported-by: Baolin Liu Suggested-by: Jan Kara Signed-off-by: Shida Zhang --- fs/ext4/ext4.h | 3 ++- fs/ext4/inline.c | 7 ++++--- fs/ext4/inode.c | 30 ++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 5f8257b68190..b653bd423b11 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3851,7 +3851,8 @@ static inline int ext4_buffer_uptodate(struct buffer_= head *bh) return buffer_uptodate(bh); } =20 -extern int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigne= d len, +extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, + loff_t pos, unsigned len, get_block_t *get_block); #endif /* __KERNEL__ */ =20 diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 0a1a8431e281..8d5599d5af27 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -601,10 +601,11 @@ static int ext4_convert_inline_data_to_extent(struct = address_space *mapping, goto out; =20 if (ext4_should_dioread_nolock(inode)) { - ret =3D ext4_block_write_begin(folio, from, to, + ret =3D ext4_block_write_begin(handle, folio, from, to, ext4_get_block_unwritten); } else - ret =3D ext4_block_write_begin(folio, from, to, ext4_get_block); + ret =3D ext4_block_write_begin(handle, folio, from, to, + ext4_get_block); =20 if (!ret && ext4_should_journal_data(inode)) { ret =3D ext4_walk_page_buffers(handle, inode, @@ -856,7 +857,7 @@ static int ext4_da_convert_inline_data_to_extent(struct= address_space *mapping, goto out; } =20 - ret =3D ext4_block_write_begin(folio, 0, inline_size, + ret =3D ext4_block_write_begin(NULL, folio, 0, inline_size, ext4_da_get_block_prep); if (ret) { up_read(&EXT4_I(inode)->xattr_sem); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6b15805ca88b..4c34827da56e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -49,6 +49,11 @@ =20 #include =20 +static void ext4_journalled_zero_new_buffers(handle_t *handle, + struct inode *inode, + struct folio *folio, + unsigned from, unsigned to); + static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw, struct ext4_inode_info *ei) { @@ -1041,7 +1046,8 @@ int do_journal_get_write_access(handle_t *handle, str= uct inode *inode, return ret; } =20 -int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, +int ext4_block_write_begin(handle_t *handle, struct folio *folio, + loff_t pos, unsigned len, get_block_t *get_block) { unsigned from =3D pos & (PAGE_SIZE - 1); @@ -1055,6 +1061,7 @@ int ext4_block_write_begin(struct folio *folio, loff_= t pos, unsigned len, struct buffer_head *bh, *head, *wait[2]; int nr_wait =3D 0; int i; + bool should_journal_data =3D ext4_should_journal_data(inode); =20 BUG_ON(!folio_test_locked(folio)); BUG_ON(from > PAGE_SIZE); @@ -1083,11 +1090,11 @@ int ext4_block_write_begin(struct folio *folio, lof= f_t pos, unsigned len, err =3D get_block(inode, block, bh, 1); if (err) break; + if (should_journal_data) + do_journal_get_write_access(handle, inode, bh); if (buffer_new(bh)) { if (folio_test_uptodate(folio)) { - clear_buffer_new(bh); set_buffer_uptodate(bh); - mark_buffer_dirty(bh); continue; } if (block_end > to || block_start < from) @@ -1117,7 +1124,11 @@ int ext4_block_write_begin(struct folio *folio, loff= _t pos, unsigned len, err =3D -EIO; } if (unlikely(err)) { - folio_zero_new_buffers(folio, from, to); + if (should_journal_data) + ext4_journalled_zero_new_buffers(handle, inode, folio, + from, to); + else + folio_zero_new_buffers(folio, from, to); } #ifdef CONFIG_FS_ENCRYPTION else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { @@ -1218,10 +1229,11 @@ static int ext4_write_begin(struct file *file, stru= ct address_space *mapping, folio_wait_stable(folio); =20 if (ext4_should_dioread_nolock(inode)) - ret =3D ext4_block_write_begin(folio, pos, len, + ret =3D ext4_block_write_begin(handle, folio, pos, len, ext4_get_block_unwritten); else - ret =3D ext4_block_write_begin(folio, pos, len, ext4_get_block); + ret =3D ext4_block_write_begin(handle, folio, pos, len, + ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { ret =3D ext4_walk_page_buffers(handle, inode, folio_buffers(folio), from, to, @@ -2954,7 +2966,8 @@ static int ext4_da_write_begin(struct file *file, str= uct address_space *mapping, if (IS_ERR(folio)) return PTR_ERR(folio); =20 - ret =3D ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep); + ret =3D ext4_block_write_begin(NULL, folio, pos, len, + ext4_da_get_block_prep); if (ret < 0) { folio_unlock(folio); folio_put(folio); @@ -6208,7 +6221,8 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) if (folio_pos(folio) + len > size) len =3D size - folio_pos(folio); =20 - err =3D __block_write_begin(&folio->page, 0, len, ext4_get_block); + err =3D ext4_block_write_begin(handle, folio, 0, len, + ext4_get_block); if (!err) { ret =3D VM_FAULT_SIGBUS; if (ext4_journal_folio_buffers(handle, folio, len)) --=20 2.33.0