Skip to contentSkip to conversation

fs: push list presence check into inode_io_list_del()

PATCH Applied Mateusz Guzik 3 participants 3 messages Nov 3, 2025 – Nov 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 fs: push list presence check into inode_io_list_del()

For consistency with sb routines.

ext4 is the only consumer outside of evict(). Damage-controlling it is outside of the scope of this cleanup.

---

v3:
- address feedback by Jan: take care of ext4

if you don't like the specific comment added below I would appreciate if you adjusted it yourself.

this patch replaces this guy: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/commit/?h=vfs-6.19.inode&id=7ba2ca3d17bb69276de7c97587b1e1f3d989f389

the other patch in the previous series remains unchanged

 fs/ext4/inode.c   | 3 +--
 fs/fs-writeback.c | 7 +++++++
 fs/inode.c        | 4 +---
 3 files changed, 9 insertions(+), 5 deletions(-)
fs/ext4/inode.c +1 -2
index b864e9645f85..bf978ece70b3 100644
@@ -202,8 +202,7 @@ void ext4_evict_inode(struct inode *inode)
 	 * the inode. Flush worker is ignoring it because of I_FREEING flag but
 	 * we still need to remove the inode from the writeback lists.
 	 */
-	if (!list_empty_careful(&inode->i_io_list))
-		inode_io_list_del(inode);
+	inode_io_list_del(inode);
 
 	/*
 	 * Protect us against freezing - iput() caller didn't have to have any
fs/fs-writeback.c +7 -0
index f784d8b09b04..e2eed66aabf8 100644
@@ -1349,6 +1349,13 @@ void inode_io_list_del(struct inode *inode)
 {
 	struct bdi_writeback *wb;
 
+	/*
+	 * FIXME: ext4 can call here from ext4_evict_inode() after evict() already
+	 * unlinked the inode.
+	 */
+	if (list_empty_careful(&inode->i_io_list))
+		return;
+
 	wb = inode_to_wb_and_lock_list(inode);
 	spin_lock(&inode->i_lock);
 
fs/inode.c +1 -3
index 0f3a56ea8f48..263da76ed4fc 100644
@@ -815,9 +815,7 @@ static void evict(struct inode *inode)
 	BUG_ON(!(inode_state_read_once(inode) & I_FREEING));
 	BUG_ON(!list_empty(&inode->i_lru));
 
-	if (!list_empty(&inode->i_io_list))
-		inode_io_list_del(inode);
-
+	inode_io_list_del(inode);
 	inode_sb_list_del(inode);
 
 	spin_lock(&inode->i_lock);
Signature · 1 line
2.34.1
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Mateusz Guzik

For consistency with sb routines.

ext4 is the only consumer outside of evict(). Damage-controlling it is outside of the scope of this cleanup.

Thanks. Feel free to add:

One note below:

fs/fs-writeback.c void inode_io_list_del(struct inode *inode) · line 1355

Quoted 12 lines
fs/fs-writeback.c +4 -0
index f784d8b09b04..e2eed66aabf8 100644
@@ -1349,6 +1349,13 @@ void inode_io_list_del(struct inode *inode)
 {
 	struct bdi_writeback *wb;
 
+	/*
+	 * FIXME: ext4 can call here from ext4_evict_inode() after evict() already
+	 * unlinked the inode.
+	 */

This is in fact due to a possible race between __mark_inode_dirty() called from ending page writeback (which is perfectly legal for a filesystem to do) and iput_final() + evict(). See bc12ac98ea2e ("ext4: silence the warning when evicting inode with dioread_nolock") for details. So proper solution should be in the generic code... E.g. checking emptiness of i_io_list under i_lock should be enough to close the race but it's a bit tricky to avoid the unnecessary lock roundtrip for clean inodes.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#2 lore raw
In reply to Mateusz Guzik
Quoted 6 lines · Mateusz Guzik

For consistency with sb routines.

ext4 is the only consumer outside of evict(). Damage-controlling it is outside of the scope of this cleanup.

Applied to the vfs-6.19.inode branch of the vfs/vfs.git tree. Patches in the vfs-6.19.inode branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.19.inode

[1/1] fs: push list presence check into inode_io_list_del()

      https://git.kernel.org/vfs/vfs/c/f6fe56e7a34e