From: Jan Kara <jack@suse.cz>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
paulmck@kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, torvalds@linux-foundation.org,
edumazet@google.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] fs: elide the smp_rmb fence in fd_install()
Date: Thu, 5 Dec 2024 16:29:37 +0100 [thread overview]
Message-ID: <20241205152937.v2uf65wcmnkutiqz@quack3> (raw)
In-Reply-To: <CAGudoHGtOX+XPM5Z5eWd-feCvNZQ+nv0u6iY9zqGVMhPunLXqA@mail.gmail.com>
On Thu 05-12-24 16:01:07, Mateusz Guzik wrote:
> On Thu, Dec 5, 2024 at 3:46 PM Jan Kara <jack@suse.cz> wrote:
> >
> > On Thu 05-12-24 13:03:32, Mateusz Guzik wrote:
> > > See the added commentary for reasoning.
> > >
> > > ->resize_in_progress handling is moved inside of expand_fdtable() for
> > > clarity.
> > >
> > > Whacks an actual fence on arm64.
> > >
> > > Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
> >
> > Hum, I don't think this works. What could happen now is:
> >
> > CPU1 CPU2
> > expand_fdtable() fd_install()
> > files->resize_in_progress = true;
> > ...
> > if (atomic_read(&files->count) > 1)
> > synchronize_rcu();
> > ...
> > rcu_assign_pointer(files->fdt, new_fdt);
> > if (cur_fdt != &files->fdtab)
> > call_rcu(&cur_fdt->rcu, free_fdtable_rcu);
> >
> > rcu_read_lock_sched()
> >
> > fdt = rcu_dereference_sched(files->fdt);
> > /* Fetched old FD table - without
> > * smp_rmb() the read was reordered */
> > rcu_assign_pointer(files->fdt, new_fdt);
> > /*
> > * Publish everything before we unset ->resize_in_progress, see above
> > * for an explanation.
> > */
> > smp_wmb();
> > out:
> > files->resize_in_progress = false;
> > if (unlikely(files->resize_in_progress)) {
> > - false
> > rcu_assign_pointer(fdt->fd[fd], file);
> > - store in the old table - boom.
> >
>
> I don't believe this ordering is possible because of both
> synchronize_rcu and the fence before updating resize_in_progress.
>
> Any CPU which could try racing like that had to come in after the
> synchronize_rcu() call, meaning one of the 3 possibilities:
> - the flag is true and the fd table is old
> - the flag is true and the fd table is new
> - the flag is false and the fd table is new
I agree here.
> Suppose the CPU reordered loads of the flag and the fd table. There is
> no ordering in which it can see both the old table and the unset flag.
But I disagree here. If the reads are reordered, then the fd table read can
happen during the "flag is true and the fd table is old" state and the flag
read can happen later in "flag is false and the fd table is new" state.
Just as I outlined above...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-12-05 15:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAGudoHG6zYMfFmhizJDPAw=CF8QY8dzbvg0cSEW4XVcvTYhELw@mail.gmail.com>
2024-12-05 12:03 ` Mateusz Guzik
2024-12-05 14:18 ` Al Viro
2024-12-05 14:43 ` Mateusz Guzik
2024-12-05 18:41 ` Paul E. McKenney
2024-12-05 19:03 ` Mateusz Guzik
2024-12-05 20:01 ` Paul E. McKenney
2024-12-05 20:15 ` Mateusz Guzik
2024-12-05 21:17 ` Paul E. McKenney
2024-12-05 19:26 ` Linus Torvalds
2024-12-05 19:47 ` Mateusz Guzik
2024-12-05 20:11 ` Paul E. McKenney
2024-12-06 12:11 ` Christian Brauner
2024-12-05 20:06 ` Paul E. McKenney
2024-12-05 14:46 ` Jan Kara
2024-12-05 15:01 ` Mateusz Guzik
2024-12-05 15:29 ` Jan Kara [this message]
2024-12-05 15:36 ` Mateusz Guzik
2024-12-06 15:32 ` Jan Kara
2024-12-05 14:58 ` Christian Brauner
2024-12-05 15:06 ` Mateusz Guzik
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=20241205152937.v2uf65wcmnkutiqz@quack3 \
--to=jack@suse.cz \
--cc=brauner@kernel.org \
--cc=edumazet@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=paulmck@kernel.org \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®