fsverity: lift ioctl() input masking and runtime inode flag to VFS
Subsystems (8)
v3 cover fsverity: lift ioctl() input masking and runtime inode flag to VFS
Hi folks,
This patchset lifts two things from filesystems to VFS level:
- No-op'ing FS_VERITY_FL in FS_IOC_SETFLAGS ioctl()
- Runtime fsverity construction flag on inode
The second patch fixes BTRFS get-modify-set loop with FS_IOC_GETFLAGS/SETFLAGS ioctl()s, as it does return fsverity flag but not mask it out.
Testing, -g verity passes for all fs, except btrfs/277 and btrfs+generic/574.
The btrfs/277 seems to fail due to difference between what kernel and userspace versions support (btrfs-progs v7.1 doesn't seem to support latest streams v3).
The generic/574 on BTRFS fails only for 1024 block size no matter the change (fails on v7.3 too). I haven't checked why.
Based on v7.3-rc3.
Changes in v3:
- Add comment that I_VERITY_BUILDING is set over enable
- Revert comment changes in ext4 and f2fs
- Added I_VERITY_BUILDING to show_inode_state()
- Updated comment in begin_enable; dropped -EBUSY
- Added patch changing inode_state_read_once() to const
- Use fsverity_is_building() around ->begin_enable() call
- Use fsverity_is_building() in iomap
Changes in v2:
- Return ret in btrfs_begin_enable_verity()
- Include linux-fsdevel
Andrey Albershteyn (7):
fs: constify inode argument of inode_state_read_once()
fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS fs,fsverity: add I_VERITY_BUILDING inode state flag
iomap: use fsverity_is_building() to check for fsverity IO
btrfs: use I_VERITY_BUILDING instead of private flags
ext4: use I_VERITY_BUILDING instead of private flags
f2fs: use I_VERITY_BUILDING instead of private flags
fs/btrfs/btrfs_inode.h | 7 ------- fs/btrfs/verity.c | 12 ++---------- fs/ext4/ext4.h | 7 ------- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 17 +++++++++-------- fs/ext4/ioctl.c | 3 +-- fs/ext4/verity.c | 19 ++++++------------- fs/f2fs/data.c | 10 +++++----- fs/f2fs/f2fs.h | 7 ------- fs/f2fs/verity.c | 12 +++--------- fs/file_attr.c | 10 ++++++++++ fs/iomap/buffered-io.c | 2 +- fs/verity/enable.c | 22 +++++++++++++++++++--- include/linux/fs.h | 8 +++++++- include/linux/fsverity.h | 26 ++++++++++++++++++++++++-- include/trace/events/writeback.h | 3 ++- 16 files changed, 90 insertions(+), 77 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/7 fs: constify inode argument of inode_state_read_once()
Constify inode parameter so that callers can pass const inode. Callers do not need a change.
--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs.h +1 -1
@@ -878,7 +878,7 @@ struct inode {* * We hide all of it behind helpers so that we can validate consumers. */ -static inline enum inode_state_flags_enum inode_state_read_once (struct inode *inode) +static inline enum inode_state_flags_enum inode_state_read_once (const struct inode *inode) {return READ_ONCE (inode->i_state.__state); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 1/7] fs: constify inode argument of inode_state_read_once()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Constify inode parameter so that callers can pass const inode. Callers do not need a change.
Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 1/7] fs: constify inode argument of inode_state_read_once()
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 4 lines
Constify inode parameter so that callers can pass const inode. Callers do not need a change.
Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/7 fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS
In reply to Andrey AlbershteynThe common use of FS_IOC_GETFLAGS/SETFLAGS is get-modify-set loop. Filesystems could return verity status with GETFLAGS, attempting to then pass FS_VERITY_FL to SETFLAGS is not allowed.
The ext4 and f2fs already treat FS_VERITY_FL in the set path as no-op, however, BTRFS returns -EOPNOTSUPP. So, the modification of other flags doesn't work on BTRFS for fsverity inodes.
Fix it for BTRFS and anyone else, the ext4 and f2fs masking becomes no-op. The file_get/setattr() path is fine here as this flag is cleared right before fileattr_set_prepare(). The future fsverity support in XFS would also need it.
--- fs/file_attr.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/file_attr.c +10 -0
@@ -199,6 +199,16 @@ static int fileattr_set_prepare(struct inode *inode,if (err)return err; +/* +* FS_VERITY_FL is settable only via FS_IOC_ENABLE_VERITY; never through +* fileattr +* +* Treat it as a no-op so the FS_IOC_GETFLAGS/SETFLAGS round-trip +* doesn't break for other flags +*/ + fa->flags &= ~FS_VERITY_FL ; + fa->fsx_xflags &= ~FS_XFLAG_VERITY ; +/* * Project Quota ID state is only allowed to change from within the init * namespace. Enforce that restriction only if we are trying to change
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 2/7] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
The common use of FS_IOC_GETFLAGS/SETFLAGS is get-modify-set loop. Filesystems could return verity status with GETFLAGS, attempting to then pass
FS_VERITY_FLto SETFLAGS is not allowed.The ext4 and f2fs already treat
FS_VERITY_FLin the set path as no-op, however, BTRFS returns-EOPNOTSUPP. So, the modification of other flags doesn't work on BTRFS for fsverity inodes.Fix it for BTRFS and anyone else, the ext4 and f2fs masking becomes no-op. The file_get/setattr() path is fine here as this flag is cleared right before
fileattr_set_prepare(). The future fsverity support in XFS would also need it.
Quoted 4 lines
Cc Boris Burkov <[email protected]>Cc David Sterba <[email protected]>Fixes 146054090b08 ("btrfs: initial fsverity support")Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 2/7] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 13 lines
The common use of FS_IOC_GETFLAGS/SETFLAGS is get-modify-set loop. Filesystems could return verity status with GETFLAGS, attempting to then pass
FS_VERITY_FLto SETFLAGS is not allowed.The ext4 and f2fs already treat
FS_VERITY_FLin the set path as no-op, however, BTRFS returns-EOPNOTSUPP. So, the modification of other flags doesn't work on BTRFS for fsverity inodes.Fix it for BTRFS and anyone else, the ext4 and f2fs masking becomes no-op. The file_get/setattr() path is fine here as this flag is cleared right before
fileattr_set_prepare(). The future fsverity support in XFS would also need it.
Quoted 4 lines
Cc Boris Burkov <[email protected]>Cc David Sterba <[email protected]>Fixes 146054090b08 ("btrfs: initial fsverity support")Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Eric Biggers
maintainerRe: [PATCH v3 2/7] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS
In reply to Andrey AlbershteynQuoted 4 lines · Andrey Albershteyn
The common use of FS_IOC_GETFLAGS/SETFLAGS is get-modify-set loop. Filesystems could return verity status with GETFLAGS, attempting to then pass
FS_VERITY_FLto SETFLAGS is not allowed.
Quoted 8 lines
The ext4 and f2fs already treat
FS_VERITY_FLin the set path as no-op, however, BTRFS returns-EOPNOTSUPP. So, the modification of other flags doesn't work on BTRFS for fsverity inodes.Fix it for BTRFS and anyone else, the ext4 and f2fs masking becomes no-op. The file_get/setattr() path is fine here as this flag is cleared right before
fileattr_set_prepare(). The future fsverity support in XFS would also need it.
The commit message should explicitly state that this changes behavior not just in the get-modify-set case on btrfs, but also makes FS_VERITY_FL be silently ignored if it's attempted to be set on a file that didn't have it before. I guess that behavior is okay since ext4 and f2fs do that, but we should be intentional about it.
- Eric
PATCH v3 3/7 fs,fsverity: add I_VERITY_BUILDING inode state flag
In reply to Andrey AlbershteynEvery filesystem that supports fs-verity keeps a private runtime inode flag meaning Merkle tree is currently being built *_VERITY_IN_PROGRESS. They all serve the same two purposes: reject a concurrent enable with -EBUSY and let the write paths recognize the special writes done while the tree is under construction.
Hoist this flag into the VFS as a new inode state flag, I_VERITY_BUILDING, and manage its lifetime in the generic fs-verity enable path. The flag is set after ->begin_enable_verity() succeeds and cleared after ->end_enable_verity() returns (both on the success and the rollback paths). Add the concurrent-enable guard.
A new helper, fsverity_is_building(), is provided for filesystems to query the flag. No filesystem uses it yet; the per-fs flags are converted in following patches.
--- fs/verity/enable.c | 22 +++++++++++++++++++--- include/linux/fs.h | 6 ++++++ include/linux/fsverity.h | 26 ++++++++++++++++++++++++-- include/trace/events/writeback.h | 3 ++- 4 files changed, 51 insertions(+), 6 deletions(-)
fs/verity/enable.c +19 -3
@@ -229,13 +229,23 @@ static int enable_verity(struct file *filp,/* * Start enabling verity on this file, serialized by the inode lock. -* Fail if verity is already enabled or is already being enabled. +* Fail if verity is already enabled or is already being enabled. Set +* I_VERITY_BUILDING inode runtime flag which will be cleared when +* enablement succeeded or rolled back. */ inode_lock (inode); -if (IS_VERITY (inode)) +if (IS_VERITY (inode)) { err = -EEXIST ; -else + }else if (fsverity_is_building (inode)) { + err = -EBUSY ; + }else { err = vops->begin_enable_verity (filp); +if (!err) { +spin_lock (&inode->i_lock); +inode_state_set (inode,I_VERITY_BUILDING ); +spin_unlock (&inode->i_lock); + } + }inode_unlock (inode);if (err) goto out;
@@ -291,6 +301,9 @@ static int enable_verity(struct file *filp,*/ inode_lock (inode); err = vops->end_enable_verity (filp, desc, desc_size, params.tree_size); +spin_lock (&inode->i_lock); +inode_state_clear (inode,I_VERITY_BUILDING ); +spin_unlock (&inode->i_lock);inode_unlock (inode);if (err) { fsverity_err(inode, "%ps() failed with err %d",
@@ -317,6 +330,9 @@ static int enable_verity(struct file *filp, rollback:inode_lock (inode); (void )vops->end_enable_verity (filp,NULL ,0 , params.tree_size); +spin_lock (&inode->i_lock); +inode_state_clear (inode,I_VERITY_BUILDING ); +spin_unlock (&inode->i_lock);inode_unlock (inode); goto out; }
include/linux/fs.h +6 -0
@@ -708,6 +708,11 @@ is_uncached_acl(struct posix_acl *acl)* I_LRU_ISOLATING Inode is pinned being isolated from LRU without holding * i_count. * +* I_VERITY_BUILDING fs-verity is being enabled on the inode: the Merkle +* tree is under construction. The file is effectively +* read-only to userspace; the only writes happening are +* for the fs-verity metadata. +* * Q: What is the difference between I_WILL_FREE and I_FREEING? * * __I_{SYNC,NEW,LRU_ISOLATING} are used to derive unique addresses to wait
@@ -742,6 +747,7 @@ enum inode_state_flags_enum {I_SYNC_QUEUED = (1U <<17 ),I_PINNING_NETFS_WB = (1U <<18 ),I_METADATA_WRITEBACK = (1U <<19 ), + I_VERITY_BUILDING = (1U << 20), };#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
include/linux/fsverity.h +24 -2
@@ -36,11 +36,12 @@ struct fsverity_operations {* @filp: a readonly file descriptor for the file * * The filesystem must do any needed filesystem-specific preparations -* for enabling verity, e.g. evicting inline data. It also must return -* -EBUSY if verity is already being enabled on the given file. +* for enabling verity, e.g. evicting inline data. * * i_rwsem is held for write. * +* I_VERITY_BUILDING is set on the inode for the duration of enabling. +* * Return: 0 on success, -errno on failure */ int (*begin_enable_verity)(struct file *filp);
@@ -164,6 +165,22 @@ static inline bool fsverity_active(const struct inode *inode)return false; } +/** +* fsverity_is_building() - is fs-verity being enabled on the inode +* @inode: inode to check +* +* This checks whether the inode's Merkle tree is currently being built. +* While this is the case the file is read-only to userspace and the only writes +* allowed are for the fs-verity metadata. This becomes false when fsverity +* metadata is fully created and written to disk or building failed. +* +* Return: true if fs-verity is being enabled on the inode +*/ +static inline bool fsverity_is_building (const struct inode *inode) +{ +return inode_state_read_once (inode) &I_VERITY_BUILDING ; +} +struct fsverity_info *__fsverity_get_info (const struct inode *inode);/** * fsverity_get_info - get fsverity information for an inode
@@ -217,6 +234,11 @@ static inline bool fsverity_active(const struct inode *inode)return false; } +static inline bool fsverity_is_building (const struct inode *inode) +{ +return false; +} +static inline struct fsverity_info *fsverity_get_info (const struct inode *inode) {return NULL ;
include/trace/events/writeback.h +2 -1
@@ -28,7 +28,8 @@ {I_DONTCACHE, "I_DONTCACHE"}, \ {I_SYNC_QUEUED, "I_SYNC_QUEUED"}, \ {I_PINNING_NETFS_WB, "I_PINNING_NETFS_WB"}, \ - {I_LRU_ISOLATING, "I_LRU_ISOLATING"} \ + {I_LRU_ISOLATING, "I_LRU_ISOLATING"}, \ + {I_VERITY_BUILDING, "I_VERITY_BUILDING"} \ )/* enums need to be exported to user space */
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 3/7] fs,fsverity: add I_VERITY_BUILDING inode state flag
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
Every filesystem that supports fs-verity keeps a private runtime inode flag meaning Merkle tree is currently being built
*_VERITY_IN_PROGRESS. They all serve the same two purposes: reject a concurrent enable with-EBUSYand let the write paths recognize the special writes done while the tree is under construction.Hoist this flag into the VFS as a new inode state flag,
I_VERITY_BUILDING, and manage its lifetime in the generic fs-verity enable path. The flag is set after ->begin_enable_verity() succeeds and cleared after ->end_enable_verity() returns (both on the success and the rollback paths). Add the concurrent-enable guard.
Quoted 5 lines
A new helper,
fsverity_is_building(), is provided for filesystems to query the flag. No filesystem uses it yet; the per-fs flags are converted in following patches.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 3/7] fs,fsverity: add I_VERITY_BUILDING inode state flag
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 12 lines
Every filesystem that supports fs-verity keeps a private runtime inode flag meaning Merkle tree is currently being built
*_VERITY_IN_PROGRESS. They all serve the same two purposes: reject a concurrent enable with-EBUSYand let the write paths recognize the special writes done while the tree is under construction.Hoist this flag into the VFS as a new inode state flag,
I_VERITY_BUILDING, and manage its lifetime in the generic fs-verity enable path. The flag is set after ->begin_enable_verity() succeeds and cleared after ->end_enable_verity() returns (both on the success and the rollback paths). Add the concurrent-enable guard.
Quoted 5 lines
A new helper,
fsverity_is_building(), is provided for filesystems to query the flag. No filesystem uses it yet; the per-fs flags are converted in following patches.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Eric Biggers
maintainerRe: [PATCH v3 3/7] fs,fsverity: add I_VERITY_BUILDING inode state flag
In reply to Andrey AlbershteynQuoted 4 lines · Andrey Albershteyn
+ *
I_VERITY_BUILDINGfs-verity is being enabled on the inode: the Merkle
+ * tree is under construction. The file is effectively
+ * read-only to userspace; the only writes happening are
+ * for the fs-verity metadata.
Existing dirty data can still be written out though, right?
Quoted 9 lines
include/linux/fsverity.h +0
-1@@ -36,11 +36,12 @@ struct fsverity_operations {* @filp: a readonly file descriptor for the file * * The filesystem must do any needed filesystem-specific preparations -* for enabling verity, e.g. evicting inline data. It also must return
include/linux/fsverity.h struct fsverity_operations { · line 47
Quoted 10 lines
include/linux/fsverity.h +3
-1-* -EBUSY if verity is already being enabled on the given file. +* for enabling verity, e.g. evicting inline data. * * i_rwsem is held for write. * +* I_VERITY_BUILDING is set on the inode for the duration of enabling. +* * Return: 0 on success, -errno on failure */ int (*begin_enable_verity)(struct file *filp);
The new sentence doesn't seem relevant here, as the flag isn't set during this method call.
- Eric
PATCH v3 4/7 iomap: use fsverity_is_building() to check for fsverity IO
In reply to Andrey AlbershteynRecently, inode gained new I_VERITY_BUILDING flag. This flag indicates that inode is undergoing fsverity metadata construction. Previously, it was indicated by stale iomap flag on the IO, now we can check the inode instead. As fsverity inodes are read-only, the only write IO happening during I_VERITY_BUILDING is fsverity metadata.
--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode); -if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 4/7] iomap: use fsverity_is_building() to check for fsverity IO
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] iomap: false warning and skipped EOF zeroing in iomap_writeback_handle_eof() - [Low] iomap…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] iomap: false warning and skipped EOF zeroing in iomap_writeback_handle_eof()
- [Low] iomap: missing Fixes trailer for commit 63e242afa466 --
commit d5a593fe13feaadaf9eccdc0fdcb54b6905598bb
Author: Andrey Albershteyn <[email protected]>
Quoted 9 lines
iomap: use
fsverity_is_building()to check for fsverity IORecently, inode gained new
I_VERITY_BUILDINGflag. This flag indicates that inode is undergoing fsverity metadata construction. Previously, it was indicated by stale iomap flag on the IO, now we can check the inode instead. As fsverity inodes are read-only, the only write IO happening duringI_VERITY_BUILDINGis fsverity metadata.Signed-off-by Andrey Albershteyn <[email protected]>
[Severity: Low]
Since this fixes the check on the uninitialized or stale wpc->iomap.flags in iomap_writeback_handle_eof(), should it carry:
fs/iomap/buffered-io.c static bool iomap_writeback_handle_eof(struct folio *folio, · line 1936
Quoted 13 lines
fs/iomap/buffered-io.c +1
-1@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode); -if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }
[Severity: Medium]
Can this trigger a false WARN_ON_ONCE() and skip EOF tail zeroing when pre-existing dirty data folios are written back while I_VERITY_BUILDING is set?
fsverity_ioctl_enable() calls deny_write_access(), and enable_verity() sets I_VERITY_BUILDING after ->begin_enable_verity() without flushing dirty data folios already in inode->i_mapping:
fs/verity/enable.c:enable_verity() {
...
err = vops->begin_enable_verity(filp);
if (!err) {
spin_lock(&inode->i_lock);
inode_state_set(inode, I_VERITY_BUILDING);
spin_unlock(&inode->i_lock);
}
...
}If a file is written via buffered write or mmap, closed without fsync, and reopened O_RDONLY for FS_IOC_ENABLE_VERITY, writeback of dirty data folios below i_size can run while I_VERITY_BUILDING is set. Because fsverity_is_building() is an inode-wide flag, iomap_writeback_handle_eof() fires WARN_ON_ONCE(folio_pos(folio) < isize) and returns early. For a dirty data folio straddling i_size, returning early also skips folio_zero_segment() and leaves *end_pos unclamped past i_size.
Checking fsverity_is_building(inode) only when the folio is completely at or beyond i_size (where iomap_writeback_handle_eof() otherwise returns false) would avoid affecting regular data folios.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 4/7] iomap: use fsverity_is_building() to check for fsverity IO
In reply to Andrey AlbershteynThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] iomap: inode-wide fsverity_is_building() check in iomap_writeback_handle_eof() - [Low] iomap…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] iomap: inode-wide fsverity_is_building() check in iomap_writeback_handle_eof()
- [Low] iomap: missing Fixes trailer for broken fsverity check in writeback
--
commit f52ac6dc651e2b12c5452600fd41f0db8111577f
Author: Andrey Albershteyn <[email protected]>
Quoted 9 lines
iomap: use
fsverity_is_building()to check for fsverity IORecently, inode gained new
I_VERITY_BUILDINGflag. This flag indicates that inode is undergoing fsverity metadata construction. Previously, it was indicated by stale iomap flag on the IO, now we can check the inode instead. As fsverity inodes are read-only, the only write IO happening duringI_VERITY_BUILDINGis fsverity metadata.Signed-off-by Andrey Albershteyn <[email protected]>
[Severity: Low]
This fixes the check that read an uninitialized or stale wpc->iomap before wpc->ops->writeback_range() mapped the folio. Should it carry:
fs/iomap/buffered-io.c static bool iomap_writeback_handle_eof(struct folio *folio, · line 1936
Quoted 13 lines
fs/iomap/buffered-io.c +1
-1@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode); -if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }
[Severity: Medium]
Can writeback of a dirty data folio while I_VERITY_BUILDING is set hit this WARN_ON_ONCE() and skip post-EOF tail zeroing?
enable_verity() sets I_VERITY_BUILDING without flushing pre-existing
dirty data folios in inode->i_mapping, and filesystems write back both dirty data and verity metadata folios while I_VERITY_BUILDING is still
set (either during background writeback or in ->end_enable_verity()). Because fsverity_is_building(inode) is an inode-wide flag checked before comparing the folio offset against isize, any dirty regular data folio written back during verity construction triggers WARN_ON_ONCE(folio_pos(folio) < isize), and a dirty data folio straddling isize returns early without running folio_zero_segment() or clamping *end_pos to isize.
Should the fsverity_is_building(inode) exemption apply only when the folio lies entirely at or beyond isize?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v3 4/7] iomap: use fsverity_is_building() to check for fsverity IO
Quoted 19 lines · On 2026-11-20 16:21:51, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] iomap: inode-widefsverity_is_building()check iniomap_writeback_handle_eof()
- [Low] iomap: missing Fixes trailer for broken fsverity check in writeback
--commit
f52ac6dc651e2b12c5452600fd41f0db8111577f
Author: Andrey Albershteyn <[email protected]>Quoted 8 lines
iomap: use
fsverity_is_building()to check for fsverity IORecently, inode gained new
I_VERITY_BUILDINGflag. This flag indicates that inode is undergoing fsverity metadata construction. Previously, it was indicated by stale iomap flag on the IO, now we can check the inode instead. As fsverity inodes are read-only, the only write IO happening duringI_VERITY_BUILDINGis fsverity metadata.
Quoted 7 lines
Quoted 1 line
Signed-off-by Andrey Albershteyn <[email protected]>[Severity: Low]
This fixes the check that read an uninitialized or stalewpc->iomapbeforewpc->ops->writeback_range()mapped the folio. Should it carry:Fixes 63e242afa466 ("iomap: introduce IOMAP_F_FSVERITY and teach writeback to handle fsverity")
This is not really a fix for that commit, I don't think Fixes: is necessary here.
Quoted 29 lines
Quoted 6 lines
fs/iomap/buffered-io.c +0
-0fs/iomap/buffered-io.c static bool iomap_writeback_handle_eof(struct folio *folio, · line 1936
Quoted 8 lines
fs/iomap/buffered-io.c +1
-1@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode); -if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }[Severity: Medium]
Can writeback of a dirty data folio whileI_VERITY_BUILDINGis set hit thisWARN_ON_ONCE()and skip post-EOF tail zeroing?
enable_verity()setsI_VERITY_BUILDINGwithout flushing pre-existing
dirty data folios ininode->i_mapping, and filesystems write back both dirty data and verity metadata folios whileI_VERITY_BUILDINGis still
set (either during background writeback or in ->end_enable_verity()). Becausefsverity_is_building(inode)is an inode-wide flag checked before comparing the folio offset against isize, any dirty regular data folio written back during verity construction triggersWARN_ON_ONCE(folio_pos(folio) < isize), and a dirty data folio straddling isize returns early without runningfolio_zero_segment()or clamping*end_posto isize.
Quoted 2 lines
Should the
fsverity_is_building(inode)exemption apply only when the folio lies entirely at or beyond isize?
I think this warning is better to be fired for data folios in writeback while fsverity is being enabled. The only user of this, so far, would be XFS. XFS will flush data folios before starting to write fsverity metadata. Ext4 doesn't flush data folios before starting the build, but I think it make sense to have data on disk before starting merkle tree build.
Signature · 1 line
- Andrey
Eric Biggers
maintainerRe: [PATCH v3 4/7] iomap: use fsverity_is_building() to check for fsverity IO
In reply to Andrey AlbershteynQuoted 2 lines · Andrey Albershteyn
As fsverity inodes are read-only, the only write IO happening during
I_VERITY_BUILDINGis fsverity metadata.
I think this is not accurate? The inode is not a "fsverity inode" yet, and it can still have dirty data in it that is undergoing writeback.
fs/iomap/buffered-io.c static bool iomap_writeback_handle_eof(struct folio *folio, · line 1936
Quoted 13 lines
fs/iomap/buffered-io.c +1
-1@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode); -if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }
This function no longer needs the 'wpc' parameter: it can be passed 'inode' directly instead.
Sashiko also found an issue with this change.
- Eric
Re: [PATCH v3 4/7] iomap: use fsverity_is_building() to check for fsverity IO
Quoted 6 lines · Eric Biggers
Quoted 2 lines · Andrey Albershteyn
As fsverity inodes are read-only, the only write IO happening during
I_VERITY_BUILDINGis fsverity metadata.I think this is not accurate? The inode is not a "fsverity inode" yet, and it can still have dirty data in it that is undergoing writeback.
XFS flushes data folios in _begin_enable(). Make sense for me to have data stable on disk before starting the build, if any error happens in data writeback we won't spent time building the tree. That why the warning below.
But as I_VERITY_BUILDING exists now, I don't think there's requirement to sync data before starting the build, I will update the comment.
Quoted 9 lines
Quoted 9 lines
fs/iomap/buffered-io.c +0
-0@@ -1930,7 +1930,7 @@ static bool iomap_writeback_handle_eof(struct folio *folio,struct inode *inode = wpc->inode;u64 isize =i_size_read (inode);
Quoted 8 lines
fs/iomap/buffered-io.c static bool iomap_writeback_handle_eof(struct folio *folio, · line 1936
Quoted 5 lines
fs/iomap/buffered-io.c +1
-1-if (wpc->iomap.flags &IOMAP_F_FSVERITY ) { +if (fsverity_is_building (inode)) {WARN_ON_ONCE (folio_pos (folio) < isize);return true; }This function no longer needs the 'wpc' parameter: it can be passed 'inode' directly instead.
Sure, I will update it.
Quoted 1 line
Sashiko also found an issue with this change.
That's related to my response above.
Signature · 1 line
- Andrey
PATCH v3 5/7 btrfs: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynNow that the VFS tracks an inode whose Merkle tree is under construction via I_VERITY_BUILDING and handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this.
btrfs only used BTRFS_INODE_VERITY_IN_PROGRESS internally, so remove it outright.
--- fs/btrfs/btrfs_inode.h | 7 ------- fs/btrfs/verity.c | 12 ++---------- 2 files changed, 2 insertions(+), 17 deletions(-)
fs/btrfs/btrfs_inode.h +0 -7
@@ -78,13 +78,6 @@ enum {* the file range, inode's io_tree). */ BTRFS_INODE_NO_DELALLOC_FLUSH , -/* -* Set when we are working on enabling verity for a file. Computing and -* writing the whole Merkle tree can take a while so we want to prevent -* races where two separate tasks attempt to simultaneously start verity -* on the same file. -*/ -BTRFS_INODE_VERITY_IN_PROGRESS ,/* Set when this inode is a free space inode. */ BTRFS_INODE_FREE_SPACE_INODE,/* Set when there are no capabilities in XATTs for the inode. */
fs/btrfs/verity.c +2 -10
@@ -461,7 +461,6 @@ static int rollback_verity(struct btrfs_inode *inode)btrfs_assert_inode_locked (inode);truncate_inode_pages (inode->vfs_inode.i_mapping, inode->vfs_inode.i_size); -clear_bit (BTRFS_INODE_VERITY_IN_PROGRESS , &inode->runtime_flags); ret =btrfs_drop_verity_items (inode);if (ret) { btrfs_handle_fs_error(root->fs_info, ret,
@@ -513,7 +512,6 @@ static int rollback_verity(struct btrfs_inode *inode)* - mark the inode with the verity flag * - delete the orphan item * - mark the ro compat bit -* - clear the in progress bit * * Returns 0 on success, negative error code on failure. */
@@ -555,7 +553,6 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc, goto end_trans;/* Now that rollback is no longer possible, set S_VERITY. */ btrfs_sync_inode_flags_to_i_flags (inode); -clear_bit (BTRFS_INODE_VERITY_IN_PROGRESS , &inode->runtime_flags);btrfs_set_fs_compat_ro (root->fs_info,VERITY ); end_trans:if (ret)
@@ -570,8 +567,8 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,* * @filp: file to enable verity on * -* Begin enabling fsverity for the file. We drop any existing verity items, add -* an orphan and set the in progress bit. +* Begin enabling fsverity for the file. We drop any existing verity items and +* add an orphan. * * Returns 0 on success, negative error code on failure. */
@@ -587,9 +584,6 @@ static int btrfs_begin_enable_verity(struct file *filp)if (IS_ENCRYPTED (&inode->vfs_inode))return -EOPNOTSUPP ; -if (test_bit (BTRFS_INODE_VERITY_IN_PROGRESS , &inode->runtime_flags)) -return -EBUSY ; -/* * This should almost never do anything, but theoretically, it's * possible that we failed to enable verity on a file, then were
@@ -606,8 +600,6 @@ static int btrfs_begin_enable_verity(struct file *filp)return PTR_ERR (trans); ret =btrfs_orphan_add (trans, inode); -if (!ret) -set_bit (BTRFS_INODE_VERITY_IN_PROGRESS , &inode->runtime_flags);btrfs_end_transaction (trans);return ret;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 5/7] btrfs: use I_VERITY_BUILDING instead of private flags
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this.btrfs only used
BTRFS_INODE_VERITY_IN_PROGRESSinternally, so remove it outright.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v3 5/7] btrfs: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 9 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this.btrfs only used
BTRFS_INODE_VERITY_IN_PROGRESSinternally, so remove it outright.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v3 6/7 ext4: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynNow that the VFS tracks an inode whose Merkle tree is under construction via I_VERITY_BUILDING and handles the concurrent-enable guard in the generic fs-verity enable path, drop the per-filesystem runtime flags that duplicated this state.
Replace ext4 own helper ext4_verity_in_progress() with fsverity_is_building(), and remove the EXT4_STATE_VERITY_IN_PROGRESS flags. The IS_ENABLED() guard is fine to remove now as fsverity_is_building() has stub for disabled fsverity.
--- fs/ext4/ext4.h | 7 ------- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 17 +++++++++-------- fs/ext4/ioctl.c | 3 +-- fs/ext4/verity.c | 19 ++++++------------- 5 files changed, 17 insertions(+), 31 deletions(-)
fs/ext4/ext4.h +0 -7
@@ -2050,7 +2050,6 @@ enum {EXT4_STATE_MAY_INLINE_DATA ,/* may have in-inode data */ EXT4_STATE_EXT_PRECACHED ,/* extents have been precached */ EXT4_STATE_LUSTRE_EA_INODE ,/* Lustre-style ea_inode */ -EXT4_STATE_VERITY_IN_PROGRESS ,/* building fs-verity Merkle tree */ EXT4_STATE_FC_COMMITTING ,/* Fast commit ongoing */ EXT4_STATE_FC_FLUSHING_DATA ,/* Fast commit flushing data */ EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */
@@ -2129,12 +2128,6 @@ static inline int ext4_inode_state_wait_bit(int bit)#define EXT4_SB (sb) (sb)#endif -static inline bool ext4_verity_in_progress (struct inode *inode) -{ -return IS_ENABLED (CONFIG_FS_VERITY ) && -ext4_test_inode_state (inode,EXT4_STATE_VERITY_IN_PROGRESS ); -} -#define NEXT_ORPHAN (inode) EXT4_I(inode)->i_dtime/*
fs/ext4/file.c +1 -1
@@ -318,7 +318,7 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *from)* partial block that beyond the existing EOF, as it may contains * stale data written through mmap. */ -if (iocb->ki_pos > old_size && !ext4_verity_in_progress (inode)) { +if (iocb->ki_pos > old_size && !fsverity_is_building (inode)) {if (iocb->ki_flags &IOCB_NOWAIT )return -EAGAIN ;
fs/ext4/inode.c +9 -8
@@ -42,6 +42,7 @@#include <linux/bitops.h> #include <linux/iomap.h> #include <linux/iversion.h> +#include <linux/fsverity.h> #include "ext4_jbd2.h" #include "ext4_extents.h"
@@ -506,7 +507,7 @@ void ext4_check_map_extents_env(struct inode *inode)is_special_ino (inode->i_sb, inode->i_ino) || (inode_state_read_once (inode) & (I_FREEING |I_WILL_FREE |I_NEW )) ||ext4_test_inode_flag (inode,EXT4_INODE_EA_INODE ) || - ext4_verity_in_progress(inode)) + fsverity_is_building(inode)) return; WARN_ON_ONCE(!inode_is_locked(inode) &&
@@ -1493,7 +1494,7 @@ static int ext4_write_begin(const struct kiocb *iocb,if (ret) {bool extended = (pos + len > inode->i_size) && - !ext4_verity_in_progress (inode); + !fsverity_is_building (inode);folio_unlock (folio);/*
@@ -1560,7 +1561,7 @@ static int ext4_write_end(const struct kiocb *iocb,loff_t old_size = inode->i_size;int ret =0 , ret2;int i_size_changed =0 ; -bool verity =ext4_verity_in_progress (inode); +bool verity =fsverity_is_building (inode);trace_ext4_write_end (inode, pos, len, copied);
@@ -1665,7 +1666,7 @@ static int ext4_journalled_write_end(const struct kiocb *iocb,int partial =0 ;unsigned from, to;int size_changed =0 ; -bool verity =ext4_verity_in_progress (inode); +bool verity =fsverity_is_building (inode);trace_ext4_journalled_write_end (inode, pos, len, copied); from = pos & (PAGE_SIZE -1 );
@@ -2210,7 +2211,7 @@ static void mpage_submit_folio(struct mpage_da_data *mpd, struct folio *folio) size =i_size_read (mpd->inode); len =folio_size (folio);if (folio_pos (folio) + len > size && - !ext4_verity_in_progress (mpd->inode)) + !fsverity_is_building (mpd->inode)) len = size & (len -1 );ext4_bio_write_folio (&mpd->io_submit, folio, len); }
@@ -2300,7 +2301,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd,ext4_lblk_t blocks = (i_size_read (inode) +i_blocksize (inode) -1 ) >> inode->i_blkbits; -if (ext4_verity_in_progress (inode)) +if (fsverity_is_building (inode)) blocks =EXT_MAX_BLOCKS ; do {
@@ -2706,7 +2707,7 @@ static int mpage_journal_page_buffers(handle_t *handle, mpd->wbc->nr_to_write -=folio_nr_pages (folio);if (folio_pos (folio) + len > size && - !ext4_verity_in_progress (inode)) + !fsverity_is_building (inode)) len = size & (len -1 );return ext4_journal_folio_buffers (handle, folio, len);
@@ -3271,7 +3272,7 @@ static int ext4_da_write_begin(const struct kiocb *iocb, index = pos >>PAGE_SHIFT ; -if (ext4_nonda_switch (inode->i_sb) ||ext4_verity_in_progress (inode)) { +if (ext4_nonda_switch (inode->i_sb) ||fsverity_is_building (inode)) { *fsdata = (void *)FALL_BACK_TO_NONDELALLOC ;return ext4_write_begin (iocb, mapping, pos, len, foliop, fsdata);
fs/ext4/ioctl.c +1 -2
@@ -575,8 +575,7 @@ static bool dax_compatible(struct inode *inode, unsigned int oldflags,if (flags &EXT4_DAX_FL ) {if ((oldflags &EXT4_DAX_MUT_EXCL ) || -ext4_test_inode_state (inode, -EXT4_STATE_VERITY_IN_PROGRESS )) { +fsverity_is_building (inode)) {return false; } }
fs/ext4/verity.c +6 -13
@@ -83,9 +83,6 @@ static int ext4_begin_enable_verity(struct file *filp)if (IS_DAX (inode) ||ext4_test_inode_flag (inode,EXT4_INODE_DAX ))return -EINVAL ; -if (ext4_verity_in_progress (inode)) -return -EBUSY ; -/* * Since the file was opened readonly, we have to initialize the jbd * inode and quotas here and not rely on ->open() doing it. This must
@@ -123,8 +120,6 @@ static int ext4_begin_enable_verity(struct file *filp)return PTR_ERR (handle); err =ext4_orphan_add (handle, inode); -if (err ==0 ) -ext4_set_inode_state (inode,EXT4_STATE_VERITY_IN_PROGRESS );ext4_journal_stop (handle);return err;
@@ -185,10 +180,10 @@ static int ext4_end_enable_verity(struct file *filp, const void *desc, goto cleanup;/* -* Write all pages (both data and verity metadata). Note that this must -* happen before clearing EXT4_STATE_VERITY_IN_PROGRESS; otherwise pages -* beyond i_size won't be written properly. For crash consistency, this -* also must happen before the verity inode flag gets persisted. +* Write all pages (both data and verity metadata). Note that this must +* happen before I_VERITY_BUILDING is cleared; otherwise pages beyond +* i_size won't be written properly. For crash consistency, this also +* must happen before the verity inode flag gets persisted. */ err =filemap_write_and_wait (inode->i_mapping);if (err)
@@ -224,7 +219,6 @@ static int ext4_end_enable_verity(struct file *filp, const void *desc,/* Now that rollback is no longer possible, set S_VERITY. */ ext4_set_inode_flags (inode, false); -ext4_clear_inode_state (inode,EXT4_STATE_VERITY_IN_PROGRESS );return 0 ; stop_and_cleanup:
@@ -234,13 +228,12 @@ static int ext4_end_enable_verity(struct file *filp, const void *desc,/* * Verity failed to be enabled, so clean up by truncating any verity * metadata that was written beyond i_size (both from cache and from -* disk), removing the inode from the orphan list (if it wasn't done -* already), and clearing EXT4_STATE_VERITY_IN_PROGRESS. +* disk) and removing the inode from the orphan list (if it wasn't done +* already). */ truncate_inode_pages (inode->i_mapping, inode->i_size);ext4_truncate (inode);ext4_orphan_del (NULL , inode); -ext4_clear_inode_state (inode,EXT4_STATE_VERITY_IN_PROGRESS );return err; }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 6/7] ext4: use I_VERITY_BUILDING instead of private flags
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the per-filesystem runtime flags that duplicated this state.Replace ext4 own helper
ext4_verity_in_progress()withfsverity_is_building(), and remove theEXT4_STATE_VERITY_IN_PROGRESSflags. TheIS_ENABLED()guard is fine to remove now asfsverity_is_building()has stub for disabled fsverity.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v3 6/7] ext4: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 11 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the per-filesystem runtime flags that duplicated this state.Replace ext4 own helper
ext4_verity_in_progress()withfsverity_is_building(), and remove theEXT4_STATE_VERITY_IN_PROGRESSflags. TheIS_ENABLED()guard is fine to remove now asfsverity_is_building()has stub for disabled fsverity.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v3 7/7 f2fs: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynNow that the VFS tracks an inode whose Merkle tree is under construction via I_VERITY_BUILDING and handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this state.
Replace f2fs own helper f2fs_verity_in_progress() with fsverity_is_building(), and remove the and FI_VERITY_IN_PROGRESS flags. It's fine to remove IS_ENABLED() guard as fsverity_is_building() has stub.
--- fs/f2fs/data.c | 10 +++++----- fs/f2fs/f2fs.h | 7 ------- fs/f2fs/verity.c | 12 +++--------- 3 files changed, 8 insertions(+), 21 deletions(-)
fs/f2fs/data.c +5 -5
@@ -3356,7 +3356,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted, goto redirty_out;if (folio->index < end_index || -f2fs_verity_in_progress (inode) || +fsverity_is_building (inode) || compr_blocks) goto write;
@@ -3889,7 +3889,7 @@ void f2fs_write_failed(struct inode *inode, loff_t to)return ;/* In the fs-verity case, f2fs_end_enable_verity() does the truncate */ -if (to > i_size && !f2fs_verity_in_progress (inode)) { +if (to > i_size && !fsverity_is_building (inode)) {f2fs_down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);filemap_invalidate_lock (inode->i_mapping);
@@ -4205,7 +4205,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,return 0 ;if (!(pos & (PAGE_SIZE -1 )) && (pos + len) >=i_size_read (inode) && - !f2fs_verity_in_progress (inode)) { + !fsverity_is_building (inode)) {folio_zero_segment (folio, len,folio_size (folio));return 0 ; }
@@ -4279,7 +4279,7 @@ static int f2fs_write_end(const struct kiocb *iocb,f2fs_update_time (F2FS_I_SB (inode),REQ_TIME );if (pos + copied >i_size_read (inode) && - !f2fs_verity_in_progress (inode)) + !fsverity_is_building (inode))f2fs_i_size_write (inode, pos + copied);return copied; }
@@ -4294,7 +4294,7 @@ static int f2fs_write_end(const struct kiocb *iocb,folio_set_f2fs_atomic (folio);if (pos + copied >i_size_read (inode) && - !f2fs_verity_in_progress (inode)) { + !fsverity_is_building (inode)) {f2fs_i_size_write (inode, pos + copied);if (f2fs_is_atomic_file (inode)) f2fs_i_size_write(F2FS_I(inode)->cow_inode,
fs/f2fs/f2fs.h +0 -7
@@ -926,7 +926,6 @@ enum {FI_EXTRA_ATTR ,/* indicate file has extra attribute */ FI_PROJ_INHERIT ,/* indicate file inherits projectid */ FI_PIN_FILE ,/* indicate file should not be gced */ -FI_VERITY_IN_PROGRESS ,/* building fs-verity Merkle tree */ FI_COMPRESSED_FILE ,/* indicate file's data can be compressed */ FI_COMPRESS_CORRUPT ,/* indicate compressed cluster is corrupted */ FI_MMAP_FILE, /* indicate file was mmapped */
@@ -3536,12 +3535,6 @@ static inline void clear_inode_flag(struct inode *inode, int flag)__mark_inode_dirty_flag (inode, flag, false); } -static inline bool f2fs_verity_in_progress (struct inode *inode) -{ -return IS_ENABLED (CONFIG_FS_VERITY ) && -is_inode_flag_set (inode,FI_VERITY_IN_PROGRESS ); -} -static inline void set_acl_inode (struct inode *inode,umode_t mode) {F2FS_I (inode)->i_acl_mode = mode;
fs/f2fs/verity.c +3 -9
@@ -94,9 +94,6 @@ static int f2fs_begin_enable_verity(struct file *filp)struct inode *inode =file_inode (filp);int err; -if (f2fs_verity_in_progress (inode)) -return -EBUSY ; -if (f2fs_is_atomic_file (inode))return -EOPNOTSUPP ;
@@ -113,7 +110,6 @@ static int f2fs_begin_enable_verity(struct file *filp)if (err)return err; -set_inode_flag (inode,FI_VERITY_IN_PROGRESS );return 0 ; }
@@ -143,8 +139,8 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc, goto cleanup;/* -* Write all pages (both data and verity metadata). Note that this must -* happen before clearing FI_VERITY_IN_PROGRESS; otherwise pages beyond +* Write all pages (both data and verity metadata). Note that this must +* happen before I_VERITY_BUILDING is cleared; otherwise pages beyond * i_size won't be written properly. For crash consistency, this also * must happen before the verity inode flag gets persisted. */
@@ -164,14 +160,13 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,f2fs_set_inode_flags (inode);f2fs_mark_inode_dirty_sync (inode, true); -clear_inode_flag (inode,FI_VERITY_IN_PROGRESS );return 0 ; cleanup:/* * Verity failed to be enabled, so clean up by truncating any verity * metadata that was written beyond i_size (both from cache and from -* disk) and clearing FI_VERITY_IN_PROGRESS. +* disk). * * Taking i_gc_rwsem[WRITE] is needed to stop f2fs garbage collection * from re-instantiating cached pages we are truncating (since unlike
@@ -186,7 +181,6 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,set_sbi_flag (sbi,SBI_NEED_FSCK ); }f2fs_up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]); -clear_inode_flag (inode,FI_VERITY_IN_PROGRESS );return err ?: err2; }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 7/7] f2fs: use I_VERITY_BUILDING instead of private flags
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this state.Replace f2fs own helper
f2fs_verity_in_progress()withfsverity_is_building(), and remove the andFI_VERITY_IN_PROGRESSflags. It's fine to removeIS_ENABLED()guard asfsverity_is_building()has stub.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v3 7/7] f2fs: use I_VERITY_BUILDING instead of private flags
In reply to Andrey AlbershteynSashiko has reviewed this patch and found no issues.
Quoted 11 lines
Now that the VFS tracks an inode whose Merkle tree is under construction via
I_VERITY_BUILDINGand handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this state.Replace f2fs own helper
f2fs_verity_in_progress()withfsverity_is_building(), and remove the andFI_VERITY_IN_PROGRESSflags. It's fine to removeIS_ENABLED()guard asfsverity_is_building()has stub.Signed-off-by Andrey Albershteyn <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7