* [PATCH] ovl: set I_CREATING on inode being created @ 2018-08-22 8:55 Miklos Szeredi 2018-08-22 14:53 ` Linus Torvalds 0 siblings, 1 reply; 4+ messages in thread From: Miklos Szeredi @ 2018-08-22 8:55 UTC (permalink / raw) To: Linus Torvalds; +Cc: linux-kernel, linux-fsdevel, linux-unionfs, viro ...otherwise there will be list corruption due to inode_sb_list_add() being called for inode already on the sb list. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: e950564b97fd ("vfs: don't evict uninitialized inode") --- This missed the 4.19 overlay pull request, because it fixes a bug introduced by patch not in said pull (buggy patch is also mine, incidentally). fs/overlayfs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -603,6 +603,10 @@ static int ovl_create_object(struct dent if (!inode) goto out_drop_write; + spin_lock(&inode->i_lock); + inode->i_state |= I_CREATING; + spin_unlock(&inode->i_lock); + inode_init_owner(inode, dentry->d_parent->d_inode, mode); attr.mode = inode->i_mode; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ovl: set I_CREATING on inode being created 2018-08-22 8:55 [PATCH] ovl: set I_CREATING on inode being created Miklos Szeredi @ 2018-08-22 14:53 ` Linus Torvalds 2018-08-22 19:58 ` Miklos Szeredi 0 siblings, 1 reply; 4+ messages in thread From: Linus Torvalds @ 2018-08-22 14:53 UTC (permalink / raw) To: Miklos Szeredi Cc: Linux Kernel Mailing List, linux-fsdevel, linux-unionfs, Al Viro On Wed, Aug 22, 2018 at 1:55 AM Miklos Szeredi <miklos@szeredi.hu> wrote: > > + spin_lock(&inode->i_lock); > + inode->i_state |= I_CREATING; > + spin_unlock(&inode->i_lock); > + Why is that spinlock protection there? Isn't this a new inode that cannot possibly be reached any other way yet? NOTE! This is a question. Maybe there is something I missed, and there *are* other ways to reach that inode. But if that's true, isn't it already too late to set I_CREATING? So I'd like some clarification on this point before applying it. It's possible that the spinlock is required, I just want to understand why. Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ovl: set I_CREATING on inode being created 2018-08-22 14:53 ` Linus Torvalds @ 2018-08-22 19:58 ` Miklos Szeredi 2018-08-22 20:14 ` Linus Torvalds 0 siblings, 1 reply; 4+ messages in thread From: Miklos Szeredi @ 2018-08-22 19:58 UTC (permalink / raw) To: Linus Torvalds Cc: Linux Kernel Mailing List, linux-fsdevel, overlayfs, Al Viro On Wed, Aug 22, 2018 at 4:53 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote: > On Wed, Aug 22, 2018 at 1:55 AM Miklos Szeredi <miklos@szeredi.hu> wrote: >> >> + spin_lock(&inode->i_lock); >> + inode->i_state |= I_CREATING; >> + spin_unlock(&inode->i_lock); >> + > > Why is that spinlock protection there? > > Isn't this a new inode that cannot possibly be reached any other way yet? new_inode() puts it on sb->s_inodes list, so it *is* reachable. Following operate on s_inodes: - evict_inodes() called from generic_shutdown_super(): a) we shouldn't get here while in creation, b) it's careful to not touch inodes with non-zero refcount - invalidate_inodes(), called from block devices, so it doesn't apply to overlayfs, also it skips inodes with non-zero refcount - iterate_bdevs(), operates on blockdev_superblock - fsnotify_unmount_inodes() called from generic_shutdown_super(): we shouldn't get here while in creation, - add_dquot_ref(), remove_dquot_ref(): not quite sure what these do, but quotas are not (yet) supported on overlayfs So looks like we are safe without a spinlock. And there's another, more fundamental reason: if anything starts messing with i_state of an inode that is not yet even had its state changed to I_NEW, then lots of filesystems are in trouble. > NOTE! This is a question. Maybe there is something I missed, and there > *are* other ways to reach that inode. But if that's true, isn't it > already too late to set I_CREATING? No, it's not too late, I_CREATING can be set anytime up to inode_insert5(), which is the first one to actually look at that flag. > So I'd like some clarification on this point before applying it. It's > possible that the spinlock is required, I just want to understand why. I added the spinlock, because it's cheap (new_inode() already pulls it into L1 cache) and because it's much harder to prove that lockless one is correct than just adding that locking. Thanks, Miklos ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ovl: set I_CREATING on inode being created 2018-08-22 19:58 ` Miklos Szeredi @ 2018-08-22 20:14 ` Linus Torvalds 0 siblings, 0 replies; 4+ messages in thread From: Linus Torvalds @ 2018-08-22 20:14 UTC (permalink / raw) To: Miklos Szeredi Cc: Linux Kernel Mailing List, linux-fsdevel, linux-unionfs, Al Viro On Wed, Aug 22, 2018 at 12:58 PM Miklos Szeredi <miklos@szeredi.hu> wrote: > > > So I'd like some clarification on this point before applying it. It's > > possible that the spinlock is required, I just want to understand why. > > I added the spinlock, because it's cheap (new_inode() already pulls it > into L1 cache) and because it's much harder to prove that lockless one > is correct than just adding that locking. Ok, thanks, looks good to me. And looking around, I think it matches most of the other cases of us setting those I_NEW and I_CREATING flags, so I guess it's good from a consistency standpoint too. I just wanted that clarified, but I'll just apply the patch directly. Thanks, Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-08-22 23:41 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-08-22 8:55 [PATCH] ovl: set I_CREATING on inode being created Miklos Szeredi 2018-08-22 14:53 ` Linus Torvalds 2018-08-22 19:58 ` Miklos Szeredi 2018-08-22 20:14 ` Linus Torvalds
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).