From: Christian Brauner <brauner@kernel.org>
To: aloktiagi <aloktiagi@gmail.com>
Cc: viro@zeniv.linux.org.uk, willy@infradead.org,
David.Laight@ACULAB.COM, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, keescook@chromium.org,
hch@infradead.org, tycho@tycho.pizza
Subject: Re: [RFC v6 1/2] epoll: Implement eventpoll_replace_file()
Date: Tue, 23 May 2023 14:32:06 +0200 [thread overview]
Message-ID: <20230523-unleserlich-impfen-e193df4b4b30@brauner> (raw)
In-Reply-To: <20230523065802.2253926-1-aloktiagi@gmail.com>
On Tue, May 23, 2023 at 06:58:01AM +0000, aloktiagi wrote:
> Introduce a mechanism to replace a file linked in the epoll interface with a new
> file.
>
> eventpoll_replace() finds all instances of the file to be replaced and replaces
> them with the new file and the interested events.
>
> Signed-off-by: aloktiagi <aloktiagi@gmail.com>
> ---
> Changes in v6:
> - incorporate latest changes that get rid of the global epmutex lock.
>
> Changes in v5:
> - address review comments and move the call to replace old file in each
> subsystem (epoll, io_uring, etc.) outside the fdtable helpers like
> replace_fd().
>
> Changes in v4:
> - address review comment to remove the redundant eventpoll_replace() function.
> - removed an extra empty line introduced in include/linux/file.h
>
> Changes in v3:
> - address review comment and iterate over the file table while holding the
> spin_lock(&files->file_lock).
> - address review comment and call filp_close() outside the
> spin_lock(&files->file_lock).
> ---
> fs/eventpoll.c | 76 +++++++++++++++++++++++++++++++++++++++
> include/linux/eventpoll.h | 8 +++++
> 2 files changed, 84 insertions(+)
>
> diff --git a/fs/eventpoll.c b/fs/eventpoll.c
> index 980483455cc0..9c7bffa8401b 100644
> --- a/fs/eventpoll.c
> +++ b/fs/eventpoll.c
> @@ -973,6 +973,82 @@ void eventpoll_release_file(struct file *file)
> spin_unlock(&file->f_lock);
> }
>
> +static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
> + struct file *tfile, int fd, int full_check);
> +
> +/*
> + * This is called from eventpoll_replace() to replace a linked file in the epoll
> + * interface with a new file received from another process. This is useful in
> + * cases where a process is trying to install a new file for an existing one
> + * that is linked in the epoll interface
> + */
> +int eventpoll_replace_file(struct file *toreplace, struct file *file, int tfd)
> +{
> + struct file *to_remove = toreplace;
> + struct epoll_event event;
> + struct hlist_node *next;
> + struct eventpoll *ep;
> + struct epitem *epi;
> + int error = 0;
> + bool dispose;
> + int fd;
> +
> + if (!file_can_poll(file))
> + return 0;
> +
> + spin_lock(&toreplace->f_lock);
> + if (unlikely(!toreplace->f_ep)) {
> + spin_unlock(&toreplace->f_lock);
> + return 0;
> + }
> + hlist_for_each_entry_safe(epi, next, toreplace->f_ep, fllink) {
> + ep = epi->ep;
> + mutex_lock(&ep->mtx);
Afaict, you're under a spinlock and you're acquiring a mutex. The
spinlock can't sleep (on non-rt kernels at least) but the mutex can.
> + fd = epi->ffd.fd;
> + if (fd != tfd) {
> + mutex_unlock(&ep->mtx);
> + continue;
> + }
> + event = epi->event;
> + error = ep_insert(ep, &event, file, fd, 1);
> + mutex_unlock(&ep->mtx);
> + if (error != 0) {
> + break;
> + }
nit: we don't do { } around single lines.
next prev parent reply other threads:[~2023-05-23 12:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 6:58 [RFC v6 1/2] epoll: Implement eventpoll_replace_file() aloktiagi
2023-05-23 6:58 ` [RFC v6 2/2] seccomp: replace existing file in the epoll interface by a new file injected by the syscall supervisor aloktiagi
2023-05-23 12:32 ` Christian Brauner [this message]
2023-05-24 6:36 ` [RFC v6 1/2] epoll: Implement eventpoll_replace_file() Alok Tiagi
2023-05-23 13:31 ` Matthew Wilcox
2023-05-24 6:37 ` Alok Tiagi
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=20230523-unleserlich-impfen-e193df4b4b30@brauner \
--to=brauner@kernel.org \
--cc=David.Laight@ACULAB.COM \
--cc=aloktiagi@gmail.com \
--cc=hch@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tycho@tycho.pizza \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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).