From: Pavel Begunkov <[email protected]>
To: Bernd Schubert <[email protected]>, Miklos Szeredi <[email protected]>
Cc: Jens Axboe <[email protected]>,
[email protected], [email protected],
Joanne Koong <[email protected]>,
Josef Bacik <[email protected]>,
Amir Goldstein <[email protected]>,
Ming Lei <[email protected]>, David Wei <[email protected]>,
[email protected]
Subject: Re: [PATCH v8 15/16] fuse: {io-uring} Prevent mount point hang on fuse-server termination
Date: Fri, 13 Dec 2024 15:05:17 +0000 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 12/9/24 14:56, Bernd Schubert wrote:
> When the fuse-server terminates while the fuse-client or kernel
> still has queued URING_CMDs, these commands retain references
> to the struct file used by the fuse connection. This prevents
> fuse_dev_release() from being invoked, resulting in a hung mount
> point.
>
> This patch addresses the issue by making queued URING_CMDs
> cancelable, allowing fuse_dev_release() to proceed as expected
> and preventing the mount point from hanging.
io_uring bits look good
> Signed-off-by: Bernd Schubert <[email protected]>
> ---
> fs/fuse/dev_uring.c | 87 ++++++++++++++++++++++++++++++++++++++++++---------
> fs/fuse/dev_uring_i.h | 12 +++++++
> 2 files changed, 85 insertions(+), 14 deletions(-)
>
> diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
> index 8bdfb6fcfa51976cd121bee7f2e8dec1ff9aa916..be7eaf7cc569ff77f8ebdff323634b84ea0a3f63 100644
> --- a/fs/fuse/dev_uring.c
> +++ b/fs/fuse/dev_uring.c
...
> @@ -294,24 +302,27 @@ static void fuse_uring_stop_fuse_req_end(struct fuse_ring_ent *ent)
> /*
> * Release a request/entry on connection tear down
> */
> -static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent,
> - bool need_cmd_done)
> +static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent)
> {
> - /*
> - * fuse_request_end() might take other locks like fi->lock and
> - * can lead to lock ordering issues
> - */
> - lockdep_assert_not_held(&ent->queue->lock);
> + struct fuse_ring_queue *queue = ent->queue;
>
> - if (need_cmd_done)
> + if (ent->need_cmd_done)
> io_uring_cmd_done(ent->cmd, -ENOTCONN, 0,
> IO_URING_F_UNLOCKED);
nit: might be better to pair all io_uring_cmd_done() with
ent->cmd = NULL;
since after the call the request is released and can't be used
by fuse anymore.
>
> if (ent->fuse_req)
> fuse_uring_stop_fuse_req_end(ent);
>
> - list_del_init(&ent->list);
> - kfree(ent);
> + /*
> + * The entry must not be freed immediately, due to access of direct
> + * pointer access of entries through IO_URING_F_CANCEL - there is a risk
> + * of race between daemon termination (which triggers IO_URING_F_CANCEL
> + * and accesses entries without checking the list state first
> + */
> + spin_lock(&queue->lock);
> + list_move(&ent->list, &queue->ent_released);
> + ent->state = FRRS_RELEASED;
> + spin_unlock(&queue->lock);
...
> + * Handle IO_URING_F_CANCEL, typically should come on daemon termination.
> + *
> + * Releasing the last entry should trigger fuse_dev_release() if
> + * the daemon was terminated
> + */
> +static int fuse_uring_cancel(struct io_uring_cmd *cmd, unsigned int issue_flags)
> +{
> + struct fuse_ring_ent *ent = fuse_uring_cmd_to_ring_ent(cmd);
> + struct fuse_ring_queue *queue;
> + bool need_cmd_done = false;
> + int ret = 0;
> +
> + /*
> + * direct access on ent - it must not be destructed as long as
> + * IO_URING_F_CANCEL might come up
> + */
> + queue = ent->queue;
> + spin_lock(&queue->lock);
> + if (ent->state == FRRS_WAIT) {
> + ent->state = FRRS_USERSPACE;
> + list_move(&ent->list, &queue->ent_in_userspace);
> + need_cmd_done = true;
> + }
> + spin_unlock(&queue->lock);
> +
> + if (need_cmd_done) {
> + io_uring_cmd_done(cmd, -ENOTCONN, 0, issue_flags);
> + } else {
> + /* io-uring handles resending */
> + ret = -EAGAIN;
FWIW, apparently io_uring ignores error codes returned from here.
It only cares if the request is removed from a list via
io_uring_cmd_done() or not.
> + }
> +
> + return ret;
> +}
> +
> +static void fuse_uring_prepare_cancel(struct io_uring_cmd *cmd, int issue_flags,
> + struct fuse_ring_ent *ring_ent)
> +{
> + fuse_uring_cmd_set_ring_ent(cmd, ring_ent);
> + io_uring_cmd_mark_cancelable(cmd, issue_flags);
> +}
> +
--
Pavel Begunkov
next prev parent reply other threads:[~2024-12-13 15:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 14:56 [PATCH v8 00/16] fuse: fuse-over-io-uring Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 01/16] fuse: rename to fuse_dev_end_requests and make non-static Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 02/16] fuse: Move fuse_get_dev to header file Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 03/16] fuse: Move request bits Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 04/16] fuse: Add fuse-io-uring design documentation Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 05/16] fuse: make args->in_args[0] to be always the header Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 06/16] fuse: {io-uring} Handle SQEs - register commands Bernd Schubert
2024-12-12 1:29 ` Joanne Koong
2024-12-17 23:50 ` Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 07/16] fuse: Make fuse_copy non static Bernd Schubert
2024-12-13 0:50 ` Joanne Koong
2024-12-09 14:56 ` [PATCH v8 08/16] fuse: Add fuse-io-uring handling into fuse_copy Bernd Schubert
2024-12-13 1:25 ` Joanne Koong
2024-12-09 14:56 ` [PATCH v8 09/16] fuse: {io-uring} Make hash-list req unique finding functions non-static Bernd Schubert
2024-12-13 1:41 ` Joanne Koong
2024-12-09 14:56 ` [PATCH v8 10/16] fuse: Add io-uring sqe commit and fetch support Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 11/16] fuse: {io-uring} Handle teardown of ring entries Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 12/16] fuse: {io-uring} Make fuse_dev_queue_{interrupt,forget} non-static Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 13/16] fuse: Allow to queue fg requests through io-uring Bernd Schubert
2024-12-10 23:14 ` kernel test robot
2024-12-09 14:56 ` [PATCH v8 14/16] fuse: Allow to queue bg " Bernd Schubert
2024-12-09 14:56 ` [PATCH v8 15/16] fuse: {io-uring} Prevent mount point hang on fuse-server termination Bernd Schubert
2024-12-13 15:05 ` Pavel Begunkov [this message]
2024-12-09 14:56 ` [PATCH v8 16/16] fuse: enable fuse-over-io-uring Bernd Schubert
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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