Linux filesystem development
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: brauner@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-bcachefs@vger.kernel.org, kent.overstreet@linux.dev,
	linux-xfs@vger.kernel.org, david@fromorbit.com
Subject: Re: [PATCH v2 2/4] vfs: partially sanitize i_state zeroing on inode creation
Date: Wed, 12 Jun 2024 11:27:03 +0200	[thread overview]
Message-ID: <20240612092703.u5ialfzz74pfnafk@quack3> (raw)
In-Reply-To: <20240611120626.513952-3-mjguzik@gmail.com>

On Tue 11-06-24 14:06:24, Mateusz Guzik wrote:
> new_inode used to have the following:
> 	spin_lock(&inode_lock);
> 	inodes_stat.nr_inodes++;
> 	list_add(&inode->i_list, &inode_in_use);
> 	list_add(&inode->i_sb_list, &sb->s_inodes);
> 	inode->i_ino = ++last_ino;
> 	inode->i_state = 0;
> 	spin_unlock(&inode_lock);
> 
> over time things disappeared, got moved around or got replaced (global
> inode lock with a per-inode lock), eventually this got reduced to:
> 	spin_lock(&inode->i_lock);
> 	inode->i_state = 0;
> 	spin_unlock(&inode->i_lock);
> 
> But the lock acquire here does not synchronize against anyone.
> 
> Additionally iget5_locked performs i_state = 0 assignment without any
> locks to begin with, the two combined look confusing at best.
> 
> It looks like the current state is a leftover which was not cleaned up.
> 
> Ideally it would be an invariant that i_state == 0 to begin with, but
> achieving that would require dealing with all filesystem alloc handlers
> one by one.
> 
> In the meantime drop the misleading locking and move i_state zeroing to
> inode_init_always so that others don't need to deal with it by hand.
> 
> Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>

Just one nit below:

> diff --git a/fs/inode.c b/fs/inode.c
> index 3a4c67bfe085..8f05d79de01d 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -231,6 +231,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
>  
>  	if (unlikely(security_inode_alloc(inode)))
>  		return -ENOMEM;
> +
> +	inode->i_state = 0;
>  	this_cpu_inc(nr_inodes);

This would be more logical above where inode content is initialized (and
less errorprone just in case security_inode_alloc() grows dependency on
i_state value) - like just after:

	inode->i_flags = 0;

With that fixed feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-06-12  9:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11 12:06 [PATCH v2 0/4] inode_init_always zeroing i_state Mateusz Guzik
2024-06-11 12:06 ` [PATCH v2 1/4] xfs: preserve i_state around inode_init_always in xfs_reinit_inode Mateusz Guzik
2024-06-11 12:06 ` [PATCH v2 2/4] vfs: partially sanitize i_state zeroing on inode creation Mateusz Guzik
2024-06-12  9:27   ` Jan Kara [this message]
2024-06-13 11:41     ` Christian Brauner
2024-06-11 12:06 ` [PATCH v2 3/4] xfs: remove now spurious i_state initialization in xfs_inode_alloc Mateusz Guzik
2024-06-11 12:06 ` [PATCH v2 4/4] bcachefs: remove now spurious i_state initialization Mateusz Guzik
2024-06-11 23:38   ` Kent Overstreet
2024-06-12 12:17 ` [PATCH v2 0/4] inode_init_always zeroing i_state 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=20240612092703.u5ialfzz74pfnafk@quack3 \
    --to=jack@suse.cz \
    --cc=brauner@kernel.org \
    --cc=david@fromorbit.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --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