Skip to content

Commit 2ef435a

Browse files
MaxKellermannbrauner
authored andcommitted
fs: add might_sleep() annotation to iput() and more
When iput() drops the reference counter to zero, it may sleep via inode_wait_for_writeback(). This happens rarely because it's usually the dcache which evicts inodes, but really iput() should only ever be called in contexts where sleeping is allowed. This annotation allows finding buggy callers. Additionally, this patch annotates a few low-level functions that can call iput() conditionally. Cc: Mateusz Guzik <mjguzik@gmail.com> Signed-off-by: Max Kellermann <max.kellermann@ionos.com> Link: https://lore.kernel.org/20250917153632.2228828-1-max.kellermann@ionos.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent cde560f commit 2ef435a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

fs/inode.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
12791279
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
12801280
struct inode *old;
12811281

1282+
might_sleep();
1283+
12821284
again:
12831285
spin_lock(&inode_hash_lock);
12841286
old = find_inode(inode->i_sb, head, test, data, true);
@@ -1382,6 +1384,8 @@ struct inode *iget5_locked_rcu(struct super_block *sb, unsigned long hashval,
13821384
struct hlist_head *head = inode_hashtable + hash(sb, hashval);
13831385
struct inode *inode, *new;
13841386

1387+
might_sleep();
1388+
13851389
again:
13861390
inode = find_inode(sb, head, test, data, false);
13871391
if (inode) {
@@ -1422,6 +1426,9 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
14221426
{
14231427
struct hlist_head *head = inode_hashtable + hash(sb, ino);
14241428
struct inode *inode;
1429+
1430+
might_sleep();
1431+
14251432
again:
14261433
inode = find_inode_fast(sb, head, ino, false);
14271434
if (inode) {
@@ -1605,6 +1612,9 @@ struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
16051612
int (*test)(struct inode *, void *), void *data)
16061613
{
16071614
struct inode *inode;
1615+
1616+
might_sleep();
1617+
16081618
again:
16091619
inode = ilookup5_nowait(sb, hashval, test, data);
16101620
if (inode) {
@@ -1630,6 +1640,9 @@ struct inode *ilookup(struct super_block *sb, unsigned long ino)
16301640
{
16311641
struct hlist_head *head = inode_hashtable + hash(sb, ino);
16321642
struct inode *inode;
1643+
1644+
might_sleep();
1645+
16331646
again:
16341647
inode = find_inode_fast(sb, head, ino, false);
16351648

@@ -1780,6 +1793,8 @@ int insert_inode_locked(struct inode *inode)
17801793
ino_t ino = inode->i_ino;
17811794
struct hlist_head *head = inode_hashtable + hash(sb, ino);
17821795

1796+
might_sleep();
1797+
17831798
while (1) {
17841799
struct inode *old = NULL;
17851800
spin_lock(&inode_hash_lock);
@@ -1826,6 +1841,8 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval,
18261841
{
18271842
struct inode *old;
18281843

1844+
might_sleep();
1845+
18291846
inode->i_state |= I_CREATING;
18301847
old = inode_insert5(inode, hashval, test, NULL, data);
18311848

@@ -1908,6 +1925,7 @@ static void iput_final(struct inode *inode)
19081925
*/
19091926
void iput(struct inode *inode)
19101927
{
1928+
might_sleep();
19111929
if (unlikely(!inode))
19121930
return;
19131931

0 commit comments

Comments
 (0)