fuse: Fix the return code of fuse_direct_IO() to deal with the error for aio
Subsystems (2)
PATCH 1/1 fuse: Fix the return code of fuse_direct_IO() to deal with the error for aio
From: Masayoshi Mizuma <[email protected]>
exit_aio() is sometimes stuck in wait_for_completion() after aio is issued with direct IO and the task receives a signal.
That is because kioctx in mm->ioctx_table is in use by aio_kiocb. aio_kiocb->ki_refcnt is 1 at that time. That means iocb_put() isn't called correctly.
fuse_get_req() returns as -EINTR when it's blocked and receives a signal. fuse_direct_IO() deals with the -EINTER as -EIOCBQUEUED and returns as -EIOCBQUEUED even though the aio isn't queued.
As the result, aio_rw_done() doesn't handle the error, so iocb_put() isn't called via aio_complete_rw(), which is the callback.
The flow is something like as:
io_submit
aio_get_req
refcount_set(&req->ki_refcnt, 2)
__io_submit_one
aio_read
...
fuse_direct_IO # return as -EIOCBQUEUED
__fuse_direct_read
...
fuse_get_req # return as -EINTR
aio_rw_done
# Nothing to do because ret is -EIOCBQUEUED...
iocb_put
refcount_dec_and_test(&iocb->ki_refcnt) # 2->1Return as the error code of fuse_direct_io() or __fuse_direct_read() in fuse_direct_IO() so that aio_rw_done() can handle the error and call iocb_put().
This issue is trucked as a virtio-fs issue:
https://gitlab.com/virtio-fs/qemu/issues/14
--- fs/fuse/file.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/fuse/file.c +6 -2
@@ -3115,8 +3115,12 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)fuse_aio_complete (io, ret <0 ? ret :0 ,-1 );/* we have a non-extending, async request, so return */ -if (!blocking) -return -EIOCBQUEUED ; +if (!blocking) { +if (ret >=0 ) +return -EIOCBQUEUED ; +else +return ret; + }wait_for_completion (&wait); ret =fuse_get_res_by_io (io);
Signature · 1 line
2.18.1
Quoted 32 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
exit_aio()is sometimes stuck inwait_for_completion()after aio is issued with direct IO and the task receives a signal.That is because kioctx in
mm->ioctx_tableis in use byaio_kiocb.aio_kiocb->ki_refcntis 1 at that time. That meansiocb_put()isn't called correctly.
fuse_get_req()returns as-EINTRwhen it's blocked and receives a signal.fuse_direct_IO()deals with the-EINTERas-EIOCBQUEUEDand returns as-EIOCBQUEUEDeven though the aio isn't queued.
As the result,aio_rw_done()doesn't handle the error, soiocb_put()isn't called viaaio_complete_rw(), which is the callback.The flow is something like as:
io_submitaio_get_req refcount_set(&req->ki_refcnt, 2) __io_submit_one aio_read ... fuse_direct_IO # return as -EIOCBQUEUED __fuse_direct_read ... fuse_get_req # return as -EINTR aio_rw_done # Nothing to do because ret is -EIOCBQUEUED... iocb_put refcount_dec_and_test(&iocb->ki_refcnt) # 2->1
Quoted 7 lines
Return as the error code of
fuse_direct_io()or__fuse_direct_read()infuse_direct_IO()so thataio_rw_done()can handle the error and calliocb_put().This issue is trucked as a virtio-fs issue:
https://gitlab.com/virtio-fs/qemu/issues/14
I didn't reproduce this issue on kernel v5.4-rc7, but did on 5.4-rc8. And verified this patch fixed the case in issue 14 on v5.4-rc8 and virtiofsd (virtio-fs-dev 5f068fa9).
Signature · 2 lines
Sincerely, Cao jin
Miklos Szeredi
maintainerQuoted 10 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
exit_aio()is sometimes stuck inwait_for_completion()after aio is issued with direct IO and the task receives a signal.That is because kioctx in
mm->ioctx_tableis in use byaio_kiocb.aio_kiocb->ki_refcntis 1 at that time. That meansiocb_put()isn't called correctly.
Quoted 5 lines
fuse_get_req()returns as-EINTRwhen it's blocked and receives a signal.fuse_direct_IO()deals with the-EINTERas-EIOCBQUEUEDand returns as-EIOCBQUEUEDeven though the aio isn't queued.
As the result,aio_rw_done()doesn't handle the error, soiocb_put()isn't called viaaio_complete_rw(), which is the callback.
Hi,
Thanks for the report.
Can you please test the attached patch (without your patch)?
Thanks,
Miklos
--- fs/fuse/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fuse/file.c +3 -1
@@ -713,8 +713,10 @@ static ssize_t fuse_async_req_send(struc ia->ap.args.end = fuse_aio_complete_req; err =fuse_simple_background (fc, &ia->ap.args,GFP_KERNEL ); +if (err) +fuse_aio_complete_req (fc, &ia->ap.args, err); -return err ?: num_bytes; +return num_bytes; } static ssize_t fuse_send_read(struct fuse_io_args *ia, loff_t pos, size_t count,
Quoted 17 lines · Miklos Szeredi
Quoted 10 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
exit_aio()is sometimes stuck inwait_for_completion()after aio is issued with direct IO and the task receives a signal.That is because kioctx in
mm->ioctx_tableis in use byaio_kiocb.aio_kiocb->ki_refcntis 1 at that time. That meansiocb_put()isn't called correctly.Quoted 5 lines
fuse_get_req()returns as-EINTRwhen it's blocked and receives a signal.fuse_direct_IO()deals with the-EINTERas-EIOCBQUEUEDand returns as-EIOCBQUEUEDeven though the aio isn't queued.
As the result,aio_rw_done()doesn't handle the error, soiocb_put()isn't called viaaio_complete_rw(), which is the callback.
Quoted 5 lines
Hi,
Thanks for the report.
Can you please test the attached patch (without your patch)?
The patch you attached works well, thanks! I tested it with virtiofs.
Should I post the patch? Or could you take care of it? Let me know.
Thanks!
Masa