Skip to content

Commit 3393ff9

Browse files
bsberndMiklos Szeredi
authored andcommitted
fuse: block request allocation until io-uring init is complete
Avoid races and block request allocation until io-uring queues are ready. This is a especially important for background requests, as bg request completion might cause lock order inversion of the typical queue->lock and then fc->bg_lock fuse_request_end spin_lock(&fc->bg_lock); flush_bg_queue fuse_send_one fuse_uring_queue_fuse_req spin_lock(&queue->lock); Signed-off-by: Bernd Schubert <[email protected]> Reviewed-by: Luis Henriques <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent b6236c8 commit 3393ff9

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

fs/fuse/dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ void fuse_set_initialized(struct fuse_conn *fc)
7676

7777
static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
7878
{
79-
return !fc->initialized || (for_background && fc->blocked);
79+
return !fc->initialized || (for_background && fc->blocked) ||
80+
(fc->io_uring && !fuse_uring_ready(fc));
8081
}
8182

8283
static void fuse_drop_waiting(struct fuse_conn *fc)

fs/fuse/dev_uring.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ static void fuse_uring_do_register(struct fuse_ring_ent *ent,
957957
if (ready) {
958958
WRITE_ONCE(fiq->ops, &fuse_io_uring_ops);
959959
WRITE_ONCE(ring->ready, true);
960+
wake_up_all(&fc->blocked_waitq);
960961
}
961962
}
962963
}
@@ -1130,6 +1131,8 @@ int __maybe_unused fuse_uring_cmd(struct io_uring_cmd *cmd,
11301131
if (err) {
11311132
pr_info_once("FUSE_IO_URING_CMD_REGISTER failed err=%d\n",
11321133
err);
1134+
fc->io_uring = 0;
1135+
wake_up_all(&fc->blocked_waitq);
11331136
return err;
11341137
}
11351138
break;

fs/fuse/fuse_i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,9 @@ struct fuse_conn {
867867
/* Use pages instead of pointer for kernel I/O */
868868
unsigned int use_pages_for_kvec_io:1;
869869

870+
/* Use io_uring for communication */
871+
unsigned int io_uring;
872+
870873
/** Maximum stack depth for passthrough backing files */
871874
int max_stack_depth;
872875

fs/fuse/inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,8 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
13901390
else
13911391
ok = false;
13921392
}
1393+
if (flags & FUSE_OVER_IO_URING && fuse_uring_enabled())
1394+
fc->io_uring = 1;
13931395
} else {
13941396
ra_pages = fc->max_read / PAGE_SIZE;
13951397
fc->no_lock = 1;

0 commit comments

Comments
 (0)