From: Christian Brauner <brauner@kernel.org>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Miklos Szeredi <miklos@szeredi.hu>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fsnotify: move fsnotify_open() hook into do_dentry_open()
Date: Mon, 12 Jun 2023 08:43:26 +0200 [thread overview]
Message-ID: <20230612-tankwagen-gelistet-d63006c4753f@brauner> (raw)
In-Reply-To: <20230611122429.1499617-1-amir73il@gmail.com>
On Sun, Jun 11, 2023 at 03:24:29PM +0300, Amir Goldstein wrote:
> fsnotify_open() hook is called only from high level system calls
> context and not called for the very many helpers to open files.
>
> This may makes sense for many of the special file open cases, but it is
> inconsistent with fsnotify_close() hook that is called for every last
> fput() of on a file object with FMODE_OPENED.
>
> As a result, it is possible to observe ACCESS, MODIFY and CLOSE events
> without ever observing an OPEN event.
>
> Fix this inconsistency by replacing all the fsnotify_open() hooks with
> a single hook inside do_dentry_open().
>
> If there are special cases that would like to opt-out of the possible
> overhead of fsnotify() call in fsnotify_open(), they would probably also
> want to avoid the overhead of fsnotify() call in the rest of the fsnotify
> hooks, so they should be opening that file with the __FMODE_NONOTIFY flag.
>
> However, in the majority of those cases, the s_fsnotify_connectors
> optimization in fsnotify_parent() would be sufficient to avoid the
> overhead of fsnotify() call anyway.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>
> Jan,
>
> I found out about this problem when I tested the work to remove
> FMODE_NONOTIFY from overlayfs internal files - even after I enabled
> notifications on the underlying fs, the LTS tests [2] did not observe
> the OPEN events.
>
> Because this change is independent of the ovl work and has implications
> on other subsystems as well (e.g. cachefiles), I think it is better
> if the change came through your tree.
>
> This change has a potential to regress some micro-benchmarks, so if
> you could queue it up for soaking in linux-next that would be great.
>
> Thanks,
> Amir.
>
>
> [1] https://lore.kernel.org/linux-fsdevel/20230609073239.957184-1-amir73il@gmail.com/
> [2] https://github.com/amir73il/ltp/commits/ovl_encode_fid
>
> fs/exec.c | 5 -----
> fs/fhandle.c | 1 -
> fs/open.c | 6 +++++-
> io_uring/openclose.c | 1 -
> 4 files changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/fs/exec.c b/fs/exec.c
> index a466e797c8e2..238473de1ec5 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -152,8 +152,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
> path_noexec(&file->f_path)))
> goto exit;
>
> - fsnotify_open(file);
> -
> error = -ENOEXEC;
>
> read_lock(&binfmt_lock);
> @@ -934,9 +932,6 @@ static struct file *do_open_execat(int fd, struct filename *name, int flags)
> if (err)
> goto exit;
>
> - if (name->name[0] != '\0')
> - fsnotify_open(file);
> -
> out:
> return file;
>
> diff --git a/fs/fhandle.c b/fs/fhandle.c
> index fd0d6a3b3699..6ea8d35a9382 100644
> --- a/fs/fhandle.c
> +++ b/fs/fhandle.c
> @@ -242,7 +242,6 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
> retval = PTR_ERR(file);
> } else {
> retval = fd;
> - fsnotify_open(file);
> fd_install(fd, file);
> }
> path_put(&path);
> diff --git a/fs/open.c b/fs/open.c
> index 4478adcc4f3a..81444ebf6091 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -969,6 +969,11 @@ static int do_dentry_open(struct file *f,
> }
> }
>
> + /*
> + * Once we return a file with FMODE_OPENED, __fput() will call
> + * fsnotify_close(), so we need fsnotify_open() here for symetry.
s/symetry/symmetry/
next prev parent reply other threads:[~2023-06-12 6:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-11 12:24 [PATCH] fsnotify: move fsnotify_open() hook into do_dentry_open() Amir Goldstein
2023-06-12 6:43 ` Christian Brauner [this message]
2023-06-12 8:54 ` Jan Kara
2023-06-12 9:35 ` Christian Brauner
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=20230612-tankwagen-gelistet-d63006c4753f@brauner \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--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).