fuse: end fuse_req on io-uring cancel task work
Subsystems (3)
Joanne Koong
maintainerPATCH v2 1/1 fuse: end fuse_req on io-uring cancel task work
From: Chris Mason <[email protected]>
When io_uring delivers task work with tw.cancel set (PF_EXITING, PF_KTHREAD fallback, or percpu_ref_is_dying on the ring context), fuse_uring_send_in_task() takes the cancel branch, assigns -ECANCELED, and falls through to fuse_uring_send(). That path only flips the entry to FRRS_USERSPACE and completes the io_uring cmd; it never discharges the ring entry's owning reference to the fuse_req that fuse_uring_add_req_to_ring_ent() handed it at dispatch time.
fuse_uring_send_in_task()
tw.cancel == true
err = -ECANCELED
fuse_uring_send(ent, cmd, err, issue_flags)
ent->state = FRRS_USERSPACE
list_move(&ent->list, &queue->ent_in_userspace)
ent->cmd = NULL
io_uring_cmd_done(-ECANCELED)
/* ent->fuse_req still set, req still hashed */The fuse_req stays linked on fpq->processing[hash] and fuse_request_end() is never invoked. The originating syscall thread blocks in D-state in request_wait_answer() until fuse_abort_conn() runs, which can be the entire connection lifetime. For FR_BACKGROUND requests fc->num_background is never decremented either, so repeated cancels inflate the counter until max_background is hit and all later background ops stall. tw.cancel does not imply a connection abort (e.g. a single io_uring worker thread exits while the fuse connection stays up), so this cannot be left for fuse_abort_conn() to clean up.
Ending the req but still routing the entry through fuse_uring_send() is not enough: that leaves a req-less entry on ent_in_userspace, and ent_list_request_expired() dereferences ent->fuse_req unconditionally on the head of that list, which would then NULL-deref.
Fix the cancel branch to release the entry directly. Remove it from the queue, complete the io_uring cmd, end the fuse_req, free the entry, and drop its queue_refs (waking the teardown waiter if it was the last).
---
This depends on "fuse: fix moving cancelled entry to ent_in_userspace list" [1] and should be applied after it. That patch removes the queue_refs > 0 gate in fuse_uring_abort(); without it, once this cancel path drops queue_refs to 0 with requests still queued, fuse_uring_abort() skips fuse_uring_abort_end_requests() and those requests are never flushed.
[1] https://lore.kernel.org/fuse-devel/[email protected]/
Changelog:
v1: https://lore.kernel.org/fuse-devel/[email protected]/
v1 -> v2:
* Also clean up ent (Bernd)
fs/fuse/dev_uring.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
fs/fuse/dev_uring.c +12 -2
@@ -1236,11 +1236,21 @@ static void fuse_uring_send_in_task(struct io_tw_req tw_req, io_tw_token_t tw)fuse_uring_next_fuse_req (ent, queue, issue_flags);return ; } +fuse_uring_send (ent, cmd, err, issue_flags); }else { err = -ECANCELED ; - } -fuse_uring_send (ent, cmd, err, issue_flags); +spin_lock (&queue->lock); +list_del_init (&ent->list); +spin_unlock (&queue->lock); + +io_uring_cmd_done (cmd, err, issue_flags); + +fuse_uring_req_end (ent, ent->fuse_req, err); +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)
Signature · 1 line
2.52.0