fuse: fix missing barriers in io-uring init
Subsystems (3)
Joanne Koong
maintainercover fuse: fix missing barriers in io-uring init
These are two pre-existing issues Sashiko reported [1] on the fuse zerocopy series.
[1] https://sashiko.dev/#/patchset/20260630211436.2062816-1-joannelkoong%40gmail.com
Joanne Koong (2):
fuse: fix missing barrier when checking io-uring readiness
fuse: publish io-uring queues with release semantics
fs/fuse/dev.c | 8 +++++++- fs/fuse/dev_uring.c | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.52.0
Joanne Koong
maintainerPATCH 1/2 fuse: fix missing barrier when checking io-uring readiness
fuse_block_alloc() reads fch->initialized and then fch->io_uring. fch->io_uring is set before fch->initialized, ordered by the smp_wmb() in fuse_chan_set_intialized(), but fuse_block_alloc() has no matching read barrier between the two loads.
This may lead a CPU to observe fch->initialized=1 but fch->io_uring=0, and skip the check that blocks request allocation until the io-uring queues are ready.
Add an smp_rmb() barrier to pair with the smp_wmb() in fuse_chan_set_initialized() to prevent this.
--- fs/fuse/dev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/fuse/dev.c +7 -1
@@ -85,7 +85,13 @@ void fuse_chan_set_initialized(struct fuse_chan *fch, struct fuse_chan_param *pastatic bool fuse_block_alloc (struct fuse_chan *fch,bool for_background) { -return !fch->initialized || (for_background && fch->blocked) || +if (!fch->initialized) +return true; + +/* Pairs with smp_wmb() in fuse_chan_set_initialized() */ +smp_rmb (); + +return (for_background && fch->blocked) || (fch->io_uring && fch->connected && !fuse_uring_ready (fch)); }
Signature · 1 line
2.52.0
Joanne Koong
maintainerPATCH 2/2 fuse: publish io-uring queues with release semantics
In reply to Joanne Koongfuse_uring_create_queue() initializes a fuse_ring_queue and then publishes the pointer into ring->queues[qid] with WRITE_ONCE() under the fch->lock. On the reader side, fuse_uring_register() reads that pointer on a fast path locklessly with
queue = ring->queues[qid];
There's no barrier that orders the initialization/setup of the queue's fields and the WRITE_ONCE() that publishes the queue. As a result, the lockless concurrent reader can see a non-null queue but uninitialized queue fields (eg spinlock and list heads) and then operate on uninitialized memory.
Publish the queue with smp_store_release() and read it on the lockless fast path with smp_load_acquire().
--- fs/fuse/dev_uring.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/fuse/dev_uring.c +7 -3
@@ -321,9 +321,12 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, }/* -* write_once and lock as the caller mostly doesn't take the lock at all +* fch->lock serializes concurrent creators for this qid. +* smp_store_release() is for the lockless reader in +* fuse_uring_register(), which pairs it with smp_load_acquire() and +* must see the fully initialized queue if it sees a non-null queue */ -WRITE_ONCE (ring->queues[qid], queue); +smp_store_release (&ring->queues[qid], queue);spin_unlock (&fch->lock);return queue;
@@ -1191,7 +1194,8 @@ static int fuse_uring_register(struct io_uring_cmd *cmd,return -EINVAL ; } - queue = ring->queues[qid]; +/* Pairs with smp_store_release() in fuse_uring_create_queue() */ + queue =smp_load_acquire (&ring->queues[qid]);if (!queue) { queue =fuse_uring_create_queue (ring, qid);if (!queue)
Signature · 1 line
2.52.0
Joanne Koong
maintainerQuoted 5 lines · Joanne Koong
These are two pre-existing issues Sashiko reported [1] on the fuse zerocopy series.
[1] https://sashiko.dev/#/patchset/20260630211436.2062816-1-joannelkoong%40gmail.com
Sashiko noted some other places that are also missing barriers [1]. Will send v2 to add these places as well.
[1] https://sashiko.dev/#/patchset/20260713175345.2542331-1-joannelkoong%40gmail.com
Joanne Koong
maintainerQuoted 10 lines · Joanne Koong
Quoted 5 lines · Joanne Koong
These are two pre-existing issues Sashiko reported [1] on the fuse zerocopy series.
[1] https://sashiko.dev/#/patchset/20260630211436.2062816-1-joannelkoong%40gmail.com
Sashiko noted some other places that are also missing barriers [1]. Will send v2 to add these places as well.
These additional ones aren't real bugs. They're not reachable on a well-behaved server and on a malicious/buggy server, the failure is benign / self-correcting.
I think we need some sort of way to help Sashiko understand so it doesn't keep flagging this on every future patch anyone submits. I think there's a few other places where some of Sashiko's assumptions/analysis are wrong (eg uring-cmd sqe stability semantics
[1] in the zero-copy series). I'll look into this unless anyone already knows how to do this.
Thanks,
Joanne
Quoted 17 lines · Joanne Koong
Quoted 10 lines · Joanne Koong
Quoted 5 lines · Joanne Koong
These are two pre-existing issues Sashiko reported [1] on the fuse zerocopy series.
[1] https://sashiko.dev/#/patchset/20260630211436.2062816-1-joannelkoong%40gmail.com
Sashiko noted some other places that are also missing barriers [1]. Will send v2 to add these places as well.
These additional ones aren't real bugs. They're not reachable on a well-behaved server and on a malicious/buggy server, the failure is benign / self-correcting.
Quoted 6 lines
I think we need some sort of way to help Sashiko understand so it doesn't keep flagging this on every future patch anyone submits. I think there's a few other places where some of Sashiko's assumptions/analysis are wrong (eg uring-cmd sqe stability semantics
[1] in the zero-copy series). I'll look into this unless anyone already knows how to do this.
You may want to talk with your colleague Chris Mason about adding review prompts for FUSE, because he is also running AI analysis on existing subsystems regardless of mailing list patches.
I didn't try, but you can probably figure out how to add FUSE specific review prompts
to Sashiko yourself...
Thanks,
Amir.
Joanne Koong
maintainerQuoted 33 lines · Amir Goldstein
Quoted 17 lines · Joanne Koong
Quoted 10 lines · Joanne Koong
Quoted 5 lines · Joanne Koong
These are two pre-existing issues Sashiko reported [1] on the fuse zerocopy series.
[1] https://sashiko.dev/#/patchset/20260630211436.2062816-1-joannelkoong%40gmail.com
Sashiko noted some other places that are also missing barriers [1]. Will send v2 to add these places as well.
These additional ones aren't real bugs. They're not reachable on a well-behaved server and on a malicious/buggy server, the failure is benign / self-correcting.
Quoted 6 lines
I think we need some sort of way to help Sashiko understand so it doesn't keep flagging this on every future patch anyone submits. I think there's a few other places where some of Sashiko's assumptions/analysis are wrong (eg uring-cmd sqe stability semantics
[1] in the zero-copy series). I'll look into this unless anyone already knows how to do this.You may want to talk with your colleague Chris Mason about adding review prompts for FUSE, because he is also running AI analysis on existing subsystems regardless of mailing list patches.
I didn't try, but you can probably figure out how to add FUSE specific review prompts
to Sashiko yourself...
Quoted 2 lines
Thanks,
Amir.
The prompts Sashiko uses are in this subdirectory, which is open source and anyone can contribute:
https://github.com/sashiko-dev/sashiko/tree/main/third_party/prompts/kernel/subsystem
I added a minimal fuse prompt [1], I think we can continue improving on that as we go.
Thanks,
Joanne
[1] https://github.com/sashiko-dev/sashiko/blob/main/third_party/prompts/kernel/subsystem/fuse.md