mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bernd Schubert <bernd@bsbernd.com>
To: joberdorf@ddn.com, Joanne Koong <joannelkoong@gmail.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Luis Henriques <luis@igalia.com>
Cc: Miklos Szeredi <mszeredi@redhat.com>,
	Bernd Schubert <bschubert@ddn.com>,
	fuse-devel@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] fuse: io-uring: end the request of a pending send on abort
Date: Fri, 4 Dec 2026 00:17:23 +0100	[thread overview]
Message-ID: <f878a08e-6ea9-45a5-b4aa-618a754268f1@bsbernd.com> (raw)
In-Reply-To: <20261201-fuse-uring-abort-pending-send-v1-1-3386615f48c3@ddn.com>

Hi Justin,

I will review before Monday. Please note that my DDN mail address still
works, but likely not for long anymore.


Thanks,
Bend

On 12/1/26 17:12, Justin Oberdorf via B4 Relay wrote:
> From: Justin Oberdorf <joberdorf@ddn.com>
> 
> When a request is queued through io-uring and a ring entry is available,
> fuse_uring_queue_fuse_req() (and fuse_uring_queue_bq_req()) assigns the
> request to the entry and dispatches the send as task work in the server's
> task (fuse_uring_dispatch_ent -> io_uring_cmd_complete_in_task). Until that
> task work runs, the entry sits on ent_w_req_queue and the request is on no
> list at all (fuse_uring_add_req_to_ring_ent() detaches it; it is hashed
> into fpq->processing only by fuse_uring_send()).
> 
> A stopped server never runs that task work: SIGSTOP, a frozen cgroup, a
> debugger. That is exactly the server the request timeout is there for, and
> fuse_uring_request_expired() does see the entry (ent_list_request_expired()
> on ent_w_req_queue) and aborts the connection. But the abort ends nothing
> for it: fuse_uring_abort_end_requests() ends only fuse_req_queue and
> fuse_uring_teardown_entries() handles only ent_in_userspace and
> ent_avail_queue. The caller stays in request_wait_answer() until the server
> is continued or killed, and fuse_uring_async_stop_queues() logs
> " ent-req-queue ... state=3" every 50 ms meanwhile. An idle server has
> every entry available, so this is the common shape of a frozen server, and
> the request timeout is ineffective for it. With FUSE_HAS_SYNCFS the caller
> is sync(2): one stopped server pins every host-wide sync in D state. The
> classic /dev/fuse transport leaves such a request on fiq->pending, which
> the abort ends.
> 
> Reproducer, with libfuse 3.18's example/passthrough_ll (its io-uring
> queues run in the multi-threaded loop) and the timeout from the sysctl, so
> no server option is involved:
> 
>   echo 10 > /proc/sys/fs/fuse/default_request_timeout
>   passthrough_ll -f -o io_uring -o source=/some/dir /mnt/x &
>   cat /mnt/x/file          # the ring serves
>   kill -STOP $!
>   stat /mnt/x/file         # from another shell
> 
> v7.4-rc5: the stat hangs; from 5 s after the abort the kernel logs
> " ent-req-queue ring=... state=3" every 50 ms; kill -CONT (or -KILL)
> frees it - 45 s later in the run traced here. ftrace of that run:
> fuse_uring_queue_fuse_req from stat on CPU 5, fuse_chan_abort from the
> timeout work 15 s later, and the queue-5 thread's
> fuse_uring_send_in_task only after SIGCONT. With this patch the stat
> returns ECONNABORTED 15 s after it was issued (the timeout plus one check
> period), the server still stopped. Our own server, which negotiates the
> timeout at INIT, showed the same with sync(2) as the caller.
> 
> Fix it in two halves that hand the entry over under the queue lock:
> 
>  - Entries dispatched to task work get a state of their own,
>    FRRS_FUSE_REQ_PENDING_SEND, set under the queue lock by the two
>    dispatching paths. The synchronous send in
>    fuse_uring_get_next_fuse_req() keeps FRRS_FUSE_REQ: it copies at once in
>    the server's own syscall.
> 
>  - fuse_uring_abort_end_requests() detaches and ends the requests of every
>    FRRS_FUSE_REQ_PENDING_SEND entry (fuse_dev_end_requests(), as for
>    fuse_req_queue). The entries stay for their task work.
> 
>  - fuse_uring_send_in_task() takes the queue lock first: on a live queue it
>    claims the entry (state FRRS_FUSE_REQ) and proceeds as before; on a
>    stopped queue, or on cancel, it releases the entry the way the cancel
>    branch did, ending the request only if the abort has not.
> 
> ent_list_request_expired() tolerates an entry whose request the abort took
> (a concurrent fusectl abort can race the timeout check there).
> 
> The entry's cmd still completes only when its task work runs, so
> fuse_uring_wait_stopped_queues() keeps its semantics: killing the stopped
> server is what releases the ring, as before.
> 
> Fixes: c2c9af9a0b13 ("fuse: Allow to queue fg requests through io-uring")
> Cc: stable@vger.kernel.org
> Signed-off-by: Justin Oberdorf <joberdorf@ddn.com>
> ---
> Single patch; the description is in the commit message.
> ---
>  fs/fuse/dev_uring.c   | 89 ++++++++++++++++++++++++++++++++++++++++++---------
>  fs/fuse/dev_uring_i.h |  6 ++++
>  2 files changed, 80 insertions(+), 15 deletions(-)
> 
> diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
> index 460776cd69cd..874ea0c2a561 100644
> --- a/fs/fuse/dev_uring.c
> +++ b/fs/fuse/dev_uring.c
> @@ -194,6 +194,40 @@ static void fuse_uring_abort_end_queue_requests(struct fuse_ring_queue *queue)
>  	fuse_dev_end_requests(&req_list);
>  }
>  
> +/*
> + * End the requests of entries whose send is still pending as task work in
> + * the server's task (fuse_uring_dispatch_ent). That task work does not run
> + * while the server is stopped (SIGSTOP, a frozen cgroup) - exactly the case
> + * the request timeout aborts the connection for - and nothing else would end
> + * these requests: they are on no list, only reachable through their entry.
> + * The entries stay for their task work, which finds the queue stopped and
> + * releases them (fuse_uring_send_in_task).
> + */
> +static void fuse_uring_abort_end_pending_send_requests(struct fuse_ring_queue *queue)
> +{
> +	struct fuse_ring_ent *ent;
> +	struct fuse_req *req;
> +	LIST_HEAD(req_list);
> +
> +	spin_lock(&queue->lock);
> +	list_for_each_entry(ent, &queue->ent_w_req_queue, list) {
> +		if (ent->state != FRRS_FUSE_REQ_PENDING_SEND)
> +			continue;
> +
> +		req = ent->fuse_req;
> +		if (WARN_ON_ONCE(!req))
> +			continue;
> +
> +		ent->fuse_req = NULL;
> +		/* detached since fuse_uring_add_req_to_ring_ent() */
> +		list_add_tail(&req->list, &req_list);
> +	}
> +	spin_unlock(&queue->lock);
> +
> +	/* must not hold queue lock to avoid order issues with fi->lock */
> +	fuse_dev_end_requests(&req_list);
> +}
> +
>  void fuse_uring_abort_end_requests(struct fuse_ring *ring)
>  {
>  	int qid;
> @@ -213,6 +247,7 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring)
>  		spin_unlock(&fch->bg_lock);
>  		spin_unlock(&queue->lock);
>  		fuse_uring_abort_end_queue_requests(queue);
> +		fuse_uring_abort_end_pending_send_requests(queue);
>  	}
>  }
>  
> @@ -225,7 +260,10 @@ static bool ent_list_request_expired(struct fuse_chan *fch, struct list_head *li
>  	if (!ent)
>  		return false;
>  
> +	/* NULL once an abort ended the request of a pending send */
>  	req = ent->fuse_req;
> +	if (!req)
> +		return false;
>  
>  	return time_is_before_jiffies(req->create_time +
>  				      fch->timeout.req_timeout);
> @@ -1745,9 +1783,19 @@ static void fuse_uring_send_in_task(struct io_tw_req tw_req, io_tw_token_t tw)
>  	struct io_uring_cmd *cmd = io_uring_cmd_from_tw(tw_req);
>  	struct fuse_ring_ent *ent = uring_cmd_to_ring_ent(cmd);
>  	struct fuse_ring_queue *queue = ent->queue;
> +	struct fuse_req *req;
>  	int err;
>  
> -	if (!tw.cancel) {
> +	spin_lock(&queue->lock);
> +	WARN_ON_ONCE(ent->state != FRRS_FUSE_REQ_PENDING_SEND);
> +	if (!tw.cancel && !queue->stopped) {
> +		/*
> +		 * Claim the entry: from here on an abort leaves it and its
> +		 * request to this path (fuse_uring_abort_end_pending_send_requests).
> +		 */
> +		ent->state = FRRS_FUSE_REQ;
> +		spin_unlock(&queue->lock);
> +
>  		err = fuse_uring_prepare_send(ent, ent->fuse_req, issue_flags);
>  		if (err) {
>  			if (!fuse_uring_get_next_fuse_req(ent, queue,
> @@ -1756,21 +1804,28 @@ static void fuse_uring_send_in_task(struct io_tw_req tw_req, io_tw_token_t tw)
>  			err = 0;
>  		}
>  		fuse_uring_send(ent, cmd, err, issue_flags);
> -	} else {
> -		err = -ECANCELED;
> -
> -		spin_lock(&queue->lock);
> -		list_del_init(&ent->list);
> -		fuse_uring_recycle_buffer(ent);
> -		spin_unlock(&queue->lock);
> -
> -		io_uring_cmd_done(cmd, err, issue_flags);
> -
> -		fuse_uring_req_end(ent, ent->fuse_req, err, issue_flags);
> -		kfree(ent);
> -		if (atomic_dec_and_test(&queue->ring->queue_refs))
> -			wake_up_all(&queue->ring->stop_waitq);
> +		return;
>  	}
> +
> +	/*
> +	 * The task is dying (cancel) or the connection got aborted before the
> +	 * send ran: release the entry. The abort may have ended the request
> +	 * already (fuse_req is NULL then); end it here otherwise.
> +	 */
> +	err = tw.cancel ? -ECANCELED : -ENOTCONN;
> +	req = ent->fuse_req;
> +	list_del_init(&ent->list);
> +	fuse_uring_recycle_buffer(ent);
> +	spin_unlock(&queue->lock);
> +
> +	io_uring_cmd_done(cmd, err, issue_flags);
> +
> +	if (req)
> +		fuse_uring_req_end(ent, req, tw.cancel ? err : -ECONNABORTED,
> +				   issue_flags);
> +	kfree(ent);
> +	if (atomic_dec_and_test(&queue->ring->queue_refs))
> +		wake_up_all(&queue->ring->stop_waitq);
>  }
>  
>  static struct fuse_ring_queue *fuse_uring_task_to_queue(struct fuse_ring *ring)
> @@ -1831,6 +1886,8 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req)
>  	}
>  
>  	fuse_uring_add_req_to_ring_ent(ent, req);
> +	/* sent by the server's task work; an abort before that ends the req */
> +	ent->state = FRRS_FUSE_REQ_PENDING_SEND;
>  	spin_unlock(&queue->lock);
>  	fuse_uring_dispatch_ent(ent);
>  	return;
> @@ -1882,6 +1939,8 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req)
>  				       list);
>  	if (ent && req && !fuse_uring_prep_buffer(ent, req)) {
>  		fuse_uring_add_req_to_ring_ent(ent, req);
> +		/* sent by the server's task work; an abort before that ends the req */
> +		ent->state = FRRS_FUSE_REQ_PENDING_SEND;
>  		spin_unlock(&queue->lock);
>  		fuse_uring_dispatch_ent(ent);
>  	} else {
> diff --git a/fs/fuse/dev_uring_i.h b/fs/fuse/dev_uring_i.h
> index 263d0f8b9714..95c182d5087b 100644
> --- a/fs/fuse/dev_uring_i.h
> +++ b/fs/fuse/dev_uring_i.h
> @@ -28,6 +28,12 @@ enum fuse_ring_req_state {
>  	/* The ring entry got assigned a fuse req */
>  	FRRS_FUSE_REQ,
>  
> +	/*
> +	 * The ring entry got assigned a fuse req and the send is pending as
> +	 * task work in the server's task (fuse_uring_dispatch_ent)
> +	 */
> +	FRRS_FUSE_REQ_PENDING_SEND,
> +
>  	/* The ring entry is in or on the way to user space */
>  	FRRS_USERSPACE,
>  
> 
> ---
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
> change-id: 20261201-fuse-uring-abort-pending-send-dc6919e986dc
> 
> Best regards,
> --  
> Justin Oberdorf <joberdorf@ddn.com>
> 
> 


      reply	other threads:[~2026-12-03 23:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:12 Justin Oberdorf via B4 Relay
2026-12-03 23:17 ` Bernd Schubert [this message]

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=f878a08e-6ea9-45a5-b4aa-618a754268f1@bsbernd.com \
    --to=bernd@bsbernd.com \
    --cc=asml.silence@gmail.com \
    --cc=bschubert@ddn.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=joannelkoong@gmail.com \
    --cc=joberdorf@ddn.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luis@igalia.com \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.com \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®