From: Al Viro <viro@zeniv.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH][RFC] make take_dentry_name_snapshot() lockless
Date: Mon, 9 Dec 2024 20:27:36 +0000 [thread overview]
Message-ID: <20241209202736.GZ3387508@ZenIV> (raw)
In-Reply-To: <CAHk-=whnCrFZ+id8E3Y0uXVDyT4Kbu6pLdPgL42LYTNPdYDVpQ@mail.gmail.com>
On Mon, Dec 09, 2024 at 11:06:48AM -0800, Linus Torvalds wrote:
> On Sun, 8 Dec 2024 at 19:52, Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> > + struct external_name *p;
> > + p = container_of(name->name.name, struct external_name, name[0]);
> > + // get a valid reference
> > + if (unlikely(!atomic_inc_not_zero(&p->u.count)))
> > + goto retry;
>
> Oh - this is very much *not* safe.
>
> The other comment I had was really about "that's bad for performance".
> But this is actually actively buggy.
>
> If the external name ref has gone down to zero, we can *not* do that
>
> atomic_inc_not_zero(..)
>
> thing any more, because the recount is in a union with the rcu_head
> for delaying the free.
D'oh. Right you are; missed it...
> In other words: the *name* will exist for the duration of the
> rcu_read_lock() we hold, but that "p->u.count" will not. When the
> refcount has gone to zero, the refcount is no longer usable.
>
> IOW, you may be happily incrementing what is now a RCU list head
> rather than a count.
>
> So NAK. This cannot work.
>
> It's probably easily fixable by just not using a union in struct
> external_name, and just having separate fields for the refcount and
> the rcu_head, but in the current state your patch is fundamentally and
> dangerously buggy.
Agreed. And yes, separating the fields (and slapping a comment explaining
why they can not be combined) would be the easiest solution - any attempts
to be clever here would be too brittle for no good reason.
prev parent reply other threads:[~2024-12-09 20:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 3:52 [PATCH][RFC] make take_dentry_name_snapshot() lockless Al Viro
2024-12-09 6:33 ` Mateusz Guzik
2024-12-09 6:58 ` Al Viro
2024-12-09 7:18 ` Mateusz Guzik
2024-12-09 7:41 ` Al Viro
2024-12-09 18:27 ` Linus Torvalds
2024-12-09 21:17 ` Al Viro
2024-12-09 22:28 ` Al Viro
2024-12-09 22:49 ` Linus Torvalds
2024-12-09 22:55 ` Linus Torvalds
2024-12-09 23:12 ` Al Viro
2024-12-10 2:45 ` Al Viro
2024-12-10 2:48 ` [PATCH 1/5] make sure that DCACHE_INLINE_LEN is a multiple of word size Al Viro
2024-12-10 2:48 ` [PATCH 2/5] dcache: back inline names with a struct-wrapped array of unsigned long Al Viro
2024-12-10 2:48 ` [PATCH 3/5] make take_dentry_name_snapshot() lockless Al Viro
2024-12-10 2:48 ` [PATCH 4/5] dissolve external_name.u into separate members Al Viro
2024-12-10 2:48 ` [PATCH 5/5] ext4 fast_commit: make use of name_snapshot primitives Al Viro
2024-12-23 4:25 ` [PATCH][RFC] make take_dentry_name_snapshot() lockless Al Viro
2024-12-23 4:37 ` Al Viro
2024-12-23 21:31 ` Jens Axboe
2024-12-24 19:18 ` Al Viro
2024-12-24 19:44 ` Linus Torvalds
2024-12-24 20:24 ` Al Viro
2024-12-09 19:06 ` Linus Torvalds
2024-12-09 20:27 ` Al Viro [this message]
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=20241209202736.GZ3387508@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.