From: Al Viro <viro@zeniv.linux.org.uk>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] vfs: avoid spurious dentry ref/unref cycle on open
Date: Tue, 6 Aug 2024 16:53:19 +0100 [thread overview]
Message-ID: <20240806155319.GP5334@ZenIV> (raw)
In-Reply-To: <20240806144628.874350-1-mjguzik@gmail.com>
On Tue, Aug 06, 2024 at 04:46:28PM +0200, Mateusz Guzik wrote:
> The flag thing is optional and can be dropped, but I think the general
> direction should be to add *more* asserts and whatnot (even if they are
> to land separately). A debug-only variant would not hurt.
Asserts do *not* clarify anything; if you want your optional flag,
come up with clear description of its semantics. In terms of state,
_not_ control flow.
> @@ -3683,6 +3685,7 @@ static const char *open_last_lookups(struct nameidata *nd,
> static int do_open(struct nameidata *nd,
> struct file *file, const struct open_flags *op)
> {
> + struct vfsmount *mnt;
> struct mnt_idmap *idmap;
> int open_flag = op->open_flag;
> bool do_truncate;
> @@ -3720,11 +3723,22 @@ static int do_open(struct nameidata *nd,
> error = mnt_want_write(nd->path.mnt);
> if (error)
> return error;
> + /*
> + * We grab an additional reference here because vfs_open_consume()
> + * may error out and free the mount from under us, while we need
> + * to undo write access below.
> + */
> + mnt = mntget(nd->path.mnt);
It's "after vfs_open_consume() we no longer own the reference in nd->path.mnt",
error or no error...
> do_truncate = true;
> }
> error = may_open(idmap, &nd->path, acc_mode, open_flag);
> - if (!error && !(file->f_mode & FMODE_OPENED))
> - error = vfs_open(&nd->path, file);
> + if (!error && !(file->f_mode & FMODE_OPENED)) {
> + BUG_ON(nd->state & ND_PATH_CONSUMED);
> + error = vfs_open_consume(&nd->path, file);
> + nd->state |= ND_PATH_CONSUMED;
> + nd->path.mnt = NULL;
> + nd->path.dentry = NULL;
Umm... The thing that feels wrong here is that you get an extra
asymmetry with ->atomic_open() ;-/ We obviously can't do that
kind of thing there (if nothing else, we have the parent directory's
inode to unlock, error or no error).
I don't hate that patch, but it really feels like the calling
conventions are not right. Let me try to tweak it a bit and
see if anything falls out...
next prev parent reply other threads:[~2024-08-06 15:53 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 14:46 [PATCH] vfs: avoid spurious dentry ref/unref cycle on open Mateusz Guzik
2024-08-06 15:53 ` Al Viro [this message]
2024-08-06 16:09 ` Mateusz Guzik
2024-08-06 16:14 ` Mateusz Guzik
2024-08-07 3:38 ` Al Viro
2024-08-07 3:57 ` Mateusz Guzik
2024-08-07 5:32 ` Al Viro
2024-08-07 5:46 ` Mateusz Guzik
2024-08-07 6:23 ` Al Viro
2024-08-07 6:33 ` Al Viro
2024-08-07 6:40 ` Mateusz Guzik
2024-08-07 7:05 ` Al Viro
2024-08-07 7:22 ` Mateusz Guzik
2024-08-07 7:52 ` Al Viro
2024-08-07 7:59 ` Mateusz Guzik
2024-08-07 9:50 ` Mateusz Guzik
2024-08-07 12:43 ` Al Viro
2024-08-07 20:38 ` Al Viro
2024-08-20 11:38 ` Mateusz Guzik
2024-08-22 0:33 ` Al Viro
2024-08-22 0:34 ` [PATCH 1/3] don't duplicate vfs_open() in kernel_file_open() Al Viro
2024-08-22 7:53 ` Christian Brauner
2024-08-22 0:41 ` [PATCH 2/3] lift grabbing path into caller of do_dentry_open() Al Viro
2024-08-22 7:54 ` Christian Brauner
2024-08-22 0:41 ` [PATCH 3/3] avoid extra path_get/path_put cycle in path_openat() Al Viro
2024-08-22 9:31 ` Christian Brauner
2024-08-22 10:21 ` Mateusz Guzik
2024-08-22 15:16 ` kernel test robot
2024-08-22 16:28 ` kernel test robot
2025-02-17 8:03 ` [PATCH] vfs: avoid spurious dentry ref/unref cycle on open Mateusz Guzik
2024-08-08 6:26 ` Mateusz Guzik
2024-08-06 22:51 ` Dave Chinner
2024-08-06 22:55 ` Mateusz Guzik
2024-08-07 2:56 ` Dave Chinner
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=20240806155319.GP5334@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
/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.