Re: [PATCH v7 07/12] kernfs: hold kernfs_iattr_rwsem when initializing a new inode
From: Greg Kroah-Hartman
Date: Fri Oct 16 2026 - 10:52:20 EST
On Fri, Oct 16, 2026 at 04:38:01PM +0200, Jori Koolstra wrote:
> kernfs_refresh_inode() copies the uid, gid, timestamps and nlink of a
> kernfs_node into its VFS inode. Since commit 9caf69614225 ("kernfs:
> Introduce separate rwsem to protect inode attributes.") these are
> protected by kernfs_iattr_rwsem.
>
> kernfs_init_inode() calls kernfs_refresh_inode(), but was not converted.
> Its callers in turn hold kernfs_rwsem (kernfs_iop_lookup(),
> kernfs_fill_super()) or no lock at all (__kernfs_fh_to_dentry()),
> neither of which excludes a concurrent
> kernfs_setattr()/kernfs_iop_setattr().
>
> Take kernfs_iattr_rwsem for reading around the refresh in
> kernfs_init_inode(). This nests inside kernfs_rwsem, which matches
> kernfs_link_sibling() and kernfs_unlink_sibling().
>
> Also, kernfs_get_inode() then does not need to hold kernfs_rwsem, so
> drop it from kernfs_fill_super().
Oh, nice, this fixes the issue of kernfs not keeping the inode like we
talked about at LPC? Can't argue with this tiny patch, nice work!
Reviewed-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>