mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [PATCH v2 14/20] f2fs: support subpage blocks in fs-verity enablement
Date: Sun, 15 Nov 2026 20:08:45 -0800	[thread overview]
Message-ID: <20261116040851.2849696-15-daeho43@gmail.com> (raw)
In-Reply-To: <20261116040851.2849696-1-daeho43@gmail.com>

From: Daeho Jeong <daehojeong@google.com>

Check verity per block. While enabling verity, dirty and write back
only the data blocks below i_size in the folios before the verity
metadata. Do not zero the blocks past i_size on read while enabling
verity, since GC can read a folio of the verity metadata that is already
written. Remove the -EOPNOTSUPP checks. The changes for enabling
verity also apply to large folios when the block size equals PAGE_SIZE.

Stop the data reads of a verity file at i_size in
f2fs_read_data_large_folio(), so that the blocks past EOF in the folio
that spans EOF are zeroed instead of read. A pinned file can have such
blocks allocated without being zeroed, and fs-verity rejects non-zero
data past EOF. The reads of the verity metadata still go past i_size.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 fs/f2fs/data.c   | 29 +++++++++++++++++++++--------
 fs/f2fs/f2fs.h   |  5 +++++
 fs/f2fs/file.c   |  3 ---
 fs/f2fs/verity.c |  8 --------
 4 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index f23f29d45763..9f7f8214d10e 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1671,7 +1671,7 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
 static inline struct fsverity_info *f2fs_need_verity(const struct inode *inode,
 						     pgoff_t idx)
 {
-	if (idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE))
+	if (idx < F2FS_BLK_ALIGN(F2FS_SB(inode->i_sb), inode->i_size))
 		return fsverity_get_info(inode);
 	return NULL;
 }
@@ -2619,7 +2619,12 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
 static inline loff_t f2fs_readpage_limit(struct inode *inode)
 {
-	if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode))
+	/*
+	 * The verity metadata is past i_size. GC can read it while verity is
+	 * being enabled, so do not zero it.
+	 */
+	if (IS_ENABLED(CONFIG_FS_VERITY) &&
+	    (IS_VERITY(inode) || f2fs_verity_in_progress(inode)))
 		return F2FS_BLK_TO_BYTES(F2FS_I_SB(inode),
 				max_file_blocks(F2FS_I_SB(inode), inode));
 
@@ -2913,10 +2918,10 @@ static unsigned int f2fs_folio_valid_blocks(struct inode *inode,
 	pgoff_t last_lblk = F2FS_BLK_ALIGN(sbi, i_size_read(inode));
 	pgoff_t first_lblk = f2fs_folio_lblk(sbi, folio);
 
-	if (f2fs_verity_in_progress(inode))
-		return nr_blocks;
 	if (first_lblk < last_lblk)
 		return min_t(pgoff_t, nr_blocks, last_lblk - first_lblk);
+	if (f2fs_verity_in_progress(inode))
+		return nr_blocks;
 	return 0;
 }
 
@@ -3409,7 +3414,14 @@ static int f2fs_read_data_large_folio(struct inode *inode,
 	index = f2fs_folio_lblk(sbi, folio);
 	offset = 0;
 	nr_blocks = f2fs_blocks_per_folio(sbi, folio);
-	last_block_in_file = F2FS_BLK_ALIGN(sbi, f2fs_readpage_limit(inode));
+	/*
+	 * A data read of a verity file, which has vi, stops at i_size. A
+	 * pinned file can have blocks past EOF that were allocated without
+	 * being zeroed, and fs-verity rejects non-zero data past EOF. Only
+	 * the reads of the verity metadata, which have no vi, go past i_size.
+	 */
+	last_block_in_file = F2FS_BLK_ALIGN(sbi, vi ? i_size_read(inode) :
+					    f2fs_readpage_limit(inode));
 
 	for (; nr_blocks;
 	     nr_blocks -= len_blks, max_nr_blocks -= len_blks,
@@ -3719,7 +3731,7 @@ static int f2fs_read_data_folio(struct file *file, struct folio *folio)
 			return ret;
 	}
 
-	vi = f2fs_need_verity(inode, folio->index);
+	vi = f2fs_need_verity(inode, f2fs_folio_lblk(F2FS_I_SB(inode), folio));
 	if (vi)
 		fsverity_readahead(vi, folio->index, folio_nr_pages(folio));
 	return f2fs_mpage_readpages(inode, vi, NULL, folio);
@@ -3739,7 +3751,8 @@ static void f2fs_readahead(struct readahead_control *rac)
 	if (f2fs_has_inline_data(inode))
 		return;
 
-	vi = f2fs_need_verity(inode, readahead_index(rac));
+	vi = f2fs_need_verity(inode, F2FS_BYTES_TO_BLK(F2FS_I_SB(inode),
+						      readahead_pos(rac)));
 	if (vi)
 		fsverity_readahead(vi, readahead_index(rac),
 				   readahead_count(rac));
@@ -4777,7 +4790,7 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
 			op_locked = true;
 		}
 
-		if (!verity_in_progress) {
+		if (!verity_in_progress || end_pos <= f2fs_verity_metadata_pos(inode)) {
 			poff = offset_in_folio(folio, isize);
 			end_index = isize >> PAGE_SHIFT;
 
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index f588603dd1d0..f84d6f4cd1eb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -5349,6 +5349,11 @@ static inline bool f2fs_allow_multi_device_dio(struct f2fs_sb_info *sbi,
 	return sbi->aligned_blksize;
 }
 
+static inline loff_t f2fs_verity_metadata_pos(const struct inode *inode)
+{
+	return round_up(i_size_read(inode), 65536);
+}
+
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 extern int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,
 					unsigned long type, enum fault_option fo);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 26dd06961389..8540613e3b22 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4331,9 +4331,6 @@ static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg)
 {
 	struct inode *inode = file_inode(filp);
 
-	if (f2fs_has_subpage_blocks(F2FS_I_SB(inode)))
-		return -EOPNOTSUPP;
-
 	f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
 
 	if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) {
diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
index af1b7f21c1d8..5f579d0b917b 100644
--- a/fs/f2fs/verity.c
+++ b/fs/f2fs/verity.c
@@ -32,11 +32,6 @@
 
 #define F2FS_VERIFY_VER	(1)
 
-static inline loff_t f2fs_verity_metadata_pos(const struct inode *inode)
-{
-	return round_up(inode->i_size, 65536);
-}
-
 /*
  * Write some verity metadata to the inode for FS_IOC_ENABLE_VERITY.
  * kernel_write() can't be used because the file descriptor is readonly.
@@ -94,9 +89,6 @@ static int f2fs_begin_enable_verity(struct file *filp)
 	struct inode *inode = file_inode(filp);
 	int err;
 
-	if (f2fs_has_subpage_blocks(F2FS_I_SB(inode)))
-		return -EOPNOTSUPP;
-
 	if (f2fs_verity_in_progress(inode))
 		return -EBUSY;
 
-- 
2.56.0.611.g1030f0b940-goog


  parent reply	other threads:[~2026-11-16  4:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  4:08 [PATCH v2 00/20] f2fs: support block size smaller than PAGE_SIZE Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 01/20] f2fs: use block-based index and size calculations in more paths Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 02/20] f2fs: support subpage block size superblock and mount Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 03/20] f2fs: extend f2fs_folio_state for subpage blocks Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 04/20] f2fs: support subpage blocks in directory operations Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 05/20] f2fs: convert inode dirty page counters to dirty block counters Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 06/20] f2fs: support subpage blocks in data read path and GC Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 07/20] f2fs: support subpage blocks in data write path and writeback Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 08/20] f2fs: adapt range operations and mmap for subpage blocks Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 09/20] f2fs: support subpage blocks in pinned files Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 10/20] f2fs: support subpage blocks in collapse and insert range Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 11/20] f2fs: support subpage blocks in move range Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 12/20] f2fs: support subpage blocks in defragmentation Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 13/20] f2fs: support subpage blocks in swapfile activation Daeho Jeong
2026-11-16  4:08 ` Daeho Jeong [this message]
2026-11-16  4:08 ` [PATCH v2 15/20] f2fs: support subpage blocks in atomic writes Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 16/20] f2fs: preserve inline data in subpage block mode Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 17/20] f2fs: support subpage blocks in online resize Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 18/20] f2fs: support subpage blocks in compression Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 19/20] f2fs: count compress cache entries in pages for its memory limit Daeho Jeong
2026-11-16  4:08 ` [PATCH v2 20/20] f2fs: enable subpage block size support Daeho Jeong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116040851.2849696-15-daeho43@gmail.com \
    --to=daeho43@gmail.com \
    --cc=daehojeong@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®