From: Nathan Chancellor <nathan@kernel.org>
To: Christian Brauner <brauner@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Mateusz Guzik <mjguzik@gmail.com>, Jann Horn <jannh@google.com>,
viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, llvm@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2] vfs: shave work on failed file open
Date: Tue, 3 Oct 2023 09:45:05 -0700 [thread overview]
Message-ID: <20231003164505.GA624737@dev-arch.thelio-3990X> (raw)
In-Reply-To: <20230930-glitzer-errungenschaft-b86880c177c4@brauner>
Hi Christian,
> >From d266eee9d9d917f07774e2c2bab0115d2119a311 Mon Sep 17 00:00:00 2001
> From: Christian Brauner <brauner@kernel.org>
> Date: Fri, 29 Sep 2023 08:45:59 +0200
> Subject: [PATCH] file: convert to SLAB_TYPESAFE_BY_RCU
>
> In recent discussions around some performance improvements in the file
> handling area we discussed switching the file cache to rely on
> SLAB_TYPESAFE_BY_RCU which allows us to get rid of call_rcu() based
> freeing for files completely. This is a pretty sensitive change overall
> but it might actually be worth doing.
>
> The main downside is the subtlety. The other one is that we should
> really wait for Jann's patch to land that enables KASAN to handle
> SLAB_TYPESAFE_BY_RCU UAFs. Currently it doesn't but a patch for this
> exists.
>
> With SLAB_TYPESAFE_BY_RCU objects may be freed and reused multiple times
> which requires a few changes. So it isn't sufficient anymore to just
> acquire a reference to the file in question under rcu using
> atomic_long_inc_not_zero() since the file might have already been
> recycled and someone else might have bumped the reference.
>
> In other words, callers might see reference count bumps from newer
> users. For this is reason it is necessary to verify that the pointer is
> the same before and after the reference count increment. This pattern
> can be seen in get_file_rcu() and __files_get_rcu().
>
> In addition, it isn't possible to access or check fields in struct file
> without first aqcuiring a reference on it. Not doing that was always
> very dodgy and it was only usable for non-pointer data in struct file.
> With SLAB_TYPESAFE_BY_RCU it is necessary that callers first acquire a
> reference under rcu or they must hold the files_lock of the fdtable.
> Failing to do either one of this is a bug.
>
> Thanks to Jann for pointing out that we need to ensure memory ordering
> between reallocations and pointer check by ensuring that all subsequent
> loads have a dependency on the second load in get_file_rcu() and
> providing a fixup that was folded into this patch.
>
> Cc: Jann Horn <jannh@google.com>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
<snip>
> --- a/arch/powerpc/platforms/cell/spufs/coredump.c
> +++ b/arch/powerpc/platforms/cell/spufs/coredump.c
> @@ -74,10 +74,13 @@ static struct spu_context *coredump_next_context(int *fd)
> *fd = n - 1;
>
> rcu_read_lock();
> - file = lookup_fd_rcu(*fd);
> - ctx = SPUFS_I(file_inode(file))->i_ctx;
> - get_spu_context(ctx);
> + file = lookup_fdget_rcu(*fd);
> rcu_read_unlock();
> + if (file) {
> + ctx = SPUFS_I(file_inode(file))->i_ctx;
> + get_spu_context(ctx);
> + fput(file);
> + }
>
> return ctx;
> }
This hunk now causes a clang warning (or error, since arch/powerpc builds
with -Werror by default) in next-20231003.
$ make -skj"$(nproc)" ARCH=powerpc LLVM=1 ppc64_guest_defconfig arch/powerpc/platforms/cell/spufs/coredump.o
...
arch/powerpc/platforms/cell/spufs/coredump.c:79:6: error: variable 'ctx' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
79 | if (file) {
| ^~~~
arch/powerpc/platforms/cell/spufs/coredump.c:85:9: note: uninitialized use occurs here
85 | return ctx;
| ^~~
arch/powerpc/platforms/cell/spufs/coredump.c:79:2: note: remove the 'if' if its condition is always true
79 | if (file) {
| ^~~~~~~~~
arch/powerpc/platforms/cell/spufs/coredump.c:69:25: note: initialize the variable 'ctx' to silence this warning
69 | struct spu_context *ctx;
| ^
| = NULL
1 error generated.
Cheers,
Nathan
next prev parent reply other threads:[~2023-10-03 16:45 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 16:22 [PATCH v2] vfs: shave work on failed file open Mateusz Guzik
2023-09-26 19:00 ` Linus Torvalds
2023-09-26 19:28 ` Mateusz Guzik
2023-09-27 14:09 ` Christian Brauner
2023-09-27 14:34 ` Mateusz Guzik
2023-09-27 17:48 ` Linus Torvalds
2023-09-27 17:56 ` Mateusz Guzik
2023-09-27 18:05 ` Linus Torvalds
2023-09-27 18:32 ` Mateusz Guzik
2023-09-27 20:27 ` Linus Torvalds
2023-09-27 21:06 ` Mateusz Guzik
2023-09-27 21:18 ` Linus Torvalds
2023-09-27 21:30 ` Mateusz Guzik
2023-09-28 13:25 ` Christian Brauner
2023-09-28 14:05 ` Christian Brauner
2023-09-28 14:43 ` Jann Horn
2023-09-28 17:21 ` Linus Torvalds
2023-09-29 9:20 ` Christian Brauner
2023-09-29 13:31 ` Jann Horn
2023-09-29 19:57 ` Christian Brauner
2023-09-29 21:23 ` Mateusz Guzik
2023-09-29 21:39 ` Mateusz Guzik
2023-09-29 23:57 ` Linus Torvalds
2023-09-30 9:04 ` Christian Brauner
2023-10-03 16:45 ` Nathan Chancellor [this message]
2023-10-10 3:06 ` Al Viro
2023-10-10 8:29 ` Christian Brauner
2023-09-29 22:24 ` Matthew Wilcox
2023-09-29 23:02 ` Jann Horn
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=20231003164505.GA624737@dev-arch.thelio-3990X \
--to=nathan@kernel.org \
--cc=brauner@kernel.org \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=llvm@lists.linux.dev \
--cc=mjguzik@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).