From: Mateusz Guzik <mjguzik@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: brauner@kernel.org, viro@zeniv.linux.org.uk,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fs: assert on ->i_count in iput_final()
Date: Wed, 1 Oct 2025 16:28:15 +0200 [thread overview]
Message-ID: <CAGudoHFAar2rHaCDWP4uD2QD_BO42-Fi6b9uxwFvHTmkXTCQfA@mail.gmail.com> (raw)
In-Reply-To: <7ck3szsab4zb3uzgh6aub5kmvm2slold5la2oyi264klwjel36@crjlqzwdmrgh>
On Wed, Oct 1, 2025 at 3:08 PM Jan Kara <jack@suse.cz> wrote:
>
> On Wed 01-10-25 14:12:13, Mateusz Guzik wrote:
> > On Wed, Oct 1, 2025 at 2:07 PM Jan Kara <jack@suse.cz> wrote:
> > > > diff --git a/fs/inode.c b/fs/inode.c
> > > > index ec9339024ac3..fa82cb810af4 100644
> > > > --- a/fs/inode.c
> > > > +++ b/fs/inode.c
> > > > @@ -1879,6 +1879,7 @@ static void iput_final(struct inode *inode)
> > > > int drop;
> > > >
> > > > WARN_ON(inode->i_state & I_NEW);
> > > > + VFS_BUG_ON_INODE(atomic_read(&inode->i_count) != 0, inode);
> > >
> > > This seems pointless given when iput_final() is called...
> > >
> >
> > This and the other check explicitly "wrap" the ->drop_inode call.
>
> I understand but given iput() has just decremented i_count to 0 before
> calling iput_final() this beginning of the "wrap" looks pretty pointless to
> me.
>
To my understanding you are not NAKing the patch, are merely not
particularly fond of it. ;)
Given that these asserts don't show up in production kernels, the
layer should be moving towards always spelling out all assumptions at
the entry point. Worst case does not hurt in production anyway, best
case it will catch something.
For iput_final specifically, at the moment there is only one consumer
so this indeed may look overzealous.
But for the sake of argument suppose someone noticed that
dentry_unlink_inode() performs:
spin_unlock(&inode->i_lock);
if (!inode->i_nlink)
fsnotify_inoderemove(inode);
if (dentry->d_op && dentry->d_op->d_iput)
dentry->d_op->d_iput(dentry, inode);
else
iput(inode);
... and that with some minor rototoiling the inode lock can survive
both fsnotify and custom d_iput in the common case. Should that
happen, iput_locked() could be added to shave off a lock trip in the
common case of whacking the inode. But then there is 2 consumers of
iput_final. etc.
next prev parent reply other threads:[~2025-10-01 14:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 1:00 [PATCH] fs: assert on ->i_count in iput_final() Mateusz Guzik
2025-10-01 12:06 ` Jan Kara
2025-10-01 12:12 ` Mateusz Guzik
2025-10-01 13:07 ` Jan Kara
2025-10-01 14:28 ` Mateusz Guzik [this message]
2025-10-01 15:11 ` Jan Kara
2025-10-06 11:36 ` Christian Brauner
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=CAGudoHFAar2rHaCDWP4uD2QD_BO42-Fi6b9uxwFvHTmkXTCQfA@mail.gmail.com \
--to=mjguzik@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).