Skip to content

Commit eccb95c

Browse files
jankaratorvalds
authored andcommitted
vfs: fix lock inversion in drop_pagecache_sb()
Fix longstanding lock inversion in drop_pagecache_sb by dropping inode_lock before calling __invalidate_mapping_pages(). We just have to make sure inode won't go away from under us by keeping reference to it and putting the reference only after we have safely resumed the scan of the inode list. A bit tricky but not too bad... Signed-off-by: Jan Kara <jack@suse.cz> Cc: Fengguang Wu <wfg@mail.ustc.edu.cn> Cc: David Chinner <dgc@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a852250 commit eccb95c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎fs/drop_caches.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ int sysctl_drop_caches;
1414

1515
static void drop_pagecache_sb(struct super_block *sb)
1616
{
17-
struct inode *inode;
17+
struct inode *inode, *toput_inode = NULL;
1818

1919
spin_lock(&inode_lock);
2020
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
2121
if (inode->i_state & (I_FREEING|I_WILL_FREE))
2222
continue;
23+
__iget(inode);
24+
spin_unlock(&inode_lock);
2325
__invalidate_mapping_pages(inode->i_mapping, 0, -1, true);
26+
iput(toput_inode);
27+
toput_inode = inode;
28+
spin_lock(&inode_lock);
2429
}
2530
spin_unlock(&inode_lock);
31+
iput(toput_inode);
2632
}
2733

2834
static void drop_pagecache(void)

0 commit comments

Comments
 (0)