From: Al Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
Cc: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Jan Kara" <jack@suse.cz>, "Sargun Dhillon" <sargun@sargun.me>,
"Kees Cook" <kees@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] fs: always return zero on success from replace_fd()
Date: Tue, 5 Aug 2025 16:34:57 +0100 [thread overview]
Message-ID: <20250805153457.GB222315@ZenIV> (raw)
In-Reply-To: <20250805-beleidigen-klugheit-c19b1657674a@brauner>
On Tue, Aug 05, 2025 at 01:55:59PM +0200, Christian Brauner wrote:
> The calling conventions of do_dup2() are terrible. The only reason it
> drops file_lock itself instead of leaving it to the two callers that
> have to acquire it anyway is because it wants to call filp_close() if
> there's already a file on that fd.
Alternative calling conventions end up being nastier - I've tried.
> And really the side-effect of dropping a lock implicitly is nasty
> especially when the function doesn't even indicate that it does that in
> it's name.
>
> And guards are great.
They do no allow to express things like "foo() consumes lock X".
From time to time, we *do* need that, and when that happens guards
become a menace.
Another case is
lock
if (lock-dependent condition)
some work
unlock
work that can't be under that lock
else
some other work
unlock
more work that can't be under that lock
Fairly common, especially when that's a spinlock and "can't be under that
lock" includes blocking operations. Can't be expressed with guards, not
without a massage that often ends up with bloody awful results.
next prev parent reply other threads:[~2025-08-05 15:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 8:40 [PATCH v2] fs: always return zero on success from replace_fd() Thomas Weißschuh
2025-08-04 12:33 ` Christian Brauner
2025-08-04 15:52 ` Al Viro
2025-08-04 16:02 ` Thomas Weißschuh
2025-08-05 11:56 ` Christian Brauner
2025-08-04 17:27 ` Al Viro
2025-08-05 11:55 ` Christian Brauner
2025-08-05 15:34 ` Al Viro [this message]
2025-08-05 19:50 ` Al Viro
2025-08-06 1:54 ` Al Viro
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=20250805153457.GB222315@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sargun@sargun.me \
--cc=stable@vger.kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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).