From: Mateusz Guzik <mjguzik@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: brauner@kernel.org, viro@zeniv.linux.org.uk,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2] vfs: shave work on failed file open
Date: Tue, 26 Sep 2023 21:28:28 +0200 [thread overview]
Message-ID: <CAGudoHGej+gmmv0OOoep2ENkf7hMBib-KL44Fu=Ym46j=r6VEA@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wjUCLfuKks-VGTG9hrFAORb5cuzqyC0gRXptYGGgL=YYg@mail.gmail.com>
On 9/26/23, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Tue, 26 Sept 2023 at 09:22, Mateusz Guzik <mjguzik@gmail.com> wrote:
>>
>> +void fput_badopen(struct file *file)
>> +{
>> + if (unlikely(file->f_mode & (FMODE_BACKING | FMODE_OPENED))) {
>> + fput(file);
>> + return;
>> + }
>
> I don't understand.
>
> Why the FMODE_BACKING test?
>
> The only thing that sets FMODE_BACKING is alloc_empty_backing_file(),
> and we know that isn't involved, because the file that is free'd is
>
> file = alloc_empty_file(op->open_flag, current_cred());
>
> so that test makes no sense.
>
I tried to future proof by dodging the thing, but I can drop it if you
insist. Also see below.
> It might make sense as another WARN_ON_ONCE(), but honestly, why even
> that? Why worry about FMODE_BACKING?
>
> Now, the FMODE_OPENED check makes sense to me, in that it most
> definitely can be set, and means we need to call the ->release()
> callback and a lot more. Although I get the feeling that this test
> would make more sense in the caller, since path_openat() _already_
> checks for FMODE_OPENED in the non-error path too.
>
>> + if (WARN_ON_ONCE(atomic_long_cmpxchg(&file->f_count, 1, 0) != 1))
>> {
>> + fput(file);
>> + return;
>> + }
>
> Ok, I kind of see why you'd want this safety check. I don't see how
> f_count could be validly anything else, but that's what the
> WARN_ON_ONCE is all about.
>
This would be VFSDEBUG or whatever if it was available. But between
nobody checking this and production kernels suffering the check when
they should not, I take the latter.
I wanted to propose debug macros for vfs but could not be bothered to
type it up and argue about it, maybe I'll get around to it.
> Anyway, I think I'd be happier about this if it was more of a "just
> the reverse of alloc_empty_file()", and path_openat() literally did
> just
>
> if (likely(file->f_mode & FMODE_OPENED))
> release_empty_file(file);
> else
> fput(file);
>
> instead of having this fput_badopen() helper that feels like it needs
> to care about other cases than alloc_empty_file().
>
I don't have a strong opinion, I think my variant is cleaner and more
generic, but this boils down to taste and this is definitely not the
hill I'm willing to die on.
I am enable to whatever tidy ups without a fight as long as the core
remains (task work and rcu dodged).
All that said, I think it is Christian's call on how it should look like.
--
Mateusz Guzik <mjguzik gmail.com>
next prev parent reply other threads:[~2023-09-26 19:28 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 [this message]
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
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='CAGudoHGej+gmmv0OOoep2ENkf7hMBib-KL44Fu=Ym46j=r6VEA@mail.gmail.com' \
--to=mjguzik@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).